From: Jaakko Salli Date: Sun, 14 Sep 2008 16:20:48 +0000 (+0000) Subject: Fixed bug: Setting property value string did not update children of composed parent... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/8f18b25245b3a5d09ac7caa7c378408edfdd88eb Fixed bug: Setting property value string did not update children of composed parent (ported from wxPG SVN trunk) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55606 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index 1d3d12e68c..44fb26e764 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -399,7 +399,8 @@ enum wxPG_SETVALUE_FLAGS { wxPG_SETVAL_REFRESH_EDITOR = 0x0001, wxPG_SETVAL_AGGREGATED = 0x0002, - wxPG_SETVAL_FROM_PARENT = 0x0004 + wxPG_SETVAL_FROM_PARENT = 0x0004, + wxPG_SETVAL_BY_USER = 0x0008 // Set if value changed by user }; // ----------------------------------------------------------------------- diff --git a/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index c5db4a6739..8e32907ee4 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -875,6 +875,31 @@ bool FormMain::RunTests( bool fullTest, bool interactive ) pgman->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000)); if ( pgman->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) ) RT_FAILURE(); + + // Make sure children of composite parent get updated as well + // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000" + + // This updates children as well + wxString nvs = "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002"; + pgman->SetPropertyValue(wxT("Car"), nvs); + + if ( pgman->GetPropertyValueAsString(wxT("Car.Model")) != "Lamborghini Diablo XYZ" ) + { + wxLogDebug("Did not match: Car.Model=%s", pgman->GetPropertyValueAsString(wxT("Car.Model")).c_str()); + RT_FAILURE(); + } + + if ( pgman->GetPropertyValueAsInt(wxT("Car.Speeds.Max. Speed (mph)")) != 100 ) + { + wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman->GetPropertyValueAsString(wxT("Car.Speeds.Max. Speed (mph)")).c_str()); + RT_FAILURE(); + } + + if ( pgman->GetPropertyValueAsInt(wxT("Car.Price ($)")) != 3000002 ) + { + wxLogDebug("Did not match: Car.Price ($)=%s", pgman->GetPropertyValueAsString(wxT("Car.Price ($)")).c_str()); + RT_FAILURE(); + } } { diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 7137863f7b..b8a691dbde 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -892,12 +892,22 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags ) { if ( !value.IsNull() ) { + wxVariant tempListVariant; + SetCommonValue(-1); // List variants are reserved a special purpose // as intermediate containers for child values // of properties with children. if ( wxPGIsVariantType(value, list) ) { + // + // However, situation is different for composed string properties + if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) ) + { + tempListVariant = value; + pList = &tempListVariant; + } + wxVariant newValue; AdaptListToValue(value, &newValue); value = newValue; @@ -942,15 +952,13 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags ) } } else if ( !wxPG_VARIANT_EQ(child->GetValue(), childValue) ) - // This flag is not normally set when setting value programmatically. - // However, this loop is usually only executed when called from - // DoPropertyChanged, which should set this flag. { // For aggregate properties, we will trust RefreshChildren() // to update child values. if ( !HasFlag(wxPG_PROP_AGGREGATE) ) child->SetValue(childValue, NULL, flags|wxPG_SETVAL_FROM_PARENT); - child->SetFlag(wxPG_PROP_MODIFIED); + if ( flags & wxPG_SETVAL_BY_USER ) + child->SetFlag(wxPG_PROP_MODIFIED); } } i++; @@ -966,7 +974,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags ) UpdateParentValues(); } - if ( pList ) + if ( flags & wxPG_SETVAL_BY_USER ) SetFlag(wxPG_PROP_MODIFIED); if ( HasFlag(wxPG_PROP_AGGREGATE) ) diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 4575d4e49f..892e2e5d0f 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -3076,7 +3076,7 @@ bool wxPropertyGrid::DoPropertyChanged( wxPGProperty* p, unsigned int selFlags ) topPaintedProperty = topPaintedProperty->GetParent(); } - changedProperty->SetValue(value, &m_chgInfo_valueList); + changedProperty->SetValue(value, &m_chgInfo_valueList, wxPG_SETVAL_BY_USER); // Set as Modified (not if dragging just began) if ( !(p->m_flags & wxPG_PROP_MODIFIED) )