Support inherited attributes in wxPropertyGrid XRC handler
Allow specifying recurse="1" to inherit the attribute, as this is much nicer than having to specify it for all the children. Also add support for this to wxPropertyGridPopulator, which is used by the XRC handler.
This commit is contained in:
parent
0ddbf965c9
commit
9550c37e29
5 changed files with 42 additions and 4 deletions
|
|
@ -1865,6 +1865,11 @@ to use it.
|
||||||
@row3col{choices, @ref overview_xrcformat_type_string,
|
@row3col{choices, @ref overview_xrcformat_type_string,
|
||||||
Space-separated string containing the possible choices for the properties
|
Space-separated string containing the possible choices for the properties
|
||||||
using them, e.g. wxFlagsProperty or wxEnumProperty.}
|
using them, e.g. wxFlagsProperty or wxEnumProperty.}
|
||||||
|
@row3col{attribute, @ref overview_xrcformat_type_string,
|
||||||
|
Value for the property attribute with the name specified by the `name`
|
||||||
|
attribute of this element. Additional `recurse` attribute is supported and,
|
||||||
|
if specified with the value of `1`, results in the attribute being set for
|
||||||
|
this property and all its children recursively.}
|
||||||
@endTable
|
@endTable
|
||||||
|
|
||||||
These elements define individual rows of @ref xrc_wxpropertygrid or @ref
|
These elements define individual rows of @ref xrc_wxpropertygrid or @ref
|
||||||
|
|
|
||||||
|
|
@ -2157,7 +2157,8 @@ public:
|
||||||
// Empty string mean autodetect.
|
// Empty string mean autodetect.
|
||||||
bool AddAttribute( const wxString& name,
|
bool AddAttribute( const wxString& name,
|
||||||
const wxString& type,
|
const wxString& type,
|
||||||
const wxString& value );
|
const wxString& value,
|
||||||
|
wxPGPropertyValuesFlags flags = wxPGPropertyValuesFlags::DontRecurse );
|
||||||
|
|
||||||
// Called once in AddChildren.
|
// Called once in AddChildren.
|
||||||
virtual void DoScanForChildren() = 0;
|
virtual void DoScanForChildren() = 0;
|
||||||
|
|
@ -2197,6 +2198,9 @@ protected:
|
||||||
// Tree-hierarchy of added properties (that can have children).
|
// Tree-hierarchy of added properties (that can have children).
|
||||||
std::vector<wxPGProperty*> m_propHierarchy;
|
std::vector<wxPGProperty*> m_propHierarchy;
|
||||||
|
|
||||||
|
// Recursively set attributes.
|
||||||
|
std::unordered_map<wxString, wxVariant> m_inheritedAttributes;
|
||||||
|
|
||||||
// Hashmap for string-id to wxPGChoicesData mapping.
|
// Hashmap for string-id to wxPGChoicesData mapping.
|
||||||
std::unordered_map<wxString, wxPGChoicesData*> m_dictIdChoices;
|
std::unordered_map<wxString, wxPGChoicesData*> m_dictIdChoices;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1534,10 +1534,16 @@ public:
|
||||||
|
|
||||||
@param value
|
@param value
|
||||||
Attribute value.
|
Attribute value.
|
||||||
|
|
||||||
|
@param flags
|
||||||
|
Flags used when setting the attribute. Currently only
|
||||||
|
wxPGPropertyValuesFlags::Recurse is used here. This parameter is
|
||||||
|
only available since wxWidgets 3.3.0.
|
||||||
*/
|
*/
|
||||||
bool AddAttribute( const wxString& name,
|
bool AddAttribute( const wxString& name,
|
||||||
const wxString& type,
|
const wxString& type,
|
||||||
const wxString& value );
|
const wxString& value,
|
||||||
|
wxPGPropertyValuesFlags flags = wxPGPropertyValuesFlags::DontRecurse );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Called once in AddChildren.
|
Called once in AddChildren.
|
||||||
|
|
|
||||||
|
|
@ -6416,9 +6416,22 @@ wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass,
|
||||||
|
|
||||||
void wxPropertyGridPopulator::AddChildren( wxPGProperty* property )
|
void wxPropertyGridPopulator::AddChildren( wxPGProperty* property )
|
||||||
{
|
{
|
||||||
|
// Preserve inherited attributes to be able to restore them later:
|
||||||
|
// attributes recursively set for the children of this property shouldn't
|
||||||
|
// be inherited by its siblings.
|
||||||
|
const auto inheritedAttributesOrig = m_inheritedAttributes;
|
||||||
|
|
||||||
|
// Apply inherited attributes to the property.
|
||||||
|
for ( const auto& it : m_inheritedAttributes )
|
||||||
|
{
|
||||||
|
property->SetAttribute(it.first, it.second);
|
||||||
|
}
|
||||||
|
|
||||||
m_propHierarchy.push_back(property);
|
m_propHierarchy.push_back(property);
|
||||||
DoScanForChildren();
|
DoScanForChildren();
|
||||||
m_propHierarchy.pop_back();
|
m_propHierarchy.pop_back();
|
||||||
|
|
||||||
|
m_inheritedAttributes = std::move(inheritedAttributesOrig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
@ -6540,7 +6553,8 @@ bool wxPropertyGridPopulator::ToLongPCT( const wxString& s, long* pval, long max
|
||||||
|
|
||||||
bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
|
bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
|
||||||
const wxString& type,
|
const wxString& type,
|
||||||
const wxString& value )
|
const wxString& value,
|
||||||
|
wxPGPropertyValuesFlags flags )
|
||||||
{
|
{
|
||||||
if ( m_propHierarchy.empty() )
|
if ( m_propHierarchy.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -6589,6 +6603,11 @@ bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !!(flags & wxPGPropertyValuesFlags::Recurse) )
|
||||||
|
{
|
||||||
|
m_inheritedAttributes[name] = variant;
|
||||||
|
}
|
||||||
|
|
||||||
p->SetAttribute( name, variant );
|
p->SetAttribute( name, variant );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -175,8 +175,12 @@ wxObject *wxPropertyGridXmlHandler::DoCreateResource()
|
||||||
wxString s1 = node->GetAttribute("name");
|
wxString s1 = node->GetAttribute("name");
|
||||||
if ( s1.length() )
|
if ( s1.length() )
|
||||||
{
|
{
|
||||||
|
wxPGPropertyValuesFlags flags = node->GetAttribute("recurse") == "1"
|
||||||
|
? wxPGPropertyValuesFlags::Recurse
|
||||||
|
: wxPGPropertyValuesFlags::DontRecurse;
|
||||||
|
|
||||||
m_populator->AddAttribute( s1, node->GetAttribute("type"),
|
m_populator->AddAttribute( s1, node->GetAttribute("type"),
|
||||||
node->GetNodeContent() );
|
node->GetNodeContent(), flags );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( m_class == wxT("wxPropertyGrid"))
|
else if( m_class == wxT("wxPropertyGrid"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue