forked from qt-creator/qt-creator
ProjectExplorer: Introduce JsonWizardGeneratorTypedFactory
Limit code repetition by introducing convenient class template. Change-Id: I90b45a305c5a6f28bf75a602c14ff055928cda48 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -260,51 +260,9 @@ bool JsonWizardFileGenerator::writeFile(const JsonWizard *wizard, Core::Generate
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factory
|
|
||||||
|
|
||||||
class FileGeneratorFactory final : public JsonWizardGeneratorFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileGeneratorFactory()
|
|
||||||
{
|
|
||||||
setTypeIdsSuffix(QLatin1String("File"));
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonWizardGenerator *create(Id typeId, const QVariant &data,
|
|
||||||
const QString &path, Id platform,
|
|
||||||
const QVariantMap &variables) final
|
|
||||||
{
|
|
||||||
Q_UNUSED(path)
|
|
||||||
Q_UNUSED(platform)
|
|
||||||
Q_UNUSED(variables)
|
|
||||||
|
|
||||||
QTC_ASSERT(canCreate(typeId), return nullptr);
|
|
||||||
|
|
||||||
auto gen = new JsonWizardFileGenerator;
|
|
||||||
QString errorMessage;
|
|
||||||
gen->setup(data, &errorMessage);
|
|
||||||
|
|
||||||
if (!errorMessage.isEmpty()) {
|
|
||||||
qWarning() << "FileGeneratorFactory setup error:" << errorMessage;
|
|
||||||
delete gen;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gen;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool validateData(Id typeId, const QVariant &data, QString *errorMessage) final
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canCreate(typeId), return false);
|
|
||||||
|
|
||||||
QScopedPointer<JsonWizardFileGenerator> gen(new JsonWizardFileGenerator);
|
|
||||||
return gen->setup(data, errorMessage);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void setupJsonWizardFileGenerator()
|
void setupJsonWizardFileGenerator()
|
||||||
{
|
{
|
||||||
static FileGeneratorFactory theFileGeneratorFactory;
|
static JsonWizardGeneratorTypedFactory<JsonWizardFileGenerator> theFileGeneratorFactory("File");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ProjectExplorer
|
} // ProjectExplorer
|
||||||
|
|||||||
@@ -69,4 +69,40 @@ private:
|
|||||||
QList<Utils::Id> m_typeIds;
|
QList<Utils::Id> m_typeIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Generator>
|
||||||
|
class JsonWizardGeneratorTypedFactory : public JsonWizardGeneratorFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JsonWizardGeneratorTypedFactory(const QString &suffix) { setTypeIdsSuffix(suffix); }
|
||||||
|
|
||||||
|
JsonWizardGenerator *create(Utils::Id typeId, const QVariant &data,
|
||||||
|
const QString &path, Utils::Id platform,
|
||||||
|
const QVariantMap &variables) final
|
||||||
|
{
|
||||||
|
Q_UNUSED(path)
|
||||||
|
Q_UNUSED(platform)
|
||||||
|
Q_UNUSED(variables)
|
||||||
|
QTC_ASSERT(canCreate(typeId), return nullptr);
|
||||||
|
|
||||||
|
auto gen = new Generator;
|
||||||
|
QString errorMessage;
|
||||||
|
gen->setup(data, &errorMessage);
|
||||||
|
|
||||||
|
if (!errorMessage.isEmpty()) {
|
||||||
|
qWarning() << "JsonWizardGeneratorTypedFactory for " << typeId << "setup error:"
|
||||||
|
<< errorMessage;
|
||||||
|
delete gen;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateData(Utils::Id typeId, const QVariant &data, QString *errorMessage) final
|
||||||
|
{
|
||||||
|
QTC_ASSERT(canCreate(typeId), return false);
|
||||||
|
QScopedPointer<Generator> gen(new Generator);
|
||||||
|
return gen->setup(data, errorMessage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|||||||
@@ -149,51 +149,10 @@ Core::GeneratedFiles JsonWizardScannerGenerator::scan(const Utils::FilePath &dir
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JsonWizardScannerGeneratorFactory
|
|
||||||
|
|
||||||
class JsonWizardScannerGeneratorFactory final : public JsonWizardGeneratorFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
JsonWizardScannerGeneratorFactory()
|
|
||||||
{
|
|
||||||
setTypeIdsSuffix(QLatin1String("Scanner"));
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonWizardGenerator *create(Id typeId, const QVariant &data,
|
|
||||||
const QString &path, Id platform,
|
|
||||||
const QVariantMap &variables) final
|
|
||||||
{
|
|
||||||
Q_UNUSED(path)
|
|
||||||
Q_UNUSED(platform)
|
|
||||||
Q_UNUSED(variables)
|
|
||||||
|
|
||||||
QTC_ASSERT(canCreate(typeId), return nullptr);
|
|
||||||
|
|
||||||
auto gen = new JsonWizardScannerGenerator;
|
|
||||||
QString errorMessage;
|
|
||||||
gen->setup(data, &errorMessage);
|
|
||||||
|
|
||||||
if (!errorMessage.isEmpty()) {
|
|
||||||
qWarning() << "JsonWizardScannerGeneratorFactory setup error:" << errorMessage;
|
|
||||||
delete gen;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gen;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool validateData(Id typeId, const QVariant &data, QString *errorMessage) final
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canCreate(typeId), return false);
|
|
||||||
|
|
||||||
QScopedPointer<JsonWizardScannerGenerator> gen(new JsonWizardScannerGenerator);
|
|
||||||
return gen->setup(data, errorMessage);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void setupJsonWizardScannerGenerator()
|
void setupJsonWizardScannerGenerator()
|
||||||
{
|
{
|
||||||
static JsonWizardScannerGeneratorFactory theScannerGeneratorFactory;
|
static JsonWizardGeneratorTypedFactory<JsonWizardScannerGenerator>
|
||||||
|
theScannerGeneratorFactory("Scanner");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ProjectExplorer::Internal
|
} // ProjectExplorer::Internal
|
||||||
|
|||||||
@@ -417,50 +417,13 @@ bool SquishFileGenerator::allDone(const JsonWizard *wizard,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SquishGeneratorFactory final : public JsonWizardGeneratorFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SquishGeneratorFactory()
|
|
||||||
{
|
|
||||||
setTypeIdsSuffix("SquishSuiteGenerator");
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonWizardGenerator *create(Id typeId, const QVariant &data,
|
|
||||||
const QString &path, Id platform,
|
|
||||||
const QVariantMap &variables) final
|
|
||||||
{
|
|
||||||
Q_UNUSED(path)
|
|
||||||
Q_UNUSED(platform)
|
|
||||||
Q_UNUSED(variables)
|
|
||||||
QTC_ASSERT(canCreate(typeId), return nullptr);
|
|
||||||
|
|
||||||
auto generator = new SquishFileGenerator;
|
|
||||||
QString errorMessage;
|
|
||||||
generator->setup(data, &errorMessage);
|
|
||||||
|
|
||||||
if (!errorMessage.isEmpty()) {
|
|
||||||
qWarning() << "SquishSuiteGenerator setup error:" << errorMessage;
|
|
||||||
delete generator;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool validateData(Id typeId, const QVariant &data, QString *errorMessage) final
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canCreate(typeId), return false);
|
|
||||||
|
|
||||||
QScopedPointer<SquishFileGenerator> generator(new SquishFileGenerator);
|
|
||||||
return generator->setup(data, errorMessage);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void setupSquishWizardPages()
|
void setupSquishWizardPages()
|
||||||
{
|
{
|
||||||
static SquishToolkitsPageFactory theSquishToolkitsPageFactory;
|
static SquishToolkitsPageFactory theSquishToolkitsPageFactory;
|
||||||
static SquishScriptLanguagePageFactory theSquishScriptLanguagePageFactory;
|
static SquishScriptLanguagePageFactory theSquishScriptLanguagePageFactory;
|
||||||
static SquishAUTPageFactory theSquishAUTPageFactory;
|
static SquishAUTPageFactory theSquishAUTPageFactory;
|
||||||
static SquishGeneratorFactory theSquishGeneratorFactory;
|
static JsonWizardGeneratorTypedFactory<SquishFileGenerator>
|
||||||
|
theSquishGeneratorFactory("SquishSuiteGenerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Squish::Internal
|
} // Squish::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user