summaryrefslogtreecommitdiff
path: root/tests/auto/controls/data/treeview
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-01-07 12:07:28 +0100
committerGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-02-13 15:27:46 +0000
commit82c7760b819f73ebc7f4ba6203fa2fc92b383236 (patch)
treef5ae4743a45c43a4a95115679d3f1690a4a6268e /tests/auto/controls/data/treeview
parent6f15c206b069ed0fcf48a285bfcc4ad636927df0 (diff)
downloadqtquickcontrols-82c7760b819f73ebc7f4ba6203fa2fc92b383236.tar.gz
Introducing TreeView
The TreeView, as currently implemented, extends the TableView by adding support for hierarchical models. In the broad sense, it remains a list view with columns, like TableView. The main architecture is based on TreeModelAdaptor, that wraps the hierarchical model. It keeps track of which items are expanded or collapsed, and also relays model changes to the view. (TreeModelAdaptor is a private type and should be considered as an implementation detail.) The TreeView only supports QAbstractItemModels for the time being, and, just like TableView, relies on roles to pass the data to the view. This also means that model columns are not supported. Selection is supported by ItemSelectionModel which exposes part of the API of QItemSelectionModel. For this, support has been added for QModelIndex and related classes. This requires importing QtQml.Models 2.2 should an actual usage of the TreeView use selection. In the same way, TreeViewStyle currently extends TableViewStyle with the relevant features, like branch indicator. [ChangeLog][QtQuick.Controls] Introducing TreeView With-Help-From: Caroline Chao <caroline.chao@theqtcompany.com> Change-Id: Id3dba240a732744571e4a646b7b98678ab522da6 Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
Diffstat (limited to 'tests/auto/controls/data/treeview')
-rw-r--r--tests/auto/controls/data/treeview/treeview_1.qml76
-rw-r--r--tests/auto/controls/data/treeview/treeview_2.qml81
2 files changed, 157 insertions, 0 deletions
diff --git a/tests/auto/controls/data/treeview/treeview_1.qml b/tests/auto/controls/data/treeview/treeview_1.qml
new file mode 100644
index 00000000..29c2efdc
--- /dev/null
+++ b/tests/auto/controls/data/treeview/treeview_1.qml
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.4
+import QtQuick.Controls 1.4
+import QtQuick.Controls.Styles 1.4
+import QtQuickControlsTests 1.0
+
+TreeView {
+ width: 400
+ height: 400
+ model: TreeModel {}
+
+ TableViewColumn {
+ role: "display"
+ title: "Default"
+ width: 200
+ }
+
+ style: TreeViewStyle {
+ indentation: 20
+ rowDelegate: Rectangle {
+ color: styleData.selected? "blue" : styleData.alternate ? "red" : "yellow"
+ height: 50
+ width: parent.width
+ }
+ headerDelegate: Text {
+ text: styleData.value
+ height: 50
+ width: parent.width
+ }
+ itemDelegate: Text {
+ text: styleData.value
+ height: 50
+ width: parent.width
+ }
+ branchDelegate: Rectangle {
+ color: styleData.isExpanded? "purple" : "green"
+ height: 50
+ width: 20
+ }
+ }
+}
diff --git a/tests/auto/controls/data/treeview/treeview_2.qml b/tests/auto/controls/data/treeview/treeview_2.qml
new file mode 100644
index 00000000..f8c54028
--- /dev/null
+++ b/tests/auto/controls/data/treeview/treeview_2.qml
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.4
+import QtQuick.Controls 1.4
+import QtQuickControlsTests 1.0
+
+TreeView {
+ width: 500
+ height: 500
+ property var treeModel: TreeModel {}
+
+ model: treeModel
+
+ property int collapsedCount: 0
+ property int expandedCount: 0
+ property var signalArgIndex
+
+ TableViewColumn {
+ role: "display"
+ title: "Default"
+ width: 200
+ }
+ rowDelegate: Rectangle {
+ color: styleData.selected? "blue" : styleData.alternate ? "red" : "yellow"
+ height: 50
+ width: parent.width
+ }
+ headerDelegate: Text {
+ text: styleData.value
+ height: 50
+ width: parent.width
+ }
+ itemDelegate: Text {
+ text: styleData.value
+ height: 50
+ width: parent.width
+ }
+
+ onCollapsed: {
+ signalArgIndex = index
+ collapsedCount++
+ }
+ onExpanded: {
+ signalArgIndex = index
+ expandedCount++
+ }
+}