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
This commit is contained in:
Jaakko Salli
2008-09-25 16:13:32 +00:00
parent 81d73efcc3
commit 1802a91dec
4 changed files with 33 additions and 1 deletions

View File

@@ -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 );

View File

@@ -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 )
{

View File

@@ -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;

View File

@@ -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