Allow to remove user-defined properties

This commit is contained in:
wmayer 2012-11-04 13:24:22 +01:00
parent 482a73b302
commit 77144681ef
9 changed files with 57 additions and 0 deletions

View File

@ -245,6 +245,18 @@ Property* DynamicProperty::addDynamicProperty(const char* type, const char* name
return pcProperty;
}
bool DynamicProperty::removeDynamicProperty(const char* name)
{
std::map<std::string,PropData>::iterator it = props.find(name);
if (it != props.end()) {
delete it->second.property;
props.erase(it);
return true;
}
return false;
}
std::string DynamicProperty::getUniquePropertyName(const char *Name) const
{
std::string CleanName = Base::Tools::getIdentifier(Name);

View File

@ -70,6 +70,7 @@ public:
Property *getDynamicPropertyByName(const char* name) const;
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);
bool removeDynamicProperty(const char* name);
std::vector<std::string> getDynamicPropertyNames() const;
void addDynamicProperties(const PropertyContainer*);
/// get the name of a property

View File

@ -100,6 +100,9 @@ public:
short attr=0, bool ro=false, bool hidden=false) {
return props->addDynamicProperty(type, name, group, doc, attr, ro, hidden);
}
virtual bool removeDynamicProperty(const char* name) {
return props->removeDynamicProperty(name);
}
std::vector<std::string> getDynamicPropertyNames() const {
return props->getDynamicPropertyNames();
}

View File

@ -20,6 +20,13 @@ The first argument specifies the type, the second the
name of the property.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeProperty">
<Documentation>
<UserDocu>removeProperty(string) -- Remove a generic property.
Note, you can only remove user-defined properties but not built-in ones.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="supportedProperties">
<Documentation>

View File

@ -62,6 +62,16 @@ PyObject* FeaturePythonPy::addProperty(PyObject *args)
return Py::new_reference_to(this);
}
PyObject* FeaturePythonPy::removeProperty(PyObject *args)
{
char *sName;
if (!PyArg_ParseTuple(args, "s", &sName))
return NULL;
bool ok = getFeaturePythonPtr()->removeDynamicProperty(sName);
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}
PyObject* FeaturePythonPy::supportedProperties(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C

View File

@ -138,6 +138,9 @@ public:
short attr=0, bool ro=false, bool hidden=false){
return 0;
}
virtual bool removeDynamicProperty(const char* name) {
return false;
}
virtual std::vector<std::string> getDynamicPropertyNames() const {
return std::vector<std::string>();
}

View File

@ -188,6 +188,9 @@ public:
short attr=0, bool ro=false, bool hidden=false) {
return props->addDynamicProperty(type, name, group, doc, attr, ro, hidden);
}
virtual bool removeDynamicProperty(const char* name) {
return props->removeDynamicProperty(name);
}
std::vector<std::string> getDynamicPropertyNames() const {
return props->getDynamicPropertyNames();
}

View File

@ -27,6 +27,14 @@
</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeProperty">
<Documentation>
<UserDocu>
removeProperty(string) -- Remove a generic property.
Note, you can only remove user-defined properties but not built-in ones.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="supportedProperties">
<Documentation>
<UserDocu>A list of supported property types</UserDocu>

View File

@ -84,6 +84,16 @@ PyObject* ViewProviderPythonFeaturePy::addProperty(PyObject *args)
return Py::new_reference_to(this);
}
PyObject* ViewProviderPythonFeaturePy::removeProperty(PyObject *args)
{
char *sName;
if (!PyArg_ParseTuple(args, "s", &sName))
return NULL;
bool ok = getViewProviderPythonFeaturePtr()->removeDynamicProperty(sName);
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}
PyObject* ViewProviderPythonFeaturePy::supportedProperties(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C