diff options
author | BogDan Vatra <bogdan@kdab.com> | 2016-03-18 17:08:29 +0200 |
---|---|---|
committer | Kevin Funk <kevin.funk@kdab.com> | 2016-03-21 08:42:49 +0000 |
commit | d49e5ab149eeec9c22a88a722ac1848139be016c (patch) | |
tree | 53e478769b3e31349b3fc74e733104633fc4b0b9 /examples | |
parent | d55ab71853e98bf6ad33ae99a16acd3d351a25ef (diff) |
Add QMLModelViewClient
ModelViewClient is based on QTreeView which iterates all the items when
scrolling or when we go at the end.
Change-Id: I8404be2b74cfa7ddaeff54178124de8cd1fbc40f
Reviewed-by: Continuous Integration (KDAB) <build@kdab.com>
Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'examples')
8 files changed, 201 insertions, 1 deletions
diff --git a/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro b/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro index c82fa34..76f7ab2 100644 --- a/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro +++ b/examples/RemoteObjects/ModelViewServer/ModelViewServer.pro @@ -2,6 +2,7 @@ QT += widgets remoteobjects TEMPLATE = app +CONFIG += c++11 SOURCES += main.cpp diff --git a/examples/RemoteObjects/ModelViewServer/main.cpp b/examples/RemoteObjects/ModelViewServer/main.cpp index 0f1342e..cb66567 100644 --- a/examples/RemoteObjects/ModelViewServer/main.cpp +++ b/examples/RemoteObjects/ModelViewServer/main.cpp @@ -126,6 +126,13 @@ int main(int argc, char *argv[]) list << QStringLiteral("FancyTextNumber %1").arg(i); } + // Needed by QMLModelViewClient + QHash<int,QByteArray> roleNames = { + {Qt::DisplayRole, "_text"}, + {Qt::BackgroundRole, "_color"} + }; + sourceModel.setItemRoleNames(roleNames); + QVector<int> roles; roles << Qt::DisplayRole << Qt::BackgroundRole; diff --git a/examples/RemoteObjects/QMLModelViewClient/QMLModelViewClient.pro b/examples/RemoteObjects/QMLModelViewClient/QMLModelViewClient.pro new file mode 100644 index 0000000..1db9adf --- /dev/null +++ b/examples/RemoteObjects/QMLModelViewClient/QMLModelViewClient.pro @@ -0,0 +1,14 @@ +TEMPLATE = app + +QT += qml quick remoteobjects +CONFIG += c++11 + +SOURCES += main.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) diff --git a/examples/RemoteObjects/QMLModelViewClient/deployment.pri b/examples/RemoteObjects/QMLModelViewClient/deployment.pri new file mode 100644 index 0000000..265ce71 --- /dev/null +++ b/examples/RemoteObjects/QMLModelViewClient/deployment.pri @@ -0,0 +1,13 @@ +unix:!android { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/examples/RemoteObjects/QMLModelViewClient/main.cpp b/examples/RemoteObjects/QMLModelViewClient/main.cpp new file mode 100644 index 0000000..23d6042 --- /dev/null +++ b/examples/RemoteObjects/QMLModelViewClient/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> +#include <QRemoteObjectNode> +#include <QAbstractItemReplica> + +int main(int argc, char *argv[]) +{ + QLoggingCategory::setFilterRules("qt.remoteobjects.debug=false\n" + "qt.remoteobjects.warning=false\n" + "qt.remoteobjects.models.debug=false\n" + "qt.remoteobjects.models.debug=false"); + + QGuiApplication app(argc, argv); + + QRemoteObjectNode node(QUrl(QStringLiteral("local:registry"))); + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("remoteModel", node.acquireModel(QStringLiteral("RemoteModel"))); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/examples/RemoteObjects/QMLModelViewClient/main.qml b/examples/RemoteObjects/QMLModelViewClient/main.qml new file mode 100644 index 0000000..31ba2b9 --- /dev/null +++ b/examples/RemoteObjects/QMLModelViewClient/main.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.5 +import QtQuick.Window 2.2 + +Window { + visible: true + width: 800 + height: 600 + Text { + id: dummy + } + + ListView { + id: view + anchors.fill: parent + focus: true + + currentIndex: 10 + + model: remoteModel + + snapMode: ListView.SnapToItem + highlightFollowsCurrentItem: true + highlightMoveDuration: 0 + + delegate: Rectangle { + width: view.width + height: dummy.font.pixelSize * 2 + color: _color + Text { + anchors.centerIn: parent + text: _text + } + } + Keys.onPressed: { + switch (event.key) { + case Qt.Key_Home: + view.currentIndex = 0; + break; + case Qt.Key_PageUp: + currentIndex -= Math.random() * 300; + if (currentIndex < 0) + currentIndex = 0; + break; + case Qt.Key_PageDown: + currentIndex += Math.random() * 300; + if (currentIndex >= count) + currentIndex = count - 1; + break; + case Qt.Key_End: + currentIndex = count - 1; + break; + } + } + } +} diff --git a/examples/RemoteObjects/QMLModelViewClient/qml.qrc b/examples/RemoteObjects/QMLModelViewClient/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/examples/RemoteObjects/QMLModelViewClient/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/examples/RemoteObjects/RemoteObjects.pro b/examples/RemoteObjects/RemoteObjects.pro index 35dc2d7..370c260 100644 --- a/examples/RemoteObjects/RemoteObjects.pro +++ b/examples/RemoteObjects/RemoteObjects.pro @@ -10,5 +10,6 @@ SUBDIRS = \ qtHaveModule(quick) { SUBDIRS += \ plugins \ - ClientApp + ClientApp \ + QMLModelViewClient } |