diff options
-rw-r--r-- | examples/models/quickcompletionmodel/main.qml | 92 | ||||
-rw-r--r-- | examples/models/quickcompletionmodel/quickcompletionmodel.qmlproject | 16 | ||||
-rw-r--r-- | src/imports/imports.pro | 2 | ||||
-rw-r--r-- | src/imports/models/models.pro | 21 | ||||
-rw-r--r-- | src/imports/models/plugin.cpp | 63 | ||||
-rw-r--r-- | src/imports/models/qmldir | 1 | ||||
-rw-r--r-- | src/imports/models/uiquickcompletionmodel.cpp | 118 | ||||
-rw-r--r-- | src/imports/models/uiquickcompletionmodel_p.h | 73 | ||||
-rw-r--r-- | sync.profile | 2 |
9 files changed, 386 insertions, 2 deletions
diff --git a/examples/models/quickcompletionmodel/main.qml b/examples/models/quickcompletionmodel/main.qml new file mode 100644 index 0000000..d25823c --- /dev/null +++ b/examples/models/quickcompletionmodel/main.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Playground.UiHelpers.Models 1.0 + +Rectangle { + id: root + + width: 200 + height: 400 + + CompletionModel { + id: completionModel + sourceModel: ["Recife", "New York", 4.5556, "Ha!", "NEW ORLEANS", "Hawaii", + "Ascension Island", "Andorra", "United Arab Emirates", "Afghanistan", + "Antigua and Barbuda", "Anguilla", "Albania", "Armenia", + "Netherlands Antilles", "Angola", "Antarctica", true] + modelSorting: CompletionModel.CaseSensitivelySortedModel + completionPrefix: input.text + caseSensitivity: Qt.CaseInsensitive + } + + Rectangle { + id: rec + anchors { + top: parent.top + left: parent.left + right: parent.right + } + color: "lightblue" + height: 30 + + TextInput { + id: input + anchors.fill: parent + focus: true + } + } + + ListView { + anchors { + top: rec.bottom + bottom: parent.bottom + left: parent.left + right: parent.right + topMargin: 10 + } + model: completionModel + delegate: Text { + text: modelData + } + } +} diff --git a/examples/models/quickcompletionmodel/quickcompletionmodel.qmlproject b/examples/models/quickcompletionmodel/quickcompletionmodel.qmlproject new file mode 100644 index 0000000..9039f50 --- /dev/null +++ b/examples/models/quickcompletionmodel/quickcompletionmodel.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "" + } + JavaScriptFiles { + directory: "" + } + ImageFiles { + directory: "" + } + /* List of plugin directories passed to QML runtime */ + //importPaths: [ "../../../src/imports/models/" ] +} 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 diff --git a/sync.profile b/sync.profile index 8118e58..05ede2e 100644 --- a/sync.profile +++ b/sync.profile @@ -9,7 +9,7 @@ "uiundogroup.h" => "UiUndoGroup", "uicompletionmodel.h" => "UiCompletionModel", "uifilesystemmodel.h" => "UiFileSystemModel", - "uistandarditemmodel.h" => "UiStandardModel", + "uistandarditemmodel.h" => "UiStandardItemModel", "uiaction.h" => "UiAction", "uiactiongroup.h" => "UiActionGroup", ); |