Python feature/observer related changes

* Add new API and signal handler in document observer

* Pre initialize python handler function to improve performance. In
  case Python code use dynamic patching, i.e. add class method at
  runtime (which is rare and should be discouraged), the python feature
  can be re-initialized by simply assign proeprty Proxy again.

* Add property tracking in DocumentObjectT

* WidgetFactory adds support for accepting python QIcon, which is used
  by ViewProviderPythonFeature
This commit is contained in:
Zheng, Lei
2019-07-11 13:57:53 +08:00
committed by wmayer
parent f7edaabe43
commit ad57821cf9
12 changed files with 1875 additions and 950 deletions

View File

@@ -103,13 +103,18 @@ DocumentObjectT::DocumentObjectT()
{
}
DocumentObjectT::DocumentObjectT(DocumentObject* obj)
DocumentObjectT::DocumentObjectT(const DocumentObject* obj)
{
object = obj->getNameInDocument();
label = obj->Label.getValue();
document = obj->getDocument()->getName();
}
DocumentObjectT::DocumentObjectT(const Property* prop)
{
*this = prop;
}
DocumentObjectT::~DocumentObjectT()
{
}
@@ -121,6 +126,7 @@ void DocumentObjectT::operator=(const DocumentObjectT& obj)
object = obj.object;
label = obj.label;
document = obj.document;
property = obj.property;
}
void DocumentObjectT::operator=(const DocumentObject* obj)
@@ -128,6 +134,16 @@ void DocumentObjectT::operator=(const DocumentObject* obj)
object = obj->getNameInDocument();
label = obj->Label.getValue();
document = obj->getDocument()->getName();
property.clear();
}
void DocumentObjectT::operator=(const Property *prop) {
auto obj = dynamic_cast<const DocumentObject*>(prop->getContainer());
assert(obj);
object = obj->getNameInDocument();
label = obj->Label.getValue();
document = obj->getDocument()->getName();
property = prop->getName();
}
Document* DocumentObjectT::getDocument() const
@@ -192,6 +208,27 @@ std::string DocumentObjectT::getObjectPython() const
return str.str();
}
std::string DocumentObjectT::getPropertyName() const {
return property;
}
std::string DocumentObjectT::getPropertyPython() const
{
std::stringstream str;
str << "FreeCAD.getDocument('" << document
<< "').getObject('" << object
<< "')";
if(property.size())
str << '.' << property;
return str.str();
}
Property *DocumentObjectT::getProperty() const {
auto obj = getObject();
if(obj)
return obj->getPropertyByName(property.c_str());
return 0;
}
// -----------------------------------------------------------------------------
DocumentObserver::DocumentObserver() : _document(0)