From 4bbc59d3094a109b7fa8945375f98725675e841f Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Tue, 1 Apr 2025 10:32:18 +0200 Subject: [PATCH] [Core] Make PropertyItem column usage more clear - Renamed dataProperty -> dataPropertyName because the function returns variants for the property name. - Add an enum for the column to remove magic numbers --- src/Gui/propertyeditor/PropertyItem.cpp | 9 ++++----- src/Gui/propertyeditor/PropertyItem.h | 8 +++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 94bbd659f7..e7852c02a2 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -295,7 +295,7 @@ int PropertyItem::childCount() const int PropertyItem::columnCount() const { - return 2; + return PropertyItem::ColumnCount; } void PropertyItem::setReadOnly(bool ro) @@ -649,7 +649,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 @@ -742,9 +742,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); diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index b8182c4fd8..cfdcc21a1b 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -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;