Skip to content

Commit

Permalink
Gui: add more options to DlgPropertyLink
Browse files Browse the repository at this point in the history
Support user editable sub-element column.
(Dis)allow sync sub-object 3D view selection.
  • Loading branch information
realthunder authored and WandererFan committed Feb 11, 2020
1 parent c4be6c8 commit cbaee7e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 31 deletions.
45 changes: 43 additions & 2 deletions src/Gui/DlgPropertyLink.cpp
Expand Up @@ -30,6 +30,8 @@
# include <QPushButton>
#endif

#include <QStyledItemDelegate>

#include <Base/Tools.h>
#include <App/Application.h>
#include <App/Document.h>
Expand All @@ -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)
Expand All @@ -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*)));
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -586,6 +616,16 @@ void DlgPropertyLink::onSelectionChanged(const SelectionChanges& msg)

bool found = false;
auto selObj = msg.Object.getObject();

std::pair<std::string,std::string> 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;
Expand Down Expand Up @@ -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();
Expand Down
71 changes: 42 additions & 29 deletions src/Gui/DlgPropertyLink.ui
Expand Up @@ -14,7 +14,7 @@
<string>Link</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<item row="6" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
Expand All @@ -32,20 +32,17 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<item row="5" column="0">
<widget class="QTreeWidget" name="typeTree">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="showDropIndicator" stdset="0">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="headerHidden">
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
Expand All @@ -56,17 +53,27 @@
</column>
</widget>
</item>
<item row="2" column="0">
<widget class="QTreeWidget" name="typeTree">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
<item row="10" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="rootIsDecorated">
</widget>
</item>
<item row="0" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<property name="headerHidden">
<bool>true</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
Expand All @@ -77,19 +84,26 @@
</column>
</widget>
</item>
<item row="7" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkObjectType">
<property name="text">
<string>Filter by type</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkObjectType">
<property name="text">
<string>Filter by type</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkSubObject">
<property name="toolTip">
<string>If enabled, then 3D view selection will be syncrhonize with full object hierarchy.</string>
</property>
<property name="text">
<string>Sync sub-object selection</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand All @@ -102,7 +116,6 @@
</customwidgets>
<tabstops>
<tabstop>treeWidget</tabstop>
<tabstop>checkObjectType</tabstop>
<tabstop>typeTree</tabstop>
<tabstop>searchBox</tabstop>
<tabstop>buttonBox</tabstop>
Expand Down

0 comments on commit cbaee7e

Please sign in to comment.