summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-02-01 05:00:28 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-02-01 05:00:28 (GMT)
commit6c51b1c9e456f39d4e75303fe74d348e7f859e1b (patch)
tree5c7bcd5a6c4fe009a6ee7b6ef625d3f643dc1347 /src/declarative/qml
parent7e85c6dc7ba0aaa6dfcad40dc0e9df0e2adb3741 (diff)
downloadQt-6c51b1c9e456f39d4e75303fe74d348e7f859e1b.zip
Qt-6c51b1c9e456f39d4e75303fe74d348e7f859e1b.tar.gz
Qt-6c51b1c9e456f39d4e75303fe74d348e7f859e1b.tar.bz2
Don't use statics for type definition, at least for plugin modules.
Task-number: QT-2798
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlengine.cpp4
-rw-r--r--src/declarative/qml/qmlmoduleplugin.cpp26
-rw-r--r--src/declarative/qml/qmlmoduleplugin.h8
3 files changed, 35 insertions, 3 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index b3ac1bb..a33aea7 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -1234,8 +1234,10 @@ public:
QFactoryLoader *l = loader();
QmlModuleFactoryInterface *factory =
qobject_cast<QmlModuleFactoryInterface*>(l->instance(uri));
- if (factory)
+ if (factory) {
+ factory->defineModuleOnce(uri);
isbuiltin = true;
+ }
} else {
url = base.resolved(QUrl(url)).toString();
}
diff --git a/src/declarative/qml/qmlmoduleplugin.cpp b/src/declarative/qml/qmlmoduleplugin.cpp
index 3346ec7..2f2cb25 100644
--- a/src/declarative/qml/qmlmoduleplugin.cpp
+++ b/src/declarative/qml/qmlmoduleplugin.cpp
@@ -59,11 +59,12 @@ QT_BEGIN_NAMESPACE
exporting the class with the Q_EXPORT_PLUGIN2() macro. See \l{How
to Create Qt Plugins} for details.
- The plugin should register QML types with QML_DEFINE_TYPE.
-
The strings returned by keys() should be the list of URIs of modules
that the plugin registers.
+ The plugin should register QML types with qmlRegisterType() when the
+ defineModule() method is called.
+
\sa examples/declarative/plugins
*/
@@ -86,4 +87,25 @@ QmlModulePlugin::~QmlModulePlugin()
{
}
+/*!
+ \fn void QmlModulePlugin::defineModule(const QString& uri)
+
+ Subclasses must override this function to register types
+ of the module \a uri, which will be one of the strings returned by keys().
+
+ The plugin registers QML types with qmlRegisterType():
+
+ \code
+ qmlRegisterType<MyClass>("com.nokia.MyModule", 1, 0, "MyType", "MyClass");
+ \endcode
+*/
+
+void QmlModulePlugin::defineModuleOnce(const QString& uri)
+{
+ if (!defined.contains(uri)) {
+ defined += uri;
+ defineModule(uri);
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlmoduleplugin.h b/src/declarative/qml/qmlmoduleplugin.h
index 315209d..384e05e 100644
--- a/src/declarative/qml/qmlmoduleplugin.h
+++ b/src/declarative/qml/qmlmoduleplugin.h
@@ -45,6 +45,7 @@
#include <QtCore/qplugin.h>
#include <QtCore/qfactoryinterface.h>
#include <QtCore/qlist.h>
+#include <QtCore/qset.h>
#include <QtCore/qbytearray.h>
QT_BEGIN_HEADER
@@ -55,6 +56,7 @@ QT_MODULE(Declarative)
struct Q_DECLARATIVE_EXPORT QmlModuleFactoryInterface : public QFactoryInterface
{
+ virtual void defineModuleOnce(const QString& uri) = 0;
};
#define QmlModuleFactoryInterface_iid "com.nokia.Qt.QmlModuleFactoryInterface"
@@ -69,6 +71,12 @@ class Q_DECLARATIVE_EXPORT QmlModulePlugin : public QObject, public QmlModuleFac
public:
explicit QmlModulePlugin(QObject *parent = 0);
~QmlModulePlugin();
+
+ virtual void defineModule(const QString& uri) = 0;
+
+private:
+ void defineModuleOnce(const QString& uri);
+ QSet<QString> defined;
};
QT_END_NAMESPACE