From c380aeefbfa2cd1aa2d1d21f45101bfb058a40de Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 7 Apr 2010 14:01:07 +1000 Subject: Disallow creation of attached objects Keys and KeyNavigation Also adds qmlRegisterUncreatableType<>() to allow registration of named types that cannot be created. Task-number: QTBUG-9575 --- .../graphicsitems/qdeclarativeitemsmodule.cpp | 5 ++-- src/declarative/qml/qdeclarative.h | 32 ++++++++++++++++++++ src/declarative/util/qdeclarativeutilmodule.cpp | 34 +--------------------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 7989a27..35a4d00 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -101,8 +101,6 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType("Qt",4,6,"GridView"); qmlRegisterType("Qt",4,6,"Image"); qmlRegisterType("Qt",4,6,"Item"); - qmlRegisterType("Qt",4,6,"KeyNavigation"); - qmlRegisterType("Qt",4,6,"Keys"); qmlRegisterType("Qt",4,6,"LayoutItem"); qmlRegisterType("Qt",4,6,"ListView"); qmlRegisterType("Qt",4,6,"Loader"); @@ -151,4 +149,7 @@ void QDeclarativeItemModule::defineModule() #ifdef QT_WEBKIT_LIB qmlRegisterType(); #endif + + qmlRegisterUncreatableType("Qt",4,6,"KeyNavigation"); + qmlRegisterUncreatableType("Qt",4,6,"Keys"); } diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h index 7c7f6e5..6e36d4f 100644 --- a/src/declarative/qml/qdeclarative.h +++ b/src/declarative/qml/qdeclarative.h @@ -119,6 +119,38 @@ int qmlRegisterType() } template +int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) +{ + QByteArray name(T::staticMetaObject.className()); + + QByteArray pointerName(name + '*'); + QByteArray listName("QDeclarativeListProperty<" + name + ">"); + + QDeclarativePrivate::RegisterType type = { + 0, + + qRegisterMetaType(pointerName.constData()), + qRegisterMetaType >(listName.constData()), + 0, 0, + + uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, + + QDeclarativePrivate::attachedPropertiesFunc(), + QDeclarativePrivate::attachedPropertiesMetaObject(), + + QDeclarativePrivate::StaticCastSelector::cast(), + QDeclarativePrivate::StaticCastSelector::cast(), + QDeclarativePrivate::StaticCastSelector::cast(), + + 0, 0, + + 0 + }; + + return QDeclarativePrivate::registerType(type); +} + +template int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) { QByteArray name(T::staticMetaObject.className()); diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index d4c72bd..218a90b 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -71,38 +71,6 @@ #include "private/qdeclarativexmllistmodel_p.h" #endif -template -int qmlRegisterTypeEnums(const char *qmlName) -{ - QByteArray name(T::staticMetaObject.className()); - - QByteArray pointerName(name + '*'); - QByteArray listName("QDeclarativeListProperty<" + name + ">"); - - QDeclarativePrivate::RegisterType type = { - 0, - - qRegisterMetaType(pointerName.constData()), - qRegisterMetaType >(listName.constData()), - 0, 0, - - "Qt", 4, 6, qmlName, &T::staticMetaObject, - - QDeclarativePrivate::attachedPropertiesFunc(), - QDeclarativePrivate::attachedPropertiesMetaObject(), - - QDeclarativePrivate::StaticCastSelector::cast(), - QDeclarativePrivate::StaticCastSelector::cast(), - QDeclarativePrivate::StaticCastSelector::cast(), - - 0, 0, - - 0 - }; - - return QDeclarativePrivate::registerType(type); -} - void QDeclarativeUtilModule::defineModule() { qmlRegisterType("Qt",4,6,"AnchorAnimation"); @@ -142,7 +110,7 @@ void QDeclarativeUtilModule::defineModule() qmlRegisterType(); qmlRegisterType(); - qmlRegisterTypeEnums("Animation"); + qmlRegisterUncreatableType("Qt",4,6,"Animation"); qmlRegisterCustomType("Qt", 4,6, "ListModel", "QDeclarativeListModel", new QDeclarativeListModelParser); -- cgit v0.12