summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tutorials/modelview/6_treeview
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/tutorials/modelview/6_treeview')
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/6_treeview.desktop11
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro15
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/main.cpp50
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp82
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/mainwindow.h66
5 files changed, 224 insertions, 0 deletions
diff --git a/examples/widgets/tutorials/modelview/6_treeview/6_treeview.desktop b/examples/widgets/tutorials/modelview/6_treeview/6_treeview.desktop
new file mode 100644
index 0000000000..e0b872bf9c
--- /dev/null
+++ b/examples/widgets/tutorials/modelview/6_treeview/6_treeview.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=6 Model View
+Exec=/opt/usr/bin/6_treeview
+Icon=6_treeview
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro b/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro
new file mode 100644
index 0000000000..21ea5d9552
--- /dev/null
+++ b/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro
@@ -0,0 +1,15 @@
+TARGET = mv_tree
+TEMPLATE = app
+SOURCES += main.cpp \
+ mainwindow.cpp
+HEADERS += mainwindow.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/6_treeview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 6_treeview.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/6_treeview
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/tutorials/modelview/6_treeview/main.cpp b/examples/widgets/tutorials/modelview/6_treeview/main.cpp
new file mode 100644
index 0000000000..0e10352554
--- /dev/null
+++ b/examples/widgets/tutorials/modelview/6_treeview/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp
new file mode 100644
index 0000000000..aea18c11d6
--- /dev/null
+++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [Quoting ModelView Tutorial]
+// modelview.cpp
+#include <QTreeView>
+#include <QStandardItemModel>
+#include <QStandardItem>
+#include "mainwindow.h"
+
+
+const int ROWS = 2;
+const int COLUMNS = 3;
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ treeView = new QTreeView(this);
+ setCentralWidget(treeView);
+ standardModel = new QStandardItemModel ;
+
+ QList<QStandardItem *> preparedRow =prepareRow("first", "second", "third");
+ QStandardItem *item = standardModel->invisibleRootItem();
+ // adding a row to the invisible root item produces a root element
+ item->appendRow(preparedRow);
+
+ QList<QStandardItem *> secondRow =prepareRow("111", "222", "333");
+ // adding a row to an item starts a subtree
+ preparedRow.first()->appendRow(secondRow);
+
+ treeView->setModel(standardModel);
+ treeView->expandAll();
+}
+
+QList<QStandardItem *> MainWindow::prepareRow(const QString &first,
+ const QString &second,
+ const QString &third)
+{
+ QList<QStandardItem *> rowItems;
+ rowItems << new QStandardItem(first);
+ rowItems << new QStandardItem(second);
+ rowItems << new QStandardItem(third);
+ return rowItems;
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
new file mode 100644
index 0000000000..aab299ca6f
--- /dev/null
+++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtWidgets/QMainWindow>
+
+QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code
+class QTreeView; //forward declarations
+class QStandardItemModel;
+class QStandardItem;
+QT_END_NAMESPACE
+
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTreeView *treeView;
+ QStandardItemModel *standardModel;
+ QList<QStandardItem *> prepareRow( const QString &first,
+ const QString &second,
+ const QString &third );
+public:
+ MainWindow(QWidget *parent = 0);
+};
+
+#endif // MAINWINDOW_H