Commit ff5b19b4 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

experiment on sorting tiles by property

seems SplitView (or DelegateModel?) doesn't always follow the order of the
source list.
parent 2c2e4110
......@@ -17,16 +17,35 @@ Window {
ListModel {
id: tileListModel
ListElement { name: "A" }
ListElement { name: "B" }
ListElement { name: "C" }
ListElement { name: "D" }
ListElement { name: "E" }
ListElement { name: "F" }
ListElement { name: "G" }
ListElement { name: "H" }
ListElement { name: "I" }
ListElement { name: "J" }
function reorder() {
// TODO: will be rewritten to remap everything and emit layoutChanged.
let totalCount = root.leftCount + root.rightCount;
for (let i = 0; i < totalCount; ++i) {
if (get(i).tileIndex === i)
continue;
for (let j = i + 1; j < count; ++j) {
if (get(j).tileIndex !== i)
continue;
move(j, i, 1);
break;
}
if (get(i).tileIndex !== i) {
insert(i, {name: "", tileIndex: -1}); // spacer
}
}
}
ListElement { name: "A"; tileIndex: 0 }
ListElement { name: "B"; tileIndex: 1 }
ListElement { name: "C"; tileIndex: 2 }
ListElement { name: "D"; tileIndex: 3 }
ListElement { name: "E"; tileIndex: 4 }
ListElement { name: "F"; tileIndex: 5 }
ListElement { name: "G"; tileIndex: 6 }
ListElement { name: "H"; tileIndex: 7 }
ListElement { name: "I"; tileIndex: 8 }
ListElement { name: "J"; tileIndex: 9 }
}
DelegateModel {
......@@ -37,6 +56,7 @@ Window {
required property int index
required property string name
required property int tileIndex
readonly property int column: {
if (index < root.leftCount) {
return 0;
......@@ -59,13 +79,17 @@ Window {
visible: tile.column === 1
}
Item {
Pane {
id: stacked
Package.name: "stacked"
}
GridLayout {
parent: [stacked, leftPane.contentItem, rightPane.contentItem][tile.column + 1]
parent: {
if (tile.tileIndex < 0)
return stacked.contentItem;
return [stacked.contentItem, leftPane.contentItem, rightPane.contentItem][tile.column + 1]
}
anchors.fill: parent
columns: 2
Component.onCompleted: {
......@@ -78,13 +102,16 @@ Window {
text: tile.name
}
Label { text: "index:" }
Label { text: "tileIndex:" }
SpinBox {
editable: true
value: tile.index
from: -1
value: tile.tileIndex
onValueModified: {
dummyField.text += " " + value;
tileListModel.move(tile.index, value, 1);
tileListModel.setProperty(value, "tileIndex", -1);
tileListModel.setProperty(tile.index, "tileIndex", value);
tileListModel.reorder();
}
}
......@@ -147,6 +174,20 @@ Window {
root.rightCount = value;
}
}
Label {
Layout.columnSpan: 2
font.bold: true
text: "stacked tiles:"
}
ColumnLayout {
Layout.fillWidth: true
Layout.columnSpan: 2
Repeater {
model: tileContentModel.parts.stacked
}
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment