From 7e487f0feec6b4810ef1ee2504f2e673f481c37a Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 17 Apr 2017 23:00:14 -0300 Subject: [PATCH] Small improvements to the PropertyLink editor * The "Edit" link is now a button, same as the Placement editor * Added a "None" entry on top of the Link dialog --- src/Gui/DlgPropertyLink.cpp | 8 +++ src/Gui/propertyeditor/PropertyItem.cpp | 66 +++++++++++++++++-------- src/Gui/propertyeditor/PropertyItem.h | 8 ++- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index a34e027ec6..6021595a39 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -84,6 +84,8 @@ QStringList DlgPropertyLink::propertyLink() const QStringList list = link; list[1] = items[0]->data(Qt::UserRole).toString(); list[2] = items[0]->text(); + if (list[1].isEmpty()) + list[2] = QString::fromUtf8(""); return list; } } @@ -126,6 +128,12 @@ void DlgPropertyLink::findObjects(bool on) outList.push_back(par); } + // Add a "None" entry on top + QListWidgetItem* item = new QListWidgetItem(ui->listWidget); + item->setText(tr("None (Remove link)")); + QByteArray ba(""); + item->setData(Qt::UserRole, ba); + std::vector obj = doc->getObjectsOfType(baseType); for (std::vector::iterator it = obj.begin(); it != obj.end(); ++it) { Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(*it); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 66a3a67cf8..4c895bbfb7 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -34,6 +34,7 @@ # include # include # include +# include #endif #include @@ -3366,11 +3367,27 @@ void LinkSelection::select() // --------------------------------------------------------------- -LinkLabel::LinkLabel (QWidget * parent) : QLabel(parent) -{ - setTextFormat(Qt::RichText); - connect(this, SIGNAL(linkActivated(const QString&)), +LinkLabel::LinkLabel (QWidget * parent) : QWidget(parent) +{ + QHBoxLayout *layout = new QHBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(1); + + label = new QLabel(this); + label->setAutoFillBackground(true); + label->setTextFormat(Qt::RichText); + layout->addWidget(label); + + editButton = new QPushButton(QLatin1String("..."), this); + editButton->setToolTip(tr("Change the linked object")); + layout->addWidget(editButton); + + // setLayout(layout); + + connect(label, SIGNAL(linkActivated(const QString&)), this, SLOT(onLinkActivated(const QString&))); + connect(editButton, SIGNAL(clicked()), + this, SLOT(onEditClicked())); } LinkLabel::~LinkLabel() @@ -3387,17 +3404,13 @@ void LinkLabel::setPropertyLink(const QStringList& o) "" "

" "%4" - " " - "%6" "

" ) .arg(link[0]) .arg(link[1]) .arg(linkcolor) - .arg(link[2]) - .arg(linkcolor) - .arg(tr("Edit...")); - setText(text); + .arg(link[2]); + label->setText(text); } QStringList LinkLabel::propertyLink() const @@ -3407,19 +3420,26 @@ QStringList LinkLabel::propertyLink() const void LinkLabel::onLinkActivated (const QString& s) { - if (s == QLatin1String("@__edit_link_prop__@")) { - Gui::Dialog::DlgPropertyLink dlg(link, this); - if (dlg.exec() == QDialog::Accepted) { - setPropertyLink(dlg.propertyLink()); - /*emit*/ linkChanged(link); - } - } - else { - LinkSelection* select = new LinkSelection(link); - QTimer::singleShot(50, select, SLOT(select())); + Q_UNUSED(s); + LinkSelection* select = new LinkSelection(link); + QTimer::singleShot(50, select, SLOT(select())); +} + +void LinkLabel::onEditClicked () +{ + Gui::Dialog::DlgPropertyLink dlg(link, this); + if (dlg.exec() == QDialog::Accepted) { + setPropertyLink(dlg.propertyLink()); + /*emit*/ linkChanged(link); } } +void LinkLabel::resizeEvent(QResizeEvent* e) +{ + editButton->setFixedWidth(e->size().height()); +} + + PROPERTYITEM_SOURCE(Gui::PropertyEditor::PropertyLinkItem) PropertyLinkItem::PropertyLinkItem() @@ -3483,7 +3503,11 @@ void PropertyLinkItem::setValue(const QVariant& value) if (items.size() > 1) { QString d = items[0]; QString o = items[1]; - QString data = QString::fromLatin1("App.getDocument('%1').getObject('%2')").arg(d).arg(o); + QString data; + if ( o.isEmpty() ) + data = QString::fromLatin1("None"); + else + data = QString::fromLatin1("App.getDocument('%1').getObject('%2')").arg(d).arg(o); setPropertyValue(data); } } diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index 93ef4424e2..dd76cf4e4f 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -908,7 +908,7 @@ private: QStringList link; }; -class LinkLabel : public QLabel +class LinkLabel : public QWidget { Q_OBJECT @@ -918,13 +918,19 @@ public: void setPropertyLink(const QStringList& o); QStringList propertyLink() const; +protected: + void resizeEvent(QResizeEvent*); + protected Q_SLOTS: void onLinkActivated(const QString&); + void onEditClicked(); Q_SIGNALS: void linkChanged(const QStringList&); private: + QLabel* label; + QPushButton* editButton; QStringList link; };