summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLuis Gabriel Lima <luis.gabriel@openbossa.org>2012-04-02 18:23:51 -0300
committerAnselmo L. S. Melo <anselmo.melo@openbossa.org>2012-04-10 18:14:48 +0200
commitc3b707cc1182031148501ee1959b48b6af938543 (patch)
tree82545be9081d8ed0aa0324c4da092dc628e14068 /src
parent1bc52a21b374202c52bf239c246a17950a304f02 (diff)
Completion model QML API bootstrap
This patch introduces a QML-friendy API to the UiCompletionModel. For now it is accepting just JS lists as models. Each element in the JS list is converted to string and then passed to the completion model. The plan is to make this element accept also other kind of models such as ListModel, XMLListModel and C++ models in general. There is an example in 'examples/models/quickcompletionmodel'. Change-Id: Ia2c77fe778b6356cacf80bac78fabb2edd350f6e Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
Diffstat (limited to 'src')
-rw-r--r--src/imports/imports.pro2
-rw-r--r--src/imports/models/models.pro21
-rw-r--r--src/imports/models/plugin.cpp63
-rw-r--r--src/imports/models/qmldir1
-rw-r--r--src/imports/models/uiquickcompletionmodel.cpp118
-rw-r--r--src/imports/models/uiquickcompletionmodel_p.h73
6 files changed, 277 insertions, 1 deletions
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
index 6abb48b..9818f86 100644
--- a/src/imports/imports.pro
+++ b/src/imports/imports.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
-SUBDIRS += undo
+SUBDIRS += undo models
diff --git a/src/imports/models/models.pro b/src/imports/models/models.pro
new file mode 100644
index 0000000..da65bc2
--- /dev/null
+++ b/src/imports/models/models.pro
@@ -0,0 +1,21 @@
+TEMPLATE = lib
+TARGET = qmlmodelsplugin
+TARGETPATH = Playground/UiHelpers/Models
+
+QT += qml uihelpers
+
+CONFIG += qt plugin
+
+SOURCES += plugin.cpp
+
+SOURCES += uiquickcompletionmodel.cpp
+
+HEADERS += uiquickcompletionmodel_p.h
+
+DESTDIR = $$QT.qml.imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+INSTALLS += target qmldir
diff --git a/src/imports/models/plugin.cpp b/src/imports/models/plugin.cpp
new file mode 100644
index 0000000..e6f51c8
--- /dev/null
+++ b/src/imports/models/plugin.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+#include "uiquickcompletionmodel_p.h"
+
+class QmlModelsPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+
+public:
+ virtual void registerTypes(const char* uri);
+};
+
+void QmlModelsPlugin::registerTypes(const char* uri)
+{
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Playground.UiHelpers.Models"));
+
+ qmlRegisterType<UiQuickCompletionModel>(uri, 1, 0, "CompletionModel");
+}
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(qmlmodelsplugin, QT_PREPEND_NAMESPACE(QmlModelsPlugin))
diff --git a/src/imports/models/qmldir b/src/imports/models/qmldir
new file mode 100644
index 0000000..9e4d18c
--- /dev/null
+++ b/src/imports/models/qmldir
@@ -0,0 +1 @@
+plugin qmlmodelsplugin
diff --git a/src/imports/models/uiquickcompletionmodel.cpp b/src/imports/models/uiquickcompletionmodel.cpp
new file mode 100644
index 0000000..1cc4b0a
--- /dev/null
+++ b/src/imports/models/uiquickcompletionmodel.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "uiquickcompletionmodel_p.h"
+
+#include <UiHelpers/UiStandardItemModel>
+
+class WrapperModel : public UiStandardItemModel
+{
+public:
+ enum WrapperRoles { ModelDataRole };
+
+ WrapperModel() {
+ QHash<int, QByteArray> roleNames;
+ roleNames[WrapperModel::ModelDataRole] = "modelData";
+ setRoleNames(roleNames);
+ }
+};
+
+
+class UiQuickCompletionModelPrivate
+{
+ Q_DECLARE_PUBLIC(UiQuickCompletionModel)
+
+public:
+ UiQuickCompletionModelPrivate(UiQuickCompletionModel *q);
+ ~UiQuickCompletionModelPrivate();
+
+ UiQuickCompletionModel *q_ptr;
+ QVariant source;
+};
+
+UiQuickCompletionModelPrivate::UiQuickCompletionModelPrivate(UiQuickCompletionModel *q)
+ : q_ptr(q)
+{
+}
+
+UiQuickCompletionModelPrivate::~UiQuickCompletionModelPrivate()
+{
+}
+
+
+UiQuickCompletionModel::UiQuickCompletionModel(QObject *parent)
+ : UiCompletionModel(parent)
+ , d_ptr(new UiQuickCompletionModelPrivate(this))
+{
+}
+
+UiQuickCompletionModel::~UiQuickCompletionModel()
+{
+}
+
+QVariant UiQuickCompletionModel::source() const
+{
+ Q_D(const UiQuickCompletionModel);
+ return d->source;
+}
+
+void UiQuickCompletionModel::setSource(const QVariant& source)
+{
+ Q_D(UiQuickCompletionModel);
+ if (source == d->source)
+ return;
+
+ if (source.type() == QVariant::List) {
+ WrapperModel *wrapper = new WrapperModel();
+ foreach (const QVariant& var, source.toList()) {
+ UiStandardItem *item = new UiStandardItem();
+ item->setData(var.toString(), WrapperModel::ModelDataRole);
+ item->setFlags(Qt::ItemIsSelectable);
+ wrapper->appendRow(item);
+ }
+
+ setSourceModel(wrapper);
+ setCompletionRole(WrapperModel::ModelDataRole);
+ }
+
+ d->source = source;
+ emit sourceModelChanged();
+}
diff --git a/src/imports/models/uiquickcompletionmodel_p.h b/src/imports/models/uiquickcompletionmodel_p.h
new file mode 100644
index 0000000..f83b2a6
--- /dev/null
+++ b/src/imports/models/uiquickcompletionmodel_p.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef UIQUICKCOMPLETIONMODEL_H
+#define UIQUICKCOMPLETIONMODEL_H
+
+#include <UiHelpers/UiCompletionModel>
+
+QT_USE_NAMESPACE_UIHELPERS;
+
+class UiQuickCompletionModelPrivate;
+class UiQuickCompletionModel : public UiCompletionModel
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QVariant sourceModel READ source WRITE setSource NOTIFY sourceModelChanged)
+
+public:
+ UiQuickCompletionModel(QObject *parent = 0);
+ ~UiQuickCompletionModel();
+
+ QVariant source() const;
+ void setSource(const QVariant &source);
+
+Q_SIGNALS:
+ void sourceModelChanged();
+
+private:
+ Q_DISABLE_COPY(UiQuickCompletionModel)
+ Q_DECLARE_PRIVATE(UiQuickCompletionModel)
+
+ QScopedPointer<UiQuickCompletionModelPrivate> d_ptr;
+};
+
+#endif