From 09d9ce27ab9ac29aaa36c6d54fe89064dfcde69f Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 21 Jul 2015 17:07:14 +0200 Subject: TreeView: Add rootIndex property Its purpose is the same as QAbstractItemView::rootIndex and allows to display only the part of the model data that is descendant of this index. The filesystembrowser example has been updated to only show files reachable from the user's home directory. [ChangeLog][TreeView] Added rootIndex property Change-Id: Ib8d9af4ce9d1f341ab509de3cc991773830ba9f4 Reviewed-by: Friedemann Kleint Reviewed-by: Mitch Curtis --- examples/quick/controls/filesystembrowser/main.cpp | 1 + examples/quick/controls/filesystembrowser/main.qml | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'examples/quick') diff --git a/examples/quick/controls/filesystembrowser/main.cpp b/examples/quick/controls/filesystembrowser/main.cpp index 176d334c4..1322bc497 100644 --- a/examples/quick/controls/filesystembrowser/main.cpp +++ b/examples/quick/controls/filesystembrowser/main.cpp @@ -137,6 +137,7 @@ int main(int argc, char *argv[]) fsm->setRootPath(QDir::homePath()); fsm->setResolveSymlinks(true); engine.rootContext()->setContextProperty("fileSystemModel", fsm); + engine.rootContext()->setContextProperty("rootPathIndex", fsm->index(fsm->rootPath())); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); return app.exec(); diff --git a/examples/quick/controls/filesystembrowser/main.qml b/examples/quick/controls/filesystembrowser/main.qml index abc3c20cd..b85002d5e 100644 --- a/examples/quick/controls/filesystembrowser/main.qml +++ b/examples/quick/controls/filesystembrowser/main.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.2 -import QtQuick.Controls 1.4 +import QtQuick.Controls 1.5 import QtQml.Models 2.2 ApplicationWindow { @@ -90,6 +90,7 @@ ApplicationWindow { anchors.fill: parent anchors.margins: 2 * 12 + row.height model: fileSystemModel + rootIndex: rootPathIndex selection: sel TableViewColumn { @@ -103,12 +104,14 @@ ApplicationWindow { role: "size" resizable: true horizontalAlignment : Text.AlignRight + width: 70 } TableViewColumn { title: "Permissions" role: "displayableFilePermissions" resizable: true + width: 100 } TableViewColumn { @@ -117,7 +120,6 @@ ApplicationWindow { resizable: true } - onDoubleClicked: isExpanded(index) ? collapse(index) : expand(index) onActivated : Qt.openUrlExternally(fileSystemModel.data(index, 263)) } } -- cgit v1.2.3