Commit 49d0789e authored by hjk's avatar hjk

Cleanup IWizard interface and users

Added 639 lines, removed 1391.

Change-Id: I15ec7dd056d4f7ad79c6dd6a4181007ad14f6a43
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent aa32c2be
......@@ -43,27 +43,13 @@
using namespace Bazaar::Internal;
CloneWizard::CloneWizard(QObject *parent)
: VcsBase::BaseCheckoutWizard(parent),
m_icon(QIcon(QLatin1String(":/bazaar/images/bazaar.png")))
CloneWizard::CloneWizard()
{
setId(QLatin1String(VcsBase::Constants::VCS_ID_BAZAAR));
setCustomLabels(tr("Cloning"), tr("Cloning started..."));
}
QIcon CloneWizard::icon() const
{
return m_icon;
}
QString CloneWizard::description() const
{
return tr("Clones a Bazaar branch and tries to load the contained project.");
}
QString CloneWizard::displayName() const
{
return tr("Bazaar Clone (Or Branch)");
setIcon(QIcon(QLatin1String(":/bazaar/images/bazaar.png")));
setDescription(tr("Clones a Bazaar branch and tries to load the contained project."));
setDisplayName(tr("Bazaar Clone (Or Branch)"));
}
QList<QWizardPage *> CloneWizard::createParameterPages(const QString &path)
......
......@@ -42,19 +42,12 @@ class CloneWizard : public VcsBase::BaseCheckoutWizard
Q_OBJECT
public:
CloneWizard(QObject *parent = 0);
CloneWizard();
QIcon icon() const;
QString description() const;
QString displayName() const;
protected:
private:
QList<QWizardPage *> createParameterPages(const QString &path);
VcsBase::Command *createCommand(const QList<QWizardPage *> &parameterPages,
QString *checkoutPath);
private:
const QIcon m_icon;
};
} // namespace Internal
......
......@@ -63,189 +63,6 @@ static int indexOfFile(const GeneratedFiles &f, const QString &path)
return -1;
}
// ------------ BaseFileWizardParameterData
class BaseFileWizardParameterData : public QSharedData
{
public:
explicit BaseFileWizardParameterData(IWizard::WizardKind kind = IWizard::FileWizard);
void clear();
IWizard::WizardKind kind;
QIcon icon;
QString description;
QString displayName;
QString id;
QString category;
QString displayCategory;
FeatureSet requiredFeatures;
IWizard::WizardFlags flags;
QString descriptionImage;
};
BaseFileWizardParameterData::BaseFileWizardParameterData(IWizard::WizardKind k) :
kind(k)
{
}
void BaseFileWizardParameterData::clear()
{
kind = IWizard::FileWizard;
icon = QIcon();
description.clear();
displayName.clear();
id.clear();
category.clear();
displayCategory.clear();
}
/*!
\class Core::BaseFileWizardParameters
\brief The BaseFileWizardParameters class is a parameter class for
passing parameters to instances of the class Wizard containing name, icon,
and so on.
\sa Core::GeneratedFile, Core::BaseFileWizard, Core::StandardFileWizard
\sa Core::Internal::WizardEventLoop
*/
BaseFileWizardParameters::BaseFileWizardParameters(IWizard::WizardKind kind) :
m_d(new BaseFileWizardParameterData(kind))
{
}
BaseFileWizardParameters::BaseFileWizardParameters(const BaseFileWizardParameters &rhs) :
m_d(rhs.m_d)
{
}
BaseFileWizardParameters &BaseFileWizardParameters::operator=(const BaseFileWizardParameters &rhs)
{
if (this != &rhs)
m_d.operator=(rhs.m_d);
return *this;
}
BaseFileWizardParameters::~BaseFileWizardParameters()
{
}
void BaseFileWizardParameters::clear()
{
m_d->clear();
}
CORE_EXPORT QDebug operator<<(QDebug d, const BaseFileWizardParameters &p)
{
d.nospace() << "Kind: " << p.kind() << " Id: " << p.id()
<< " Category: " << p.category()
<< " DisplayName: " << p.displayName()
<< " Description: " << p.description()
<< " DisplayCategory: " << p.displayCategory()
<< " Required Features: " << p.requiredFeatures().toStringList();
return d;
}
IWizard::WizardKind BaseFileWizardParameters::kind() const
{
return m_d->kind;
}
void BaseFileWizardParameters::setKind(IWizard::WizardKind k)
{
m_d->kind = k;
}
QIcon BaseFileWizardParameters::icon() const
{
return m_d->icon;
}
void BaseFileWizardParameters::setIcon(const QIcon &icon)
{
m_d->icon = icon;
}
QString BaseFileWizardParameters::description() const
{
return m_d->description;
}
void BaseFileWizardParameters::setDescription(const QString &v)
{
m_d->description = v;
}
QString BaseFileWizardParameters::displayName() const
{
return m_d->displayName;
}
void BaseFileWizardParameters::setDisplayName(const QString &v)
{
m_d->displayName = v;
}
QString BaseFileWizardParameters::id() const
{
return m_d->id;
}
void BaseFileWizardParameters::setId(const QString &v)
{
m_d->id = v;
}
QString BaseFileWizardParameters::category() const
{
return m_d->category;
}
void BaseFileWizardParameters::setCategory(const QString &v)
{
m_d->category = v;
}
QString BaseFileWizardParameters::displayCategory() const
{
return m_d->displayCategory;
}
FeatureSet BaseFileWizardParameters::requiredFeatures() const
{
return m_d->requiredFeatures;
}
void BaseFileWizardParameters::setRequiredFeatures(FeatureSet features)
{
m_d->requiredFeatures = features;
}
void BaseFileWizardParameters::setDisplayCategory(const QString &v)
{
m_d->displayCategory = v;
}
IWizard::WizardFlags BaseFileWizardParameters::flags() const
{
return m_d->flags;
}
void BaseFileWizardParameters::setFlags(IWizard::WizardFlags flags)
{
m_d->flags = flags;
}
QString BaseFileWizardParameters::descriptionImage() const
{
return m_d->descriptionImage;
}
void BaseFileWizardParameters::setDescriptionImage(const QString &path)
{
m_d->descriptionImage = path;
}
/*!
\class Core::Internal::WizardEventLoop
\brief Special event loop that runs a QWizard and terminates if the page changes.
......@@ -359,72 +176,15 @@ void WizardEventLoop::rejected()
\sa Core::Internal::WizardEventLoop
*/
struct BaseFileWizardPrivate
{
explicit BaseFileWizardPrivate(const Core::BaseFileWizardParameters &parameters)
: m_parameters(parameters), m_wizardDialog(0)
{}
const Core::BaseFileWizardParameters m_parameters;
QWizard *m_wizardDialog;
};
// ---------------- Wizard
BaseFileWizard::BaseFileWizard(const BaseFileWizardParameters &parameters,
QObject *parent) :
IWizard(parent),
d(new BaseFileWizardPrivate(parameters))
BaseFileWizard::BaseFileWizard(QObject *parent) :
IWizard(parent)
{
}
BaseFileWizardParameters BaseFileWizard::baseFileWizardParameters() const
{
return d->m_parameters;
}
BaseFileWizard::~BaseFileWizard()
{
delete d;
}
IWizard::WizardKind BaseFileWizard::kind() const
{
return d->m_parameters.kind();
}
QIcon BaseFileWizard::icon() const
{
return d->m_parameters.icon();
}
QString BaseFileWizard::description() const
{
return d->m_parameters.description();
}
QString BaseFileWizard::displayName() const
{
return d->m_parameters.displayName();
}
QString BaseFileWizard::id() const
{
return d->m_parameters.id();
}
QString BaseFileWizard::category() const
{
return d->m_parameters.category();
}
QString BaseFileWizard::displayCategory() const
{
return d->m_parameters.displayCategory();
}
QString BaseFileWizard::descriptionImage() const
{
return d->m_parameters.descriptionImage();
}
void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues)
......@@ -548,17 +308,6 @@ void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QStri
QMessageBox::critical(0, tr("File Generation Failure"), errorMessage);
}
FeatureSet BaseFileWizard::requiredFeatures() const
{
return d->m_parameters.requiredFeatures();
}
IWizard::WizardFlags BaseFileWizard::flags() const
{
return d->m_parameters.flags();
}
/*!
\fn virtual QWizard *Core::BaseFileWizard::createWizardDialog(QWidget *parent,
const WizardDialogParameters &wizardDialogParameters) const
......@@ -799,9 +548,8 @@ QString BaseFileWizard::preferredSuffix(const QString &mimeType)
\brief Newly introduced virtual that creates the files under the path.
*/
StandardFileWizard::StandardFileWizard(const BaseFileWizardParameters &parameters,
QObject *parent) :
BaseFileWizard(parameters, parent)
StandardFileWizard::StandardFileWizard(QObject *parent) :
BaseFileWizard(parent)
{
}
......
......@@ -48,64 +48,10 @@ class QWizardPage;
class QDebug;
QT_END_NAMESPACE
namespace Utils {
class Wizard;
}
namespace Utils { class Wizard; }
namespace Core {
class IEditor;
class IFileWizardExtension;
class BaseFileWizardParameterData;
struct BaseFileWizardPrivate;
class CORE_EXPORT BaseFileWizardParameters
{
public:
explicit BaseFileWizardParameters(IWizard::WizardKind kind = IWizard::FileWizard);
BaseFileWizardParameters(const BaseFileWizardParameters &);
BaseFileWizardParameters &operator=(const BaseFileWizardParameters&);
~BaseFileWizardParameters();
void clear();
IWizard::WizardKind kind() const;
void setKind(IWizard::WizardKind k);
QIcon icon() const;
void setIcon(const QIcon &icon);
QString description() const;
void setDescription(const QString &description);
QString displayName() const;
void setDisplayName(const QString &name);
QString id() const;
void setId(const QString &id);
QString category() const;
void setCategory(const QString &category);
QString displayCategory() const;
void setDisplayCategory(const QString &trCategory);
Core::FeatureSet requiredFeatures() const;
void setRequiredFeatures(Core::FeatureSet features);
Core::IWizard::WizardFlags flags() const;
void setFlags(Core::IWizard::WizardFlags flags);
QString descriptionImage() const;
void setDescriptionImage(const QString &path);
private:
QSharedDataPointer<BaseFileWizardParameterData> m_d;
};
CORE_EXPORT QDebug operator<<(QDebug d, const BaseFileWizardParameters &);
class CORE_EXPORT WizardDialogParameters
{
public:
......@@ -163,20 +109,7 @@ public:
virtual ~BaseFileWizard();
// IWizard
virtual WizardKind kind() const;
virtual QIcon icon() const;
virtual QString description() const;
virtual QString displayName() const;
virtual QString id() const;
virtual QString category() const;
virtual QString displayCategory() const;
virtual QString descriptionImage() const;
virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues);
virtual Core::FeatureSet requiredFeatures() const;
virtual WizardFlags flags() const;
static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
static void setupWizard(QWizard *);
......@@ -185,9 +118,7 @@ public:
protected:
typedef QList<QWizardPage *> WizardPageList;
explicit BaseFileWizard(const BaseFileWizardParameters &parameters, QObject *parent = 0);
BaseFileWizardParameters baseFileWizardParameters() const;
explicit BaseFileWizard(QObject *parent = 0);
virtual QWizard *createWizardDialog(QWidget *parent,
const WizardDialogParameters &wizardDialogParameters) const = 0;
......@@ -205,9 +136,6 @@ protected:
OverwriteResult promptOverwrite(GeneratedFiles *files,
QString *errorMessage) const;
static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = 0);
private:
BaseFileWizardPrivate *d;
};
class CORE_EXPORT StandardFileWizard : public BaseFileWizard
......@@ -215,25 +143,13 @@ class CORE_EXPORT StandardFileWizard : public BaseFileWizard
Q_OBJECT
protected:
explicit StandardFileWizard(const BaseFileWizardParameters &parameters, QObject *parent = 0);
explicit StandardFileWizard(QObject *parent = 0);
virtual QWizard *createWizardDialog(QWidget *parent, const WizardDialogParameters &wizardDialogParameters) const;
virtual GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
virtual GeneratedFiles generateFilesFromPath(const QString &path, const QString &name,
QString *errorMessage) const = 0;
};
template <class WizardClass>
QList<WizardClass*> createMultipleBaseFileWizardInstances(const QList<BaseFileWizardParameters> &parametersList, ExtensionSystem::IPlugin *plugin)
{
QList<WizardClass*> list;
foreach (const BaseFileWizardParameters &parameters, parametersList) {
WizardClass *wc = new WizardClass(parameters, 0);
plugin->addAutoReleasedObject(wc);
list << wc;
}
return list;
}
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::GeneratedFile::Attributes)
......
......@@ -31,18 +31,15 @@
#define IWIZARD_H
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <coreplugin/featureprovider.h>
#include <QIcon>
#include <QObject>
#include <QVariantMap>
QT_BEGIN_NAMESPACE
class QIcon;
QT_END_NAMESPACE
namespace Core {
class FeatureSet;
class CORE_EXPORT IWizard
: public QObject
{
......@@ -60,22 +57,49 @@ public:
};
Q_DECLARE_FLAGS(WizardFlags, WizardFlag)
IWizard(QObject *parent = 0) : QObject(parent) {}
virtual ~IWizard() {}
virtual WizardKind kind() const = 0;
virtual QIcon icon() const = 0;
virtual QString description() const = 0;
virtual QString displayName() const = 0;
virtual QString id() const = 0;
virtual QString category() const = 0;
virtual QString displayCategory() const = 0;
virtual QString descriptionImage() const = 0;
class CORE_EXPORT Data
{
public:
Data() : kind(IWizard::FileWizard) {}
IWizard::WizardKind kind;
QIcon icon;
QString description;
QString displayName;
QString id;
QString category;
QString displayCategory;
FeatureSet requiredFeatures;
IWizard::WizardFlags flags;
QString descriptionImage;
};
virtual FeatureSet requiredFeatures() const = 0;
virtual WizardFlags flags() const = 0;
IWizard(QObject *parent = 0) : QObject(parent) {}
~IWizard() {}
QString id() const { return m_data.id; }
WizardKind kind() const { return m_data.kind; }
QIcon icon() const { return m_data.icon; }
QString description() const { return m_data.description; }
QString displayName() const { return m_data.displayName; }
QString category() const { return m_data.category; }
QString displayCategory() const { return m_data.displayCategory; }
QString descriptionImage() const { return m_data.descriptionImage; }
FeatureSet requiredFeatures() const { return m_data.requiredFeatures; }
WizardFlags flags() const { return m_data.flags; }
void setData(const Data &data) { m_data = data; }
void setId(const QString &id) { m_data.id = id; }
void setWizardKind(WizardKind kind) { m_data.kind = kind; }
void setIcon(const QIcon &icon) { m_data.icon = icon; }
void setDescription(const QString &description) { m_data.description = description; }
void setDisplayName(const QString &displayName) { m_data.displayName = displayName; }
void setCategory(const QString &category) { m_data.category = category; }
void setDisplayCategory(const QString &displayCategory) { m_data.displayCategory = displayCategory; }
void setDescriptionImage(const QString &descriptionImage) { m_data.descriptionImage = descriptionImage; }
void setRequiredFeatures(const FeatureSet &featureSet) { m_data.requiredFeatures = featureSet; }
void addRequiredFeature(const Feature &feature) { m_data.requiredFeatures |= feature; }
void setFlags(WizardFlags flags) { m_data.flags = flags; }
virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) = 0;
......@@ -88,6 +112,9 @@ public:
static QList<IWizard*> wizardsOfKind(WizardKind kind);
static QStringList allAvailablePlatforms();
static QString displayNameForPlatform(const QString &string);
private:
Data m_data;
};
} // namespace Core
......
......@@ -140,17 +140,10 @@ CppClassWizardParameters CppClassWizardDialog::parameters() const
// ========= CppClassWizard =========
CppClassWizard::CppClassWizard(const Core::BaseFileWizardParameters &parameters,
QObject *parent)
: Core::BaseFileWizard(parameters, parent)
CppClassWizard::CppClassWizard()
{
}
Core::FeatureSet CppClassWizard::requiredFeatures() const
{
return Core::FeatureSet();
}
QString CppClassWizard::sourceSuffix() const
{
return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
......
......@@ -96,25 +96,20 @@ class CppClassWizard : public Core::BaseFileWizard
Q_OBJECT
public:
explicit CppClassWizard(const Core::BaseFileWizardParameters &parameters,
QObject *parent = 0);
CppClassWizard();
virtual Core::FeatureSet requiredFeatures() const;
protected:
virtual QWizard *createWizardDialog(QWidget *parent,
private:
QWizard *createWizardDialog(QWidget *parent,
const Core::WizardDialogParameters &wizardDialogParameters) const;
virtual Core::GeneratedFiles generateFiles(const QWizard *w,
Core::GeneratedFiles generateFiles(const QWizard *w,
QString *errorMessage) const;
QString sourceSuffix() const;
QString headerSuffix() const;
private:
static bool generateHeaderAndSource(const CppClassWizardParameters &params,
QString *header, QString *source);
};
} // namespace Internal
......
......@@ -163,28 +163,35 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addAutoReleasedObject(m_quickFixProvider);
CppEditor::Internal::registerQuickFixes(this);
QObject *core = ICore::instance();
CppFileWizard::BaseFileWizardParameters wizardParameters(IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
wizardParameters.setDisplayCategory(QCoreApplication::translate(Constants::WIZARD_CATEGORY,
Constants::WIZARD_TR_CATEGORY));
wizardParameters.setDisplayName(tr("C++ Class"));
wizardParameters.setId(QLatin1String("A.Class"));
wizardParameters.setKind(IWizard::ClassWizard);
wizardParameters.setDescription(tr("Creates a C++ header and a source file for a new class that you can add to a C++ project."));
addAutoReleasedObject(new CppClassWizard(wizardParameters, core));
wizardParameters.setKind(IWizard::FileWizard);
wizardParameters.setDescription(tr("Creates a C++ source file that you can add to a C++ project."));
wizardParameters.setDisplayName(tr("C++ Source File"));
wizardParameters.setId(QLatin1String("B.Source"));
addAutoReleasedObject(new CppFileWizard(wizardParameters, Source, core));
wizardParameters.setDescription(tr("Creates a C++ header file that you can add to a C++ project."));
wizardParameters.setDisplayName(tr("C++ Header File"));
wizardParameters.setId(QLatin1String("C.Header"));
addAutoReleasedObject(new CppFileWizard(wizardParameters, Header, core));
QString trCat = QCoreApplication::translate(Constants::WIZARD_CATEGORY, Constants::WIZARD_TR_CATEGORY);
IWizard *wizard = new CppClassWizard;
wizard->setWizardKind(IWizard::ClassWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
wizard->setDisplayCategory(trCat);
wizard->setDisplayName(tr("C++ Class"));
wizard->setId(QLatin1String("A.Class"));
wizard->setDescription(tr("Creates a C++ header and a source file for a new class that you can add to a C++ project."));
addAutoReleasedObject(wizard);
wizard = new CppFileWizard(Source);
wizard->setWizardKind(IWizard::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
wizard->setDisplayCategory(trCat);