aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvaluetype.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-01-15 19:46:56 +0100
committerCaroline Chao <caroline.chao@theqtcompany.com>2015-02-12 11:10:04 +0000
commit005931905af62fb354c012594f9420d0acabbee3 (patch)
tree400f3a3c34bf6c47f579199655575b0d2517aa98 /src/qml/qml/qqmlvaluetype.cpp
parentc5796292adf7cb7f2ce6f95fb83a9da89ecaa730 (diff)
Add Q_GADGET wrappers for QModelIndex & Co.
The complete list of types is, * QModelIndex * QModelIndexList * QPersistentModelIndex * QItemSelection * QItemSelectionRange These wrapper types follow the QQmlValueType conventions and allow us to expose the wrapped types without introducing meta-type changes. They also allow to customize the string type representation. We also extend QQmlValueTypeFactory to return the meta-object for those types. Finally, we add two-way meta-type conversion between QModelIndex and QPersistentModelIndex to get the same interoperability as in C++ when passing an object of one type to a function requir- ing an object of the other type. Change-Id: Iaa7089ea576c901f12715ffa21e4d94603d53755 Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlvaluetype.cpp')
-rw-r--r--src/qml/qml/qqmlvaluetype.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp
index be14eb44c2..1528ebda37 100644
--- a/src/qml/qml/qqmlvaluetype.cpp
+++ b/src/qml/qml/qqmlvaluetype.cpp
@@ -37,6 +37,7 @@
#include <private/qqmlglobal_p.h>
#include <QtCore/qdebug.h>
#include <private/qmetaobjectbuilder_p.h>
+#include <private/qqmlmodelindexvaluetype_p.h>
QT_BEGIN_NAMESPACE
@@ -61,6 +62,14 @@ QQmlValueTypeFactoryImpl::QQmlValueTypeFactoryImpl()
{
for (unsigned int ii = 0; ii < QVariant::UserType; ++ii)
valueTypes[ii] = 0;
+
+ // See types wrapped in qqmlmodelindexvaluetype_p.h
+ qRegisterMetaType<QModelIndexList>();
+ qRegisterMetaType<QPersistentModelIndex>();
+ qRegisterMetaType<QItemSelectionRange>();
+ qRegisterMetaType<QItemSelection>();
+ QMetaType::registerConverter<QModelIndex, QPersistentModelIndex>(&QQmlModelIndexValueType::toPersistentModelIndex);
+ QMetaType::registerConverter<QPersistentModelIndex, QModelIndex>(&QQmlPersistentModelIndexValueType::toModelIndex);
}
QQmlValueTypeFactoryImpl::~QQmlValueTypeFactoryImpl()
@@ -101,12 +110,23 @@ const QMetaObject *QQmlValueTypeFactoryImpl::metaObjectForMetaType(int t)
return &QQmlRectFValueType::staticMetaObject;
case QVariant::EasingCurve:
return &QQmlEasingValueType::staticMetaObject;
+ case QVariant::ModelIndex:
+ return &QQmlModelIndexValueType::staticMetaObject;
default:
if (const QMetaObject *mo = QQml_valueTypeProvider()->metaObjectForMetaType(t))
return mo;
break;
}
+ if (t == qMetaTypeId<QPersistentModelIndex>())
+ return &QQmlPersistentModelIndexValueType::staticMetaObject;
+ else if (t == qMetaTypeId<QModelIndexList>())
+ return &QQmlModelIndexListValueType::staticMetaObject;
+ else if (t == qMetaTypeId<QItemSelectionRange>())
+ return &QQmlItemSelectionRangeValueType::staticMetaObject;
+ else if (t == qMetaTypeId<QItemSelection>())
+ return &QQmlItemSelectionValueType::staticMetaObject;
+
QMetaType metaType(t);
if (metaType.flags() & QMetaType::IsGadget)
return metaType.metaObject();