Gui: [skip ci] fix crash on macOS in editor of vector list property

This commit is contained in:
wmayer
2021-02-18 21:43:53 +01:00
parent de7ae73915
commit 2aca60be85
2 changed files with 66 additions and 16 deletions

View File

@@ -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<QList<Base::Vector3d>>());
@@ -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<VectorListButton*>(editor);
VectorListWidget *pe = qobject_cast<VectorListWidget*>(editor);
pe->setValue(data);
}
QVariant PropertyVectorListItem::editorData(QWidget *editor) const
{
VectorListButton *pe = qobject_cast<VectorListButton*>(editor);
VectorListWidget *pe = qobject_cast<VectorListWidget*>(editor);
return pe->value();
}

View File

@@ -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;
};
/**