]> git.saurik.com Git - wxWidgets.git/commitdiff
wxVariant list used to translate between list of property child values and composite...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 14 Sep 2008 13:14:32 +0000 (13:14 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 14 Sep 2008 13:14:32 +0000 (13:14 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/doxygen/overviews/propgrid.h
include/wx/propgrid/property.h
samples/propgrid/propgrid.cpp
src/propgrid/advprops.cpp
src/propgrid/property.cpp
src/propgrid/propgrid.cpp
src/propgrid/propgridpagestate.cpp
src/propgrid/props.cpp

index f78b7e818c96e3a72a8965b6198705b79ba65fb0..0686d5845b3e5a5df1d77f7dde4d90f514ec16c2 100644 (file)
@@ -88,10 +88,9 @@ other wxWidgets controls:
 Naturally, wxStringProperty is a property class. Only the first function argument (label)
 is mandatory. Second one, name, defaults to label and, third, the initial value, to
 default value. If constant wxPG_LABEL is used as the name argument, then the label is
-automatically used as a name as well (this is more efficient than manually
-defining both as the same). Empty name is also allowed, but in this case the
-property cannot be accessed by its name. Note that all property class constructors have
-quite similar constructor argument list.
+automatically used as a name as well (this is more efficient than manually defining both
+as the same). Use of empty name is discouraged and will sometimes result in run-time error.
+Note that all property class constructors have quite similar constructor argument list.
 
 To demonstrate other common property classes, here's another code snippet:
 
index 23584a9af613914c7b288916f426a2824eb96637..383ed10ec39bacea46d2e410b4ffdd566f1b8ac9 100644 (file)
@@ -1872,7 +1872,7 @@ protected:
     */
     wxString GetColumnText( unsigned int col ) const;
 
-    /** Returns (direct) child property with given label (or NULL if not found),
+    /** Returns (direct) child property with given name (or NULL if not found),
         with hint index.
 
         @param hintIndex
@@ -1881,8 +1881,8 @@ protected:
         @remarks
         Does not support scope (ie. Parent.Child notation).
     */
-    wxPGProperty* GetPropertyByLabelWH( const wxString& label,
-                                        unsigned int hintIndex ) const;
+    wxPGProperty* GetPropertyByNameWH( const wxString& name,
+                                       unsigned int hintIndex ) const;
 
     /** This is used by Insert etc. */
     void AddChild2( wxPGProperty* prop,
index 362fb864f6bda3cfeb6fed832f41a9dd18c64d28..fcabf03631c3c4bda687e16df5028078d8f65238 100644 (file)
@@ -1615,9 +1615,9 @@ void FormMain::PopulateWithExamples ()
     wxPGProperty* topId = pg->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL, wxT("<composed>")) );
 
     pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
-    pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxEmptyString ) );
-    pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxEmptyString ) );
-    pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxEmptyString ) );
+    pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) );
+    pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) );
+    pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) );
 
     pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
 
@@ -1626,9 +1626,9 @@ void FormMain::PopulateWithExamples ()
         wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
 
     pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
-    pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxEmptyString ) );
-    pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxEmptyString ) );
-    pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxEmptyString ) );
+    pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) );
+    pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) );
+    pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) );
 
     pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
 
index 7beb4a9fe0fa0ea5b348f3ae59119c9eb034eb03..82578fd24278bc6467d82aad001d013f115e2da9 100644 (file)
@@ -469,9 +469,9 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
 
     wxFont& font = wxFontFromVariant(m_value);
 
-    AddChild( new wxIntProperty( _("Point Size"),emptyString,(long)font.GetPointSize() ) );
+    AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font.GetPointSize() ) );
 
-    AddChild( new wxEnumProperty(_("Family"), emptyString,
+    AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
               gs_fp_es_family_labels,gs_fp_es_family_values,
               font.GetFamily()) );
 
@@ -481,20 +481,20 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
          wxPGGlobalVars->m_fontFamilyChoices->Index(faceName) == wxNOT_FOUND )
         wxPGGlobalVars->m_fontFamilyChoices->AddAsSorted(faceName);
 
