From cc00dc85d05a24c6e1695bfb644d9334f2ca2f7a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 28 Jan 2018 22:37:03 +0100 Subject: [PATCH] #3325: DlgPropertyLink as editor of Tip property --- src/App/DocumentObject.cpp | 36 +++++++++++++++++++++++++ src/App/DocumentObject.h | 4 ++- src/Gui/DlgPropertyLink.cpp | 9 ++++--- src/Gui/propertyeditor/PropertyItem.cpp | 10 +++++-- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 581d21d417..d07ad1bb9b 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -196,6 +196,42 @@ std::vector DocumentObject::getOutList(void) const return ret; } +std::vector DocumentObject::getOutListOfProperty(App::Property* prop) const +{ + std::vector ret; + if (!prop || prop->getContainer() != this) + return ret; + + if (prop->isDerivedFrom(PropertyLinkList::getClassTypeId())) { + const std::vector &OutList = static_cast(prop)->getValues(); + for (std::vector::const_iterator It2 = OutList.begin();It2 != OutList.end(); ++It2) { + if (*It2) + ret.push_back(*It2); + } + } + else if (prop->isDerivedFrom(PropertyLinkSubList::getClassTypeId())) { + const std::vector &OutList = static_cast(prop)->getValues(); + for (std::vector::const_iterator It2 = OutList.begin();It2 != OutList.end(); ++It2) { + if (*It2) + ret.push_back(*It2); + } + } + else if (prop->isDerivedFrom(PropertyLink::getClassTypeId())) { + if (static_cast(prop)->getValue()) + ret.push_back(static_cast(prop)->getValue()); + } + else if (prop->isDerivedFrom(PropertyLinkSub::getClassTypeId())) { + if (static_cast(prop)->getValue()) + ret.push_back(static_cast(prop)->getValue()); + } + else if (prop == &ExpressionEngine) { + // Get document objects that this document object relies on + ExpressionEngine.getDocumentObjectDeps(ret); + } + + return ret; +} + #ifdef USE_OLD_DAG std::vector DocumentObject::getInList(void) const { diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index 6b56a99951..9b72651312 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -138,7 +138,9 @@ public: //@{ /// returns a list of objects this object is pointing to by Links std::vector getOutList(void) const; - /// returns a list of objects this object is pointing to by Links and all further descended + /// returns a list of objects linked by the property + std::vector getOutListOfProperty(App::Property*) const; + /// returns a list of objects this object is pointing to by Links and all further descended std::vector getOutListRecursive(void) const; /// get all possible paths from this to another object following the OutList std::vector > getPathsByOutList(App::DocumentObject* to) const; diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index b4cef2c2bb..d54cc00d9a 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -48,7 +48,7 @@ DlgPropertyLink::DlgPropertyLink(const QStringList& list, QWidget* parent, Qt::W : QDialog(parent, fl), link(list), ui(new Ui_DlgPropertyLink) { #ifdef FC_DEBUG - assert(list.size() == 4); + assert(list.size() >= 5); #endif ui->setupUi(this); findObjects(ui->checkObjectType->isChecked(), QString()); @@ -125,6 +125,7 @@ void DlgPropertyLink::findObjects(bool on, const QString& searchText) QString docName = link[0]; // document name QString objName = link[1]; // internal object name QString parName = link[3]; // internal object name of the parent of the link property + QString proName = link[4]; // property name bool isSingleSelection = (ui->listWidget->selectionMode() == QAbstractItemView::SingleSelection); App::Document* doc = App::GetApplication().getDocument((const char*)docName.toLatin1()); @@ -155,8 +156,10 @@ void DlgPropertyLink::findObjects(bool on, const QString& searchText) App::DocumentObject* par = doc->getObject((const char*)parName.toLatin1()); if (par) { // for multi-selection we need all objects - if (isSingleSelection) - outList = par->getOutList(); + if (isSingleSelection) { + App::Property* prop = par->getPropertyByName((const char*)proName.toLatin1()); + outList = par->getOutListOfProperty(prop); + } outList.push_back(par); } diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 3676b2ced7..5f9ce4368b 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -3493,7 +3493,8 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const const App::PropertyLink* prop_link = static_cast(prop); App::PropertyContainer* c = prop_link->getContainer(); - // the list has four elements: [document name, internal name, label, internal name of container] + // the list has five elements: + // [document name, internal name, label, internal name of container, property name] App::DocumentObject* obj = prop_link->getValue(); QStringList list; if (obj) { @@ -3527,6 +3528,8 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const list << QString::fromLatin1("Null"); } + list << QString::fromLatin1(prop->getName()); + return QVariant(list); } @@ -3675,7 +3678,8 @@ QVariant PropertyLinkListItem::value(const App::Property* prop) const objName = QString::fromLatin1("Null"); } - // each item is a list of four elements: [document name, internal name, label, internal name of container] + // each item is a list of five elements: + //[document name, internal name, label, internal name of container, property name] // the variant list contains at least one item std::vector obj = prop_link->getValues(); QVariantList varList; @@ -3686,6 +3690,7 @@ QVariant PropertyLinkListItem::value(const App::Property* prop) const list << QString::fromLatin1((*it)->getNameInDocument()); list << QString::fromUtf8((*it)->Label.getValue()); list << objName; + list << QString::fromLatin1(prop->getName()); varList << list; } } @@ -3706,6 +3711,7 @@ QVariant PropertyLinkListItem::value(const App::Property* prop) const // the object label list << QString::fromLatin1(""); list << objName; + list << QString::fromLatin1(prop->getName()); varList << list; }