forked from qt-creator/qt-creator
ProjectExplorer: Self-register JsonWizardPage related factories
Moves the using code closer to the common factory setup pattern. Change-Id: I2ee85b911d43b63730ff994a4b07568b23b14f00 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -52,6 +52,7 @@ public:
|
||||
FormEditorFactory formEditorFactory;
|
||||
SettingsPageProvider settingsPageProvider;
|
||||
QtDesignerFormClassCodeGenerator formClassCodeGenerator;
|
||||
FormPageFactory formPageFactory;
|
||||
};
|
||||
|
||||
FormEditorPlugin::~FormEditorPlugin()
|
||||
@@ -99,8 +100,6 @@ bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
|
||||
});
|
||||
#endif
|
||||
|
||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory);
|
||||
|
||||
// Ensure that loading designer translations is done before FormEditorW is instantiated
|
||||
const QString locale = ICore::userInterfaceLanguage();
|
||||
if (!locale.isEmpty()) {
|
||||
|
||||
@@ -68,8 +68,17 @@ const char OPTIONS_KEY[] = "options";
|
||||
const char PLATFORM_INDEPENDENT_KEY[] = "platformIndependent";
|
||||
const char DEFAULT_VALUES[] = "defaultValues";
|
||||
|
||||
static QList<JsonWizardPageFactory *> s_pageFactories;
|
||||
static QList<JsonWizardGeneratorFactory *> s_generatorFactories;
|
||||
static QList<JsonWizardPageFactory *> &pageFactories()
|
||||
{
|
||||
static QList<JsonWizardPageFactory *> thePageFactories;
|
||||
return thePageFactories;
|
||||
}
|
||||
|
||||
static QList<JsonWizardGeneratorFactory *> &generatorFactories()
|
||||
{
|
||||
static QList<JsonWizardGeneratorFactory *> theGeneratorFactories;
|
||||
return theGeneratorFactories;
|
||||
}
|
||||
|
||||
int JsonWizardFactory::m_verbose = 0;
|
||||
|
||||
@@ -115,11 +124,11 @@ static JsonWizardFactory::Generator parseGenerator(const QVariant &value, QStrin
|
||||
}
|
||||
Id typeId = Id::fromString(QLatin1String(Constants::GENERATOR_ID_PREFIX) + strVal);
|
||||
JsonWizardGeneratorFactory *factory
|
||||
= findOr(s_generatorFactories, nullptr, [typeId](JsonWizardGeneratorFactory *f) { return f->canCreate(typeId); });
|
||||
= findOr(generatorFactories(), nullptr, [typeId](JsonWizardGeneratorFactory *f) { return f->canCreate(typeId); });
|
||||
if (!factory) {
|
||||
*errorMessage = Tr::tr("TypeId \"%1\" of generator is unknown. Supported typeIds are: \"%2\".")
|
||||
.arg(strVal)
|
||||
.arg(supportedTypeIds(s_generatorFactories).replace(QLatin1String(Constants::GENERATOR_ID_PREFIX), QLatin1String("")));
|
||||
.arg(supportedTypeIds(generatorFactories()).replace(QLatin1String(Constants::GENERATOR_ID_PREFIX), QLatin1String("")));
|
||||
return gen;
|
||||
}
|
||||
|
||||
@@ -133,6 +142,26 @@ static JsonWizardFactory::Generator parseGenerator(const QVariant &value, QStrin
|
||||
return gen;
|
||||
}
|
||||
|
||||
JsonWizardPageFactory::JsonWizardPageFactory()
|
||||
{
|
||||
pageFactories().append(this);
|
||||
}
|
||||
|
||||
JsonWizardPageFactory::~JsonWizardPageFactory()
|
||||
{
|
||||
pageFactories().removeOne(this);
|
||||
}
|
||||
|
||||
JsonWizardGeneratorFactory::JsonWizardGeneratorFactory()
|
||||
{
|
||||
generatorFactories().append(this);
|
||||
}
|
||||
|
||||
JsonWizardGeneratorFactory::~JsonWizardGeneratorFactory()
|
||||
{
|
||||
generatorFactories().removeOne(this);
|
||||
}
|
||||
|
||||
//FIXME: createWizardFactories() has an almost identical loop. Make the loop return the results instead of
|
||||
//internal processing and create a separate function for it. Then process the results in
|
||||
//loadDefaultValues() and createWizardFactories()
|
||||
@@ -323,11 +352,11 @@ JsonWizardFactory::Page JsonWizardFactory::parsePage(const QVariant &value, QStr
|
||||
Id typeId = Id::fromString(QLatin1String(Constants::PAGE_ID_PREFIX) + strVal);
|
||||
|
||||
JsonWizardPageFactory *factory
|
||||
= Utils::findOr(s_pageFactories, nullptr, [typeId](JsonWizardPageFactory *f) { return f->canCreate(typeId); });
|
||||
= Utils::findOr(pageFactories(), nullptr, [typeId](JsonWizardPageFactory *f) { return f->canCreate(typeId); });
|
||||
if (!factory) {
|
||||
*errorMessage = Tr::tr("TypeId \"%1\" of page is unknown. Supported typeIds are: \"%2\".")
|
||||
.arg(strVal)
|
||||
.arg(supportedTypeIds(s_pageFactories).replace(QLatin1String(Constants::PAGE_ID_PREFIX), QLatin1String("")));
|
||||
.arg(supportedTypeIds(pageFactories()).replace(QLatin1String(Constants::PAGE_ID_PREFIX), QLatin1String("")));
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -519,18 +548,6 @@ int JsonWizardFactory::verbose()
|
||||
return m_verbose;
|
||||
}
|
||||
|
||||
void JsonWizardFactory::registerPageFactory(JsonWizardPageFactory *factory)
|
||||
{
|
||||
QTC_ASSERT(!s_pageFactories.contains(factory), return);
|
||||
s_pageFactories.append(factory);
|
||||
}
|
||||
|
||||
void JsonWizardFactory::registerGeneratorFactory(JsonWizardGeneratorFactory *factory)
|
||||
{
|
||||
QTC_ASSERT(!s_generatorFactories.contains(factory), return);
|
||||
s_generatorFactories.append(factory);
|
||||
}
|
||||
|
||||
static QString qmlProjectName(const FilePath &folder)
|
||||
{
|
||||
FilePath currentFolder = folder;
|
||||
@@ -598,7 +615,7 @@ Wizard *JsonWizardFactory::runWizardImpl(const FilePath &path, QWidget *parent,
|
||||
continue;
|
||||
|
||||
havePage = true;
|
||||
JsonWizardPageFactory *factory = findOr(s_pageFactories, nullptr,
|
||||
JsonWizardPageFactory *factory = findOr(pageFactories(), nullptr,
|
||||
[&data](JsonWizardPageFactory *f) {
|
||||
return f->canCreate(data.typeId);
|
||||
});
|
||||
@@ -621,7 +638,7 @@ Wizard *JsonWizardFactory::runWizardImpl(const FilePath &path, QWidget *parent,
|
||||
|
||||
for (const Generator &data : std::as_const(m_generators)) {
|
||||
QTC_ASSERT(data.isValid(), continue);
|
||||
JsonWizardGeneratorFactory *factory = Utils::findOr(s_generatorFactories, nullptr,
|
||||
JsonWizardGeneratorFactory *factory = Utils::findOr(generatorFactories(), nullptr,
|
||||
[&data](JsonWizardGeneratorFactory *f) {
|
||||
return f->canCreate(data.typeId);
|
||||
});
|
||||
@@ -701,14 +718,6 @@ bool JsonWizardFactory::isAvailable(Id platformId) const
|
||||
return JsonWizard::boolFromVariant(m_enabledExpression, &expander);
|
||||
}
|
||||
|
||||
void JsonWizardFactory::destroyAllFactories()
|
||||
{
|
||||
qDeleteAll(s_pageFactories);
|
||||
s_pageFactories.clear();
|
||||
qDeleteAll(s_generatorFactories);
|
||||
s_generatorFactories.clear();
|
||||
}
|
||||
|
||||
bool JsonWizardFactory::initialize(const QVariantMap &data, const FilePath &baseDir, QString *errorMessage)
|
||||
{
|
||||
QTC_ASSERT(errorMessage, return false);
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
class JsonWizardFactory;
|
||||
class JsonWizardPageFactory;
|
||||
class JsonWizardGeneratorFactory;
|
||||
class ProjectExplorerPlugin;
|
||||
class ProjectExplorerPluginPrivate;
|
||||
|
||||
@@ -52,9 +49,6 @@ public:
|
||||
QVariant data;
|
||||
};
|
||||
|
||||
static void registerPageFactory(JsonWizardPageFactory *factory);
|
||||
static void registerGeneratorFactory(JsonWizardGeneratorFactory *factory);
|
||||
|
||||
static QList<QVariant> objectOrList(const QVariant &data, QString *errorMessage);
|
||||
|
||||
static QString localizedString(const QVariant &value);
|
||||
@@ -78,7 +72,6 @@ private:
|
||||
static void setVerbose(int level);
|
||||
static int verbose();
|
||||
|
||||
static void destroyAllFactories();
|
||||
bool initialize(const QVariantMap &data, const Utils::FilePath &baseDir, QString *errorMessage);
|
||||
|
||||
JsonWizardFactory::Page parsePage(const QVariant &value, QString *errorMessage);
|
||||
|
||||
@@ -47,6 +47,9 @@ class PROJECTEXPLORER_EXPORT JsonWizardGeneratorFactory : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
JsonWizardGeneratorFactory();
|
||||
~JsonWizardGeneratorFactory() override;
|
||||
|
||||
bool canCreate(Utils::Id typeId) const { return m_typeIds.contains(typeId); }
|
||||
QList<Utils::Id> supportedIds() const { return m_typeIds; }
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace ProjectExplorer {
|
||||
// JsonWizardPageFactory:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
JsonWizardPageFactory::~JsonWizardPageFactory() = default;
|
||||
|
||||
void JsonWizardPageFactory::setTypeIdsSuffixes(const QStringList &suffixes)
|
||||
{
|
||||
m_typeIds = Utils::transform(suffixes, [](const QString &suffix) {
|
||||
|
||||
@@ -18,6 +18,7 @@ class JsonWizard;
|
||||
class PROJECTEXPLORER_EXPORT JsonWizardPageFactory
|
||||
{
|
||||
public:
|
||||
JsonWizardPageFactory();
|
||||
virtual ~JsonWizardPageFactory();
|
||||
|
||||
bool canCreate(Utils::Id typeId) const { return m_typeIds.contains(typeId); }
|
||||
|
||||
@@ -690,6 +690,15 @@ public:
|
||||
|
||||
DeviceCheckBuildStepFactory deviceCheckBuildStepFactory;
|
||||
SanitizerOutputFormatterFactory sanitizerFormatterFactory;
|
||||
|
||||
// JsonWizard related
|
||||
FieldPageFactory fieldPageFactory;
|
||||
FilePageFactory filePageFactory;
|
||||
KitsPageFactory kitsPageFactory;
|
||||
ProjectPageFactory projectPageFactory;
|
||||
SummaryPageFactory summaryPageFactory;
|
||||
FileGeneratorFactory fileGeneratorFactory;
|
||||
ScannerGeneratorFactory scannerGeneratorFactory;
|
||||
};
|
||||
|
||||
static ProjectExplorerPlugin *m_instance = nullptr;
|
||||
@@ -756,7 +765,6 @@ ProjectExplorerPlugin::~ProjectExplorerPlugin()
|
||||
QTC_ASSERT(dd, return);
|
||||
|
||||
delete dd->m_proWindow; // Needs access to the kit manager.
|
||||
JsonWizardFactory::destroyAllFactories();
|
||||
|
||||
// Force sequence of deletion:
|
||||
KitManager::destroy(); // remove all the profile information
|
||||
@@ -843,15 +851,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
: FilePath());
|
||||
});
|
||||
|
||||
// For JsonWizard:
|
||||
JsonWizardFactory::registerPageFactory(new FieldPageFactory);
|
||||
JsonWizardFactory::registerPageFactory(new FilePageFactory);
|
||||
JsonWizardFactory::registerPageFactory(new KitsPageFactory);
|
||||
JsonWizardFactory::registerPageFactory(new ProjectPageFactory);
|
||||
JsonWizardFactory::registerPageFactory(new SummaryPageFactory);
|
||||
JsonWizardFactory::registerGeneratorFactory(new FileGeneratorFactory);
|
||||
JsonWizardFactory::registerGeneratorFactory(new ScannerGeneratorFactory);
|
||||
|
||||
dd->m_proWindow = new ProjectWindow;
|
||||
|
||||
Context projectTreeContext(Constants::C_PROJECT_TREE);
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
PySideBuildConfigurationFactory buildConfigFactory;
|
||||
SimpleTargetRunnerFactory runWorkerFactory{{runConfigFactory.runConfigurationId()}};
|
||||
PythonSettings settings;
|
||||
PythonWizardPageFactory pythonWizardPageFactory;
|
||||
};
|
||||
|
||||
PythonPlugin::PythonPlugin()
|
||||
@@ -61,7 +62,6 @@ void PythonPlugin::initialize()
|
||||
|
||||
ProjectManager::registerProjectType<PythonProject>(PythonMimeType);
|
||||
ProjectManager::registerProjectType<PythonProject>(PythonMimeTypeLegacy);
|
||||
JsonWizardFactory::registerPageFactory(new PythonWizardPageFactory);
|
||||
}
|
||||
|
||||
void PythonPlugin::extensionsInitialized()
|
||||
|
||||
@@ -67,6 +67,8 @@ public:
|
||||
|
||||
DesignerExternalEditor designerEditor;
|
||||
LinguistEditor linguistEditor;
|
||||
|
||||
TranslationWizardPageFactory translationWizardPageFactory;
|
||||
};
|
||||
|
||||
QtSupportPlugin::~QtSupportPlugin()
|
||||
@@ -131,7 +133,6 @@ void QtSupportPlugin::initialize()
|
||||
new ProFileCacheManager(this);
|
||||
|
||||
JsExpander::registerGlobalObject<CodeGenerator>("QtSupport");
|
||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new TranslationWizardPageFactory);
|
||||
|
||||
BuildPropertiesSettings::showQtSettings();
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ public:
|
||||
ObjectsMapEditorFactory m_objectsMapEditorFactory;
|
||||
SquishOutputPane *m_outputPane = nullptr;
|
||||
SquishTools * m_squishTools = nullptr;
|
||||
|
||||
SquishToolkitsPageFactory m_squishToolkitsPageFactory;
|
||||
SquishScriptLanguagePageFactory m_squishScriptLanguagePageFactory;
|
||||
SquishAUTPageFactory m_squishAUTPageFactory;
|
||||
SquishGeneratorFactory m_squishGeneratorFactory;
|
||||
};
|
||||
|
||||
static SquishPluginPrivate *dd = nullptr;
|
||||
@@ -59,11 +64,6 @@ SquishPluginPrivate::SquishPluginPrivate()
|
||||
m_outputPane = SquishOutputPane::instance();
|
||||
m_squishTools = new SquishTools;
|
||||
initializeMenuEntries();
|
||||
|
||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new SquishToolkitsPageFactory);
|
||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new SquishScriptLanguagePageFactory);
|
||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new SquishAUTPageFactory);
|
||||
ProjectExplorer::JsonWizardFactory::registerGeneratorFactory(new SquishGeneratorFactory);
|
||||
}
|
||||
|
||||
SquishPluginPrivate::~SquishPluginPrivate()
|
||||
|
||||
@@ -72,6 +72,9 @@ public:
|
||||
|
||||
VcsPlugin *q;
|
||||
QStandardItemModel *m_nickNameModel = nullptr;
|
||||
|
||||
VcsConfigurationPageFactory m_vcsConfigurationPageFactory;
|
||||
VcsCommandPageFactory m_vcsCommandPageFactory;
|
||||
};
|
||||
|
||||
static VcsPlugin *m_instance = nullptr;
|
||||
@@ -100,9 +103,6 @@ void VcsPlugin::initialize()
|
||||
return result;
|
||||
});
|
||||
|
||||
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
|
||||
JsonWizardFactory::registerPageFactory(new Internal::VcsCommandPageFactory);
|
||||
|
||||
JsExpander::registerGlobalObject<VcsJsExtension>("Vcs");
|
||||
|
||||
MacroExpander *expander = globalMacroExpander();
|
||||
|
||||
Reference in New Issue
Block a user