summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorBjörn Breitmeyer <bjoern.breitmeyer.ford@kdab.com>2015-03-05 13:00:17 +0100
committerBjörn Breitmeyer <bjoern.breitmeyer@kdab.com>2015-03-17 09:31:02 +0000
commit497d000d9f3243b393eada4f23dc703671c952e0 (patch)
treea87bd02fb397beb13423f85e80ba02190b14dc57 /examples
parent9df4ed194cbe76738c285439f809309d81559b25 (diff)
Added model view example.
Change-Id: Ia08f6abb05c66fe9739d0d353c6c470097890b70 Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/RemoteObjects/ModelViewClient/ModelViewClient.pro9
-rw-r--r--examples/RemoteObjects/ModelViewClient/main.cpp67
-rw-r--r--examples/RemoteObjects/ModelViewServer/ModelViewServer.pro9
-rw-r--r--examples/RemoteObjects/ModelViewServer/main.cpp128
-rw-r--r--examples/RemoteObjects/RemoteObjects.pro4
5 files changed, 216 insertions, 1 deletions
diff --git a/examples/RemoteObjects/ModelViewClient/ModelViewClient.pro b/examples/RemoteObjects/ModelViewClient/ModelViewClient.pro
new file mode 100644
index 0000000..be97787
--- /dev/null
+++ b/examples/RemoteObjects/ModelViewClient/ModelViewClient.pro
@@ -0,0 +1,9 @@
+SOURCES = main.cpp
+
+CONFIG -= app_bundle
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/RemoteObjects/ModelView
+INSTALLS += target
+
+QT += widgets remoteobjects
diff --git a/examples/RemoteObjects/ModelViewClient/main.cpp b/examples/RemoteObjects/ModelViewClient/main.cpp
new file mode 100644
index 0000000..7eecdd4
--- /dev/null
+++ b/examples/RemoteObjects/ModelViewClient/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QTableView>
+#include <QApplication>
+#include <QRemoteObjectNode>
+#include <QAbstractItemReplica>
+
+int main(int argc, char **argv)
+{
+
+ QLoggingCategory::setFilterRules("qt.remoteobjects.debug=false\n"
+ "qt.remoteobjects.warning=false"
+ "qt.remoteobjects.models.debug=false\n"
+ "qt.remoteobjects.models.debug=false\n");
+
+ QApplication app(argc, argv);
+
+
+
+ QRemoteObjectNode node = QRemoteObjectNode::createNodeConnectedToRegistry();
+ QTableView view;
+ view.setWindowTitle(QStringLiteral("RemoteView"));
+ view.resize(640,480);
+ view.setModel(node.acquireModel(QStringLiteral("RemoteModel")));
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro b/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro
new file mode 100644
index 0000000..c82fa34
--- /dev/null
+++ b/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro
@@ -0,0 +1,9 @@
+QT += widgets remoteobjects
+
+TEMPLATE = app
+
+
+SOURCES += main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/RemoteObjects/ModelViewServer
+INSTALLS += target
diff --git a/examples/RemoteObjects/ModelViewServer/main.cpp b/examples/RemoteObjects/ModelViewServer/main.cpp
new file mode 100644
index 0000000..d6cdc4f
--- /dev/null
+++ b/examples/RemoteObjects/ModelViewServer/main.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QTableView>
+#include <QApplication>
+#include <QRemoteObjectNode>
+#include <QTimer>
+#include <QStandardItemModel>
+#include <QStandardItem>
+
+
+struct TimerHandler : public QObject
+{
+ Q_OBJECT
+public:
+ QAbstractItemModel *model;
+public Q_SLOTS:
+ void changeData() {
+ Q_ASSERT(model);
+ Q_ASSERT(model->rowCount() > 50);
+ Q_ASSERT(model->columnCount() > 1);
+ for (int i = 10; i < 50; ++i)
+ model->setData(model->index(i, 1), QColor(Qt::blue), Qt::BackgroundRole);
+ }
+ void insertData() {
+ Q_ASSERT(model);
+ Q_ASSERT(model->rowCount() > 50);
+ Q_ASSERT(model->columnCount() > 1);
+ model->insertRows(2, 9);
+ for (int i = 2; i < 11; ++i) {
+ model->setData(model->index(i, 1), QColor(Qt::green), Qt::BackgroundRole);
+ model->setData(model->index(i, 1), QLatin1String("InsertedRow"), Qt::DisplayRole);
+ }
+ }
+ void removeData() {
+ model->removeRows(2, 4);
+ }
+
+ void moveData() {
+ model->moveRows(QModelIndex(), 2, 4, QModelIndex(), 10);
+ }
+};
+
+int main(int argc, char *argv[])
+{
+ QLoggingCategory::setFilterRules("qt.remoteobjects.debug=false\n"
+ "qt.remoteobjects.warning=false");
+ QApplication app(argc, argv);
+
+ const int modelSize = 100000;
+ QStringList list;
+ QStandardItemModel sourceModel;
+ QStringList hHeaderList;
+ hHeaderList << QStringLiteral("First Column with spacing") << QStringLiteral("Second Column with spacing");
+ sourceModel.setHorizontalHeaderLabels(hHeaderList);
+ list.reserve(modelSize);
+ for (int i = 0; i < modelSize; ++i) {
+ QStandardItem *firstItem = new QStandardItem(QStringLiteral("FancyTextNumber %1").arg(i));
+ QStandardItem *secondItem = new QStandardItem(QStringLiteral("FancyRow2TextNumber %1").arg(i));
+ if (i % 2 == 0)
+ firstItem->setBackground(Qt::red);
+ QList<QStandardItem*> row;
+ row << firstItem << secondItem;
+ sourceModel.appendRow(row);
+ list << QStringLiteral("FancyTextNumber %1").arg(i);
+ }
+
+ QVector<int> roles;
+ roles << Qt::DisplayRole << Qt::BackgroundRole;
+
+ qDebug() << "Creating registry host";
+ QRemoteObjectNode node = QRemoteObjectNode::createRegistryHostNode();
+
+ QRemoteObjectNode node2 = QRemoteObjectNode::createHostNodeConnectedToRegistry();
+ node2.enableRemoting(&sourceModel, QStringLiteral("RemoteModel"), roles);
+
+ QTableView view;
+ view.setWindowTitle(QStringLiteral("SourceView"));
+ view.setModel(&sourceModel);
+ view.show();
+ TimerHandler handler;
+ handler.model = &sourceModel;
+ QTimer::singleShot(5000, &handler, SLOT(changeData()));
+ QTimer::singleShot(10000, &handler, SLOT(insertData()));
+ QTimer::singleShot(12000, &handler, SLOT(removeData()));
+ QTimer::singleShot(13000, &handler, SLOT(moveData()));
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/RemoteObjects/RemoteObjects.pro b/examples/RemoteObjects/RemoteObjects.pro
index da12899..803048c 100644
--- a/examples/RemoteObjects/RemoteObjects.pro
+++ b/examples/RemoteObjects/RemoteObjects.pro
@@ -2,7 +2,9 @@ TEMPLATE = subdirs
CONFIG += debug_and_release ordered
SUBDIRS = \
server \
- CppClient
+ CppClient \
+ ModelViewClient \
+ ModelViewServer
qtHaveModule(quick) {
SUBDIRS += \