diff options
author | Tobias Hunger <tobias.hunger@digia.com> | 2014-02-13 16:17:23 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@digia.com> | 2014-02-17 11:00:58 +0100 |
commit | 354559aa71df7525d7d8d941ceb72730a594c70d (patch) | |
tree | 48f15f9bc7ccc8a7a091342660dc231be63f0e1e | |
parent | 5bd4dd7a354ce349d22898069a8a8b0039e73b73 (diff) |
CustomWizard: Use object pool to find factories
Rename class type of CustomQmakeProjectWizard from "qt4project" to
"qmakeproject" and document that change in the manual and changes-3.1.0.
Also update all the in-tree xml files to that new class name.
Change-Id: I7a9ef914a429d68e7f37a2115c03fa81d7433398
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
16 files changed, 49 insertions, 54 deletions
diff --git a/dist/changes-3.1.0 b/dist/changes-3.1.0 index 6ededf8c44..0346ffb142 100644 --- a/dist/changes-3.1.0 +++ b/dist/changes-3.1.0 @@ -96,6 +96,7 @@ Platform Specific Linux Qt Support + * Custom wizards now use class "qmakeproject" instead of "qt4project" QNX * Added support for Python based pretty printers when debugging on devices diff --git a/doc/src/projects/creator-projects-custom-wizards.qdoc b/doc/src/projects/creator-projects-custom-wizards.qdoc index d4fc42504c..cc3fd89e74 100644 --- a/doc/src/projects/creator-projects-custom-wizards.qdoc +++ b/doc/src/projects/creator-projects-custom-wizards.qdoc @@ -113,7 +113,7 @@ \code <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="A.HelloWorld" category="B.CustomProjects"> \endcode @@ -127,7 +127,7 @@ \c class. \li \c class specifies the type of the project. This attribute is - optional. Use the value \c qt4project to add Qt 4 specific pages. + optional. Use the value \c qmakeproject to add Qt specific pages. \li \c firstpage specifies the place of the new page in the standard project wizard. The value 10 ensures that the custom page diff --git a/share/qtcreator/templates/wizards/bb-cascades-app/wizard.xml b/share/qtcreator/templates/wizards/bb-cascades-app/wizard.xml index a709153132..36d1eaaba7 100644 --- a/share/qtcreator/templates/wizards/bb-cascades-app/wizard.xml +++ b/share/qtcreator/templates/wizards/bb-cascades-app/wizard.xml @@ -31,7 +31,7 @@ **************************************************************************/ --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="Q.QnxBlackBerryCascadesApp" category="F.QtApplications" featuresRequired="QtSupport.Wizards.FeatureBlackBerry"> <icon>icon.png</icon> diff --git a/share/qtcreator/templates/wizards/codesnippet/wizard.xml b/share/qtcreator/templates/wizards/codesnippet/wizard.xml index 6a67b722f9..8d06f37814 100644 --- a/share/qtcreator/templates/wizards/codesnippet/wizard.xml +++ b/share/qtcreator/templates/wizards/codesnippet/wizard.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="Z.Snippet" category="H.QtProjects"> <description>Creates a qmake-based test project for which a code snippet can be entered.</description> <displayname>Code Snippet</displayname>; diff --git a/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml b/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml index 07a183da2d..bbac13bfdd 100644 --- a/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml +++ b/share/qtcreator/templates/wizards/helloworld/wizard_sample.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="A.HelloWorld" category="B.CustomProjects"> <icon>console.png</icon> <description>Creates a hello-world-project with custom message.</description> diff --git a/share/qtcreator/templates/wizards/plaincapp/qmake/wizard.xml b/share/qtcreator/templates/wizards/plaincapp/qmake/wizard.xml index da1c2d3dc7..0f470640c6 100644 --- a/share/qtcreator/templates/wizards/plaincapp/qmake/wizard.xml +++ b/share/qtcreator/templates/wizards/plaincapp/qmake/wizard.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="R.Plain C" category="I.Projects" featuresRequired="QtSupport.Wizards.FeatureQt"> <icon>../common/console.png</icon> diff --git a/share/qtcreator/templates/wizards/plaincppapp/qmake/wizard.xml b/share/qtcreator/templates/wizards/plaincppapp/qmake/wizard.xml index 9399f89f03..125cfaf122 100644 --- a/share/qtcreator/templates/wizards/plaincppapp/qmake/wizard.xml +++ b/share/qtcreator/templates/wizards/plaincppapp/qmake/wizard.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="R.Plain C++" category="I.Projects" featuresRequired="QtSupport.Wizards.FeatureQt"> <icon>../common/console.png</icon> diff --git a/share/qtcreator/templates/wizards/qtcreatorplugin/wizard.xml b/share/qtcreator/templates/wizards/qtcreatorplugin/wizard.xml index 5429154261..c292e93bd6 100644 --- a/share/qtcreator/templates/wizards/qtcreatorplugin/wizard.xml +++ b/share/qtcreator/templates/wizards/qtcreatorplugin/wizard.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="R.QtCreatorPlugin" category="G.Libraries" featuresRequired="QtSupport.Wizards.FeatureQt,QtSupport.Wizards.FeatureDesktop"> <icon>qtcreator_logo_24.png</icon> diff --git a/share/qtcreator/templates/wizards/qtquick1-extension/wizard.xml b/share/qtcreator/templates/wizards/qtquick1-extension/wizard.xml index ceabc68376..2a3d0a4405 100644 --- a/share/qtcreator/templates/wizards/qtquick1-extension/wizard.xml +++ b/share/qtcreator/templates/wizards/qtquick1-extension/wizard.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="QtQuick1ExtensionPlugin" category="G.Libraries" featuresRequired="QtSupport.Wizards.FeatureQtQuick,QtSupport.Wizards.FeatureQtQuick.1"> <icon>lib.png</icon> diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml b/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml index 6ee6464b81..d99dc5188e 100644 --- a/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml +++ b/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml @@ -35,7 +35,7 @@ The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and leave room for the Qt 4 target page. --> <wizard version="1" kind="project" - class="qt4project" firstpage="10" + class="qmakeproject" firstpage="10" id="QtQuick2ExtensionPlugin" category="G.Libraries" featuresRequired="QtSupport.Wizards.FeatureQtQuick,QtSupport.Wizards.FeatureQtQuick.2"> <icon>lib.png</icon> diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index eaccbc186f..472cc57f22 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -36,6 +36,8 @@ #include <coreplugin/icore.h> #include <coreplugin/messagemanager.h> + +#include <extensionsystem/pluginmanager.h> #include <utils/fileutils.h> #include <utils/qtcassert.h> @@ -330,39 +332,23 @@ CustomWizard::CustomWizardContextPtr CustomWizard::context() const return d->m_context; } -// Static factory map -typedef QMap<QString, QSharedPointer<ICustomWizardFactory> > CustomWizardFactoryMap; -Q_GLOBAL_STATIC(CustomWizardFactoryMap, customWizardFactoryMap) - -void CustomWizard::registerFactory(const QString &name, const ICustomWizardFactoryPtr &f) -{ - customWizardFactoryMap()->insert(name, f); -} - -CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p, const Core::IWizard::Data &b) +CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p, + const Core::IWizard::Data &b) { - CustomWizard * rc = 0; - if (p->klass.isEmpty()) { - // Use defaults for empty class names - switch (b.kind) { - case Core::IWizard::ProjectWizard: - rc = new CustomProjectWizard; - break; - case Core::IWizard::FileWizard: - case Core::IWizard::ClassWizard: - rc = new CustomWizard; - break; - } - } else { - // Look up class name in map - const CustomWizardFactoryMap::const_iterator it = customWizardFactoryMap()->constFind(p->klass); - if (it != customWizardFactoryMap()->constEnd()) - rc = it.value()->create(); + CustomWizard *rc = 0; + QList<ICustomWizardFactory *> factories = ExtensionSystem::PluginManager::getObjects<ICustomWizardFactory>(); + foreach (ICustomWizardFactory *tmp, factories) { + if ((p->klass.isEmpty() && b.kind == tmp->kind()) + || (!p->klass.isEmpty() && p->klass == tmp->klass())) { + rc = tmp->create(); + break; + } } if (!rc) { qWarning("Unable to create custom wizard for class %s.", qPrintable(p->klass)); return 0; } + rc->setData(b); rc->setParameters(p); return rc; diff --git a/src/plugins/projectexplorer/customwizard/customwizard.h b/src/plugins/projectexplorer/customwizard/customwizard.h index 1541fc0ff9..6153ae4ad7 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.h +++ b/src/plugins/projectexplorer/customwizard/customwizard.h @@ -55,17 +55,31 @@ namespace Internal { } // Documentation inside. -class ICustomWizardFactory +class ICustomWizardFactory : public QObject { + Q_OBJECT + public: - virtual CustomWizard *create(QObject *parent = 0) const = 0; - virtual ~ICustomWizardFactory() {} + ICustomWizardFactory(const QString &klass, Core::IWizard::WizardKind kind) : + m_klass(klass), m_kind(kind) + { } + + virtual CustomWizard *create() const = 0; + QString klass() const { return m_klass; } + int kind() const { return m_kind; } + +private: + QString m_klass; + Core::IWizard::WizardKind m_kind; }; // Convenience template to create wizard factory classes. template <class Wizard> class CustomWizardFactory : public ICustomWizardFactory { - CustomWizard *create(QObject * = 0) const { return new Wizard; } +public: + CustomWizardFactory(const QString &klass, Core::IWizard::WizardKind kind) : ICustomWizardFactory(klass, kind) { } + CustomWizardFactory(Core::IWizard::WizardKind kind) : ICustomWizardFactory(QString(), kind) { } + CustomWizard *create() const { return new Wizard; } }; // Documentation inside. @@ -87,11 +101,6 @@ public: Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; - // Register a factory for a derived custom widget - static void registerFactory(const QString &name, const ICustomWizardFactoryPtr &f); - template <class Wizard> static void registerFactory(const QString &name) - { registerFactory(name, ICustomWizardFactoryPtr(new CustomWizardFactory<Wizard>)); } - // Create all wizards. As other plugins might register factories for derived // classes, call it in extensionsInitialized(). static QList<CustomWizard*> createWizards(); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 6aa9329206..5132776aeb 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -30,6 +30,7 @@ #include "projectexplorer.h" #include "buildsteplist.h" +#include "customwizard/customwizard.h" #include "deployablefile.h" #include "deployconfiguration.h" #include "gcctoolchainfactories.h" @@ -394,6 +395,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(sessionManager, SIGNAL(sessionLoaded(QString)), this, SLOT(updateWelcomePage())); + addAutoReleasedObject(new CustomWizardFactory<CustomProjectWizard>(Core::IWizard::ProjectWizard)); + addAutoReleasedObject(new CustomWizardFactory<CustomWizard>(Core::IWizard::FileWizard)); + addAutoReleasedObject(new CustomWizardFactory<CustomWizard>(Core::IWizard::ClassWizard)); + d->m_proWindow = new ProjectWindow; addAutoReleasedObject(d->m_proWindow); diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp index fd8886f653..ba4c01e797 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp @@ -127,7 +127,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString addAutoReleasedObject(new TestWizard); addAutoReleasedObject(new CustomWidgetWizard); - CustomQmakeProjectWizard::registerSelf(); + addAutoReleasedObject(new CustomWizardFactory<CustomQmakeProjectWizard> + (QLatin1String("qmakeproject"), Core::IWizard::ProjectWizard)); addAutoReleasedObject(new QMakeStepFactory); addAutoReleasedObject(new MakeStepFactory); diff --git a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp index 9242263ee8..44fca1cb6c 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp @@ -151,11 +151,6 @@ bool CustomQmakeProjectWizard::postGenerateFiles(const QWizard *w, const Core::G return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage); } -void CustomQmakeProjectWizard::registerSelf() -{ - ProjectExplorer::CustomWizard::registerFactory<CustomQmakeProjectWizard>(QLatin1String("qt4project")); -} - // ----------------- BaseQmakeProjectWizardDialog BaseQmakeProjectWizardDialog::BaseQmakeProjectWizardDialog(bool showModulesPage, QWidget *parent, const Core::WizardDialogParameters ¶meters) : diff --git a/src/plugins/qmakeprojectmanager/wizards/qtwizard.h b/src/plugins/qmakeprojectmanager/wizards/qtwizard.h index 53548335c2..5d08d38da6 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtwizard.h +++ b/src/plugins/qmakeprojectmanager/wizards/qtwizard.h @@ -91,8 +91,6 @@ class CustomQmakeProjectWizard : public ProjectExplorer::CustomProjectWizard public: CustomQmakeProjectWizard(); - static void registerSelf(); - private: QWizard *createWizardDialog(QWidget *parent, const Core::WizardDialogParameters &wizardDialogParameters) const; |