diff --git a/src/App/DynamicProperty.cpp b/src/App/DynamicProperty.cpp index af5be4b89..7acf2c496 100644 --- a/src/App/DynamicProperty.cpp +++ b/src/App/DynamicProperty.cpp @@ -130,8 +130,14 @@ unsigned int DynamicProperty::getMemSize (void) const short DynamicProperty::getPropertyType(const Property* prop) const { for (std::map::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::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::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::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::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::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) { diff --git a/src/App/DynamicProperty.h b/src/App/DynamicProperty.h index 8423e1b2c..52ec7013c 100644 --- a/src/App/DynamicProperty.h +++ b/src/App/DynamicProperty.h @@ -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 &List) const; - /// get all properties of the class (including parent) + /// Get all properties of the class (including parent) void getPropertyMap(std::map &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 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 props; }; diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index 0dcd7f408..50d079857 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -509,8 +509,7 @@ Property * Sheet::setFloatProperty(CellAddress key, double value) props.removeDynamicProperty(key.toString().c_str()); propAddress.erase(prop); } - floatProp = freecad_dynamic_cast(props.addDynamicProperty("App::PropertyFloat", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient, true, true)); - floatProp->StatusBits.set(3); + floatProp = freecad_dynamic_cast(props.addDynamicProperty("App::PropertyFloat", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient)); } else floatProp = static_cast(prop); @@ -541,9 +540,8 @@ Property * Sheet::setQuantityProperty(CellAddress key, double value, const Base: props.removeDynamicProperty(key.toString().c_str()); propAddress.erase(prop); } - Property * p = props.addDynamicProperty("Spreadsheet::PropertySpreadsheetQuantity", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient, true, true); + Property * p = props.addDynamicProperty("Spreadsheet::PropertySpreadsheetQuantity", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient); quantityProp = freecad_dynamic_cast(p); - quantityProp->StatusBits.set(3); } else quantityProp = static_cast(prop); @@ -576,8 +574,7 @@ Property * Sheet::setStringProperty(CellAddress key, const std::string & value) props.removeDynamicProperty(key.toString().c_str()); propAddress.erase(prop); } - stringProp = freecad_dynamic_cast(props.addDynamicProperty("App::PropertyString", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient, true, true)); - stringProp->StatusBits.set(3); + stringProp = freecad_dynamic_cast(props.addDynamicProperty("App::PropertyString", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient)); } propAddress[stringProp] = key; @@ -614,7 +611,7 @@ void Sheet::updateAlias(CellAddress key) } if (!aliasProp) - aliasProp = props.addDynamicProperty(prop->getTypeId().getName(), alias.c_str(), 0, 0, Prop_ReadOnly | Prop_Transient, true, true); + aliasProp = props.addDynamicProperty(prop->getTypeId().getName(), alias.c_str(), 0, 0, Prop_ReadOnly | Prop_Transient); aliasProp->Paste(*prop); }