From 354559aa71df7525d7d8d941ceb72730a594c70d Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 13 Feb 2014 16:17:23 +0100 Subject: 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 Reviewed-by: Eike Ziller --- dist/changes-3.1.0 | 1 + .../projects/creator-projects-custom-wizards.qdoc | 4 +-- .../templates/wizards/bb-cascades-app/wizard.xml | 2 +- .../templates/wizards/codesnippet/wizard.xml | 2 +- .../templates/wizards/helloworld/wizard_sample.xml | 2 +- .../templates/wizards/plaincapp/qmake/wizard.xml | 2 +- .../templates/wizards/plaincppapp/qmake/wizard.xml | 2 +- .../templates/wizards/qtcreatorplugin/wizard.xml | 2 +- .../wizards/qtquick1-extension/wizard.xml | 2 +- .../wizards/qtquick2-extension/wizard.xml | 2 +- .../projectexplorer/customwizard/customwizard.cpp | 40 +++++++--------------- .../projectexplorer/customwizard/customwizard.h | 27 ++++++++++----- src/plugins/projectexplorer/projectexplorer.cpp | 5 +++ .../qmakeprojectmanagerplugin.cpp | 3 +- .../qmakeprojectmanager/wizards/qtwizard.cpp | 5 --- src/plugins/qmakeprojectmanager/wizards/qtwizard.h | 2 -- 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 \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 @@ **************************************************************************/ --> icon.png 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. --> Creates a qmake-based test project for which a code snippet can be entered. Code Snippet; 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. --> console.png Creates a hello-world-project with custom message. 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. --> ../common/console.png 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. --> ../common/console.png 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. --> qtcreator_logo_24.png 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. --> lib.png 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. --> lib.png 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 #include + +#include #include #include @@ -330,39 +332,23 @@ CustomWizard::CustomWizardContextPtr CustomWizard::context() const return d->m_context; } -// Static factory map -typedef QMap > 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 factories = ExtensionSystem::PluginManager::getObjects(); + 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 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 static void registerFactory(const QString &name) - { registerFactory(name, ICustomWizardFactoryPtr(new CustomWizardFactory)); } - // Create all wizards. As other plugins might register factories for derived // classes, call it in extensionsInitialized(). static QList 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(Core::IWizard::ProjectWizard)); + addAutoReleasedObject(new CustomWizardFactory(Core::IWizard::FileWizard)); + addAutoReleasedObject(new CustomWizardFactory(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 + (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(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; -- cgit v1.2.3