Work around QPersistentModelIndex being a built-in meta-type

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>
This commit is contained in:
Gabriel de Dietrich 2015-03-05 12:30:58 +01:00
parent adaa3fc546
commit 7b29a983fa
1 changed files with 27 additions and 3 deletions

View 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()