From 9a49453802568fbcce5c549685a73600ef489f3c Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 18 Feb 2021 21:43:53 +0100 Subject: [PATCH] Gui: [skip ci] fix crash on macOS in editor of vector list property --- src/Gui/propertyeditor/PropertyItem.cpp | 56 ++++++++++++++++++++----- src/Gui/propertyeditor/PropertyItem.h | 26 +++++++++--- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index f59c1ad04a..69aaa57ee8 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1434,17 +1434,39 @@ void PropertyVectorItem::propertyBound() // --------------------------------------------------------------- -VectorListButton::VectorListButton(int decimals, QWidget * parent) - : LabelButton(parent) - , decimals(decimals) +VectorListWidget::VectorListWidget (int decimals, QWidget * parent) + : QWidget(parent) + , decimals(decimals) +{ + QHBoxLayout *layout = new QHBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(2); + + lineEdit = new QLineEdit(this); + lineEdit->setReadOnly(true); + layout->addWidget(lineEdit); + + button = new QPushButton(QLatin1String("..."), this); +#if defined (Q_OS_MAC) + button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct +#endif + layout->addWidget(button); + + connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked())); + setFocusProxy(lineEdit); +} + +VectorListWidget::~VectorListWidget() { } -VectorListButton::~VectorListButton() +void VectorListWidget::resizeEvent(QResizeEvent* e) { + button->setFixedWidth(e->size().height()); + button->setFixedHeight(e->size().height()); } -void VectorListButton::browse() +void VectorListWidget::buttonClicked() { VectorListEditor dlg(decimals, Gui::getMainWindow()); dlg.setValues(value().value>()); @@ -1457,7 +1479,7 @@ void VectorListButton::browse() } } -void VectorListButton::showValue(const QVariant& d) +void VectorListWidget::showValue(const QVariant& d) { QLocale loc; QString data; @@ -1471,9 +1493,23 @@ void VectorListButton::showValue(const QVariant& d) loc.toString(value[0].y, 'f', 2), loc.toString(value[0].z, 'f', 2)); } - getLabel()->setText(data); + lineEdit->setText(data); } +QVariant VectorListWidget::value() const +{ + return variant; +} + +void VectorListWidget::setValue(const QVariant& val) +{ + variant = val; + showValue(variant); + valueChanged(variant); +} + +// --------------------------------------------------------------- + PROPERTYITEM_SOURCE(Gui::PropertyEditor::PropertyVectorListItem) PropertyVectorListItem::PropertyVectorListItem() @@ -1530,7 +1566,7 @@ void PropertyVectorListItem::setValue(const QVariant& value) QWidget* PropertyVectorListItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const { - VectorListButton *pe = new VectorListButton(decimals(), parent); + VectorListWidget *pe = new VectorListWidget(decimals(), parent); QObject::connect(pe, SIGNAL(valueChanged(const QVariant &)), receiver, method); pe->setDisabled(isReadOnly()); return pe; @@ -1538,13 +1574,13 @@ QWidget* PropertyVectorListItem::createEditor(QWidget* parent, const QObject* re void PropertyVectorListItem::setEditorData(QWidget *editor, const QVariant& data) const { - VectorListButton *pe = qobject_cast(editor); + VectorListWidget *pe = qobject_cast(editor); pe->setValue(data); } QVariant PropertyVectorListItem::editorData(QWidget *editor) const { - VectorListButton *pe = qobject_cast(editor); + VectorListWidget *pe = qobject_cast(editor); return pe->value(); } diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index a879bd3c6b..571d735109 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -466,20 +466,34 @@ private: PropertyFloatItem* m_z; }; -class VectorListButton : public Gui::LabelButton +class VectorListWidget : public QWidget { Q_OBJECT public: - VectorListButton(int decimals, QWidget * parent = 0); - ~VectorListButton(); + VectorListWidget (int decimals, QWidget * parent = nullptr); + virtual ~VectorListWidget(); -private: - void browse(); - void showValue(const QVariant& d); + QVariant value() const; + +public Q_SLOTS: + void setValue(const QVariant&); + +protected: + void showValue(const QVariant& data); + void resizeEvent(QResizeEvent*); + +private Q_SLOTS: + void buttonClicked(); + +Q_SIGNALS: + void valueChanged(const QVariant &); private: int decimals; + QVariant variant; + QLineEdit *lineEdit; + QPushButton *button; }; /**