From fecbfcea9311b56dc13bd4952cbfa0a507736c75 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen <erik.verbruggen@nokia.com> Date: Tue, 28 Sep 2010 11:55:30 +0200 Subject: [PATCH] QML: tweaked the generated extension plugin wizard. --- .../templates/wizards/qml-extension/object.cpp | 14 ++++++++++---- .../templates/wizards/qml-extension/object.h | 11 ++++++----- .../templates/wizards/qml-extension/plugin.cpp | 6 +++--- .../templates/wizards/qml-extension/plugin.h | 8 ++++---- .../templates/wizards/qml-extension/project.pro | 10 +++++----- .../templates/wizards/qml-extension/wizard.xml | 9 ++++----- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/share/qtcreator/templates/wizards/qml-extension/object.cpp b/share/qtcreator/templates/wizards/qml-extension/object.cpp index 78db2a4d3df..0f9ed3e7bb0 100644 --- a/share/qtcreator/templates/wizards/qml-extension/object.cpp +++ b/share/qtcreator/templates/wizards/qml-extension/object.cpp @@ -1,11 +1,17 @@ #include "%ObjectName:l%.%CppHeaderSuffix%" -#include <QtCore/QTime> #include <QtDeclarative/qdeclarative.h> -%ObjectName%::%ObjectName%(QObject *parent): - QObject(parent) +%ObjectName%::%ObjectName%(QDeclarativeItem *parent): + QDeclarativeItem(parent) { + // By default, QDeclarativeItem does not draw anything. If you subclass + // QDeclarativeItem to create a visual item, you will need to uncomment the + // following line: + + // setFlag(ItemHasNoContents, false); } -QML_DECLARE_TYPE(%ObjectName%); +%ObjectName%::~%ObjectName%() +{ +} diff --git a/share/qtcreator/templates/wizards/qml-extension/object.h b/share/qtcreator/templates/wizards/qml-extension/object.h index e4190443e44..054174b20e4 100644 --- a/share/qtcreator/templates/wizards/qml-extension/object.h +++ b/share/qtcreator/templates/wizards/qml-extension/object.h @@ -1,17 +1,18 @@ #ifndef %ObjectName:u%_H #define %ObjectName:u%_H -#include <QtCore/QObject> -#include <QtCore/QString> -#include <QtCore/QTimer> +#include <QtDeclarative/QDeclarativeItem> -class %ObjectName% : public QObject +class %ObjectName% : public QDeclarativeItem { Q_OBJECT Q_DISABLE_COPY(%ObjectName%) public: - %ObjectName%(QObject *parent = 0); + %ObjectName%(QDeclarativeItem *parent = 0); + ~%ObjectName%(); }; +QML_DECLARE_TYPE(%ObjectName%) + #endif // %ObjectName:u%_H diff --git a/share/qtcreator/templates/wizards/qml-extension/plugin.cpp b/share/qtcreator/templates/wizards/qml-extension/plugin.cpp index 0d97d3d2080..5e86f2463a1 100644 --- a/share/qtcreator/templates/wizards/qml-extension/plugin.cpp +++ b/share/qtcreator/templates/wizards/qml-extension/plugin.cpp @@ -1,11 +1,11 @@ -#include "%ProjectName:l%.%CppHeaderSuffix%" +#include "%ProjectName:l%_plugin.%CppHeaderSuffix%" #include "%ObjectName:l%.%CppHeaderSuffix%" #include <QtDeclarative/qdeclarative.h> -void %ProjectName%::registerTypes(const char *uri) +void %ProjectName%Plugin::registerTypes(const char *uri) { qmlRegisterType<%ObjectName%>(uri, 1, 0, "%ObjectName%"); } -Q_EXPORT_PLUGIN(%ProjectName%); +Q_EXPORT_PLUGIN2(%ProjectName%, %ProjectName%Plugin) diff --git a/share/qtcreator/templates/wizards/qml-extension/plugin.h b/share/qtcreator/templates/wizards/qml-extension/plugin.h index 1ae9c559ec9..8600532f3c2 100644 --- a/share/qtcreator/templates/wizards/qml-extension/plugin.h +++ b/share/qtcreator/templates/wizards/qml-extension/plugin.h @@ -1,9 +1,9 @@ -#ifndef %ProjectName:u%_H -#define %ProjectName:u%_H +#ifndef %ProjectName:u%_PLUGIN_H +#define %ProjectName:u%_PLUGIN_H #include <QtDeclarative/QDeclarativeExtensionPlugin> -class %ProjectName% : public QDeclarativeExtensionPlugin +class %ProjectName%Plugin : public QDeclarativeExtensionPlugin { Q_OBJECT @@ -11,4 +11,4 @@ public: void registerTypes(const char *uri); }; -#endif // %ProjectName:u%_H +#endif // %ProjectName:u%_PLUGIN_H diff --git a/share/qtcreator/templates/wizards/qml-extension/project.pro b/share/qtcreator/templates/wizards/qml-extension/project.pro index 800dbffdf88..e7f123beee6 100644 --- a/share/qtcreator/templates/wizards/qml-extension/project.pro +++ b/share/qtcreator/templates/wizards/qml-extension/project.pro @@ -1,5 +1,5 @@ TEMPLATE = lib -TARGET = %ProjectName% +TARGET = %ProjectName% QT += declarative CONFIG += qt plugin @@ -7,11 +7,11 @@ TARGET = $$qtLibraryTarget($$TARGET) # Input SOURCES += \ - %ProjectName:l%.%CppSourceSuffix% \ + %ProjectName:l%_plugin.%CppSourceSuffix% \ %ObjectName:l%.%CppSourceSuffix% -OTHER_FILES=qmldir - HEADERS += \ - %ProjectName:l%.%CppHeaderSuffix% \ + %ProjectName:l%_plugin.%CppHeaderSuffix% \ %ObjectName:l%.%CppHeaderSuffix% + +OTHER_FILES = qmldir diff --git a/share/qtcreator/templates/wizards/qml-extension/wizard.xml b/share/qtcreator/templates/wizards/qml-extension/wizard.xml index d6d1fdcb285..6f202f9574f 100644 --- a/share/qtcreator/templates/wizards/qml-extension/wizard.xml +++ b/share/qtcreator/templates/wizards/qml-extension/wizard.xml @@ -43,8 +43,8 @@ leave room for the Qt 4 target page. <displaycategory>QML Extension Plugin</displaycategory> <files> <file source="qmldir" target="qmldir"/> - <file source="plugin.h" target="%ProjectName:l%.%CppHeaderSuffix%"/> - <file source="plugin.cpp" target="%ProjectName:l%.%CppSourceSuffix%"/> + <file source="plugin.h" target="%ProjectName:l%_plugin.%CppHeaderSuffix%"/> + <file source="plugin.cpp" target="%ProjectName:l%_plugin.%CppSourceSuffix%"/> <file source="object.h" target="%ObjectName:l%.%CppHeaderSuffix%"/> <file source="object.cpp" target="%ObjectName:l%.%CppSourceSuffix%" openeditor="true"/> <file source="project.pro" target="%ProjectName:l%.pro" openproject="true"/> @@ -53,14 +53,13 @@ leave room for the Qt 4 target page. <fieldpagetitle>Custom QML Extension Plugin Parameters</fieldpagetitle> <fields> <field mandatory="false" name="ObjectName"> - <fieldcontrol class="QLineEdit" validator='^[A-Za-z0-9_]+$' defaulttext="ExampleObject"/> + <fieldcontrol class="QLineEdit" validator='^[A-Za-z0-9_]+$' defaulttext="MyItem"/> <fielddescription>Object Class-name:</fielddescription> </field> </fields> <validationrules> - <validationrule condition='"%ObjectName%" != "%ProjectName%"'> + <validationrule condition='"%ObjectName%" != "%ProjectName%_plugin"'> <message>The project name and the object class-name cannot be the same.</message> - <message xml:lang='nl'>De naam voor het project en de naam voor de klasse kunnen niet hetzelfde zijn.</message> </validationrule> </validationrules> </wizard> -- GitLab