mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
understanding the delegateModelGroup mechanism...
This commit is contained in:
parent
483a716839
commit
3e17c1007a
1 changed files with 103 additions and 53 deletions
|
@ -71,9 +71,8 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property var itemFields: ['name', 'root', 'base', 'path', 'index']
|
property var itemFields: ['index', 'name', 'scheme', 'host', 'pathDir', 'url']
|
||||||
property var itemFieldsVisibility: {'name': true, 'root': false, 'base':false, 'path':false, 'index':false}
|
|
||||||
|
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: header
|
id: header
|
||||||
|
@ -120,7 +119,7 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
Item {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
height: orderSelector.height
|
height: orderSelector.height
|
||||||
|
@ -128,29 +127,25 @@ Item {
|
||||||
Prop.PropComboBox {
|
Prop.PropComboBox {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
id: orderSelector
|
id: orderSelector
|
||||||
model: [ "name", "base", "root" ]
|
model: itemFields
|
||||||
property var selectedIndex: currentIndex
|
property var selectedIndex: currentIndex
|
||||||
|
|
||||||
|
property var isSchemeVisible: (currentIndex == 2)
|
||||||
|
property var isHostVisible: (currentIndex == 3)
|
||||||
|
property var isPathDirVisible: (currentIndex == 4)
|
||||||
|
property var isURLVisible: (currentIndex == 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
Prop.PropCheckBox {
|
/* Prop.PropCheckBox {
|
||||||
id: showName
|
anchors.left: orderSelector.right
|
||||||
text: 'name'
|
id: listQRC
|
||||||
checked: itemFieldsVisibility['name']
|
checked: true
|
||||||
}
|
text: "list qrc"
|
||||||
Prop.PropCheckBox {
|
}*/
|
||||||
id: showRoot
|
|
||||||
text: 'root'
|
|
||||||
checked: itemFieldsVisibility['root']
|
|
||||||
}
|
|
||||||
Prop.PropCheckBox {
|
|
||||||
id: showBase
|
|
||||||
text: 'base'
|
|
||||||
checked: itemFieldsVisibility['base']
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: resouceItemDelegate
|
id: resouceItemDelegate
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -175,50 +170,70 @@ Item {
|
||||||
width: 30
|
width: 30
|
||||||
}
|
}
|
||||||
Prop.PropSplitter {
|
Prop.PropSplitter {
|
||||||
visible: showRoot.checked
|
visible: orderSelector.isSchemeVisible
|
||||||
size:8
|
size:8
|
||||||
}
|
}
|
||||||
Prop.PropLabel {
|
Prop.PropLabel {
|
||||||
visible: showRoot.checked
|
visible: orderSelector.isSchemeVisible
|
||||||
text: model.root
|
text: model.scheme
|
||||||
width: 30
|
width: 30
|
||||||
}
|
}
|
||||||
Prop.PropSplitter {
|
Prop.PropSplitter {
|
||||||
visible: showBase.checked
|
visible: orderSelector.isHostVisible
|
||||||
size:8
|
size:8
|
||||||
}
|
}
|
||||||
Prop.PropLabel {
|
Prop.PropLabel {
|
||||||
visible: showBase.checked
|
visible: orderSelector.isHostVisible
|
||||||
text: model.base
|
text: model.host
|
||||||
width: 60
|
width: 150
|
||||||
}
|
}
|
||||||
Prop.PropSplitter {
|
Prop.PropSplitter {
|
||||||
visible: showName.checked
|
visible: orderSelector.isPathDirVisible
|
||||||
size:8
|
size:8
|
||||||
}
|
}
|
||||||
Prop.PropLabel {
|
Prop.PropLabel {
|
||||||
visible: showName.checked
|
visible: orderSelector.isPathDirVisible
|
||||||
|
text: model.pathDir
|
||||||
|
}
|
||||||
|
Prop.PropSplitter {
|
||||||
|
size:8
|
||||||
|
}
|
||||||
|
Prop.PropLabel {
|
||||||
|
visible: !orderSelector.isURLVisible
|
||||||
text: model.name
|
text: model.name
|
||||||
}
|
}
|
||||||
|
Prop.PropLabel {
|
||||||
|
visible: orderSelector.isURLVisible
|
||||||
|
text: model.url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ['index', 'name', 'scheme', 'host', 'pathDir', 'url']
|
||||||
DelegateModel {
|
DelegateModel {
|
||||||
id: visualModel
|
id: visualModel
|
||||||
|
|
||||||
model: ListModel {}
|
model: ListModel {}
|
||||||
|
|
||||||
|
property var filterQRC: function(item) { return item.scheme == "qrc" }
|
||||||
property var lessThan: [
|
property var lessThan: [
|
||||||
|
function(left, right) { return left.index < right.index },
|
||||||
function(left, right) { return left.name < right.name },
|
function(left, right) { return left.name < right.name },
|
||||||
function(left, right) { return left.base < right.base },
|
function(left, right) { return left.scheme < right.scheme },
|
||||||
function(left, right) { return left.root < right.root }
|
function(left, right) { return left.host < right.host },
|
||||||
|
function(left, right) { return left.pathDir < right.pathDir },
|
||||||
|
function(left, right) { return left.url < right.url }
|
||||||
]
|
]
|
||||||
|
|
||||||
property int sortOrder: orderSelector.selectedIndex
|
property int sortOrder: orderSelector.selectedIndex
|
||||||
onSortOrderChanged: items.setGroups(0, items.count, "unsorted")
|
onSortOrderChanged: items.setGroups(0, items.count, "unsorted")
|
||||||
|
|
||||||
|
property bool listQRCChecked: listQRC.checked
|
||||||
|
onListQRCCheckedChanged: items.setGroups(0, items.count, "unsorted")
|
||||||
|
|
||||||
function insertPosition(lessThan, item) {
|
function insertPosition(lessThan, item) {
|
||||||
var lower = 0
|
var lower = 0
|
||||||
var upper = items.count
|
var upper = items.count
|
||||||
|
@ -237,26 +252,35 @@ Item {
|
||||||
function sort(lessThan) {
|
function sort(lessThan) {
|
||||||
while (unsortedItems.count > 0) {
|
while (unsortedItems.count > 0) {
|
||||||
var item = unsortedItems.get(0)
|
var item = unsortedItems.get(0)
|
||||||
|
// var doHide = (!listQRCChecked && filterQRC(item.model))
|
||||||
|
|
||||||
var index = insertPosition(lessThan, item)
|
var index = insertPosition(lessThan, item)
|
||||||
|
|
||||||
item.groups = "items"
|
item.groups = "items"
|
||||||
items.move(item.itemsIndex, index)
|
// if (doHide) {
|
||||||
|
// item.inItems = false;
|
||||||
|
// } else {
|
||||||
|
// item.inItems = true;
|
||||||
|
items.move(item.itemsIndex, index)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items.includeByDefault: false
|
items.includeByDefault: false
|
||||||
groups: DelegateModelGroup {
|
groups:
|
||||||
id: unsortedItems
|
DelegateModelGroup {
|
||||||
name: "unsorted"
|
id: unsortedItems
|
||||||
|
name: "unsorted"
|
||||||
|
|
||||||
includeByDefault: true
|
includeByDefault: true
|
||||||
onChanged: {
|
onChanged: {
|
||||||
if (visualModel.sortOrder == visualModel.lessThan.length)
|
if (visualModel.sortOrder == visualModel.lessThan.length)
|
||||||
setGroups(0, count, "items")
|
setGroups(0, count, "items")
|
||||||
else
|
else
|
||||||
visualModel.sort(visualModel.lessThan[visualModel.sortOrder])
|
visualModel.sort(visualModel.lessThan[visualModel.sortOrder])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
delegate: resouceItemDelegate
|
delegate: resouceItemDelegate
|
||||||
|
@ -264,16 +288,42 @@ Item {
|
||||||
property alias resourceItemsModel: visualModel.model
|
property alias resourceItemsModel: visualModel.model
|
||||||
property var currentItemsList: new Array();
|
property var currentItemsList: new Array();
|
||||||
|
|
||||||
function packItemEntry(item) {
|
function packItemEntry(item, index) {
|
||||||
var entry = { "name": "", "root": "", "path": "", "base": "", "url": item}
|
var entry = { "index": index, "name": "", "scheme": "", "host": "", "pathDir": "", "url": item}
|
||||||
if (item.length > 0) {
|
if (item.length > 0) {
|
||||||
var rootPos = item.search("://")
|
// Detect scheme:
|
||||||
entry.root = item.substring(0, rootPos)
|
var schemePos = item.search(":")
|
||||||
if (rootPos >= 0) rootPos += 3
|
entry.scheme = item.substring(0, schemePos)
|
||||||
entry.path = item.substring(rootPos, item.length)
|
if (schemePos < 0) schemePos = 0
|
||||||
var splitted = entry.path.split('/')
|
else schemePos += 1
|
||||||
entry.name = splitted[splitted.length - 1]
|
|
||||||
entry.base = splitted[0]
|
// path pos is probably after schemePos
|
||||||
|
var pathPos = schemePos
|
||||||
|
|
||||||
|
// try to detect //userinfo@host:port
|
||||||
|
var token = item.substr(schemePos, 2);
|
||||||
|
if (token.search("//") == 0) {
|
||||||
|
pathPos += 2
|
||||||
|
}
|
||||||
|
item = item.substring(pathPos, item.length)
|
||||||
|
// item is now everything after scheme:[//]
|
||||||
|
var splitted = item.split('/')
|
||||||
|
|
||||||
|
// odd ball, the rest of the url has no other'/' ?
|
||||||
|
// in theory this means it s just the host info ?
|
||||||
|
// we are assuming that path ALWAYS starts with a slash
|
||||||
|
entry.host = splitted[0]
|
||||||
|
|
||||||
|
if (splitted.length > 1) {
|
||||||
|
entry.name = splitted[splitted.length - 1]
|
||||||
|
|
||||||
|
// if splitted is longer than 2 then there should be a path dir
|
||||||
|
if (splitted.length > 2) {
|
||||||
|
for (var i = 1; i < splitted.length - 1; i++) {
|
||||||
|
entry.pathDir += '/' + splitted[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
@ -285,7 +335,7 @@ Item {
|
||||||
for (var i in itemList) {
|
for (var i in itemList) {
|
||||||
var item = itemList[i]
|
var item = itemList[i]
|
||||||
currentItemsList.push(item)
|
currentItemsList.push(item)
|
||||||
resourceItemsModel.append(packItemEntry(item))
|
resourceItemsModel.append(packItemEntry(item, currentItemsList.length -1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue