Skip to content

Commit

Permalink
feat: add id property for QtUiWidget
Browse files Browse the repository at this point in the history
This property returns the "ID_String" property for a widget.
Used mostly for MFC migration.

Change-Id: Ic4567d4c3150da7f5785a99c8de06917b1a9a7fc
Reviewed-on: https://codereview.kdab.com/c/knut/+/142901
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
  • Loading branch information
narnaud authored and LeonMatthesKDAB committed Jun 17, 2024
1 parent 3fea497 commit 6884f4e
Show file tree
Hide file tree
Showing 12 changed files with 1,012 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/API/script/qtuiwidget.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Script 1.0
| | Name |
|-|-|
|string|**[className](#className)**|
|bool|**[id](#id)**|
|bool|**[isRoot](#isRoot)**|
|string|**[name](#name)**|

Expand All @@ -24,6 +25,10 @@ import Script 1.0

Name of the widget's class.

#### <a name="id"></a>bool **id**

Read-only property returning the id of the widget (property ID_String).

#### <a name="isRoot"></a>bool **isRoot**

Read-only property returning `true` if the widget is the root widget.
Expand Down
9 changes: 9 additions & 0 deletions src/core/qtuidocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ bool QtUiDocument::doLoad(const QString &fileName)
* \qmlproperty bool QtUiWidget::isRoot
* Read-only property returning `true` if the widget is the root widget.
*/
/*!
* \qmlproperty bool QtUiWidget::id
* Read-only property returning the id of the widget (property ID_String).
*/

QtUiWidget::QtUiWidget(pugi::xml_node widget, bool isRoot, QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -151,6 +155,11 @@ QString QtUiWidget::className() const
return QString::fromLatin1(m_widget.attribute("class").value());
}

QString QtUiWidget::id() const
{
return QString::fromLatin1(m_widget.select_node("property[@name='ID_String']/string").node().text().as_string());
}

void QtUiWidget::setClassName(const QString &newClassName)
{
LOG("QtUiWidget::setClassName", newClassName);
Expand Down
3 changes: 3 additions & 0 deletions src/core/qtuidocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class QtUiWidget : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString className READ className WRITE setClassName NOTIFY classNameChanged)
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(bool isRoot READ isRoot CONSTANT)

public:
Expand All @@ -32,6 +33,8 @@ class QtUiWidget : public QObject

QString className() const;

QString id() const;

bool isRoot() const { return m_isRoot; }

public slots:
Expand Down
7 changes: 7 additions & 0 deletions src/rccore/uiwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ void UiWriter::startWidget(const QString &className, const RcCore::Widget &widge
m_writer.writeAttribute("name", widgetName);
m_widgetName[name] = count + 1;

// Add the ID as a property
m_writer.writeStartElement("property");
m_writer.writeAttribute("name", "ID_String");
m_writer.writeAttribute("stdset", "0");
m_writer.writeTextElement("string", name);
m_writer.writeEndElement();

// Geometry
const auto &geometry = widget.geometry;
m_writer.writeStartElement("property");
Expand Down
325 changes: 325 additions & 0 deletions test_data/tst_qtuidocument/TutorialDlg.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CTutorialDlg</class>
<widget class="QDialog" name="CTutorialDlg">
<property name="ID_String" stdset="0">
<string>IDD_UPDATEGUI_DIALOG</string>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>330</height>
</rect>
</property>
<property name="windowTitle">
<string>Application Update GUI Elements</string>
</property>
<widget class="QPushButton" name="btn_add">
<property name="ID_String" stdset="0">
<string>ID_BTN_ADD</string>
</property>
<property name="geometry">
<rect>
<x>97</x>
<y>11</y>
<width>75</width>
<height>27</height>
</rect>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="text">
<string comment="ID_BTN_ADD">Click to Add</string>
</property>
</widget>
<widget class="QPushButton" name="cancel_button">
<property name="ID_String" stdset="0">
<string>IDCANCEL</string>
</property>
<property name="geometry">
<rect>
<x>394</x>
<y>292</y>
<width>75</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string comment="IDCANCEL">Quit</string>
</property>
</widget>
<widget class="QLabel" name="static1">
<property name="ID_String" stdset="0">
<string>IDC_STATIC</string>
</property>
<property name="geometry">
<rect>
<x>177</x>
<y>18</y>
<width>75</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string comment="IDC_STATIC">Button Clicks:</string>
</property>
</widget>
<widget class="QLabel" name="echo_area">
<property name="ID_String" stdset="0">
<string>IDC_ECHO_AREA</string>
</property>
<property name="geometry">
<rect>
<x>249</x>
<y>16</y>
<width>83</width>
<height>19</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string comment="IDC_ECHO_AREA">0</string>
</property>
</widget>
<widget class="QSlider" name="v_slider_bar">
<property name="ID_String" stdset="0">
<string>IDC_V_SLIDER_BAR</string>
</property>
<property name="geometry">
<rect>
<x>25</x>
<y>31</y>
<width>26</width>
<height>233</height>
</rect>
</property>
<property name="invertedAppearance">
<string>true</string>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
</widget>
<widget class="QSlider" name="h_slider_bar">
<property name="ID_String" stdset="0">
<string>IDC_H_SLIDER_BAR</string>
</property>
<property name="geometry">
<rect>
<x>129</x>
<y>293</y>
<width>243</width>
<height>25</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
</widget>
<widget class="QLabel" name="static2">
<property name="ID_String" stdset="0">
<string>IDC_STATIC</string>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>265</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string comment="IDC_STATIC">Vertical Bar</string>
</property>
</widget>
<widget class="QLabel" name="static3">
<property name="ID_String" stdset="0">
<string>IDC_STATIC</string>
</property>
<property name="geometry">
<rect>
<x>220</x>
<y>268</y>
<width>71</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string comment="IDC_STATIC">Horizontal Bar</string>
</property>
</widget>
<widget class="QLabel" name="v_slider_echo">
<property name="ID_String" stdset="0">
<string>IDC_V_SLIDER_ECHO</string>
</property>
<property name="geometry">
<rect>
<x>18</x>
<y>16</y>
<width>42</width>
<height>17</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignHCenter</set>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string comment="IDC_V_SLIDER_ECHO">Static</string>
</property>
</widget>
<widget class="QLabel" name="h_slider_echo">
<property name="ID_String" stdset="0">
<string>IDC_H_SLIDER_ECHO</string>
</property>
<property name="geometry">
<rect>
<x>172</x>
<y>268</y>
<width>42</width>
<height>17</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignHCenter</set>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string comment="IDC_H_SLIDER_ECHO">Static</string>
</property>
</widget>
<widget class="QLabel" name="timerecho">
<property name="ID_String" stdset="0">
<string>IDC_TIMERECHO</string>
</property>
<property name="geometry">
<rect>
<x>250</x>
<y>234</y>
<width>219</width>
<height>19</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string comment="IDC_TIMERECHO">0</string>
</property>
</widget>
<widget class="QLabel" name="mouseecho">
<property name="ID_String" stdset="0">
<string>IDC_MOUSEECHO</string>
</property>
<property name="geometry">
<rect>
<x>250</x>
<y>211</y>
<width>219</width>
<height>19</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string comment="IDC_MOUSEECHO">0</string>
</property>
</widget>
<widget class="QLabel" name="static4">
<property name="ID_String" stdset="0">
<string>IDC_STATIC</string>
</property>
<property name="geometry">
<rect>
<x>172</x>
<y>235</y>
<width>68</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string comment="IDC_STATIC">Timer Echo:</string>
</property>
</widget>
<widget class="QLabel" name="static5">
<property name="ID_String" stdset="0">
<string>IDC_STATIC</string>
</property>
<property name="geometry">
<rect>
<x>172</x>
<y>214</y>
<width>68</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string comment="IDC_STATIC">Mouse Echo:</string>
</property>
</widget>
<widget class="QCheckBox" name="timer_control_sliders">
<property name="ID_String" stdset="0">
<string>IDC_TIMER_CONTROL_SLIDERS</string>
</property>
<property name="geometry">
<rect>
<x>174</x>
<y>122</y>
<width>129</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string comment="IDC_TIMER_CONTROL_SLIDERS">Timer Control Sliders</string>
</property>
</widget>
</widget>
<resources />
<connections />
</ui>
Loading

0 comments on commit 6884f4e

Please sign in to comment.