Gui: add more options to DlgPropertyLink
Support user editable sub-element column. (Dis)allow sync sub-object 3D view selection.
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
# include <QPushButton>
|
||||
#endif
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include <Base/Tools.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
@@ -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<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;
|
||||
@@ -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();
|
||||
|
||||
@@ -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">
|
||||
@@ -32,6 +32,34 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QTreeWidget" name="typeTree">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="editTriggers">
|
||||
@@ -56,40 +84,26 @@
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QTreeWidget" name="typeTree">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</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>
|
||||
@@ -102,7 +116,6 @@
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>treeWidget</tabstop>
|
||||
<tabstop>checkObjectType</tabstop>
|
||||
<tabstop>typeTree</tabstop>
|
||||
<tabstop>searchBox</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
|
||||
Reference in New Issue
Block a user