+ fix inconsistencies in using DynamicProperty class

This commit is contained in:
wmayer
2015-11-17 12:22:07 +01:00
parent b7a80c910c
commit dec2a2f6cd
3 changed files with 66 additions and 73 deletions

View File

@@ -130,8 +130,14 @@ unsigned int DynamicProperty::getMemSize (void) const
short DynamicProperty::getPropertyType(const Property* prop) const
{
for (std::map<std::string,PropData>::const_iterator it = props.begin(); it != props.end(); ++it) {
if (it->second.property == prop)
return it->second.attr;
if (it->second.property == prop) {
short attr = it->second.attr;
if (it->second.hidden)
attr |= Prop_Hidden;
if (it->second.readonly)
attr |= Prop_ReadOnly;
return attr;
}
}
return this->pc->PropertyContainer::getPropertyType(prop);
}
@@ -139,8 +145,14 @@ short DynamicProperty::getPropertyType(const Property* prop) const
short DynamicProperty::getPropertyType(const char *name) const
{
std::map<std::string,PropData>::const_iterator it = props.find(name);
if (it != props.end())
return it->second.attr;
if (it != props.end()) {
short attr = it->second.attr;
if (it->second.hidden)
attr |= Prop_Hidden;
if (it->second.readonly)
attr |= Prop_ReadOnly;
return attr;
}
return this->pc->PropertyContainer::getPropertyType(name);
}
@@ -178,40 +190,6 @@ const char* DynamicProperty::getPropertyDocumentation(const char *name) const
return this->pc->PropertyContainer::getPropertyDocumentation(name);
}
bool DynamicProperty::isReadOnly(const Property* prop) const
{
for (std::map<std::string,PropData>::const_iterator it = props.begin(); it != props.end(); ++it) {
if (it->second.property == prop)
return it->second.readonly;
}
return this->pc->PropertyContainer::isReadOnly(prop);
}
bool DynamicProperty::isReadOnly(const char *name) const
{
std::map<std::string,PropData>::const_iterator it = props.find(name);
if (it != props.end())
return it->second.readonly;
return this->pc->PropertyContainer::isReadOnly(name);
}
bool DynamicProperty::isHidden(const Property* prop) const
{
for (std::map<std::string,PropData>::const_iterator it = props.begin(); it != props.end(); ++it) {
if (it->second.property == prop)
return it->second.hidden;
}
return this->pc->PropertyContainer::isHidden(prop);
}
bool DynamicProperty::isHidden(const char *name) const
{
std::map<std::string,PropData>::const_iterator it = props.find(name);
if (it != props.end())
return it->second.hidden;
return this->pc->PropertyContainer::isHidden(name);
}
Property* DynamicProperty::addDynamicProperty(const char* type, const char* name, const char* group,
const char* doc, short attr, bool ro, bool hidden)
{

View File

@@ -46,59 +46,68 @@ class PropertyContainer;
class AppExport DynamicProperty : public Base::Persistence
{
public:
struct PropData {
Property* property;
std::string group;
std::string doc;
short attr;
bool readonly;
bool hidden;
};
DynamicProperty(PropertyContainer* pc);
virtual ~DynamicProperty();
/** @name Access properties */
//@{
/// get all properties of the class (including parent)
/// Get all properties of the class (including parent)
void getPropertyList(std::vector<Property*> &List) const;
/// get all properties of the class (including parent)
/// Get all properties of the class (including parent)
void getPropertyMap(std::map<std::string,Property*> &Map) const;
/// find a property by its name
/// Find a property by its name
Property *getPropertyByName(const char* name) const;
/// find a property by its name
/// Find a dynamic property by its name
Property *getDynamicPropertyByName(const char* name) const;
/*!
Add a dynamic property of the type @a type and with the name @a name.
@a Group gives the grouping name which appears in the property editor and
@a doc shows the tooltip there.
With @a attr, @a ro and @a hidden the behaviour of the property can be controlled.
@a attr is an OR'ed value of Prop_ReadOnly, Prop_Transient, Prop_Hidden or Prop_Output.
If no special attribute should be set Prop_None can be set (or leave the default of 0).
For convenience the attributes for 'Read-Only' and 'Hidden' can also be controlled with
the values @a ro or @a hidden. This means,
@code
addDynamicProperty(..., ..., "Base","blah", Prop_ReadOnly | Prop_Hidden);
@endcode
is equivalent to
@code
addDynamicProperty(..., ..., "Base","blah", Prop_None, true, true);
@endcode
*/
Property* addDynamicProperty(const char* type, const char* name=0, const char* group=0,
const char* doc=0, short attr=0, bool ro=false, bool hidden=false);
/*!
Removes a dynamic property by name. Returns true if the property is part of the container, otherwise
false is returned.
*/
bool removeDynamicProperty(const char* name);
/// Get a list of all dynamic properties.
std::vector<std::string> getDynamicPropertyNames() const;
/*!
Get all dynamic properties of the given container and add these property types to this
instance of DynamicProperty.
*/
void addDynamicProperties(const PropertyContainer*);
/// get the name of a property
/// Get the name of a property
const char* getPropertyName(const Property* prop) const;
//@}
/** @name Property attributes */
//@{
/// get the Type of a Property
/// Get the attributes of a property
short getPropertyType(const Property* prop) const;
/// get the Type of a named Property
/// Get the attributes of a named property
short getPropertyType(const char *name) const;
/// get the Group of a Property
/// Get the group name of a property
const char* getPropertyGroup(const Property* prop) const;
/// get the Group of a named Property
/// Get the group name of a named property
const char* getPropertyGroup(const char *name) const;
/// get the Group of a Property
/// Get the documentation of a property
const char* getPropertyDocumentation(const Property* prop) const;
/// get the Group of a named Property
/// Get the documentation of a named property
const char* getPropertyDocumentation(const char *name) const;
/// check if the property is read-only
bool isReadOnly(const Property* prop) const;
/// check if the named property is read-only
bool isReadOnly(const char *name) const;
/// check if the property is hidden
bool isHidden(const Property* prop) const;
/// check if the named property is hidden
bool isHidden(const char *name) const;
//@}
/** @name Property serialization */
@@ -114,6 +123,15 @@ private:
std::string getUniquePropertyName(const char *Name) const;
private:
struct PropData {
Property* property;
std::string group;
std::string doc;
short attr;
bool readonly;
bool hidden;
};
PropertyContainer* pc;
std::map<std::string,PropData> props;
};