From cbaee7e4ecb3eaaa2dc40e0de070cb3cffcad9d8 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 5 Feb 2020 21:20:09 +0800 Subject: [PATCH] Gui: add more options to DlgPropertyLink Support user editable sub-element column. (Dis)allow sync sub-object 3D view selection. --- src/Gui/DlgPropertyLink.cpp | 45 +++++++++++++++++++- src/Gui/DlgPropertyLink.ui | 83 +++++++++++++++++++++---------------- 2 files changed, 91 insertions(+), 37 deletions(-) diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index a049f6e2da..630d74099c 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -30,6 +30,8 @@ # include #endif +#include + #include #include #include @@ -51,6 +53,19 @@ using namespace Gui::Dialog; +class ItemDelegate: public QStyledItemDelegate { +public: + ItemDelegate(QObject* parent=0): QStyledItemDelegate(parent) {} + + virtual QWidget* createEditor(QWidget *parent, + const QStyleOptionViewItem &option, const QModelIndex &index) const + { + if(index.column() != 1) + return nullptr; + return QStyledItemDelegate::createEditor(parent, option, index); + } +}; + /* TRANSLATOR Gui::Dialog::DlgPropertyLink */ DlgPropertyLink::DlgPropertyLink(QWidget* parent) @@ -66,6 +81,8 @@ DlgPropertyLink::DlgPropertyLink(QWidget* parent) timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(onTimer())); + ui->treeWidget->setEditTriggers(QAbstractItemView::DoubleClicked); + ui->treeWidget->setItemDelegate(new ItemDelegate(this)); ui->treeWidget->setMouseTracking(true); connect(ui->treeWidget, SIGNAL(itemEntered(QTreeWidgetItem*, int)), this, SLOT(onItemEntered(QTreeWidgetItem*))); @@ -79,7 +96,7 @@ DlgPropertyLink::DlgPropertyLink(QWidget* parent) connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onClicked(QAbstractButton*))); - refreshButton = ui->buttonBox->addButton(tr("Refresh"), QDialogButtonBox::ActionRole); + refreshButton = ui->buttonBox->addButton(tr("Reset"), QDialogButtonBox::ActionRole); resetButton = ui->buttonBox->addButton(tr("Clear"), QDialogButtonBox::ResetRole); } @@ -268,6 +285,8 @@ void DlgPropertyLink::init(const App::DocumentObjectT &prop, bool tryFilter) { ui->treeWidget->setSelectionMode(QAbstractItemView::MultiSelection); } + ui->checkSubObject->setVisible(allowSubObject); + if(!allowSubObject) { ui->treeWidget->setColumnCount(1); } else { @@ -310,6 +329,16 @@ void DlgPropertyLink::init(const App::DocumentObjectT &prop, bool tryFilter) { if(oldLinks.isEmpty()) return; + if(allowSubObject) { + for(auto &link : oldLinks) { + auto sobj = link.getSubObject(); + if(sobj && sobj!=link.getObject()) { + ui->checkSubObject->setChecked(true); + break; + } + } + } + // Try to select items corresponding to the current links inside the // property ui->treeWidget->blockSignals(true); @@ -532,8 +561,9 @@ QTreeWidgetItem *DlgPropertyLink::findItem( obj = obj->getSubObject(subname); if(!obj) return 0; - } else + } else { sobjs = obj->getSubObjectList(subname); + } } auto itDoc = docItems.find(obj->getDocument()); @@ -586,6 +616,16 @@ void DlgPropertyLink::onSelectionChanged(const SelectionChanges& msg) bool found = false; auto selObj = msg.Object.getObject(); + + std::pair elementName; + const char *subname = msg.pSubName; + if(!ui->checkSubObject->isChecked()) { + selObj = App::GeoFeature::resolveElement(selObj,subname,elementName); + if(!selObj) + return; + subname = elementName.second.c_str(); + } + auto item = findItem(selObj, msg.pSubName, &found); if(!item || !found) return; @@ -854,6 +894,7 @@ QTreeWidgetItem *DlgPropertyLink::createItem( if(allowSubObject) { item->setChildIndicatorPolicy(obj->getLinkedObject(true)->getOutList().size()? QTreeWidgetItem::ShowIndicator:QTreeWidgetItem::DontShowIndicator); + item->setFlags(item->flags() | Qt::ItemIsEditable); } const char *typeName = obj->getTypeId().getName(); diff --git a/src/Gui/DlgPropertyLink.ui b/src/Gui/DlgPropertyLink.ui index f4698d262b..6f96917497 100644 --- a/src/Gui/DlgPropertyLink.ui +++ b/src/Gui/DlgPropertyLink.ui @@ -14,7 +14,7 @@ Link - + @@ -32,6 +32,34 @@ + + + + QAbstractItemView::ExtendedSelection + + + false + + + true + + + false + + + + 1 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -56,40 +84,26 @@ - - - - QAbstractItemView::ExtendedSelection - - - false - - - true - - - false - - - - 1 - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - Filter by type - - + + + + + Filter by type + + + + + + + If enabled, then 3D view selection will be syncrhonize with full object hierarchy. + + + Sync sub-object selection + + + + @@ -102,7 +116,6 @@ treeWidget - checkObjectType typeTree searchBox buttonBox