| 1 |
// This example demonstrates placing items in a view using |
| 2 |
// an ObjectModel |
| 3 |
|
| 4 |
import QtQuick 2.0 |
| 5 |
import QtQml.Models 2.12 |
| 6 |
|
| 7 |
Rectangle { |
| 8 |
id: root |
| 9 |
color: "lightgray" |
| 10 |
width: 240 |
| 11 |
height: 320 |
| 12 |
property variant itemModel: itemModel1 |
| 13 |
|
| 14 |
function checkProperties() { |
| 15 |
testObject.error = false; |
| 16 |
if (testObject.useModel && view.model != root.itemModel) { |
| 17 |
console.log("model property incorrect"); |
| 18 |
testObject.error = true; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
function switchModel() { |
| 23 |
root.itemModel = itemModel2 |
| 24 |
} |
| 25 |
|
| 26 |
ObjectModel { |
| 27 |
id: itemModel1 |
| 28 |
objectName: "itemModel1" |
| 29 |
Rectangle { |
| 30 |
objectName: "item1" |
| 31 |
height: 50; width: 100; color: "#FFFEF0" |
| 32 |
Text { objectName: "text1"; text: "index: " + parent.ObjectModel.index; font.bold: true; anchors.centerIn: parent } |
| 33 |
} |
| 34 |
Rectangle { |
| 35 |
objectName: "item2" |
| 36 |
height: 50; width: 100; color: "#F0FFF7" |
| 37 |
Text { objectName: "text2"; text: "index: " + parent.ObjectModel.index; font.bold: true; anchors.centerIn: parent } |
| 38 |
} |
| 39 |
Rectangle { |
| 40 |
objectName: "item3" |
| 41 |
height: 50; width: 100; color: "#F4F0FF" |
| 42 |
Text { objectName: "text3"; text: "index: " + parent.ObjectModel.index; font.bold: true; anchors.centerIn: parent } |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
ObjectModel { |
| 47 |
id: itemModel2 |
| 48 |
objectName: "itemModel2" |
| 49 |
Rectangle { |
| 50 |
objectName: "item4" |
| 51 |
height: 50; width: 100; color: "#FFFEF0" |
| 52 |
Text { objectName: "text4"; text: "index: " + parent.ObjectModel.index; font.bold: true; anchors.centerIn: parent } |
| 53 |
} |
| 54 |
Rectangle { |
| 55 |
objectName: "item5" |
| 56 |
height: 50; width: 100; color: "#F0FFF7" |
| 57 |
Text { objectName: "text5"; text: "index: " + parent.ObjectModel.index; font.bold: true; anchors.centerIn: parent } |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
Column { |
| 62 |
objectName: "container" |
| 63 |
Repeater { |
| 64 |
id: view |
| 65 |
objectName: "repeater" |
| 66 |
model: testObject.useModel ? root.itemModel : 0 |
| 67 |
} |
| 68 |
} |
| 69 |
} |