Skip to content

Commit ebccb5c

Browse files
committed
WIP: examples: add qmllint tests and fix issues
1 parent d9923f5 commit ebccb5c

16 files changed

+161
-132
lines changed

examples/qml_features/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,12 @@ if(BUILD_TESTING)
149149
else()
150150
MESSAGE(STATUS "add_valgrind_test is defined in the top level of CXX-Qt. It will not executed")
151151
endif()
152+
153+
find_program(QMLLINT_COMMAND qmllint PATHS "${QT_INSTALL_BINS}")
154+
if("${QMLLINT_COMMAND}" STREQUAL "QMLLINT_COMMAND-NOTFOUND")
155+
MESSAGE(STATUS "qmllint not found. Please install it")
156+
else()
157+
file(GLOB QMLLINT_QML_FILES ${CMAKE_CURRENT_SOURCE_DIR}/qml/**/*.qml)
158+
add_test(NAME example_qml_features_qmllint_check COMMAND ${QMLLINT_COMMAND} --max-warnings 0 -I ${CMAKE_CURRENT_BINARY_DIR}/cxxqt/qml_modules ${QMLLINT_QML_FILES})
159+
endif()
152160
endif()

examples/qml_features/qml/pages/ContainersPage.qml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import QtQuick.Layouts 1.12
99
import com.kdab.cxx_qt.demo 1.0
1010

