aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/views/listview/highlightranges.qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-09-17 18:10:59 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-02-11 19:26:05 +0100
commit90b4528b846542bfa6f0723487315140b9de17b4 (patch)
tree9356c0e6b5a736b3228ca6793416d927432c101e /examples/quick/views/listview/highlightranges.qml
parent38c03709236f6a2114ace7adf1b6bdcdfe8e4e18 (diff)
Avoid discouraged patterns in examples
In particular, use required properties where applicable, explicitly import QtQml where we use it, avoid unqualified access into the root scope of a component, use JavaScript functions with explicit parameters as signal handlers. Change-Id: I3eaaba47cc3c7a2a12d488e36f9eec145cedbb0e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/quick/views/listview/highlightranges.qml')
-rw-r--r--examples/quick/views/listview/highlightranges.qml32
1 files changed, 19 insertions, 13 deletions
diff --git a/examples/quick/views/listview/highlightranges.qml b/examples/quick/views/listview/highlightranges.qml
index 7bc9ab7fe1..dafd064332 100644
--- a/examples/quick/views/listview/highlightranges.qml
+++ b/examples/quick/views/listview/highlightranges.qml
@@ -62,17 +62,17 @@ Rectangle {
loops: -1
running: true
ScriptAction {
- script: if (increasing) {
- current++;
- if (current >= aModel.count -1) {
- current = aModel.count - 1;
- increasing = !increasing;
+ script: if (root.increasing) {
+ root.current++;
+ if (root.current >= aModel.count -1) {
+ root.current = aModel.count - 1;
+ root.increasing = !root.increasing;
}
} else {
- current--;
- if (current <= 0) {
- current = 0;
- increasing = !increasing;
+ root.current--;
+ if (root.current <= 0) {
+ root.current = 0;
+ root.increasing = !root.increasing;
}
}
}
@@ -161,16 +161,22 @@ Rectangle {
Item {
width: 160
height: column.height
+
+ required property int index
+ required property string name
+ required property string type
+ required property int age
+
Column {
id: column
- Text { text: 'Name: ' + name }
- Text { text: 'Type: ' + type }
- Text { text: 'Age: ' + age }
+ Text { text: 'Name: ' + parent.name }
+ Text { text: 'Type: ' + parent.type }
+ Text { text: 'Age: ' + parent.age }
}
MouseArea {
anchors.fill: parent
- onClicked: root.current = index
+ onClicked: root.current = parent.index
}
}
}