Merge pull request #20570 from pieterhijma/varset-dialog-units
[Core] Show units in the VarSet add property dialog
This commit is contained in:
@@ -153,7 +153,7 @@ static void printFocusChain(QWidget *widget) {
|
||||
QWidget* start = widget;
|
||||
int i = 0;
|
||||
do {
|
||||
FC_ERR(" " << widget->objectName().toStdString();
|
||||
FC_ERR(" " << widget->objectName().toStdString());
|
||||
widget = widget->nextInFocusChain();
|
||||
i++;
|
||||
} while (widget != nullptr && i < 30 && start != widget);
|
||||
@@ -245,13 +245,27 @@ static PropertyEditor::PropertyItem *createPropertyItem(App::Property *prop)
|
||||
return item;
|
||||
}
|
||||
|
||||
void DlgAddPropertyVarSet::removeSelectionEditor()
|
||||
{
|
||||
// If the editor has a lineedit, then Qt selects the string inside it when
|
||||
// the editor is created. This interferes with the editor getting focus.
|
||||
// For example, units will then be selected as well, whereas this is not
|
||||
// the behavior we want. We therefore deselect the text in the lineedit.
|
||||
if (auto lineEdit = editor->findChild<QLineEdit*>()) {
|
||||
lineEdit->deselect();
|
||||
}
|
||||
}
|
||||
|
||||
void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem,
|
||||
[[maybe_unused]]std::string& type)
|
||||
{
|
||||
editor.reset(propertyItem->createEditor(this, [this]() {
|
||||
this->valueChanged();
|
||||
}));
|
||||
propertyItem->setEditorData(editor.get(), QVariant());
|
||||
editor->blockSignals(true);
|
||||
propertyItem->setEditorData(
|
||||
editor.get(),
|
||||
propertyItem->data(PropertyEditor::PropertyItem::ValueColumn, Qt::EditRole));
|
||||
editor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
editor->setObjectName(QStringLiteral("editor"));
|
||||
auto formLayout = qobject_cast<QFormLayout*>(layout());
|
||||
@@ -260,6 +274,9 @@ void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem,
|
||||
QWidget::setTabOrder(ui->comboBoxType, editor.get());
|
||||
QWidget::setTabOrder(editor.get(), ui->checkBoxAdd);
|
||||
|
||||
removeSelectionEditor();
|
||||
editor->blockSignals(false);
|
||||
|
||||
// FC_ERR("add editor");
|
||||
// printFocusChain(editor.get());
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ private:
|
||||
void clearCurrentProperty();
|
||||
|
||||
void removeEditor();
|
||||
void removeSelectionEditor();
|
||||
void addEditor(PropertyEditor::PropertyItem* propertyItem, std::string& type);
|
||||
|
||||
bool isTypeWithEditor(const std::string& type);
|
||||
|
||||
@@ -296,7 +296,7 @@ int PropertyItem::childCount() const
|
||||
|
||||
int PropertyItem::columnCount() const
|
||||
{
|
||||
return 2;
|
||||
return PropertyItem::ColumnCount;
|
||||
}
|
||||
|
||||
void PropertyItem::setReadOnly(bool ro)
|
||||
@@ -650,7 +650,7 @@ void PropertyItem::setPropertyValue(const QString& value)
|
||||
setPropertyValue(value.toStdString());
|
||||
}
|
||||
|
||||
QVariant PropertyItem::dataProperty(int role) const
|
||||
QVariant PropertyItem::dataPropertyName(int role) const
|
||||
{
|
||||
if (role == Qt::ForegroundRole && linked) {
|
||||
return QVariant::fromValue(QColor(0x20, 0xaa, 0x20)); // NOLINT
|
||||
@@ -743,9 +743,8 @@ QVariant PropertyItem::dataValue(int role) const
|
||||
|
||||
QVariant PropertyItem::data(int column, int role) const
|
||||
{
|
||||
// property name
|
||||
if (column == 0) {
|
||||
return dataProperty(role);
|
||||
if (column == PropertyItem::NameColumn) {
|
||||
return dataPropertyName(role);
|
||||
}
|
||||
|
||||
return dataValue(role);
|
||||
|
||||
@@ -130,6 +130,12 @@ class GuiExport PropertyItem: public QObject, public ExpressionBinding
|
||||
PROPERTYITEM_HEADER
|
||||
|
||||
public:
|
||||
enum Column {
|
||||
NameColumn = 0,
|
||||
ValueColumn = 1,
|
||||
ColumnCount
|
||||
};
|
||||
|
||||
~PropertyItem() override;
|
||||
|
||||
/** Sets the current property objects. */
|
||||
@@ -216,7 +222,7 @@ protected:
|
||||
void onChange() override;
|
||||
|
||||
private:
|
||||
QVariant dataProperty(int role) const;
|
||||
QVariant dataPropertyName(int role) const;
|
||||
QVariant dataValue(int role) const;
|
||||
QString toString(const Py::Object&) const;
|
||||
QString asNone(const Py::Object&) const;
|
||||
|
||||
Reference in New Issue
Block a user