1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
import QtQuick 2.0
Rectangle {
width: 320; height: 480
Rectangle {
id: groupButtons
width: 300; height: 30
color: "yellow"
border.width: 1
Text {
anchors.centerIn: parent
text: "swap"
}
anchors {
top: parent.top
horizontalCenter: parent.horizontalCenter
}
MouseArea {
anchors.fill: parent
onClicked: switchGroups()
}
}
function switchGroups() {
myListView.model.move(0,1,1)
if ("title" === myListView.groupBy)
myListView.groupBy = "genre"
else
myListView.groupBy = "title"
}
function switchGrouped() {
if ("pageCount" === myListView.groupBy)
myListView.groupBy = "genre"
else
myListView.groupBy = "pageCount"
}
Component.onCompleted: {
myListView.model = generateModel(myListView)
}
ListView {
id: myListView
objectName: "list"
clip: true
property string groupBy: "title"
anchors {
top: groupButtons.bottom
left: parent.left
right: parent.right
bottom: parent.bottom
}
delegate: Item {
objectName: "wrapper"
height: 50
width: 320
Text { id: t; text: model.title }
Text { text: model.author; font.pixelSize: 10; anchors.top: t.bottom }
Text { text: parent.y; anchors.right: parent.right }
}
section {
criteria: ViewSection.FullString
delegate: Rectangle { width: 320; height: 25; color: "lightblue"
objectName: "sect"
Text {text: section }
Text { text: parent.y; anchors.right: parent.right }
}
property: myListView.groupBy
}
}
function generateModel(theParent)
{
var books = [
{ "author": "Billy Bob", "genre": "Anarchism", "title": "Frogs and Love", "pageCount": 80 },
{ "author": "Lefty Smith", "genre": "Horror", "title": "Chainsaws for Noobs", "pageCount": 80 }
];
var model = Qt.createQmlObject("import QtQuick 2.0; ListModel {}", theParent);
for (var i = 0; i < books.length; ++i) {
var book = books[i];
model.append(book);
}
return model;
}
}
|