1111
Page {
12+
id: root
1213
header: ToolBar {
1314
RowLayout {
1415
anchors.fill: parent
1516

1617
ToolButton {
1718
text: qsTr("Reset")
1819

19-
onClicked: rustContainers.reset()
20+
onClicked: root.rustContainers.reset()
2021
}
2122

2223
Item {
@@ -25,8 +26,7 @@ Page {
2526
}
2627
}
2728

28-
RustContainers {
29-
id: rustContainers
29+
readonly property RustContainers rustContainers: RustContainers {
3030
}
3131

3232
ColumnLayout {
@@ -54,74 +54,74 @@ Page {
5454
Label {
5555
Layout.fillWidth: true
5656
horizontalAlignment: Text.AlignHCenter
57-
text: qsTr("QHash<QString, QVariant> values: %1").arg(rustContainers.stringHash || "Empty")
57+
text: qsTr("QHash<QString, QVariant> values: %1").arg(root.rustContainers.stringHash || "Empty")
5858
wrapMode: Text.Wrap
5959
}
6060

6161
Button {
6262
text: qsTr("Insert")
6363

64-
onClicked: rustContainers.insertHash("Key" + spinBox.value, spinBox.value)
64+
onClicked: root.rustContainers.insertHash("Key" + spinBox.value, spinBox.value)
6565
}
6666
}
6767

6868
RowLayout {
6969
Label {
7070
Layout.fillWidth: true
7171
horizontalAlignment: Text.AlignHCenter
72-
text: qsTr("QList<i32> values: %1").arg(rustContainers.stringList || "Empty")
72+
text: qsTr("QList<i32> values: %1").arg(root.rustContainers.stringList || "Empty")
7373
wrapMode: Text.Wrap
7474
}
7575

7676
Button {
7777
text: qsTr("Append")
7878

79-
onClicked: rustContainers.appendList(spinBox.value)
79+
onClicked: root.rustContainers.appendList(spinBox.value)
8080
}
8181
}
8282

8383
RowLayout {
8484
Label {
8585
Layout.fillWidth: true
8686
horizontalAlignment: Text.AlignHCenter
87-
text: qsTr("QMap<QString, QVariant> values: %1").arg(rustContainers.stringMap || "Empty")
87+
text: qsTr("QMap<QString, QVariant> values: %1").arg(root.rustContainers.stringMap || "Empty")
8888
wrapMode: Text.Wrap
8989
}
9090

9191
Button {
9292
text: qsTr("Insert")
9393

94-
onClicked: rustContainers.insertMap("Key" + spinBox.value, spinBox.value)
94+
onClicked: root.rustContainers.insertMap("Key" + spinBox.value, spinBox.value)
9595
}
9696
}
9797

9898
RowLayout {
9999
Label {
100100
Layout.fillWidth: true
101101
horizontalAlignment: Text.AlignHCenter
102-
text: qsTr("QSet<i32> values: %1").arg(rustContainers.stringSet || "Empty")
102+
text: qsTr("QSet<i32> values: %1").arg(root.rustContainers.stringSet || "Empty")
103103
wrapMode: Text.Wrap
104104
}
105105

106106
Button {
107107
text: qsTr("Insert")
108108

109-
onClicked: rustContainers.insertSet(spinBox.value)
109+
onClicked: root.rustContainers.insertSet(spinBox.value)
110110
}
111111
}
112112

113113
RowLayout {
114114
Label {
115115
Layout.fillWidth: true
116116
horizontalAlignment: Text.AlignHCenter
117-
text: qsTr("QVector<i32> values: %1").arg(rustContainers.stringVector || "Empty")
117+
text: qsTr("QVector<i32> values: %1").arg(root.rustContainers.stringVector || "Empty")
118118
wrapMode: Text.Wrap
119119
}
120120

121121
Button {
122122
text: qsTr("Append")
123123

124-
onClicked: rustContainers.appendVector(spinBox.value)
124+
onClicked: root.rustContainers.appendVector(spinBox.value)
125125
}
126126
}
127127
}

examples/qml_features/qml/pages/CustomBaseClassPage.qml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ Page {
9898
id: customBaseClass
9999
}
100100
delegate: ItemDelegate {
101+
required property int id
102+
required property int index
103+
required property double value
104+
101105
highlighted: ListView.isCurrentItem
102-
text: model.id + ": " + model.value
106+
text: id + ": " + value
103107
width: ListView.view.width
104108

105109
onClicked: ListView.view.currentIndex = index
@@ -118,8 +122,12 @@ Page {
118122
id: transitiveInheritance
119123
}
120124
delegate: ItemDelegate {
125+
required property int id
126+
required property int index
127+
required property double value
128+
121129
highlighted: ListView.isCurrentItem
122-
text: model.id + ": " + model.value
130+
text: id + ": " + value
123131
width: ListView.view.width
124132

125133
onClicked: ListView.view.currentIndex = index

examples/qml_features/qml/pages/CustomParentClassPage.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Page {
4343
anchors.right: parent.right
4444
anchors.verticalCenter: parent.verticalCenter
4545

46+
// TODO: qmllint fails here possibly needs a dependency in the qmldir on QtQuick?
4647
CustomParentClass {
4748
id: customPainter
4849
color: "red"

examples/qml_features/qml/pages/ExternCxxQtPage.qml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import QtQuick.Layouts 1.12
88
import QtQuick.Window 2.12
99

1010
import com.kdab.cxx_qt.demo 1.0
11+
// C++ code is not declarative as it still supports Qt 5
12+
// qmllint disable import
1113
import com.kdab.cxx_qt.demo_cpp 1.0
14+
// qmllint enable import
1215

1316
Page {
17+
id: root
1418
property int amount: 5
1519

1620
header: ToolBar {
@@ -20,7 +24,10 @@ Page {
2024
ToolButton {
2125
text: qsTr("Trigger")
2226

23-
onClicked: rustExternCxxQt.triggerOnExternal(externalQObject, amountSpinBox.value)
27+
// C++ code is not declarative as it still supports Qt 5
28+
// qmllint disable unresolved-type
29+
onClicked: root.rustExternCxxQt.triggerOnExternal(root.externalQObject, amountSpinBox.value)
30+
// qmllint enable unresolved-type
2431
}
2532

2633
Item {
@@ -29,12 +36,13 @@ Page {
2936
}
3037
}
3138

32-
ExternalQObject {
33-
id: externalQObject
39+
// C++ code is not declarative as it still supports Qt 5
40+
// qmllint disable import unresolved-type
41+
readonly property ExternalQObject externalQObject: ExternalQObject {
3442
}
43+
// qmllint enable import unresolved-type
3544

36-
ExternalCxxQtHelper {
37-
id: rustExternCxxQt
45+
readonly property ExternalCxxQtHelper rustExternCxxQt: ExternalCxxQtHelper {
3846
}
3947

4048
ColumnLayout {
@@ -63,10 +71,13 @@ Page {
6371
Label {
6472
Layout.fillWidth: true
6573
horizontalAlignment: Text.AlignHCenter
66-
text: qsTr("Count: %1").arg(rustExternCxxQt.count)
74+
text: qsTr("Count: %1").arg(root.rustExternCxxQt.count)
6775
wrapMode: Text.Wrap
6876
}
6977
}
7078

71-
Component.onCompleted: rustExternCxxQt.connectToExternal(externalQObject)
79+
// C++ code is not declarative as it still supports Qt 5
80+
// qmllint disable unresolved-type
81+
Component.onCompleted: root.rustExternCxxQt.connectToExternal(root.externalQObject)
82+
// qmllint enable unresolved-type
7283
}

examples/qml_features/qml/pages/InvokablesPage.qml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import QtQuick.Layouts 1.12
99
import com.kdab.cxx_qt.demo 1.0
1010

1111
Page {
12+
id: root
1213
background: Rectangle {
1314
color: privateState.color
1415
}
@@ -36,26 +37,26 @@ Page {
3637

3738
onClicked: {
3839
timerSync.running = false;
39-
rustInvokables.reset();
40+
root.rustInvokables.reset();
4041
privateState.load();
4142
}
4243
}
4344

4445
// ANCHOR: book_namespaced_qenum
4546
ToolButton {
4647
text: qsTr("Red")
47-
onClicked: rustInvokables.storeColorWithEnum(Colors.Red);
48+
onClicked: root.rustInvokables.storeColorWithEnum(Colors.Red);
4849
}
4950
// ANCHOR_END: book_namespaced_qenum
5051

5152
ToolButton {
5253
text: qsTr("Green")
53-
onClicked: rustInvokables.storeColorWithEnum(Colors.Green);
54+
onClicked: root.rustInvokables.storeColorWithEnum(Colors.Green);
5455
}
5556

5657
ToolButton {
5758
text: qsTr("Blue")
58-
onClicked: rustInvokables.storeColorWithEnum(Colors.Blue);
59+
onClicked: root.rustInvokables.storeColorWithEnum(Colors.Blue);
5960
}
6061

6162
Item {
@@ -64,8 +65,7 @@ Page {
6465
}
6566
}
6667

67-
RustInvokables {
68-
id: rustInvokables
68+
readonly property RustInvokables rustInvokables: RustInvokables {
6969
}
7070

7171
QtObject {
@@ -75,7 +75,7 @@ Page {
7575
property bool loaded: false
7676

7777
function load() {
78-
color = rustInvokables.loadColor();
78+
color = root.rustInvokables.loadColor();
7979
}
8080

8181
Component.onCompleted: {
@@ -99,7 +99,7 @@ Page {
9999
if (!privateState.loaded) {
100100
return;
101101
}
102-
rustInvokables.storeColor(sliderRed.value, sliderGreen.value, sliderBlue.value);
102+
root.rustInvokables.storeColor(sliderRed.value, sliderGreen.value, sliderBlue.value);
103103
}
104104

105105
Slider {

examples/qml_features/qml/pages/MultipleQObjectsPage.qml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ import QtQuick.Layouts 1.12
99
import com.kdab.cxx_qt.demo 1.0
1010

1111
Page {
12+
id: root
1213
header: ToolBar {
1314
RowLayout {
1415
anchors.fill: parent
1516

1617
ToolButton {
1718
text: qsTr("Increment First")
1819

19-
onClicked: first.increment()
20+
onClicked: root.first.increment()
2021
}
2122

2223
ToolButton {
2324
text: qsTr("Increment Second")
2425

25-
onClicked: second.increment()
26+
onClicked: root.second.increment()
2627
}
2728

2829
Item {
@@ -31,16 +32,12 @@ Page {
3132
}
3233
}
3334

34-
FirstObject {
35-
id: first
36-
35+
readonly property FirstObject first: FirstObject {
3736
onAccepted: console.warn("First Accepted")
3837
onRejected: console.warn("First Rejected")
3938
}
4039

41-
SecondObject {
42-
id: second
43-
40+
readonly property SecondObject second: SecondObject {
4441
onAccepted: console.warn("Second Accepted")
4542
onRejected: console.warn("Second Rejected")
4643
}
@@ -58,17 +55,18 @@ Page {
5855
}
5956

6057
Label {
61-
color: first.color
58+
// TODO: QColor needs a dependency in qmldir on QtQuick
59+
color: root.first.color
6260
Layout.fillWidth: true
6361
horizontalAlignment: Text.AlignHCenter
64-
text: qsTr("First Object Count: %1, color: %2").arg(first.counter).arg(first.color)
62+
text: qsTr("First Object Count: %1, color: %2").arg(root.first.counter).arg(root.first.color)
6563
wrapMode: Text.Wrap
6664
}
6765

6866
Label {
6967
Layout.fillWidth: true
7068
horizontalAlignment: Text.AlignHCenter
71-
text: qsTr("Second Object Count: %1, URL: %2").arg(second.counter).arg(second.url)
69+
text: qsTr("Second Object Count: %1, URL: %2").arg(root.second.counter).arg(root.second.url)
7270
wrapMode: Text.Wrap
7371
}
7472
}

examples/qml_features/qml/pages/NamingPage.qml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import QtQuick.Layouts 1.12
99
import com.kdab.cxx_qt.demo 1.0
1010

1111
Page {
12-
RenamedObject {
13-
id: renamedObject
12+
id: root
13+
readonly property RenamedObject renamedObject: RenamedObject {
1414
numberProp: 1
1515
}
1616

@@ -22,20 +22,20 @@ Page {
2222
Label {
2323
Layout.fillWidth: true
2424
horizontalAlignment: Text.AlignHCenter
25-
text: qsTr("Counter: %1").arg(renamedObject.numberProp)
25+
text: qsTr("Counter: %1").arg(root.renamedObject.numberProp)
2626
wrapMode: Text.Wrap
2727
}
2828

2929
Button {
3030
text: qsTr("Increment Counter")
31-
onClicked: renamedObject.increment()
31+
onClicked: root.renamedObject.increment()
3232
}
3333

3434
Label {
3535
Layout.fillWidth: true
3636
horizontalAlignment: Text.AlignHCenter
37-
text: qsTr("Meaning of life: %1").arg(renamedObject.getNum())
37+
text: qsTr("Meaning of life: %1").arg(root.renamedObject.getNum())
3838
wrapMode: Text.Wrap
3939
}
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)