-    wxPGProperty* p = new wxEnumProperty(_("Face Name"),emptyString,
+    wxPGProperty* p = new wxEnumProperty(_("Face Name"), wxS("Face Name"),
                                          *wxPGGlobalVars->m_fontFamilyChoices);
 
     p->SetValueFromString(faceName, wxPG_FULL_VALUE);
 
     AddChild( p );
 
-    AddChild( new wxEnumProperty(_("Style"),emptyString,
+    AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
               gs_fp_es_style_labels,gs_fp_es_style_values,font.GetStyle()) );
 
-    AddChild( new wxEnumProperty(_("Weight"),emptyString,
+    AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
               gs_fp_es_weight_labels,gs_fp_es_weight_values,font.GetWeight()) );
 
-    AddChild( new wxBoolProperty(_("Underlined"),emptyString,
+    AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
               font.GetUnderlined()) );
 }
 
index 32db12d24591df4a15f5b9587b08c682afc1606d..7137863f7b066c9e2f0275ba3f56834a53dbb27b 100644 (file)
@@ -705,9 +705,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                         wxVariant variant(child->GetValueRef());
                         if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) )
                         {
-                            // Use label instead of name, as name can be empty string, but
-                            // label in practice never is.
-                            variant.SetName(child->GetLabel());
+                            variant.SetName(child->GetBaseName());
 
                             // Clear unspecified flag only if OnSetValue() didn't
                             // affect it.
@@ -726,7 +724,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                     {
                         // Empty, becomes unspecified
                         wxVariant variant2;
-                        variant2.SetName(child->GetLabel());
+                        variant2.SetName(child->GetBaseName());
                         list.Append(variant2);
                         changed = true;
                     }
@@ -779,9 +777,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                     wxVariant variant(child->GetValueRef());
                     if ( child->StringToValue( variant, token, propagatedFlags ) )
                     {
-                        // Use label instead of name, as name can be empty string, but
-                        // label in practice never is.
-                        variant.SetName(child->GetLabel());
+                        variant.SetName(child->GetBaseName());
                         list.Append(variant);
                         changed = true;
                     }
@@ -789,7 +785,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                     {
                         // Failed, becomes unspecified
                         wxVariant variant2;
-                        variant2.SetName(child->GetLabel());
+                        variant2.SetName(child->GetBaseName());
                         list.Append(variant2);
                         changed = true;
                     }
@@ -924,14 +920,14 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
             //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
 
             // Children in list can be in any order, but we will give hint to
-            // GetPropertyByLabelWH(). This optimizes for full list parsing.
+            // GetPropertyByNameWH(). This optimizes for full list parsing.
             for ( node = list.begin(); node != list.end(); node++ )
             {
                 wxVariant& childValue = *((wxVariant*)*node);
-                wxPGProperty* child = GetPropertyByLabelWH(childValue.GetName(), i);
+                wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i);
                 if ( child )
                 {
-                    //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetLabel().c_str(),childValue.GetType().c_str());
+                    //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
                     if ( wxPGIsVariantType(childValue, list) )
                     {
                         if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
@@ -1639,6 +1635,9 @@ void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
 // This is used by properties that have fixed sub-properties
 void wxPGProperty::AddChild( wxPGProperty* prop )
 {
+    wxASSERT_MSG( prop->GetBaseName().length(),
+                  "Property's children must have unique, non-empty names within their scope" );
+
     prop->m_arrIndex = m_children.GetCount();
     m_children.Add( prop );
 
@@ -1675,13 +1674,13 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
     unsigned int i;
     unsigned int n = 0;
 
-    //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetLabel().c_str());
+    //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
 
     for ( i=0; i<GetChildCount(); i++ )
     {
         const wxPGProperty* child = Item(i);
 
-        if ( childValue.GetName() == child->GetLabel() )
+        if ( childValue.GetName() == child->GetBaseName() )
         {
             //wxLogDebug(wxT("  %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
 
@@ -1736,7 +1735,7 @@ wxPGProperty* wxPGProperty::GetPropertyByName( const wxString& name ) const
     return p->GetPropertyByName(name.substr(pos+1,name.length()-pos-1));
 }
 
-wxPGProperty* wxPGProperty::GetPropertyByLabelWH( const wxString& label, unsigned int hintIndex ) const
+wxPGProperty* wxPGProperty::GetPropertyByNameWH( const wxString& name, unsigned int hintIndex ) const
 {
     unsigned int i = hintIndex;
 
@@ -1751,7 +1750,7 @@ wxPGProperty* wxPGProperty::GetPropertyByLabelWH( const wxString& label, unsigne
     for (;;)
     {
         wxPGProperty* p = Item(i);
-        if ( p->m_label == label )
+        if ( p->m_name == name )
             return p;
 
         if ( i == lastIndex )
@@ -1896,8 +1895,6 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
         node = pList->begin();
     }
 
-    // Children in list can be in any order, but we will give hint to
-    // GetPropertyByLabelWH(). This optimizes for full list parsing.
     for ( i=0; i<GetChildCount(); i++ )
     {
         wxPGProperty* child = Item(i);
@@ -1906,12 +1903,12 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
 
         if ( pendingList )
         {
-            const wxString& childLabel = child->GetLabel();
+            const wxString& childName = child->GetBaseName();
 
             for ( ; node != pList->end(); node++ )
             {
                 const wxVariant& item = *((const wxVariant*)*node);
-                if ( item.GetName() == childLabel )
+                if ( item.GetName() == childName )
                 {
                     listValue = &item;
                     value = item;
index 46bb22f9ff9c123dfbe36ea14d52c21c2864d70e..4575d4e49fa1fcaee5737d8ec2cbd26d420d4162 100644 (file)
@@ -2849,13 +2849,13 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
     wxVariant bcpPendingList;
 
     listValue = pendingValue;
-    listValue.SetName(p->GetLabel());
+    listValue.SetName(p->GetBaseName());
 
     while ( pwc &&
             (pwc->HasFlag(wxPG_PROP_AGGREGATE) || pwc->HasFlag(wxPG_PROP_COMPOSED_VALUE)) )
     {
         wxVariantList tempList;
-        wxVariant lv(tempList, pwc->GetLabel());
+        wxVariant lv(tempList, pwc->GetBaseName());
         lv.Append(listValue);
         listValue = lv;
         pPendingValue = &listValue;
index ac1792083f1940336016cf88ce103e886f92a0bf..e7cb9539a28dc4a157e7efc9332d2f6683a8d5a1 100644 (file)
@@ -1503,6 +1503,12 @@ int wxPropertyGridPageState::PrepareToAddItem( wxPGProperty* property,
     if ( scheduledParent == m_properties )
         scheduledParent = (wxPGProperty*) NULL;
 
+    if ( scheduledParent && !scheduledParent->IsCategory() )
+    {
+        wxASSERT_MSG( property->GetBaseName().length(),
+                      "Property's children must have unique, non-empty names within their scope" );
+    }
+
     property->m_parentState = this;
 
     if ( property->IsCategory() )
index 20812ce956c5515782bef359fce718d59ff4ace9..8b1d54342c7588d16839dbd118451a70b9b07906 100644 (file)
@@ -1241,16 +1241,17 @@ void wxFlagsProperty::Init()
                 child_val = ( value & (1<<i) )?true:false;
 
             wxPGProperty* boolProp;
+            wxString label = GetLabel(i);
 
         #if wxUSE_INTL
             if ( wxPGGlobalVars->m_autoGetTranslation )
             {
-                boolProp = new wxBoolProperty( ::wxGetTranslation( GetLabel(i) ), wxEmptyString, child_val );
+                boolProp = new wxBoolProperty( ::wxGetTranslation(label), label, child_val );
             }
             else
         #endif
             {
-                boolProp = new wxBoolProperty( GetLabel(i), wxEmptyString, child_val );
+                boolProp = new wxBoolProperty( label, label, child_val );
             }
             AddChild(boolProp);
         }