From df25c6cda7980356a9d07eabdcae66ebde9912fe Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Sat, 2 Sep 2017 21:42:24 +0200 Subject: [PATCH] Simplify QQC2 file system tree --- demo/qml/FileTreeView2.qml | 127 ++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 66 deletions(-) diff --git a/demo/qml/FileTreeView2.qml b/demo/qml/FileTreeView2.qml index b6081fd..91478bf 100644 --- a/demo/qml/FileTreeView2.qml +++ b/demo/qml/FileTreeView2.qml @@ -3,82 +3,77 @@ import QtQml.Models 2.2 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 -Item { - anchors.fill: parent - - ListView { - id: view - property string title - anchors.fill: parent - header: Column { +ListView { + id: view + property string title + header: Column { + width: parent.width + ToolBar { width: parent.width - ToolBar { - width: parent.width - RowLayout { - anchors.fill: parent - ToolButton { - text: qsTr("‹") - enabled: dirModel.rootIndex.valid - onClicked: { - dirModel.rootIndex = dirModel.rootIndex.parent - } - } - Label { - text: view.title - elide: Label.ElideRight - horizontalAlignment: Qt.AlignHCenter - verticalAlignment: Qt.AlignVCenter - Layout.fillWidth: true + RowLayout { + anchors.fill: parent + ToolButton { + text: qsTr("‹") + enabled: dirModel.rootIndex.valid + onClicked: { + dirModel.rootIndex = dirModel.rootIndex.parent } } - } Row { - Text { - width: 200 - text: qsTr("Name") - } - Text { - text: qsTr("Size") + Label { + text: view.title + elide: Label.ElideRight + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + Layout.fillWidth: true } } + } Row { + Text { + width: 200 + text: qsTr("Name") + } + Text { + text: qsTr("Size") + } } - model: DelegateModel { - id: dirModel - model: sortedFileSystem - onRootIndexChanged: { - view.title = model.data(rootIndex) - } - delegate: Item { - width: parent.width - height: row.height - Row { - id: row - Button { - id: button - width: 200 - text: fileName - enabled: model.hasModelChildren - onClicked: { + } + model: DelegateModel { + id: dirModel + model: sortedFileSystem + onRootIndexChanged: { + view.title = model.data(rootIndex) + } + delegate: Item { + width: parent.width + height: row.height + Row { + id: row + Button { + id: button + width: 200 + text: fileName + enabled: model.hasModelChildren + onClicked: { + if (model.hasModelChildren) { + view.model.rootIndex = view.model.modelIndex(index) + } + } + Timer { + id: checkChildren + interval: 100 + running: true + repeat: true + onTriggered: { if (model.hasModelChildren) { - view.model.rootIndex = view.model.modelIndex(index) - } - } - Timer { - id: checkChildren - interval: 100 - running: true - repeat: true - onTriggered: { - if (model.hasModelChildren) { - button.enabled = true - checkChildren.stop() - } + button.enabled = true + checkChildren.stop() } } } - Label { - text: fileSize - padding: button.padding - } + } + Label { + text: fileSize + padding: button.padding } } }