Commit 0888390b authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Remove IWizardFactory::Data



It makes the code more complicated in one place just to make it harder
to follow in another...

Remove CustomWizardParameters::toString() while at it: It would need some
extending to work with this change and I do not think it is worth it, considering
that it is only used when the CustomWizard is set to verbose.

Change-Id: Ice14b197ed2fe98c54bc9c1c55ece3ed2222fbbf
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 4b00a2bf
......@@ -57,48 +57,30 @@ public:
};
Q_DECLARE_FLAGS(WizardFlags, WizardFlag)
class CORE_EXPORT Data
{
public:
Data() : kind(IWizardFactory::FileWizard) {}
IWizardFactory::WizardKind kind;
QIcon icon;
QString description;
QString displayName;
QString id;
QString category;
QString displayCategory;
FeatureSet requiredFeatures;
IWizardFactory::WizardFlags flags;
QString descriptionImage;
};
IWizardFactory() { }
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; }
QString id() const { return m_id; }
WizardKind kind() const { return m_kind; }
QIcon icon() const { return m_icon; }
QString description() const { return m_description; }
QString displayName() const { return m_displayName; }
QString category() const { return m_category; }
QString displayCategory() const { return m_displayCategory; }
QString descriptionImage() const { return m_descriptionImage; }
FeatureSet requiredFeatures() const { return m_requiredFeatures; }
WizardFlags flags() const { return m_flags; }
void setId(const QString &id) { m_id = id; }
void setWizardKind(WizardKind kind) { m_kind = kind; }
void setIcon(const QIcon &icon) { m_icon = icon; }
void setDescription(const QString &description) { m_description = description; }
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
void setCategory(const QString &category) { m_category = category; }
void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
void setDescriptionImage(const QString &descriptionImage) { m_descriptionImage = descriptionImage; }
void setRequiredFeatures(const FeatureSet &featureSet) { m_requiredFeatures = featureSet; }
void addRequiredFeature(const Feature &feature) { m_requiredFeatures |= feature; }
void setFlags(WizardFlags flags) { m_flags = flags; }
virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) = 0;
......@@ -113,7 +95,16 @@ public:
static QString displayNameForPlatform(const QString &string);
private:
Data m_data;
IWizardFactory::WizardKind m_kind;
QIcon m_icon;
QString m_description;
QString m_displayName;
QString m_id;
QString m_category;
QString m_displayCategory;
FeatureSet m_requiredFeatures;
WizardFlags m_flags;
QString m_descriptionImage;
};
} // namespace Core
......
......@@ -113,7 +113,19 @@ int CustomWizard::verbose()
void CustomWizard::setParameters(const CustomWizardParametersPtr &p)
{
QTC_ASSERT(p, return);
d->m_parameters = p;
setId(p->id);
setWizardKind(p->kind);
setIcon(p->icon);
setDescription(p->description);
setDisplayName(p->displayName);
setCategory(p->category);
setDisplayCategory(p->displayCategory);
setRequiredFeatures(p->requiredFeatures);
setFlags(p->flags);
}
Core::BaseFileWizard *CustomWizard::create(QWidget *parent, const Core::WizardDialogParameters &p) const
......@@ -307,13 +319,11 @@ CustomWizard::CustomWizardContextPtr CustomWizard::context() const
return d->m_context;
}
CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p,
const Core::IWizardFactory::Data &b)
CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p)
{
ICustomWizardFactory * factory = ExtensionSystem::PluginManager::getObject<ICustomWizardFactory>(
[&p, &b](ICustomWizardFactory *factory) {
return ((p->klass.isEmpty() && b.kind == factory->kind())
|| (!p->klass.isEmpty() && p->klass == factory->klass()));
ICustomWizardFactory *factory = ExtensionSystem::PluginManager::getObject<ICustomWizardFactory>(
[&p](ICustomWizardFactory *factory) {
return p->klass.isEmpty() ? (p->kind == factory->kind()) : (p->klass == factory->klass());
});
CustomWizard *rc = 0;
......@@ -325,7 +335,6 @@ CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizard
return 0;
}
rc->setData(b);
rc->setParameters(p);
return rc;
}
......@@ -413,20 +422,13 @@ QList<CustomWizard*> CustomWizard::createWizards()
verboseLog += QString::fromLatin1("CustomWizard: Scanning %1\n").arg(dirFi.absoluteFilePath());
if (dir.exists(configFile)) {
CustomWizardParametersPtr parameters(new Internal::CustomWizardParameters);
IWizardFactory::Data data;
switch (parameters->parse(dir.absoluteFilePath(configFile), &data, &errorMessage)) {
switch (parameters->parse(dir.absoluteFilePath(configFile), &errorMessage)) {
case Internal::CustomWizardParameters::ParseOk:
parameters->directory = dir.absolutePath();
if (CustomWizardPrivate::verbose)
QTextStream(&verboseLog)
<< "\n### Adding: " << data.id << " / " << data.displayName << '\n'
<< data.category << " / " << data.displayCategory << '\n'
<< " (" << data.description << ")\n"
<< parameters->toString();
if (CustomWizard *w = createWizard(parameters, data))
if (CustomWizard *w = createWizard(parameters))
rc.push_back(w);
else
qWarning("Custom wizard factory function failed for %s", qPrintable(data.id));
qWarning("Custom wizard factory function failed for %s", qPrintable(parameters->id));
break;
case Internal::CustomWizardParameters::ParseDisabled:
if (CustomWizardPrivate::verbose)
......
......@@ -120,12 +120,11 @@ protected:
CustomWizardParametersPtr parameters() const;
CustomWizardContextPtr context() const;
static CustomWizard *createWizard(const CustomWizardParametersPtr &p, const Core::IWizardFactory::Data &b);
static CustomWizard *createWizard(const CustomWizardParametersPtr &p);
private:
void setParameters(const CustomWizardParametersPtr &p);
static CustomWizard *createWizard(const CustomWizardParametersPtr &p);
CustomWizardPrivate *d;
};
......
......@@ -272,8 +272,7 @@ static inline bool assignLanguageElementText(QXmlStreamReader &reader,
static bool parseCustomProjectElement(QXmlStreamReader &reader,
const QString &configFileFullPath,
const QString &language,
CustomWizardParameters *p,
IWizardFactory::Data *bp)
CustomWizardParameters *p)
{
const QStringRef elementName = reader.name();
if (elementName == QLatin1String(iconElementC)) {
......@@ -283,20 +282,20 @@ static bool parseCustomProjectElement(QXmlStreamReader &reader,
qWarning("Invalid icon path '%s' encountered in custom project template %s.",
qPrintable(path), qPrintable(configFileFullPath));
} else {
bp->icon = icon;
p->icon = icon;
}
return true;
}
if (elementName == QLatin1String(descriptionElementC)) {
assignLanguageElementText(reader, language, &bp->description);
assignLanguageElementText(reader, language, &p->description);
return true;
}
if (elementName == QLatin1String(displayNameElementC)) {
assignLanguageElementText(reader, language, &bp->displayName);
assignLanguageElementText(reader, language, &p->displayName);
return true;
}
if (elementName == QLatin1String(displayCategoryElementC)) {
assignLanguageElementText(reader, language, &bp->displayCategory);
assignLanguageElementText(reader, language, &p->displayCategory);
return true;
}
if (elementName == QLatin1String(fieldPageTitleElementC)) {
......@@ -460,7 +459,7 @@ static inline IWizardFactory::WizardKind kindAttribute(const QXmlStreamReader &r
return IWizardFactory::ProjectWizard;
}
static inline FeatureSet requiredFeatures(const QXmlStreamReader &reader)
static inline FeatureSet readRequiredFeatures(const QXmlStreamReader &reader)
{
QString value = reader.attributes().value(QLatin1String(featuresRequiredC)).toString();
QStringList stringList = value.split(QLatin1Char(','), QString::SkipEmptyParts);
......@@ -550,18 +549,15 @@ GeneratorScriptArgument::GeneratorScriptArgument(const QString &v) :
// Main parsing routine
CustomWizardParameters::ParseResult
CustomWizardParameters::parse(QIODevice &device,
const QString &configFileFullPath,
IWizardFactory::Data *bp,
QString *errorMessage)
CustomWizardParameters::parse(QIODevice &device, const QString &configFileFullPath,
QString *errorMessage)
{
int comboEntryCount = 0;
QXmlStreamReader reader(&device);
QXmlStreamReader::TokenType token = QXmlStreamReader::EndDocument;
ParseState state = ParseBeginning;
clear();
*bp = IWizardFactory::Data();
bp->kind = IWizardFactory::ProjectWizard;
kind = IWizardFactory::ProjectWizard;
const QString language = languageSetting();
CustomWizardField field;
do {
......@@ -573,7 +569,7 @@ CustomWizardParameters::ParseResult
case QXmlStreamReader::StartElement:
do {
// Read out subelements applicable to current state
if (state == ParseWithinWizard && parseCustomProjectElement(reader, configFileFullPath, language, this, bp))
if (state == ParseWithinWizard && parseCustomProjectElement(reader, configFileFullPath, language, this))
break;
// switch to next state
state = nextOpeningState(state, reader.name());
......@@ -586,12 +582,11 @@ CustomWizardParameters::ParseResult
case ParseWithinWizard:
if (!booleanAttributeValue(reader, wizardEnabledAttributeC, true))
return ParseDisabled;
bp->id = attributeValue(reader, idAttributeC);
id = bp->id;
bp->category = attributeValue(reader, categoryAttributeC);
bp->kind = kindAttribute(reader);
bp->requiredFeatures = requiredFeatures(reader);
bp->flags = wizardFlags(reader);
id = attributeValue(reader, idAttributeC);
category = attributeValue(reader, categoryAttributeC);
kind = kindAttribute(reader);
requiredFeatures = readRequiredFeatures(reader);
flags = wizardFlags(reader);
klass = attributeValue(reader, klassAttributeC);
firstPageId = integerAttributeValue(reader, firstPageAttributeC, -1);
break;
......@@ -704,67 +699,14 @@ CustomWizardParameters::ParseResult
}
CustomWizardParameters::ParseResult
CustomWizardParameters::parse(const QString &configFileFullPath,
IWizardFactory::Data *bp,
QString *errorMessage)
CustomWizardParameters::parse(const QString &configFileFullPath, QString *errorMessage)
{
QFile configFile(configFileFullPath);
if (!configFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
*errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(configFileFullPath, configFile.errorString());
return ParseFailed;
}
return parse(configFile, configFileFullPath, bp, errorMessage);
}
QString CustomWizardParameters::toString() const
{
QString rc;
QTextStream str(&rc);
str << "Directory: " << directory << " Klass: '" << klass << "'\n";
if (!filesGeneratorScriptArguments.isEmpty()) {
str << "Script:";
foreach (const QString &a, filesGeneratorScript)
str << " '" << a << '\'';
if (!filesGeneratorScriptWorkingDirectory.isEmpty())
str << "\nrun in '" << filesGeneratorScriptWorkingDirectory << '\'';
str << "\nArguments: ";
foreach (const GeneratorScriptArgument &a, filesGeneratorScriptArguments) {
str << " '" << a.value << '\'';
if (a.flags & GeneratorScriptArgument::OmitEmpty)
str << " [omit empty]";
if (a.flags & GeneratorScriptArgument::WriteFile)
str << " [write file]";
str << ',';
}
str << '\n';
}
foreach (const CustomWizardFile &f, files) {
str << " File source: " << f.source << " Target: " << f.target;
if (f.openEditor)
str << " [editor]";
if (f.openProject)
str << " [project]";
if (f.binary)
str << " [binary]";
str << '\n';
}
foreach (const CustomWizardField &f, fields) {
str << " Field name: " << f.name;
if (f.mandatory)
str << '*';
str << " Description: '" << f.description << '\'';
if (!f.controlAttributes.isEmpty()) {
typedef CustomWizardField::ControlAttributeMap::const_iterator AttrMapConstIt;
str << " Control: ";
const AttrMapConstIt cend = f.controlAttributes.constEnd();
for (AttrMapConstIt it = f.controlAttributes.constBegin(); it != cend; ++it)
str << '\'' << it.key() << "' -> '" << it.value() << "' ";
}
str << '\n';
}
foreach (const CustomWizardValidationRule &r, rules)
str << " Rule: '" << r.condition << "'->'" << r.message << '\n';
return rc;
return parse(configFile, configFileFullPath, errorMessage);
}
// ------------ CustomWizardContext
......
......@@ -107,10 +107,8 @@ public:
CustomWizardParameters();
void clear();
ParseResult parse(QIODevice &device, const QString &configFileFullPath,
Core::IWizardFactory::Data *bp, QString *errorMessage);
ParseResult parse(const QString &configFileFullPath,
Core::IWizardFactory::Data *bp, QString *errorMessage);
QString toString() const;
QString *errorMessage);
ParseResult parse(const QString &configFileFullPath, QString *errorMessage);
QString id;
QString directory;
......@@ -124,6 +122,16 @@ public:
QList<CustomWizardField> fields;
QList<CustomWizardValidationRule> rules;
int firstPageId;
// Wizard Factory data:
Core::IWizardFactory::WizardKind kind;
QIcon icon;
QString description;
QString displayName;
QString category;
QString displayCategory;
Core::FeatureSet requiredFeatures;
Core::IWizardFactory::WizardFlags flags;
};
// Documentation inside.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment