summaryrefslogtreecommitdiffstats
path: root/examples/tutorials/modelview
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tutorials/modelview')
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/1_readonly.pro17
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/main.cpp56
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.cpp70
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.h59
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/2_formatting.pro16
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/main.cpp56
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/mymodel.cpp112
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/mymodel.h56
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/3_changingmodel.pro16
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/main.cpp53
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/mymodel.cpp94
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/mymodel.h62
-rwxr-xr-xexamples/tutorials/modelview/4_headers/4_headers.pro16
-rwxr-xr-xexamples/tutorials/modelview/4_headers/main.cpp53
-rwxr-xr-xexamples/tutorials/modelview/4_headers/mymodel.cpp91
-rwxr-xr-xexamples/tutorials/modelview/4_headers/mymodel.h57
-rwxr-xr-xexamples/tutorials/modelview/5_edit/5_edit.pro18
-rwxr-xr-xexamples/tutorials/modelview/5_edit/main.cpp50
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mainwindow.cpp60
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mainwindow.h62
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mymodel.cpp101
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mymodel.h70
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/6_treeview.pro13
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/main.cpp50
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/mainwindow.cpp82
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/mainwindow.h66
-rwxr-xr-xexamples/tutorials/modelview/7_selections/7_selections.pro13
-rwxr-xr-xexamples/tutorials/modelview/7_selections/main.cpp50
-rwxr-xr-xexamples/tutorials/modelview/7_selections/mainwindow.cpp109
-rwxr-xr-xexamples/tutorials/modelview/7_selections/mainwindow.h65
-rwxr-xr-xexamples/tutorials/modelview/modelview.pro16
31 files changed, 1709 insertions, 0 deletions
diff --git a/examples/tutorials/modelview/1_readonly/1_readonly.pro b/examples/tutorials/modelview/1_readonly/1_readonly.pro
new file mode 100755
index 0000000000..8ef0bdca5e
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/1_readonly.pro
@@ -0,0 +1,17 @@
+TARGET = mv_readonly
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/1_readonly
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 1_readonly.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/1_readonly
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp
new file mode 100755
index 0000000000..fdde141b4c
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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]
+// main.cpp
+#include <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp
new file mode 100755
index 0000000000..9b5bdd7df2
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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]
+// mymodel.cpp
+#include "mymodel.h"
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+int MyModel::rowCount(const QModelIndex & /*parent*/) const
+{
+ return 2;
+}
+
+int MyModel::columnCount(const QModelIndex & /*parent*/) const
+{
+ return 3;
+}
+
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ return QString("Row%1, Column%2")
+ .arg(index.row() + 1)
+ .arg(index.column() +1);
+ }
+ return QVariant();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h
new file mode 100755
index 0000000000..f60546897a
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/mymodel.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 MYMODEL_H
+#define MYMODEL_H
+
+//! [Quoting ModelView Tutorial]
+// mymodel.h
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+//! [Quoting ModelView Tutorial]
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/2_formatting/2_formatting.pro b/examples/tutorials/modelview/2_formatting/2_formatting.pro
new file mode 100755
index 0000000000..f8babd5799
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/2_formatting.pro
@@ -0,0 +1,16 @@
+TARGET = mv_formatting
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/2_formatting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 2_formatting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/2_formatting
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/2_formatting/main.cpp b/examples/tutorials/modelview/2_formatting/main.cpp
new file mode 100755
index 0000000000..fdde141b4c
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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]
+// main.cpp
+#include <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp
new file mode 100755
index 0000000000..8363af9252
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QFont>
+#include <QBrush>
+#include "mymodel.h"
+#include <QDebug>
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+int MyModel::rowCount(const QModelIndex & /*parent */) const
+{
+ return 2;
+}
+
+int MyModel::columnCount(const QModelIndex & /*parent */) const
+{
+ return 3;
+}
+
+//! [Quoting ModelView Tutorial]
+// mymodel.cpp
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ int row = index.row();
+ int col = index.column();
+ // generate a log message when this method gets called
+ qDebug() << QString("row %1, col%2, role %3")
+ .arg(row).arg(col).arg(role);
+
+ switch(role){
+ case Qt::DisplayRole:
+ if (row == 0 && col == 1) return QString("<--left");
+ if (row == 1 && col == 1) return QString("right-->");
+
+ return QString("Row%1, Column%2")
+ .arg(row + 1)
+ .arg(col +1);
+ break;
+ case Qt::FontRole:
+ if (row == 0 && col == 0) //change font only for cell(0,0)
+ {
+ QFont boldFont;
+ boldFont.setBold(true);
+ return boldFont;
+ }
+ break;
+ case Qt::BackgroundRole:
+
+ if (row == 1 && col == 2) //change background only for cell(1,2)
+ {
+ QBrush redBackground(Qt::red);
+ return redBackground;
+ }
+ break;
+ case Qt::TextAlignmentRole:
+
+ if (row == 1 && col == 1) //change text alignment only for cell(1,1)
+ {
+ return Qt::AlignRight + Qt::AlignVCenter;
+ }
+ break;
+ case Qt::CheckStateRole:
+
+ if (row == 1 && col == 0) //add a checkbox to cell(1,0)
+ {
+ return Qt::Checked;
+ }
+ }
+ return QVariant();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/2_formatting/mymodel.h b/examples/tutorials/modelview/2_formatting/mymodel.h
new file mode 100755
index 0000000000..7ad876c1bf
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/mymodel.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro
new file mode 100755
index 0000000000..205571d4e1
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro
@@ -0,0 +1,16 @@
+TARGET = mv_changingmodel
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/3_changingmodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 3_changingmodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/3_changingmodel
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/3_changingmodel/main.cpp b/examples/tutorials/modelview/3_changingmodel/main.cpp
new file mode 100755
index 0000000000..8a4ab8f6ab
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+}
diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
new file mode 100755
index 0000000000..fa50005701
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QBrush>
+#include <QTime>
+#include "mymodel.h"
+
+//! [quoting mymodel_a]
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+// selectedCell = 0;
+ timer = new QTimer(this);
+ timer->setInterval(1000);
+ connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()));
+ timer->start();
+}
+//! [quoting mymodel_a]
+//-------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent */) const
+{
+ return 2;
+}
+
+//-------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent */) const
+{
+ return 3;
+}
+
+//-------------------------------------------------------
+//! [quoting mymodel_QVariant ]
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ int row = index.row();
+ int col = index.column();
+
+ if (role == Qt::DisplayRole)
+ {
+ if (row == 0 && col == 0)
+ {
+ return QTime::currentTime().toString();
+ }
+ }
+ return QVariant();
+}
+//! [quoting mymodel_QVariant ]
+//-------------------------------------------------------
+//! [quoting mymodel_b ]
+void MyModel::timerHit()
+{
+ //we identify the top left cell
+ QModelIndex topLeft = createIndex(0,0);
+ //emit a signal to make the view reread identified data
+ emit dataChanged(topLeft, topLeft);
+}
+//! [quoting mymodel_b ]
diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.h b/examples/tutorials/modelview/3_changingmodel/mymodel.h
new file mode 100755
index 0000000000..be59c59207
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/mymodel.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+#include <QTimer>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ QTimer *timer;
+private:
+ int selectedCell;
+private slots:
+ void timerHit();
+};
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/4_headers/4_headers.pro b/examples/tutorials/modelview/4_headers/4_headers.pro
new file mode 100755
index 0000000000..d3004e39d2
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/4_headers.pro
@@ -0,0 +1,16 @@
+TARGET = mv_headers
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/4_headers
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 4_headers.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/4_headers
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/4_headers/main.cpp b/examples/tutorials/modelview/4_headers/main.cpp
new file mode 100755
index 0000000000..c89829ab42
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+} \ No newline at end of file
diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp
new file mode 100755
index 0000000000..ee0e609228
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/mymodel.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 "mymodel.h"
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+//-------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent*/) const
+{
+ return 2;
+}
+
+//-------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent*/) const
+{
+ return 3;
+}
+
+//-------------------------------------------------------
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ return QString("Row%1, Column%2")
+ .arg(index.row() + 1)
+ .arg(index.column() +1);
+ }
+ return QVariant();
+}
+
+//! [quoting mymodel_c]
+QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ if (orientation == Qt::Horizontal) {
+ switch (section)
+ {
+ case 0:
+ return QString("first");
+ case 1:
+ return QString("second");
+ case 2:
+ return QString("third");
+ }
+ }
+ }
+ return QVariant();
+}
+//! [quoting mymodel_c]
diff --git a/examples/tutorials/modelview/4_headers/mymodel.h b/examples/tutorials/modelview/4_headers/mymodel.h
new file mode 100755
index 0000000000..5a185d92e4
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/mymodel.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+};
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/5_edit/5_edit.pro b/examples/tutorials/modelview/5_edit/5_edit.pro
new file mode 100755
index 0000000000..d2fb983a13
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/5_edit.pro
@@ -0,0 +1,18 @@
+TARGET = mv_edit
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ mymodel.cpp
+
+HEADERS += mainwindow.h \
+ mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/5_edit
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 5_edit.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/5_edit
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/5_edit/main.cpp b/examples/tutorials/modelview/5_edit/main.cpp
new file mode 100755
index 0000000000..75246f7dc7
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/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/tutorials/modelview/5_edit/mainwindow.cpp b/examples/tutorials/modelview/5_edit/mainwindow.cpp
new file mode 100755
index 0000000000..4b7e59a290
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mainwindow.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QTableView>
+#include "mainwindow.h"
+#include "mymodel.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ tableView = new QTableView(this);
+ setCentralWidget(tableView);
+ QAbstractTableModel *myModel = new MyModel(this);
+ tableView->setModel(myModel);
+
+ //transfer changes to the model to the window title
+ connect(myModel, SIGNAL(editCompleted(const QString &)), this, SLOT(setWindowTitle(const QString &)));
+}
+
+void MainWindow::showWindowTitle(const QString & title)
+{
+setWindowTitle(title);
+}
diff --git a/examples/tutorials/modelview/5_edit/mainwindow.h b/examples/tutorials/modelview/5_edit/mainwindow.h
new file mode 100755
index 0000000000..37303f8293
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mainwindow.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/QMainWindow>
+
+QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code
+class QTableView; //forward declaration
+QT_END_NAMESPACE
+
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTableView *tableView;
+public:
+ MainWindow(QWidget *parent = 0);
+public slots:
+ void showWindowTitle(const QString & title);
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp
new file mode 100755
index 0000000000..e5d20949b3
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mymodel.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 "mymodel.h"
+
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+//-----------------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent*/) const
+{
+ return ROWS;
+}
+
+//-----------------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent*/) const
+{
+ return COLS;
+}
+
+//-----------------------------------------------------------------
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ return m_gridData[index.row()][index.column()];
+ }
+ return QVariant();
+}
+
+//-----------------------------------------------------------------
+//! [quoting mymodel_e]
+bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role)
+{
+ if (role == Qt::EditRole)
+ {
+ //save value from editor to member m_gridData
+ m_gridData[index.row()][index.column()] = value.toString();
+ //for presentation purposes only: build and emit a joined string
+ QString result;
+ for(int row= 0; row < ROWS; row++)
+ {
+ for(int col= 0; col < COLS; col++)
+ {
+ result += m_gridData[row][col] + " ";
+ }
+ }
+ emit editCompleted( result );
+ }
+ return true;
+}
+//! [quoting mymodel_e]
+
+//-----------------------------------------------------------------
+//! [quoting mymodel_f]
+Qt::ItemFlags MyModel::flags(const QModelIndex & /*index*/) const
+{
+ return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ;
+}
+//! [quoting mymodel_f]
diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h
new file mode 100755
index 0000000000..ecfd58ef6b
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mymodel.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 MYMODEL_H
+#define MYMODEL_H
+
+//! [Quoting ModelView Tutorial]
+// mymodel.h
+#include <QAbstractTableModel>
+#include <QString>
+
+const int COLS= 3;
+const int ROWS= 2;
+
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
+ Qt::ItemFlags flags(const QModelIndex & index) const ;
+private:
+ QString m_gridData[ROWS][COLS]; //holds text entered into QTableView
+signals:
+ void editCompleted(const QString &);
+};
+//! [Quoting ModelView Tutorial]
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/6_treeview/6_treeview.pro b/examples/tutorials/modelview/6_treeview/6_treeview.pro
new file mode 100755
index 0000000000..63b43e06da
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/6_treeview.pro
@@ -0,0 +1,13 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/6_treeview/main.cpp b/examples/tutorials/modelview/6_treeview/main.cpp
new file mode 100755
index 0000000000..75246f7dc7
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/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/tutorials/modelview/6_treeview/mainwindow.cpp b/examples/tutorials/modelview/6_treeview/mainwindow.cpp
new file mode 100755
index 0000000000..0fa8da0ec4
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/mainwindow.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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/tutorials/modelview/6_treeview/mainwindow.h b/examples/tutorials/modelview/6_treeview/mainwindow.h
new file mode 100755
index 0000000000..6398485cda
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/mainwindow.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/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
diff --git a/examples/tutorials/modelview/7_selections/7_selections.pro b/examples/tutorials/modelview/7_selections/7_selections.pro
new file mode 100755
index 0000000000..5b01b0a190
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/7_selections.pro
@@ -0,0 +1,13 @@
+TARGET = mv_selections
+TEMPLATE = app
+SOURCES += main.cpp \
+ mainwindow.cpp
+HEADERS += mainwindow.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/7_selections
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 7_selections.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/7_selections
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/7_selections/main.cpp b/examples/tutorials/modelview/7_selections/main.cpp
new file mode 100755
index 0000000000..75246f7dc7
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/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/tutorials/modelview/7_selections/mainwindow.cpp b/examples/tutorials/modelview/7_selections/mainwindow.cpp
new file mode 100755
index 0000000000..3bd36d9df4
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/mainwindow.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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_a]
+#include <QTreeView>
+#include <QStandardItemModel>
+#include <QItemSelectionModel>
+#include "mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ treeView = new QTreeView(this);
+ setCentralWidget(treeView);
+ standardModel = new QStandardItemModel ;
+ QStandardItem *rootNode = standardModel->invisibleRootItem();
+
+
+ //defining a couple of items
+ QStandardItem *americaItem = new QStandardItem("America");
+ QStandardItem *mexicoItem = new QStandardItem("Canada");
+ QStandardItem *usaItem = new QStandardItem("USA");
+ QStandardItem *bostonItem = new QStandardItem("Boston");
+ QStandardItem *europeItem = new QStandardItem("Europe");
+ QStandardItem *italyItem = new QStandardItem("Italy");
+ QStandardItem *romeItem = new QStandardItem("Rome");
+ QStandardItem *veronaItem = new QStandardItem("Verona");
+
+ //building up the hierarchy
+ rootNode-> appendRow(americaItem);
+ rootNode-> appendRow(europeItem);
+ americaItem-> appendRow(mexicoItem);
+ americaItem-> appendRow(usaItem);
+ usaItem-> appendRow(bostonItem);
+ europeItem-> appendRow(italyItem);
+ italyItem-> appendRow(romeItem);
+ italyItem-> appendRow(veronaItem);
+
+ //register the model
+ treeView->setModel(standardModel);
+ treeView->expandAll();
+
+ //selection changes shall trigger a slot
+ QItemSelectionModel *selectionModel= treeView->selectionModel();
+ connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
+ this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));
+}
+//! [quoting modelview_a]
+
+//------------------------------------------------------------------------------------
+
+//! [quoting modelview_b]
+void MainWindow::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/)
+{
+ //get the text of the selected item
+ const QModelIndex index = treeView->selectionModel()->currentIndex();
+ QString selectedText = index.data(Qt::DisplayRole).toString();
+ //find out the hierarchy level of the selected item
+ int hierarchyLevel=1;
+ QModelIndex seekRoot = index;
+ while(seekRoot.parent() != QModelIndex())
+ {
+ seekRoot = seekRoot.parent();
+ hierarchyLevel++;
+ }
+ QString showString = QString("%1, Level %2").arg(selectedText)
+ .arg(hierarchyLevel);
+ setWindowTitle(showString);
+}
+//! [quoting modelview_b]
+
+
diff --git a/examples/tutorials/modelview/7_selections/mainwindow.h b/examples/tutorials/modelview/7_selections/mainwindow.h
new file mode 100755
index 0000000000..0a30dab085
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/mainwindow.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 <QtGui/QMainWindow>
+
+QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code
+class QTreeView; //forward declarations
+class QStandardItemModel;
+class QItemSelection;
+QT_END_NAMESPACE
+
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTreeView *treeView;
+ QStandardItemModel *standardModel;
+private slots:
+ void selectionChangedSlot(const QItemSelection & newSelection, const QItemSelection & oldSelection);
+public:
+ MainWindow(QWidget *parent = 0);
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/tutorials/modelview/modelview.pro b/examples/tutorials/modelview/modelview.pro
new file mode 100755
index 0000000000..45dc9c0612
--- /dev/null
+++ b/examples/tutorials/modelview/modelview.pro
@@ -0,0 +1,16 @@
+TEMPLATE = subdirs
+SUBDIRS = 1_readonly \
+ 2_formatting \
+ 3_changingmodel \
+ 4_headers \
+ 5_edit \
+ 6_treeview \
+ 7_selections
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS modelview.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)