+ fix inconsistencies in using DynamicProperty class
This commit is contained in:
parent
78e9319587
commit
c159a8ddc2
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -509,8 +509,7 @@ Property * Sheet::setFloatProperty(CellAddress key, double value)
|
|||
props.removeDynamicProperty(key.toString().c_str());
|
||||
propAddress.erase(prop);
|
||||
}
|
||||
floatProp = freecad_dynamic_cast<PropertyFloat>(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<PropertyFloat>(props.addDynamicProperty("App::PropertyFloat", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Hidden | Prop_Transient));
|
||||
}
|
||||
else
|
||||
floatProp = static_cast<PropertyFloat*>(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<PropertySpreadsheetQuantity>(p);
|
||||
quantityProp->StatusBits.set(3);
|
||||
}
|
||||
else
|
||||
quantityProp = static_cast<PropertySpreadsheetQuantity*>(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<PropertyString>(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<PropertyString>(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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user