aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qtsupport/baseqtversion.cpp
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2018-06-22 13:53:02 +0200
committerTobias Hunger <tobias.hunger@qt.io>2018-06-22 14:25:30 +0000
commitffc651d54ee619c8779a79c6f430efbf106ee61b (patch)
tree764a8b1c4b7fafc2a0a507ec0b03d8d098063ec2 /src/plugins/qtsupport/baseqtversion.cpp
parent1058e21d029f9f45ec7e14d71484c3f282e16e1d (diff)
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>
Diffstat (limited to 'src/plugins/qtsupport/baseqtversion.cpp')
-rw-r--r--src/plugins/qtsupport/baseqtversion.cpp180
1 files changed, 45 insertions, 135 deletions
diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp
index af6cdcb44a..86c188617c 100644
--- a/src/plugins/qtsupport/baseqtversion.cpp
+++ b/src/plugins/qtsupport/baseqtversion.cpp
@@ -102,12 +102,21 @@ static QSet<Id> versionedIds(const QByteArray &prefix, int major, int minor)
}
///////////////
+// 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);
-}
-
-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; });
-}
+ m_autodetectionSource(autodetectionSource),
+ m_qmakeCommand(qmakeCommand)
+{ }
+BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) = default;
+BaseQtVersion::BaseQtVersion() = default;
-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");
}));