forked from qt-creator/qt-creator
BaseQtVersion: Modernize code
Use member initialization, remove lots of duplication in the different constructors. This adds a wrapper around the unique_ptr of the MacroExpander to enable use of the default copy constructor, which would be blocked by the deleted copy constructor of unique_ptr otherwise. Change-Id: I8bad5cedb71069b3d535436b89057f68319367ea Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -101,13 +101,22 @@ static QSet<Id> versionedIds(const QByteArray &prefix, int major, int minor)
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////
|
||||
// MacroExpanderWrapper
|
||||
///////////////
|
||||
MacroExpander *MacroExpanderWrapper::macroExpander(const BaseQtVersion *qtversion) const
|
||||
{
|
||||
if (!m_expander)
|
||||
m_expander = BaseQtVersion::createMacroExpander([qtversion]() { return qtversion; });
|
||||
return m_expander.get();
|
||||
}
|
||||
|
||||
///////////////
|
||||
// QtVersionNumber
|
||||
///////////////
|
||||
QtVersionNumber::QtVersionNumber(int ma, int mi, int p)
|
||||
: majorVersion(ma), minorVersion(mi), patchVersion(p)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
QtVersionNumber::QtVersionNumber(const QString &versionString)
|
||||
{
|
||||
@@ -116,11 +125,6 @@ QtVersionNumber::QtVersionNumber(const QString &versionString)
|
||||
majorVersion = minorVersion = patchVersion = -1;
|
||||
}
|
||||
|
||||
QtVersionNumber::QtVersionNumber()
|
||||
{
|
||||
majorVersion = minorVersion = patchVersion = -1;
|
||||
}
|
||||
|
||||
QSet<Id> QtVersionNumber::features() const
|
||||
{
|
||||
return versionedIds(Constants::FEATURE_QT_PREFIX, majorVersion, minorVersion);
|
||||
@@ -182,112 +186,17 @@ bool QtVersionNumber::operator >=(const QtVersionNumber &b) const
|
||||
///////////////
|
||||
// BaseQtVersion
|
||||
///////////////
|
||||
int BaseQtVersion::getUniqueId()
|
||||
{
|
||||
return QtVersionManager::getUniqueId();
|
||||
}
|
||||
|
||||
BaseQtVersion::BaseQtVersion(const FileName &qmakeCommand, bool isAutodetected, const QString &autodetectionSource)
|
||||
: m_id(getUniqueId()),
|
||||
: m_id(QtVersionManager::getUniqueId()),
|
||||
m_isAutodetected(isAutodetected),
|
||||
m_hasQmlDump(false),
|
||||
m_mkspecUpToDate(false),
|
||||
m_mkspecReadUpToDate(false),
|
||||
m_defaultConfigIsDebug(true),
|
||||
m_defaultConfigIsDebugAndRelease(true),
|
||||
m_frameworkBuild(false),
|
||||
m_versionInfoUpToDate(false),
|
||||
m_installed(true),
|
||||
m_hasExamples(false),
|
||||
m_hasDemos(false),
|
||||
m_hasDocumentation(false),
|
||||
m_qmakeIsExecutable(true),
|
||||
m_hasQtAbis(false),
|
||||
m_autodetectionSource(autodetectionSource)
|
||||
{
|
||||
ctor(qmakeCommand);
|
||||
}
|
||||
m_autodetectionSource(autodetectionSource),
|
||||
m_qmakeCommand(qmakeCommand)
|
||||
{ }
|
||||
BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) = default;
|
||||
BaseQtVersion::BaseQtVersion() = default;
|
||||
|
||||
BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) :
|
||||
m_id(other.m_id),
|
||||
m_isAutodetected(other.m_isAutodetected),
|
||||
m_hasQmlDump(other.m_hasQmlDump),
|
||||
m_mkspecUpToDate(other.m_mkspecUpToDate),
|
||||
m_mkspecReadUpToDate(other.m_mkspecReadUpToDate),
|
||||
m_defaultConfigIsDebug(other.m_defaultConfigIsDebug),
|
||||
m_defaultConfigIsDebugAndRelease(other.m_defaultConfigIsDebugAndRelease),
|
||||
m_frameworkBuild(other.m_frameworkBuild),
|
||||
m_versionInfoUpToDate(other.m_versionInfoUpToDate),
|
||||
m_installed(other.m_installed),
|
||||
m_hasExamples(other.m_hasExamples),
|
||||
m_hasDemos(other.m_hasDemos),
|
||||
m_hasDocumentation(other.m_hasDocumentation),
|
||||
m_qmakeIsExecutable(other.m_qmakeIsExecutable),
|
||||
m_hasQtAbis(other.m_hasQtAbis),
|
||||
m_configValues(other.m_configValues),
|
||||
m_qtConfigValues(other.m_qtConfigValues),
|
||||
m_unexpandedDisplayName(other.m_unexpandedDisplayName),
|
||||
m_autodetectionSource(other.m_autodetectionSource),
|
||||
m_overrideFeatures(other.m_overrideFeatures),
|
||||
m_sourcePath(other.m_sourcePath),
|
||||
m_mkspec(other.m_mkspec),
|
||||
m_mkspecFullPath(other.m_mkspecFullPath),
|
||||
m_mkspecValues(other.m_mkspecValues),
|
||||
m_versionInfo(other.m_versionInfo),
|
||||
m_qmakeCommand(other.m_qmakeCommand),
|
||||
m_qtVersionString(other.m_qtVersionString),
|
||||
m_uicCommand(other.m_uicCommand),
|
||||
m_designerCommand(other.m_designerCommand),
|
||||
m_linguistCommand(other.m_linguistCommand),
|
||||
m_qscxmlcCommand(other.m_qscxmlcCommand),
|
||||
m_qtAbis(other.m_qtAbis)
|
||||
{
|
||||
setupExpander();
|
||||
}
|
||||
|
||||
BaseQtVersion::BaseQtVersion()
|
||||
: m_id(-1), m_isAutodetected(false),
|
||||
m_hasQmlDump(false),
|
||||
m_mkspecUpToDate(false),
|
||||
m_mkspecReadUpToDate(false),
|
||||
m_defaultConfigIsDebug(true),
|
||||
m_defaultConfigIsDebugAndRelease(true),
|
||||
m_frameworkBuild(false),
|
||||
m_versionInfoUpToDate(false),
|
||||
m_installed(true),
|
||||
m_hasExamples(false),
|
||||
m_hasDemos(false),
|
||||
m_hasDocumentation(false),
|
||||
m_qmakeIsExecutable(true),
|
||||
m_hasQtAbis(false)
|
||||
{
|
||||
ctor(FileName());
|
||||
}
|
||||
|
||||
void BaseQtVersion::ctor(const FileName &qmakePath)
|
||||
{
|
||||
m_qmakeCommand = qmakePath;
|
||||
m_designerCommand.clear();
|
||||
m_linguistCommand.clear();
|
||||
m_uicCommand.clear();
|
||||
m_qscxmlcCommand.clear();
|
||||
m_mkspecUpToDate = false;
|
||||
m_mkspecReadUpToDate = false;
|
||||
m_versionInfoUpToDate = false;
|
||||
m_hasQtAbis = false;
|
||||
m_qtVersionString.clear();
|
||||
m_sourcePath.clear();
|
||||
setupExpander();
|
||||
}
|
||||
|
||||
void BaseQtVersion::setupExpander()
|
||||
{
|
||||
m_expander = createMacroExpander([this]{ return this; });
|
||||
}
|
||||
|
||||
BaseQtVersion::~BaseQtVersion()
|
||||
{
|
||||
}
|
||||
BaseQtVersion::~BaseQtVersion() = default;
|
||||
|
||||
QString BaseQtVersion::defaultUnexpandedDisplayName(const FileName &qmakePath, bool fromPath)
|
||||
{
|
||||
@@ -602,7 +511,7 @@ void BaseQtVersion::fromMap(const QVariantMap &map)
|
||||
string = BuildableHelperLibrary::qtChooserToQmakePath(fi.symLinkTarget());
|
||||
}
|
||||
|
||||
ctor(FileName::fromString(string));
|
||||
m_qmakeCommand = Utils::FileName::fromString(string);
|
||||
}
|
||||
|
||||
QVariantMap BaseQtVersion::toMap() const
|
||||
@@ -723,7 +632,7 @@ void BaseQtVersion::setAutoDetectionSource(const QString &autodetectionSource)
|
||||
|
||||
QString BaseQtVersion::displayName() const
|
||||
{
|
||||
return m_expander->expand(m_unexpandedDisplayName);
|
||||
return macroExpander()->expand(m_unexpandedDisplayName);
|
||||
}
|
||||
|
||||
QString BaseQtVersion::unexpandedDisplayName() const
|
||||
@@ -1234,15 +1143,16 @@ QStringList BaseQtVersion::qtConfigValues() const
|
||||
|
||||
MacroExpander *BaseQtVersion::macroExpander() const
|
||||
{
|
||||
return m_expander.get();
|
||||
return m_expander.macroExpander(this);
|
||||
}
|
||||
|
||||
std::unique_ptr<MacroExpander> BaseQtVersion::createMacroExpander(const std::function<BaseQtVersion *()> &qtVersion)
|
||||
std::unique_ptr<MacroExpander>
|
||||
BaseQtVersion::createMacroExpander(const std::function<const BaseQtVersion *()> &qtVersion)
|
||||
{
|
||||
const auto versionProperty =
|
||||
[qtVersion](const std::function<QString(BaseQtVersion *)> &property) {
|
||||
[qtVersion](const std::function<QString(const BaseQtVersion *)> &property) {
|
||||
return [property, qtVersion]() -> QString {
|
||||
BaseQtVersion *version = qtVersion();
|
||||
const BaseQtVersion *version = qtVersion();
|
||||
return version ? property(version) : QString();
|
||||
};
|
||||
};
|
||||
@@ -1252,140 +1162,140 @@ std::unique_ptr<MacroExpander> BaseQtVersion::createMacroExpander(const std::fun
|
||||
expander->registerVariable(
|
||||
"Qt:Version",
|
||||
QtKitInformation::tr("The version string of the current Qt version."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qtVersionString();
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:Type",
|
||||
QtKitInformation::tr("The type of the current Qt version."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->type();
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:Mkspec",
|
||||
QtKitInformation::tr("The mkspec of the current Qt version."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->mkspec().toUserOutput();
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_PREFIX",
|
||||
QtKitInformation::tr("The installation prefix of the current Qt version."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_PREFIX");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_DATA",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's data."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_DATA");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_HEADERS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's header files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_HEADERS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_LIBS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's library files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_LIBS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_DOCS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's documentation files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_DOCS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_BINS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's executable files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_BINS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_PLUGINS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's plugins."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_PLUGINS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_QML",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's QML files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_QML");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_IMPORTS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's imports."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_IMPORTS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_TRANSLATIONS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's translation files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_TRANSLATIONS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_CONFIGURATION",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's translation files."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_CONFIGURATION");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_EXAMPLES",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's examples."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_EXAMPLES");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QT_INSTALL_DEMOS",
|
||||
QtKitInformation::tr("The installation location of the current Qt version's demos."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_DEMOS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QMAKE_MKSPECS",
|
||||
QtKitInformation::tr("The current Qt version's default mkspecs (Qt 4)."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QMAKE_MKSPECS");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QMAKE_SPEC",
|
||||
QtKitInformation::tr("The current Qt version's default mkspec (Qt 5; host system)."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QMAKE_SPEC");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QMAKE_XSPEC",
|
||||
QtKitInformation::tr("The current Qt version's default mkspec (Qt 5; target system)."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QMAKE_XSPEC");
|
||||
}));
|
||||
|
||||
expander->registerVariable(
|
||||
"Qt:QMAKE_VERSION",
|
||||
QtKitInformation::tr("The current Qt's qmake version."),
|
||||
versionProperty([](BaseQtVersion *version) {
|
||||
versionProperty([](const BaseQtVersion *version) {
|
||||
return version->qmakeProperty(version->m_versionInfo, "QMAKE_VERSION");
|
||||
}));
|
||||
|
||||
|
||||
@@ -63,12 +63,26 @@ namespace QtSupport
|
||||
{
|
||||
class QtConfigWidget;
|
||||
|
||||
class BaseQtVersion;
|
||||
|
||||
// Wrapper to make the std::unique_ptr<Utils::MacroExpander> "copyable":
|
||||
class MacroExpanderWrapper
|
||||
{
|
||||
public:
|
||||
MacroExpanderWrapper() = default;
|
||||
MacroExpanderWrapper(const MacroExpanderWrapper &other) { Q_UNUSED(other); }
|
||||
MacroExpanderWrapper(MacroExpanderWrapper &&other) = default;
|
||||
|
||||
Utils::MacroExpander *macroExpander(const BaseQtVersion *qtversion) const;
|
||||
private:
|
||||
mutable std::unique_ptr<Utils::MacroExpander> m_expander;
|
||||
};
|
||||
|
||||
class QTSUPPORT_EXPORT QtVersionNumber
|
||||
{
|
||||
public:
|
||||
QtVersionNumber(int ma, int mi, int p);
|
||||
QtVersionNumber(int ma = -1, int mi = -1, int p = -1);
|
||||
QtVersionNumber(const QString &versionString);
|
||||
QtVersionNumber();
|
||||
|
||||
QSet<Core::Id> features() const;
|
||||
|
||||
@@ -232,8 +246,8 @@ public:
|
||||
QStringList qtConfigValues() const;
|
||||
|
||||
Utils::MacroExpander *macroExpander() const; // owned by the Qt version
|
||||
static std::unique_ptr<Utils::MacroExpander> createMacroExpander(
|
||||
const std::function<BaseQtVersion *()> &qtVersion);
|
||||
static std::unique_ptr<Utils::MacroExpander>
|
||||
createMacroExpander(const std::function<const BaseQtVersion *()> &qtVersion);
|
||||
|
||||
static void populateQmlFileFinder(Utils::FileInProjectFinder *finder,
|
||||
const ProjectExplorer::Target *target);
|
||||
@@ -256,9 +270,6 @@ protected:
|
||||
|
||||
private:
|
||||
void setAutoDetectionSource(const QString &autodetectionSource);
|
||||
static int getUniqueId();
|
||||
void ctor(const Utils::FileName &qmakePath);
|
||||
void setupExpander();
|
||||
void updateSourcePath() const;
|
||||
void updateVersionInfo() const;
|
||||
enum HostBinaries { Designer, Linguist, Uic, QScxmlc };
|
||||
@@ -278,22 +289,22 @@ private:
|
||||
void setId(int id); // used by the qtversionmanager for legacy restore
|
||||
// and by the qtoptionspage to replace Qt versions
|
||||
|
||||
int m_id;
|
||||
int m_id = -1;
|
||||
|
||||
bool m_isAutodetected;
|
||||
mutable bool m_hasQmlDump; // controlled by m_versionInfoUpToDate
|
||||
mutable bool m_mkspecUpToDate;
|
||||
mutable bool m_mkspecReadUpToDate;
|
||||
mutable bool m_defaultConfigIsDebug;
|
||||
mutable bool m_defaultConfigIsDebugAndRelease;
|
||||
mutable bool m_frameworkBuild;
|
||||
mutable bool m_versionInfoUpToDate;
|
||||
mutable bool m_installed;
|
||||
mutable bool m_hasExamples;
|
||||
mutable bool m_hasDemos;
|
||||
mutable bool m_hasDocumentation;
|
||||
mutable bool m_qmakeIsExecutable;
|
||||
mutable bool m_hasQtAbis;
|
||||
bool m_isAutodetected = false;
|
||||
mutable bool m_hasQmlDump = false; // controlled by m_versionInfoUpToDate
|
||||
mutable bool m_mkspecUpToDate = false;
|
||||
mutable bool m_mkspecReadUpToDate = false;
|
||||
mutable bool m_defaultConfigIsDebug = true;
|
||||
mutable bool m_defaultConfigIsDebugAndRelease = true;
|
||||
mutable bool m_frameworkBuild = false;
|
||||
mutable bool m_versionInfoUpToDate = false;
|
||||
mutable bool m_installed = true;
|
||||
mutable bool m_hasExamples = false;
|
||||
mutable bool m_hasDemos = false;
|
||||
mutable bool m_hasDocumentation = false;
|
||||
mutable bool m_qmakeIsExecutable = true;
|
||||
mutable bool m_hasQtAbis = false;
|
||||
|
||||
mutable QStringList m_configValues;
|
||||
mutable QStringList m_qtConfigValues;
|
||||
@@ -320,7 +331,7 @@ private:
|
||||
|
||||
mutable QList<ProjectExplorer::Abi> m_qtAbis;
|
||||
|
||||
std::unique_ptr<Utils::MacroExpander> m_expander;
|
||||
MacroExpanderWrapper m_expander;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user