From: Jaakko Salli Date: Thu, 25 Sep 2008 16:13:32 +0000 (+0000) Subject: Fixed bug: Settings property attribute to wxNullVariant would cause GetAttribute... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1802a91dec8bf45fbcfc89332c97dd63461aa4c6?ds=inline Fixed bug: Settings property attribute to wxNullVariant would cause GetAttribute() to fail (wxPG SourceForge bug #2128485) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index 8394762127..cd267eb3fd 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -1144,6 +1144,9 @@ public: @param value Value of attribute. + + @remarks Setting attribute's value to Null variant will simply remove it + from property's set of attributes. */ void SetAttribute( const wxString& name, wxVariant value ); diff --git a/interface/wx/propgrid/propgridiface.h b/interface/wx/propgrid/propgridiface.h index 950c16c8d8..32932af310 100644 --- a/interface/wx/propgrid/propgridiface.h +++ b/interface/wx/propgrid/propgridiface.h @@ -659,6 +659,9 @@ public: Value of attribute. @param argFlags Optional. Use wxPG_RECURSE to set the attribute to child properties recursively. + + @remarks Setting attribute's value to Null variant will simply remove it + from property's set of attributes. */ void SetPropertyAttribute( wxPGPropArg id, const wxString& attrName, wxVariant value, long argFlags = 0 ) { diff --git a/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index 7685b2978d..fcbb3e6a04 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -946,6 +946,21 @@ bool FormMain::RunTests( bool fullTest, bool interactive ) #endif } + { + RT_START_TEST(Attributes) + + wxPGProperty* prop = pgman->GetProperty(wxT("StringProperty")); + prop->SetAttribute(wxT("Dummy Attribute"), (long)15); + + if ( prop->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 ) + RT_FAILURE(); + + prop->SetAttribute(wxT("Dummy Attribute"), wxVariant()); + + if ( !prop->GetAttribute(wxT("Dummy Attribute")).IsNull() ) + RT_FAILURE(); + } + { wxPropertyGridPage* page1; wxPropertyGridPage* page2; diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index c083039124..980f915cb1 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2093,12 +2093,23 @@ void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value ) // Free old, if any wxPGHashMapS2P::iterator it = m_map.find(name); if ( it != m_map.end() ) + { ((wxVariantData*)it->second)->DecRef(); + if ( !data ) + { + // If Null variant, just remove from set + m_map.erase(it); + return; + } + } + if ( data ) + { data->IncRef(); - m_map[name] = data; + m_map[name] = data; + } } #endif // wxUSE_PROPGRID