forked from qt-creator/qt-creator
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>
This commit is contained in:
1
dist/changes-3.1.0
vendored
1
dist/changes-3.1.0
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p,
|
||||
const Core::IWizard::Data &b)
|
||||
{
|
||||
customWizardFactoryMap()->insert(name, f);
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
// Look up class name in map
|
||||
const CustomWizardFactoryMap::const_iterator it = customWizardFactoryMap()->constFind(p->klass);
|
||||
if (it != customWizardFactoryMap()->constEnd())
|
||||
rc = it.value()->create();
|
||||
}
|
||||
if (!rc) {
|
||||
qWarning("Unable to create custom wizard for class %s.", qPrintable(p->klass));
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc->setData(b);
|
||||
rc->setParameters(p);
|
||||
return rc;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) :
|
||||
|
||||
@@ -91,8 +91,6 @@ class CustomQmakeProjectWizard : public ProjectExplorer::CustomProjectWizard
|
||||
public:
|
||||
CustomQmakeProjectWizard();
|
||||
|
||||
static void registerSelf();
|
||||
|
||||
private:
|
||||
QWizard *createWizardDialog(QWidget *parent,
|
||||
const Core::WizardDialogParameters &wizardDialogParameters) const;
|
||||
|
||||
Reference in New Issue
Block a user