Skip to content

Commit

Permalink
fix: add stdset="0" we don't want to generate property
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Jul 9, 2024
1 parent f8c61a1 commit 4ff2b07
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 221 deletions.
12 changes: 7 additions & 5 deletions src/core/qtuidocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,24 @@ QVariant QtUiWidget::getProperty(const QString &name) const
}

/*!
* \qmlmethod QtUiWidget::addProperty(string name, var value, object attributes = {})
* Adds a new property with the given `name`, `value` and `attributes`.
* \qmlmethod QtUiWidget::addProperty(string name, var value, object attributes = {}, bool userProperty = false)
* Adds a new property with the given `name`, `value`, `attributes` and `userProperty`.
*
* Attributes is a has<string, string> object, where the key is the attribute name and the value is the attribute value.
* For example:
*
* ```
* widget.setProperty("text", "My text", { "comment": "some comment for translation" });
* ```
* Set userProperty to true if you doesn't want to generate property.
*/
void QtUiWidget::addProperty(const QString &name, const QVariant &value, const QHash<QString, QString> &attributes)
void QtUiWidget::addProperty(const QString &name, const QVariant &value, const QHash<QString, QString> &attributes,
bool userProperty)
{
LOG("QtUiWidget::addProperty", name, value);

const auto result =
qobject_cast<QtUiDocument *>(parent())->uiWriter()->addWidgetProperty(m_widget, name, value, attributes);
const auto result = qobject_cast<QtUiDocument *>(parent())->uiWriter()->addWidgetProperty(m_widget, name, value,
attributes, userProperty);

switch (result) {
case Utils::QtUiWriter::Success:
Expand Down
2 changes: 1 addition & 1 deletion src/core/qtuidocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class QtUiWidget : public QObject

Q_INVOKABLE QVariant getProperty(const QString &name) const;
Q_INVOKABLE void addProperty(const QString &name, const QVariant &value,
const QHash<QString, QString> &attributes = {});
const QHash<QString, QString> &attributes = {}, bool userProperty = false);

public slots:
void setName(const QString &newName);
Expand Down
2 changes: 1 addition & 1 deletion src/rccore/rc_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void writeWidget(Utils::QtUiWriter &writer, const Widget &widget, pugi::x
{
auto widgetNode = writer.addWidget(widget.className, widget.id, parent);

writer.addWidgetProperty(widgetNode, "mfc_id", widget.id, {{"notr", "true"}});
writer.addWidgetProperty(widgetNode, "mfc_id", widget.id, {{"notr", "true"}}, true);
writer.addWidgetProperty(widgetNode, "geometry", widget.geometry);

for (const auto &property : widget.properties.asKeyValueRange()) {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/qtuiwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ QtUiWriter::Status QtUiWriter::addCustomWidget(const QString &className, const Q
}

QtUiWriter::Status QtUiWriter::addWidgetProperty(pugi::xml_node widget, const QString &name, const QVariant &value,
const QHash<QString, QString> &attributes)
const QHash<QString, QString> &attributes, bool userProperty)
{
// Special case for stringlist
if (static_cast<QMetaType::Type>(value.typeId()) == QMetaType::QStringList) {
Expand All @@ -98,9 +98,12 @@ QtUiWriter::Status QtUiWriter::addWidgetProperty(pugi::xml_node widget, const QS
return Success;
}

auto createPropertyNode = [&widget, name]() {
auto createPropertyNode = [&widget, name, userProperty]() {
auto propertyNode = widget.append_child("property");
propertyNode.append_attribute("name").set_value(name.toLatin1().constData());
if (userProperty) {
propertyNode.append_attribute("stdset").set_value("0");
}
return propertyNode;
};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/qtuiwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QtUiWriter
bool isContainer = false);

Status addWidgetProperty(pugi::xml_node widget, const QString &name, const QVariant &value,
const QHash<QString, QString> &attributes = {});
const QHash<QString, QString> &attributes = {}, bool userProperty = false);

Status setWidgetName(pugi::xml_node widget, const QString &name, bool isRoot = false);
Status setWidgetClassName(pugi::xml_node widget, const QString &className);
Expand Down
42 changes: 21 additions & 21 deletions test_data/tst_rcwriter/IDD_ABCCOMPILE.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ui version="4.0">
<class>IDD_ABCCOMPILE</class>
<widget class="QDialog" name="IDD_ABCCOMPILE">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDD_ABCCOMPILE</string>
</property>
<property name="geometry">
Expand All @@ -17,7 +17,7 @@
<string>Compile Alembic</string>
</property>
<widget class="QPushButton" name="IDOK">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDOK</string>
</property>
<property name="geometry">
Expand All @@ -36,7 +36,7 @@
</property>
</widget>
<widget class="QPushButton" name="IDCANCEL">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDCANCEL</string>
</property>
<property name="geometry">
Expand All @@ -52,7 +52,7 @@
</property>
</widget>
<widget class="QCheckBox" name="IDC_PLAYBACKFROMMEMORY">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_PLAYBACKFROMMEMORY</string>
</property>
<property name="geometry">
Expand All @@ -68,7 +68,7 @@
</property>
</widget>
<widget class="QGroupBox" name="IDC_STATIC">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC</string>
</property>
<property name="geometry">
Expand All @@ -83,7 +83,7 @@
<string>Compilation Settings</string>
</property>
<widget class="QRadioButton" name="IDC_RADIO_YUP">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_RADIO_YUP</string>
</property>
<property name="geometry">
Expand All @@ -99,7 +99,7 @@
</property>
</widget>
<widget class="QRadioButton" name="IDC_RADIO_ZUP">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_RADIO_ZUP</string>
</property>
<property name="geometry">
Expand All @@ -116,7 +116,7 @@
</widget>
</widget>
<widget class="QGroupBox" name="IDC_STATIC_5">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_5</string>
</property>
<property name="geometry">
Expand All @@ -132,7 +132,7 @@
</property>
</widget>
<widget class="QGroupBox" name="IDC_STATIC_7">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_7</string>
</property>
<property name="geometry">
Expand All @@ -147,7 +147,7 @@
<string>Preset</string>
</property>
<widget class="QComboBox" name="IDC_PRESET">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_PRESET</string>
</property>
<property name="geometry">
Expand All @@ -161,7 +161,7 @@
</widget>
</widget>
<widget class="QGroupBox" name="IDC_STATIC_2">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_2</string>
</property>
<property name="geometry">
Expand All @@ -176,7 +176,7 @@
<string>Compression Settings</string>
</property>
<widget class="QLabel" name="IDC_STATIC_8">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_8</string>
</property>
<property name="geometry">
Expand All @@ -192,7 +192,7 @@
</property>
</widget>
<widget class="QLineEdit" name="IDC_INDEXFRAMEDISTANCE">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_INDEXFRAMEDISTANCE</string>
</property>
<property name="geometry">
Expand All @@ -208,7 +208,7 @@
</property>
</widget>
<widget class="QLabel" name="IDC_STATIC_6">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_6</string>
</property>
<property name="geometry">
Expand All @@ -224,7 +224,7 @@
</property>
</widget>
<widget class="QLabel" name="IDC_STATIC_4">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_4</string>
</property>
<property name="geometry">
Expand All @@ -240,7 +240,7 @@
</property>
</widget>
<widget class="QLineEdit" name="IDC_PRECISION">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_PRECISION</string>
</property>
<property name="geometry">
Expand All @@ -256,7 +256,7 @@
</property>
</widget>
<widget class="QLabel" name="IDC_STATIC_3">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_STATIC_3</string>
</property>
<property name="geometry">
Expand All @@ -272,7 +272,7 @@
</property>
</widget>
<widget class="QComboBox" name="IDC_BLOCKCOMPRESSION">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_BLOCKCOMPRESSION</string>
</property>
<property name="geometry">
Expand All @@ -285,7 +285,7 @@
</property>
</widget>
<widget class="QLineEdit" name="IDC_UV_MAX">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_UV_MAX</string>
</property>
<property name="geometry">
Expand All @@ -301,7 +301,7 @@
</property>
</widget>
<widget class="QCheckBox" name="IDC_MESHPREDICTION">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_MESHPREDICTION</string>
</property>
<property name="geometry">
Expand All @@ -317,7 +317,7 @@
</property>
</widget>
<widget class="QCheckBox" name="IDC_USEBFRAMES">
<property name="mfc_id">
<property name="mfc_id" stdset="0">
<string notr="true">IDC_USEBFRAMES</string>
</property>
<property name="geometry">
Expand Down
Loading

0 comments on commit 4ff2b07

Please sign in to comment.