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:
*/
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
@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,
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") ) );
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") ) );
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()) );
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()) );
}
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.
{
// Empty, becomes unspecified
wxVariant variant2;
- variant2.SetName(child->GetLabel());
+ variant2.SetName(child->GetBaseName());
list.Append(variant2);
changed = true;
}
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;
}
{
// Failed, becomes unspecified
wxVariant variant2;
- variant2.SetName(child->GetLabel());
+ variant2.SetName(child->GetBaseName());
list.Append(variant2);
changed = true;
}
//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) )
// 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 );
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());
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;
for (;;)
{
wxPGProperty* p = Item(i);
- if ( p->m_label == label )
+ if ( p->m_name == name )
return p;
if ( i == lastIndex )
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);
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;
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;
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() )
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);
}