Work around QPersistentModelIndex being a built-in meta-type
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Thu, 5 Mar 2015 11:30:58 +0000 (12:30 +0100)
committerGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Thu, 5 Mar 2015 14:04:24 +0000 (14:04 +0000)
This is a temporary work-around and will be removed once
I63d733d1eb66aa61691e7afce27fe7372a83ac00 is merged in qtbase.

Change-Id: I6cfcf1ddc2c9d408c26c171be865d40141de7fa0
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
src/qml/qml/qqmlvaluetype.cpp

index 1528ebd..d3142af 100644 (file)
@@ -58,6 +58,30 @@ struct QQmlValueTypeFactoryImpl
     QMutex mutex;
 };
 
+
+namespace {
+// This should be removed once the QPersistentModelIndex as built-in type is merged in qtbase
+#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
+#error Please, someone remove this. QPersistentModelIndex should be a built-in meta-type by now.
+#else
+template <typename T, bool builtin = QMetaTypeId2<T>::IsBuiltIn>
+struct QPMIConvertersRegistrer {
+    void registerConverters()
+    {
+    }
+};
+
+template <typename T> struct QPMIConvertersRegistrer<T, false> {
+    void registerConverters()
+    {
+        qRegisterMetaType<QPersistentModelIndex>();
+        QMetaType::registerConverter<QModelIndex, QPersistentModelIndex>(&QQmlModelIndexValueType::toPersistentModelIndex);
+        QMetaType::registerConverter<QPersistentModelIndex, QModelIndex>(&QQmlPersistentModelIndexValueType::toModelIndex);
+    }
+};
+#endif
+}
+
 QQmlValueTypeFactoryImpl::QQmlValueTypeFactoryImpl()
 {
     for (unsigned int ii = 0; ii < QVariant::UserType; ++ii)
@@ -65,11 +89,11 @@ QQmlValueTypeFactoryImpl::QQmlValueTypeFactoryImpl()
 
     // 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);
+
+    QPMIConvertersRegistrer<QPersistentModelIndex> conv;
+    conv.registerConverters();
 }
 
 QQmlValueTypeFactoryImpl::~QQmlValueTypeFactoryImpl()