QtSupport: Use setup pattern for UIC and SCXML extracompilers

Change-Id: I4727333e9716eae41ea41a37f032fb44b383212c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2024-01-18 09:28:04 +01:00
parent a4e6d36427
commit 6467797af2
5 changed files with 66 additions and 87 deletions

View File

@@ -5,6 +5,8 @@
#include <qtsupport/baseqtversion.h> #include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitaspect.h> #include <qtsupport/qtkitaspect.h>
#include <projectexplorer/extracompiler.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -16,7 +18,7 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace QtSupport { namespace QtSupport::Internal {
static QLoggingCategory log("qtc.qscxmlcgenerator", QtWarningMsg); static QLoggingCategory log("qtc.qscxmlcgenerator", QtWarningMsg);
@@ -85,12 +87,9 @@ Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
FilePath QScxmlcGenerator::command() const FilePath QScxmlcGenerator::command() const
{ {
QtSupport::QtVersion *version = nullptr; Target *target = project()->activeTarget();
Target *target; Kit *kit = target ? target->kit() : KitManager::defaultKit();
if ((target = project()->activeTarget())) QtVersion *version = QtKitAspect::qtVersion(kit);
version = QtSupport::QtKitAspect::qtVersion(target->kit());
else
version = QtSupport::QtKitAspect::qtVersion(KitManager::defaultKit());
if (!version) if (!version)
return {}; return {};
@@ -125,21 +124,28 @@ FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Process *process)
return result; return result;
} }
FileType QScxmlcGeneratorFactory::sourceType() const // QScxmlcGeneratorFactory
class QScxmlcGeneratorFactory final : public ExtraCompilerFactory
{ {
return FileType::StateChart; public:
QScxmlcGeneratorFactory() = default;
FileType sourceType() const final { return FileType::StateChart; }
QString sourceTag() const final { return QStringLiteral("scxml"); }
ExtraCompiler *create(const Project *project,
const FilePath &source,
const FilePaths &targets) final
{
return new QScxmlcGenerator(project, source, targets, this);
}
};
void setupQScxmlcGenerator()
{
static QScxmlcGeneratorFactory theQScxmlcGeneratorFactory;
} }
QString QScxmlcGeneratorFactory::sourceTag() const } // QtSupport::Internal
{
return QStringLiteral("scxml");
}
ExtraCompiler *QScxmlcGeneratorFactory::create(
const Project *project, const FilePath &source,
const FilePaths &targets)
{
return new QScxmlcGenerator(project, source, targets, this);
}
} // namespace QtSupport

View File

@@ -3,24 +3,8 @@
#pragma once #pragma once
#include <projectexplorer/extracompiler.h> namespace QtSupport::Internal {
#include <utils/filepath.h> void setupQScxmlcGenerator();
namespace QtSupport { } // QtSupport::Internal
class QScxmlcGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
{
public:
QScxmlcGeneratorFactory() = default;
ProjectExplorer::FileType sourceType() const override;
QString sourceTag() const override;
ProjectExplorer::ExtraCompiler *create(const ProjectExplorer::Project *project,
const Utils::FilePath &source,
const Utils::FilePaths &targets) override;
};
} // QtSupport

View File

@@ -48,9 +48,6 @@ namespace QtSupport::Internal {
class QtSupportPluginPrivate class QtSupportPluginPrivate
{ {
public: public:
UicGeneratorFactory uicGeneratorFactory;
QScxmlcGeneratorFactory qscxmlcGeneratorFactory;
DesignerExternalEditor designerEditor; DesignerExternalEditor designerEditor;
LinguistEditor linguistEditor; LinguistEditor linguistEditor;
@@ -109,6 +106,8 @@ void QtSupportPlugin::initialize()
setupGettingStartedWelcomePage(); setupGettingStartedWelcomePage();
setupQtSettingsPage(); setupQtSettingsPage();
setupQtOutputFormatter(); setupQtOutputFormatter();
setupUicGenerator();
setupQScxmlcGenerator();
theProcessRunner() = processRunnerCallback; theProcessRunner() = processRunnerCallback;

View File

@@ -7,6 +7,7 @@
#include "qtkitaspect.h" #include "qtkitaspect.h"
#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/extracompiler.h>
#include <projectexplorer/kitmanager.h> #include <projectexplorer/kitmanager.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -19,7 +20,7 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace QtSupport { namespace QtSupport::Internal {
class UicGenerator final : public ProcessExtraCompiler class UicGenerator final : public ProcessExtraCompiler
{ {
@@ -32,19 +33,16 @@ public:
} }
protected: protected:
FilePath command() const override; FilePath command() const final;
QStringList arguments() const override { return {"-p"}; } QStringList arguments() const final { return {"-p"}; }
FileNameToContentsHash handleProcessFinished(Process *process) override; FileNameToContentsHash handleProcessFinished(Process *process) final;
}; };
FilePath UicGenerator::command() const FilePath UicGenerator::command() const
{ {
QtSupport::QtVersion *version = nullptr; Target *target = project()->activeTarget();
Target *target; Kit *kit = target ? target->kit() : KitManager::defaultKit();
if ((target = project()->activeTarget())) QtVersion *version = QtKitAspect::qtVersion(kit);
version = QtSupport::QtKitAspect::qtVersion(target->kit());
else
version = QtSupport::QtKitAspect::qtVersion(KitManager::defaultKit());
if (!version) if (!version)
return {}; return {};
@@ -69,21 +67,28 @@ FileNameToContentsHash UicGenerator::handleProcessFinished(Process *process)
return result; return result;
} }
FileType UicGeneratorFactory::sourceType() const // UicGeneratorFactory
class UicGeneratorFactory final : public ExtraCompilerFactory
{ {
return FileType::Form; public:
UicGeneratorFactory() = default;
FileType sourceType() const final { return FileType::Form; }
QString sourceTag() const final { return QLatin1String("ui"); }
ExtraCompiler *create(const Project *project,
const FilePath &source,
const FilePaths &targets) final
{
return new UicGenerator(project, source, targets, this);
}
};
void setupUicGenerator()
{
static UicGeneratorFactory theUicGeneratorFactory;
} }
QString UicGeneratorFactory::sourceTag() const } // QtSupport::Internal
{
return QLatin1String("ui");
}
ExtraCompiler *UicGeneratorFactory::create(const Project *project,
const FilePath &source,
const FilePaths &targets)
{
return new UicGenerator(project, source, targets, this);
}
} // QtSupport

View File

@@ -3,23 +3,8 @@
#pragma once #pragma once
#include <projectexplorer/extracompiler.h> namespace QtSupport::Internal {
#include <utils/filepath.h>
namespace QtSupport { void setupUicGenerator();
class UicGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory } // QtSupport::Internal
{
public:
UicGeneratorFactory() = default;
ProjectExplorer::FileType sourceType() const override;
QString sourceTag() const override;
ProjectExplorer::ExtraCompiler *create(const ProjectExplorer::Project *project,
const Utils::FilePath &source,
const Utils::FilePaths &targets) override;
};
} // QtSupport