QMakeLibraryInfo: Move reading of default values into separate function

Reduce code duplication.

Change-Id: Ic20c124ad664d16552e3cfea8dde465fc0b6066f
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2021-03-05 12:36:10 +01:00
parent 17055f5f48
commit b788c87457

View File

@ -156,6 +156,28 @@ QString QMakeLibraryInfo::path(int loc)
return ret; return ret;
} }
struct LocationInfo
{
QString key;
QString defaultValue;
};
static LocationInfo defaultLocationInfo(int loc)
{
LocationInfo result;
if (unsigned(loc) < sizeof(qtConfEntries) / sizeof(qtConfEntries[0])) {
result.key = QLatin1String(qtConfEntries[loc].key);
result.defaultValue = QLatin1String(qtConfEntries[loc].value);
}
#ifndef Q_OS_WIN // On Windows we use the registry
else if (loc == QLibraryInfo::SettingsPath) {
result.key = QLatin1String("Settings");
result.defaultValue = QLatin1String(".");
}
#endif
return result;
}
QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group) QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group)
{ {
QString ret; QString ret;
@ -175,19 +197,8 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group
|| (group = orig_group, false)) { || (group = orig_group, false)) {
fromConf = true; fromConf = true;
QString key; LocationInfo locinfo = defaultLocationInfo(loc);
QString defaultValue; if (!locinfo.key.isNull()) {
if (unsigned(loc) < sizeof(qtConfEntries) / sizeof(qtConfEntries[0])) {
key = QLatin1String(qtConfEntries[loc].key);
defaultValue = QLatin1String(qtConfEntries[loc].value);
}
#ifndef Q_OS_WIN // On Windows we use the registry
else if (loc == QLibraryInfo::SettingsPath) {
key = QLatin1String("Settings");
defaultValue = QLatin1String(".");
}
#endif
if (!key.isNull()) {
QSettings *config = QMakeLibraryInfo::configuration(); QSettings *config = QMakeLibraryInfo::configuration();
config->beginGroup(QLatin1String(group == DevicePaths ? "DevicePaths" config->beginGroup(QLatin1String(group == DevicePaths ? "DevicePaths"
: group == EffectiveSourcePaths : group == EffectiveSourcePaths
@ -195,17 +206,16 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group
: group == EffectivePaths ? "EffectivePaths" : group == EffectivePaths ? "EffectivePaths"
: "Paths")); : "Paths"));
ret = config->value(key, defaultValue).toString(); ret = config->value(locinfo.key, locinfo.defaultValue).toString();
if (ret.isEmpty()) { if (ret.isEmpty()) {
if (loc == HostPrefixPath) if (loc == HostPrefixPath) {
ret = config->value(QLatin1String(qtConfEntries[QLibraryInfo::PrefixPath].key), locinfo = defaultLocationInfo(QLibraryInfo::PrefixPath);
QLatin1String( ret = config->value(locinfo.key, locinfo.defaultValue).toString();
qtConfEntries[QLibraryInfo::PrefixPath].value)) } else if (loc == TargetSpecPath || loc == HostSpecPath
.toString(); || loc == SysrootifyPrefixPath) {
else if (loc == TargetSpecPath || loc == HostSpecPath
|| loc == SysrootifyPrefixPath)
fromConf = false; fromConf = false;
}
// The last case here is SysrootPath, which can be legitimately empty. // The last case here is SysrootPath, which can be legitimately empty.
// All other keys have non-empty fallbacks to start with. // All other keys have non-empty fallbacks to start with.
} }