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:
hjk
2023-08-17 11:02:25 +02:00
parent 7b0a3e7e28
commit b48e10717f
11 changed files with 62 additions and 59 deletions

View File

@@ -52,6 +52,7 @@ public:
FormEditorFactory formEditorFactory; FormEditorFactory formEditorFactory;
SettingsPageProvider settingsPageProvider; SettingsPageProvider settingsPageProvider;
QtDesignerFormClassCodeGenerator formClassCodeGenerator; QtDesignerFormClassCodeGenerator formClassCodeGenerator;
FormPageFactory formPageFactory;
}; };
FormEditorPlugin::~FormEditorPlugin() FormEditorPlugin::~FormEditorPlugin()
@@ -99,8 +100,6 @@ bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
}); });
#endif #endif
ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory);
// Ensure that loading designer translations is done before FormEditorW is instantiated // Ensure that loading designer translations is done before FormEditorW is instantiated
const QString locale = ICore::userInterfaceLanguage(); const QString locale = ICore::userInterfaceLanguage();
if (!locale.isEmpty()) { if (!locale.isEmpty()) {

View File

@@ -68,8 +68,17 @@ const char OPTIONS_KEY[] = "options";
const char PLATFORM_INDEPENDENT_KEY[] = "platformIndependent"; const char PLATFORM_INDEPENDENT_KEY[] = "platformIndependent";
const char DEFAULT_VALUES[] = "defaultValues"; const char DEFAULT_VALUES[] = "defaultValues";
static QList<JsonWizardPageFactory *> s_pageFactories; static QList<JsonWizardPageFactory *> &pageFactories()
static QList<JsonWizardGeneratorFactory *> s_generatorFactories; {
static QList<JsonWizardPageFactory *> thePageFactories;
return thePageFactories;
}
static QList<JsonWizardGeneratorFactory *> &generatorFactories()
{
static QList<JsonWizardGeneratorFactory *> theGeneratorFactories;
return theGeneratorFactories;
}
int JsonWizardFactory::m_verbose = 0; 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); Id typeId = Id::fromString(QLatin1String(Constants::GENERATOR_ID_PREFIX) + strVal);
JsonWizardGeneratorFactory *factory 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) { if (!factory) {
*errorMessage = Tr::tr("TypeId \"%1\" of generator is unknown. Supported typeIds are: \"%2\".") *errorMessage = Tr::tr("TypeId \"%1\" of generator is unknown. Supported typeIds are: \"%2\".")
.arg(strVal) .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; return gen;
} }
@@ -133,6 +142,26 @@ static JsonWizardFactory::Generator parseGenerator(const QVariant &value, QStrin
return gen; 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 //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 //internal processing and create a separate function for it. Then process the results in
//loadDefaultValues() and createWizardFactories() //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); Id typeId = Id::fromString(QLatin1String(Constants::PAGE_ID_PREFIX) + strVal);
JsonWizardPageFactory *factory 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) { if (!factory) {
*errorMessage = Tr::tr("TypeId \"%1\" of page is unknown. Supported typeIds are: \"%2\".") *errorMessage = Tr::tr("TypeId \"%1\" of page is unknown. Supported typeIds are: \"%2\".")
.arg(strVal) .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; return p;
} }
@@ -519,18 +548,6 @@ int JsonWizardFactory::verbose()
return m_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) static QString qmlProjectName(const FilePath &folder)
{ {
FilePath currentFolder = folder; FilePath currentFolder = folder;
@@ -598,7 +615,7 @@ Wizard *JsonWizardFactory::runWizardImpl(const FilePath &path, QWidget *parent,
continue; continue;
havePage = true; havePage = true;
JsonWizardPageFactory *factory = findOr(s_pageFactories, nullptr, JsonWizardPageFactory *factory = findOr(pageFactories(), nullptr,
[&data](JsonWizardPageFactory *f) { [&data](JsonWizardPageFactory *f) {
return f->canCreate(data.typeId); 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)) { for (const Generator &data : std::as_const(m_generators)) {
QTC_ASSERT(data.isValid(), continue); QTC_ASSERT(data.isValid(), continue);
JsonWizardGeneratorFactory *factory = Utils::findOr(s_generatorFactories, nullptr, JsonWizardGeneratorFactory *factory = Utils::findOr(generatorFactories(), nullptr,
[&data](JsonWizardGeneratorFactory *f) { [&data](JsonWizardGeneratorFactory *f) {
return f->canCreate(data.typeId); return f->canCreate(data.typeId);
}); });
@@ -701,14 +718,6 @@ bool JsonWizardFactory::isAvailable(Id platformId) const
return JsonWizard::boolFromVariant(m_enabledExpression, &expander); 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) bool JsonWizardFactory::initialize(const QVariantMap &data, const FilePath &baseDir, QString *errorMessage)
{ {
QTC_ASSERT(errorMessage, return false); QTC_ASSERT(errorMessage, return false);

View File

@@ -15,9 +15,6 @@
namespace ProjectExplorer { namespace ProjectExplorer {
class JsonWizardFactory;
class JsonWizardPageFactory;
class JsonWizardGeneratorFactory;
class ProjectExplorerPlugin; class ProjectExplorerPlugin;
class ProjectExplorerPluginPrivate; class ProjectExplorerPluginPrivate;
@@ -52,9 +49,6 @@ public:
QVariant data; QVariant data;
}; };
static void registerPageFactory(JsonWizardPageFactory *factory);
static void registerGeneratorFactory(JsonWizardGeneratorFactory *factory);
static QList<QVariant> objectOrList(const QVariant &data, QString *errorMessage); static QList<QVariant> objectOrList(const QVariant &data, QString *errorMessage);
static QString localizedString(const QVariant &value); static QString localizedString(const QVariant &value);
@@ -78,7 +72,6 @@ private:
static void setVerbose(int level); static void setVerbose(int level);
static int verbose(); static int verbose();
static void destroyAllFactories();
bool initialize(const QVariantMap &data, const Utils::FilePath &baseDir, QString *errorMessage); bool initialize(const QVariantMap &data, const Utils::FilePath &baseDir, QString *errorMessage);
JsonWizardFactory::Page parsePage(const QVariant &value, QString *errorMessage); JsonWizardFactory::Page parsePage(const QVariant &value, QString *errorMessage);

View File

@@ -47,6 +47,9 @@ class PROJECTEXPLORER_EXPORT JsonWizardGeneratorFactory : public QObject
Q_OBJECT Q_OBJECT
public: public:
JsonWizardGeneratorFactory();
~JsonWizardGeneratorFactory() override;
bool canCreate(Utils::Id typeId) const { return m_typeIds.contains(typeId); } bool canCreate(Utils::Id typeId) const { return m_typeIds.contains(typeId); }
QList<Utils::Id> supportedIds() const { return m_typeIds; } QList<Utils::Id> supportedIds() const { return m_typeIds; }

View File

@@ -13,8 +13,6 @@ namespace ProjectExplorer {
// JsonWizardPageFactory: // JsonWizardPageFactory:
// -------------------------------------------------------------------- // --------------------------------------------------------------------
JsonWizardPageFactory::~JsonWizardPageFactory() = default;
void JsonWizardPageFactory::setTypeIdsSuffixes(const QStringList &suffixes) void JsonWizardPageFactory::setTypeIdsSuffixes(const QStringList &suffixes)
{ {
m_typeIds = Utils::transform(suffixes, [](const QString &suffix) { m_typeIds = Utils::transform(suffixes, [](const QString &suffix) {

View File

@@ -18,6 +18,7 @@ class JsonWizard;
class PROJECTEXPLORER_EXPORT JsonWizardPageFactory class PROJECTEXPLORER_EXPORT JsonWizardPageFactory
{ {
public: public:
JsonWizardPageFactory();
virtual ~JsonWizardPageFactory(); virtual ~JsonWizardPageFactory();
bool canCreate(Utils::Id typeId) const { return m_typeIds.contains(typeId); } bool canCreate(Utils::Id typeId) const { return m_typeIds.contains(typeId); }

View File

@@ -690,6 +690,15 @@ public:
DeviceCheckBuildStepFactory deviceCheckBuildStepFactory; DeviceCheckBuildStepFactory deviceCheckBuildStepFactory;
SanitizerOutputFormatterFactory sanitizerFormatterFactory; SanitizerOutputFormatterFactory sanitizerFormatterFactory;
// JsonWizard related
FieldPageFactory fieldPageFactory;
FilePageFactory filePageFactory;
KitsPageFactory kitsPageFactory;
ProjectPageFactory projectPageFactory;
SummaryPageFactory summaryPageFactory;
FileGeneratorFactory fileGeneratorFactory;
ScannerGeneratorFactory scannerGeneratorFactory;
}; };
static ProjectExplorerPlugin *m_instance = nullptr; static ProjectExplorerPlugin *m_instance = nullptr;
@@ -756,7 +765,6 @@ ProjectExplorerPlugin::~ProjectExplorerPlugin()
QTC_ASSERT(dd, return); QTC_ASSERT(dd, return);
delete dd->m_proWindow; // Needs access to the kit manager. delete dd->m_proWindow; // Needs access to the kit manager.
JsonWizardFactory::destroyAllFactories();
// Force sequence of deletion: // Force sequence of deletion:
KitManager::destroy(); // remove all the profile information KitManager::destroy(); // remove all the profile information
@@ -843,15 +851,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
: FilePath()); : 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; dd->m_proWindow = new ProjectWindow;
Context projectTreeContext(Constants::C_PROJECT_TREE); Context projectTreeContext(Constants::C_PROJECT_TREE);

View File

@@ -37,6 +37,7 @@ public:
PySideBuildConfigurationFactory buildConfigFactory; PySideBuildConfigurationFactory buildConfigFactory;
SimpleTargetRunnerFactory runWorkerFactory{{runConfigFactory.runConfigurationId()}}; SimpleTargetRunnerFactory runWorkerFactory{{runConfigFactory.runConfigurationId()}};
PythonSettings settings; PythonSettings settings;
PythonWizardPageFactory pythonWizardPageFactory;
}; };
PythonPlugin::PythonPlugin() PythonPlugin::PythonPlugin()
@@ -61,7 +62,6 @@ void PythonPlugin::initialize()
ProjectManager::registerProjectType<PythonProject>(PythonMimeType); ProjectManager::registerProjectType<PythonProject>(PythonMimeType);
ProjectManager::registerProjectType<PythonProject>(PythonMimeTypeLegacy); ProjectManager::registerProjectType<PythonProject>(PythonMimeTypeLegacy);
JsonWizardFactory::registerPageFactory(new PythonWizardPageFactory);
} }
void PythonPlugin::extensionsInitialized() void PythonPlugin::extensionsInitialized()

View File

@@ -67,6 +67,8 @@ public:
DesignerExternalEditor designerEditor; DesignerExternalEditor designerEditor;
LinguistEditor linguistEditor; LinguistEditor linguistEditor;
TranslationWizardPageFactory translationWizardPageFactory;
}; };
QtSupportPlugin::~QtSupportPlugin() QtSupportPlugin::~QtSupportPlugin()
@@ -131,7 +133,6 @@ void QtSupportPlugin::initialize()
new ProFileCacheManager(this); new ProFileCacheManager(this);
JsExpander::registerGlobalObject<CodeGenerator>("QtSupport"); JsExpander::registerGlobalObject<CodeGenerator>("QtSupport");
ProjectExplorer::JsonWizardFactory::registerPageFactory(new TranslationWizardPageFactory);
BuildPropertiesSettings::showQtSettings(); BuildPropertiesSettings::showQtSettings();

View File

@@ -48,6 +48,11 @@ public:
ObjectsMapEditorFactory m_objectsMapEditorFactory; ObjectsMapEditorFactory m_objectsMapEditorFactory;
SquishOutputPane *m_outputPane = nullptr; SquishOutputPane *m_outputPane = nullptr;
SquishTools * m_squishTools = nullptr; SquishTools * m_squishTools = nullptr;
SquishToolkitsPageFactory m_squishToolkitsPageFactory;
SquishScriptLanguagePageFactory m_squishScriptLanguagePageFactory;
SquishAUTPageFactory m_squishAUTPageFactory;
SquishGeneratorFactory m_squishGeneratorFactory;
}; };
static SquishPluginPrivate *dd = nullptr; static SquishPluginPrivate *dd = nullptr;
@@ -59,11 +64,6 @@ SquishPluginPrivate::SquishPluginPrivate()
m_outputPane = SquishOutputPane::instance(); m_outputPane = SquishOutputPane::instance();
m_squishTools = new SquishTools; m_squishTools = new SquishTools;
initializeMenuEntries(); initializeMenuEntries();
ProjectExplorer::JsonWizardFactory::registerPageFactory(new SquishToolkitsPageFactory);
ProjectExplorer::JsonWizardFactory::registerPageFactory(new SquishScriptLanguagePageFactory);
ProjectExplorer::JsonWizardFactory::registerPageFactory(new SquishAUTPageFactory);
ProjectExplorer::JsonWizardFactory::registerGeneratorFactory(new SquishGeneratorFactory);
} }
SquishPluginPrivate::~SquishPluginPrivate() SquishPluginPrivate::~SquishPluginPrivate()

View File

@@ -72,6 +72,9 @@ public:
VcsPlugin *q; VcsPlugin *q;
QStandardItemModel *m_nickNameModel = nullptr; QStandardItemModel *m_nickNameModel = nullptr;
VcsConfigurationPageFactory m_vcsConfigurationPageFactory;
VcsCommandPageFactory m_vcsCommandPageFactory;
}; };
static VcsPlugin *m_instance = nullptr; static VcsPlugin *m_instance = nullptr;
@@ -100,9 +103,6 @@ void VcsPlugin::initialize()
return result; return result;
}); });
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
JsonWizardFactory::registerPageFactory(new Internal::VcsCommandPageFactory);
JsExpander::registerGlobalObject<VcsJsExtension>("Vcs"); JsExpander::registerGlobalObject<VcsJsExtension>("Vcs");
MacroExpander *expander = globalMacroExpander(); MacroExpander *expander = globalMacroExpander();