summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCidorvan Leite <cidorvan.leite@openbossa.org>2012-05-17 10:28:15 -0300
committerLuis Gabriel Lima <luis.gabriel@openbossa.org>2012-05-21 18:59:04 +0200
commit26e9688af547488e404b364f8db81608b55cd267 (patch)
tree3a8a26498fdbc2a65d0b42a5ccd82294ec58f8e9
parent39b564fff58410eab4b3ec38d0515a6e4cf87179 (diff)
Added proxy model from QML model
This model will convert a QML model to QStandardItemModel format. Change-Id: I61c44d5e20b0302c408be23be1f97cd04b2745fa Reviewed-by: Luis Gabriel Lima <luis.gabriel@openbossa.org>
-rw-r--r--src/models/models.pri6
-rw-r--r--src/models/uiproxyqmlmodel.cpp104
-rw-r--r--src/models/uiproxyqmlmodel.h80
-rw-r--r--src/src.pro2
-rw-r--r--sync.profile1
5 files changed, 190 insertions, 3 deletions
diff --git a/src/models/models.pri b/src/models/models.pri
index c0eba60..4aae74f 100644
--- a/src/models/models.pri
+++ b/src/models/models.pri
@@ -9,11 +9,13 @@ HEADERS += \
$$PWD/uistandarditemmodel.h \
$$PWD/uistandarditemmodel_p.h \
$$PWD/uitextfilemodel.h \
- $$PWD/uitextfilemodel_p.h
+ $$PWD/uitextfilemodel_p.h \
+ $$PWD/uiproxyqmlmodel.h
SOURCES += \
$$PWD/uifilesystemmodel.cpp \
$$PWD/uifileinfogatherer.cpp \
$$PWD/uicompletionmodel.cpp \
$$PWD/uistandarditemmodel.cpp \
- $$PWD/uitextfilemodel.cpp
+ $$PWD/uitextfilemodel.cpp \
+ $$PWD/uiproxyqmlmodel.cpp
diff --git a/src/models/uiproxyqmlmodel.cpp b/src/models/uiproxyqmlmodel.cpp
new file mode 100644
index 0000000..991c028
--- /dev/null
+++ b/src/models/uiproxyqmlmodel.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** 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 QT_NO_PROXYQMLMODEL
+
+#include "uiproxyqmlmodel.h"
+#include <QtQml/private/qquicklistmodel_p.h>
+
+QT_BEGIN_NAMESPACE_UIHELPERS
+
+UiProxyQmlModel::UiProxyQmlModel(QObject *parent)
+ : UiStandardItemModel(parent)
+{
+}
+
+UiProxyQmlModel::ListType UiProxyQmlModel::setSource(const QVariant &sourceModel)
+{
+ clear();
+
+ if (sourceModel.type() == QVariant::List) {
+ createFromList(sourceModel.toList());
+ return ArrayList;
+ } else if (QQuickListModel *list = qvariant_cast<QQuickListModel*>(sourceModel)) {
+ createFromQuickList(list);
+ return QuickList;
+ }
+
+ return InvalidList;
+}
+
+void UiProxyQmlModel::createFromList(const QVariantList &list)
+{
+ QHash<int, QByteArray> roleNames;
+
+ roleNames[Qt::DisplayRole] = "display";
+ setRoleNames(roleNames);
+
+ foreach (const QVariant& var, list) {
+ UiStandardItem *item = new UiStandardItem();
+ item->setData(var, Qt::DisplayRole);
+ item->setFlags(Qt::ItemIsSelectable);
+ appendRow(item);
+ }
+}
+
+void UiProxyQmlModel::createFromQuickList(QQuickListModel *list)
+{
+ QHash<int, QByteArray> roleNames;
+
+ foreach (int role, list->roles())
+ roleNames[role] = list->toString(role).toAscii();
+ setRoleNames(roleNames);
+
+ for (int i = 0; i < list->count(); i++) {
+ UiStandardItem *item = new UiStandardItem();
+
+ foreach (int role, list->roles())
+ item->setData(list->data(i, role), role);
+ item->setFlags(Qt::ItemIsSelectable);
+ appendRow(item);
+ }
+}
+
+QT_END_NAMESPACE_UIHELPERS
+
+#endif // QT_NO_PROXYQMLMODEL
diff --git a/src/models/uiproxyqmlmodel.h b/src/models/uiproxyqmlmodel.h
new file mode 100644
index 0000000..42f5159
--- /dev/null
+++ b/src/models/uiproxyqmlmodel.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtGui 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 UIPROXYQMLMODEL_H
+#define UIPROXYQMLMODEL_H
+
+#ifndef QT_NO_PROXYQMLMODEL
+
+#include "uihelpersglobal.h"
+#include <UiStandardItemModel>
+
+QT_BEGIN_HEADER
+
+class QQuickListModel;
+
+QT_BEGIN_NAMESPACE_UIHELPERS
+
+class UIHELPERS_EXPORT UiProxyQmlModel : public UiStandardItemModel
+{
+public:
+ enum ListType {
+ InvalidList,
+ ArrayList,
+ QuickList
+ };
+
+ UiProxyQmlModel(QObject *parent = 0);
+
+ ListType setSource(const QVariant &sourceModel);
+
+protected:
+ void createFromList(const QVariantList &list);
+ void createFromQuickList(QQuickListModel *list);
+};
+
+QT_END_NAMESPACE_UIHELPERS
+
+QT_END_HEADER
+
+#endif // QT_NO_PROXYQMLMODEL
+#endif // UIPROXYQMLMODEL_H
diff --git a/src/src.pro b/src/src.pro
index 96157e4..11dcc0c 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -2,7 +2,7 @@ load(qt_module)
TARGET = UiHelpers
QPRO_PWD = $$PWD
-QT = core core-private gui gui-private
+QT = core core-private gui gui-private qml-private v8-private
CONFIG += module
MODULE_PRI = ../modules/qt_uihelpers.pri
diff --git a/sync.profile b/sync.profile
index e9703b0..82cf1ed 100644
--- a/sync.profile
+++ b/sync.profile
@@ -8,6 +8,7 @@
"uiundostack.h" => "UiUndoStack",
"uiundogroup.h" => "UiUndoGroup",
"uicompletionmodel.h" => "UiCompletionModel",
+ "uiproxyqmlmodel.h" => "UiProxyQmlModel",
"uifilesystemmodel.h" => "UiFileSystemModel",
"uitextfilemodel.h" => "UiTextFileModel",
"uistandarditemmodel.h" => "UiStandardItemModel",