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:
Tobias Hunger
2018-06-22 13:53:02 +02:00
parent 1058e21d02
commit ffc651d54e
2 changed files with 79 additions and 158 deletions

View File

@@ -101,13 +101,22 @@ static QSet<Id> versionedIds(const QByteArray &prefix, int major, int minor)
return result; 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::QtVersionNumber(int ma, int mi, int p) QtVersionNumber::QtVersionNumber(int ma, int mi, int p)
: majorVersion(ma), minorVersion(mi), patchVersion(p) : majorVersion(ma), minorVersion(mi), patchVersion(p)
{ { }
}
QtVersionNumber::QtVersionNumber(const QString &versionString) QtVersionNumber::QtVersionNumber(const QString &versionString)
{ {
@@ -116,11 +125,6 @@ QtVersionNumber::QtVersionNumber(const QString &versionString)
majorVersion = minorVersion = patchVersion = -1; majorVersion = minorVersion = patchVersion = -1;
} }
QtVersionNumber::QtVersionNumber()
{
majorVersion = minorVersion = patchVersion = -1;
}
QSet<Id> QtVersionNumber::features() const QSet<Id> QtVersionNumber::features() const
{ {
return versionedIds(Constants::FEATURE_QT_PREFIX, majorVersion, minorVersion); return versionedIds(Constants::FEATURE_QT_PREFIX, majorVersion, minorVersion);
@@ -182,112 +186,17 @@ bool QtVersionNumber::operator >=(const QtVersionNumber &b) const
/////////////// ///////////////
// BaseQtVersion // BaseQtVersion
/////////////// ///////////////
int BaseQtVersion::getUniqueId()
{
return QtVersionManager::getUniqueId();
}
BaseQtVersion::BaseQtVersion(const FileName &qmakeCommand, bool isAutodetected, const QString &autodetectionSource) BaseQtVersion::BaseQtVersion(const FileName &qmakeCommand, bool isAutodetected, const QString &autodetectionSource)
: m_id(getUniqueId()), : m_id(QtVersionManager::getUniqueId()),
m_isAutodetected(isAutodetected), m_isAutodetected(isAutodetected),
m_hasQmlDump(false), m_autodetectionSource(autodetectionSource),
m_mkspecUpToDate(false), m_qmakeCommand(qmakeCommand)
m_mkspecReadUpToDate(false), { }
m_defaultConfigIsDebug(true), BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) = default;
m_defaultConfigIsDebugAndRelease(true), BaseQtVersion::BaseQtVersion() = default;
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) : BaseQtVersion::~BaseQtVersion() = default;
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()
{
}
QString BaseQtVersion::defaultUnexpandedDisplayName(const FileName &qmakePath, bool fromPath) QString BaseQtVersion::defaultUnexpandedDisplayName(const FileName &qmakePath, bool fromPath)
{ {
@@ -602,7 +511,7 @@ void BaseQtVersion::fromMap(const QVariantMap &map)
string = BuildableHelperLibrary::qtChooserToQmakePath(fi.symLinkTarget()); string = BuildableHelperLibrary::qtChooserToQmakePath(fi.symLinkTarget());
} }
ctor(FileName::fromString(string)); m_qmakeCommand = Utils::FileName::fromString(string);
} }
QVariantMap BaseQtVersion::toMap() const QVariantMap BaseQtVersion::toMap() const
@@ -723,7 +632,7 @@ void BaseQtVersion::setAutoDetectionSource(const QString &autodetectionSource)
QString BaseQtVersion::displayName() const QString BaseQtVersion::displayName() const
{ {
return m_expander->expand(m_unexpandedDisplayName); return macroExpander()->expand(m_unexpandedDisplayName);
} }
QString BaseQtVersion::unexpandedDisplayName() const QString BaseQtVersion::unexpandedDisplayName() const
@@ -1234,15 +1143,16 @@ QStringList BaseQtVersion::qtConfigValues() const
MacroExpander *BaseQtVersion::macroExpander() 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 = const auto versionProperty =
[qtVersion](const std::function<QString(BaseQtVersion *)> &property) { [qtVersion](const std::function<QString(const BaseQtVersion *)> &property) {
return [property, qtVersion]() -> QString { return [property, qtVersion]() -> QString {
BaseQtVersion *version = qtVersion(); const BaseQtVersion *version = qtVersion();
return version ? property(version) : QString(); return version ? property(version) : QString();
}; };
}; };
@@ -1252,140 +1162,140 @@ std::unique_ptr<MacroExpander> BaseQtVersion::createMacroExpander(const std::fun
expander->registerVariable( expander->registerVariable(
"Qt:Version", "Qt:Version",
QtKitInformation::tr("The version string of the current Qt version."), QtKitInformation::tr("The version string of the current Qt version."),
versionProperty([](BaseQtVersion *version) { versionProperty([](const BaseQtVersion *version) {
return version->qtVersionString(); return version->qtVersionString();
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:Type", "Qt:Type",
QtKitInformation::tr("The type of the current Qt version."), QtKitInformation::tr("The type of the current Qt version."),
versionProperty([](BaseQtVersion *version) { versionProperty([](const BaseQtVersion *version) {
return version->type(); return version->type();
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:Mkspec", "Qt:Mkspec",
QtKitInformation::tr("The mkspec of the current Qt version."), QtKitInformation::tr("The mkspec of the current Qt version."),
versionProperty([](BaseQtVersion *version) { versionProperty([](const BaseQtVersion *version) {
return version->mkspec().toUserOutput(); return version->mkspec().toUserOutput();
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_PREFIX", "Qt:QT_INSTALL_PREFIX",
QtKitInformation::tr("The installation prefix of the current Qt version."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_PREFIX");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_DATA", "Qt:QT_INSTALL_DATA",
QtKitInformation::tr("The installation location of the current Qt version's 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_DATA");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_HEADERS", "Qt:QT_INSTALL_HEADERS",
QtKitInformation::tr("The installation location of the current Qt version's header files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_HEADERS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_LIBS", "Qt:QT_INSTALL_LIBS",
QtKitInformation::tr("The installation location of the current Qt version's library files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_LIBS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_DOCS", "Qt:QT_INSTALL_DOCS",
QtKitInformation::tr("The installation location of the current Qt version's documentation files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_DOCS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_BINS", "Qt:QT_INSTALL_BINS",
QtKitInformation::tr("The installation location of the current Qt version's executable files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_BINS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_PLUGINS", "Qt:QT_INSTALL_PLUGINS",
QtKitInformation::tr("The installation location of the current Qt version's 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_PLUGINS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_QML", "Qt:QT_INSTALL_QML",
QtKitInformation::tr("The installation location of the current Qt version's QML files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_QML");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_IMPORTS", "Qt:QT_INSTALL_IMPORTS",
QtKitInformation::tr("The installation location of the current Qt version's 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_IMPORTS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_TRANSLATIONS", "Qt:QT_INSTALL_TRANSLATIONS",
QtKitInformation::tr("The installation location of the current Qt version's translation files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_TRANSLATIONS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_CONFIGURATION", "Qt:QT_INSTALL_CONFIGURATION",
QtKitInformation::tr("The installation location of the current Qt version's translation files."), 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_CONFIGURATION");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_EXAMPLES", "Qt:QT_INSTALL_EXAMPLES",
QtKitInformation::tr("The installation location of the current Qt version's 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_EXAMPLES");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_DEMOS", "Qt:QT_INSTALL_DEMOS",
QtKitInformation::tr("The installation location of the current Qt version's 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"); return version->qmakeProperty(version->m_versionInfo, "QT_INSTALL_DEMOS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QMAKE_MKSPECS", "Qt:QMAKE_MKSPECS",
QtKitInformation::tr("The current Qt version's default mkspecs (Qt 4)."), 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"); return version->qmakeProperty(version->m_versionInfo, "QMAKE_MKSPECS");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QMAKE_SPEC", "Qt:QMAKE_SPEC",
QtKitInformation::tr("The current Qt version's default mkspec (Qt 5; host system)."), 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"); return version->qmakeProperty(version->m_versionInfo, "QMAKE_SPEC");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QMAKE_XSPEC", "Qt:QMAKE_XSPEC",
QtKitInformation::tr("The current Qt version's default mkspec (Qt 5; target system)."), 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"); return version->qmakeProperty(version->m_versionInfo, "QMAKE_XSPEC");
})); }));
expander->registerVariable( expander->registerVariable(
"Qt:QMAKE_VERSION", "Qt:QMAKE_VERSION",
QtKitInformation::tr("The current Qt's 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"); return version->qmakeProperty(version->m_versionInfo, "QMAKE_VERSION");
})); }));

View File

@@ -63,12 +63,26 @@ namespace QtSupport
{ {
class QtConfigWidget; 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 class QTSUPPORT_EXPORT QtVersionNumber
{ {
public: public:
QtVersionNumber(int ma, int mi, int p); QtVersionNumber(int ma = -1, int mi = -1, int p = -1);
QtVersionNumber(const QString &versionString); QtVersionNumber(const QString &versionString);
QtVersionNumber();
QSet<Core::Id> features() const; QSet<Core::Id> features() const;
@@ -232,8 +246,8 @@ public:
QStringList qtConfigValues() const; QStringList qtConfigValues() const;
Utils::MacroExpander *macroExpander() const; // owned by the Qt version Utils::MacroExpander *macroExpander() const; // owned by the Qt version
static std::unique_ptr<Utils::MacroExpander> createMacroExpander( static std::unique_ptr<Utils::MacroExpander>
const std::function<BaseQtVersion *()> &qtVersion); createMacroExpander(const std::function<const BaseQtVersion *()> &qtVersion);
static void populateQmlFileFinder(Utils::FileInProjectFinder *finder, static void populateQmlFileFinder(Utils::FileInProjectFinder *finder,
const ProjectExplorer::Target *target); const ProjectExplorer::Target *target);
@@ -256,9 +270,6 @@ protected:
private: private:
void setAutoDetectionSource(const QString &autodetectionSource); void setAutoDetectionSource(const QString &autodetectionSource);
static int getUniqueId();
void ctor(const Utils::FileName &qmakePath);
void setupExpander();
void updateSourcePath() const; void updateSourcePath() const;
void updateVersionInfo() const; void updateVersionInfo() const;
enum HostBinaries { Designer, Linguist, Uic, QScxmlc }; enum HostBinaries { Designer, Linguist, Uic, QScxmlc };
@@ -278,22 +289,22 @@ private:
void setId(int id); // used by the qtversionmanager for legacy restore void setId(int id); // used by the qtversionmanager for legacy restore
// and by the qtoptionspage to replace Qt versions // and by the qtoptionspage to replace Qt versions
int m_id; int m_id = -1;
bool m_isAutodetected; bool m_isAutodetected = false;
mutable bool m_hasQmlDump; // controlled by m_versionInfoUpToDate mutable bool m_hasQmlDump = false; // controlled by m_versionInfoUpToDate
mutable bool m_mkspecUpToDate; mutable bool m_mkspecUpToDate = false;
mutable bool m_mkspecReadUpToDate; mutable bool m_mkspecReadUpToDate = false;
mutable bool m_defaultConfigIsDebug; mutable bool m_defaultConfigIsDebug = true;
mutable bool m_defaultConfigIsDebugAndRelease; mutable bool m_defaultConfigIsDebugAndRelease = true;
mutable bool m_frameworkBuild; mutable bool m_frameworkBuild = false;
mutable bool m_versionInfoUpToDate; mutable bool m_versionInfoUpToDate = false;
mutable bool m_installed; mutable bool m_installed = true;
mutable bool m_hasExamples; mutable bool m_hasExamples = false;
mutable bool m_hasDemos; mutable bool m_hasDemos = false;
mutable bool m_hasDocumentation; mutable bool m_hasDocumentation = false;
mutable bool m_qmakeIsExecutable; mutable bool m_qmakeIsExecutable = true;
mutable bool m_hasQtAbis; mutable bool m_hasQtAbis = false;
mutable QStringList m_configValues; mutable QStringList m_configValues;
mutable QStringList m_qtConfigValues; mutable QStringList m_qtConfigValues;
@@ -320,7 +331,7 @@ private:
mutable QList<ProjectExplorer::Abi> m_qtAbis; mutable QList<ProjectExplorer::Abi> m_qtAbis;
std::unique_ptr<Utils::MacroExpander> m_expander; MacroExpanderWrapper m_expander;
}; };
} }