Port QSettingsPrivate::get() to std::optional
... instead of a bool return and a QVariant out parameter. Change-Id: I9d937668ede668075d1de5bb57f61e4c260aaddc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
82063d9af1
commit
c587ebf54c
@ -1202,7 +1202,7 @@ void QConfFileSettingsPrivate::set(const QString &key, const QVariant &value)
|
||||
confFile->addedKeys.insert(theKey, value);
|
||||
}
|
||||
|
||||
bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const
|
||||
std::optional<QVariant> QConfFileSettingsPrivate::get(const QString &key) const
|
||||
{
|
||||
QSettingsKey theKey(key, caseSensitivity);
|
||||
ParsedSettingsMap::const_iterator j;
|
||||
@ -1222,15 +1222,12 @@ bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const
|
||||
&& !confFile->removedKeys.contains(theKey));
|
||||
}
|
||||
|
||||
if (found && value)
|
||||
*value = *j;
|
||||
|
||||
if (found)
|
||||
return true;
|
||||
return *j;
|
||||
if (!fallbacks)
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
||||
@ -3213,7 +3210,7 @@ void QSettings::remove(const QString &key)
|
||||
bool QSettings::contains(const QString &key) const
|
||||
{
|
||||
Q_D(const QSettings);
|
||||
return d->get(d->actualKey(key), nullptr);
|
||||
return d->get(d->actualKey(key)) != std::nullopt;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -3282,9 +3279,7 @@ QVariant QSettings::value(const QString &key, const QVariant &defaultValue) cons
|
||||
qWarning("QSettings::value: Empty key passed");
|
||||
return QVariant();
|
||||
}
|
||||
QVariant result = defaultValue;
|
||||
d->get(d->actualKey(key), &result);
|
||||
return result;
|
||||
return d->get(d->actualKey(key)).value_or(defaultValue);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -332,7 +332,7 @@ public:
|
||||
|
||||
void remove(const QString &key) override;
|
||||
void set(const QString &key, const QVariant &value) override;
|
||||
bool get(const QString &key, QVariant *value) const override;
|
||||
std::optional<QVariant> get(const QString &key) const override;
|
||||
QStringList children(const QString &prefix, ChildSpec spec) const override;
|
||||
void clear() override;
|
||||
void sync() override;
|
||||
@ -448,7 +448,7 @@ void QMacSettingsPrivate::set(const QString &key, const QVariant &value)
|
||||
domains[0].userName, hostName);
|
||||
}
|
||||
|
||||
bool QMacSettingsPrivate::get(const QString &key, QVariant *value) const
|
||||
std::optional<QVariant> QMacSettingsPrivate::get(const QString &key) const
|
||||
{
|
||||
QCFString k = macKey(key);
|
||||
for (int i = 0; i < numDomains; ++i) {
|
||||
@ -456,17 +456,14 @@ bool QMacSettingsPrivate::get(const QString &key, QVariant *value) const
|
||||
QCFType<CFPropertyListRef> ret =
|
||||
CFPreferencesCopyValue(k, domains[i].applicationOrSuiteId, domains[i].userName,
|
||||
hostNames[j]);
|
||||
if (ret) {
|
||||
if (value)
|
||||
*value = qtValue(ret);
|
||||
return true;
|
||||
}
|
||||
if (ret)
|
||||
return qtValue(ret);
|
||||
}
|
||||
|
||||
if (!fallbacks)
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
||||
@ -536,7 +533,7 @@ bool QMacSettingsPrivate::isWritable() const
|
||||
|
||||
that->set(impossibleKey, QVariant());
|
||||
that->sync();
|
||||
bool writable = (status == QSettings::NoError) && that->get(impossibleKey, 0);
|
||||
bool writable = (status == QSettings::NoError) && that->get(impossibleKey).has_value();
|
||||
that->remove(impossibleKey);
|
||||
that->sync();
|
||||
|
||||
|
@ -197,7 +197,7 @@ public:
|
||||
|
||||
virtual void remove(const QString &key) = 0;
|
||||
virtual void set(const QString &key, const QVariant &value) = 0;
|
||||
virtual bool get(const QString &key, QVariant *value) const = 0;
|
||||
virtual std::optional<QVariant> get(const QString &key) const = 0;
|
||||
|
||||
enum ChildSpec { AllKeys, ChildKeys, ChildGroups };
|
||||
virtual QStringList children(const QString &prefix, ChildSpec spec) const = 0;
|
||||
@ -264,7 +264,7 @@ public:
|
||||
|
||||
void remove(const QString &key) override;
|
||||
void set(const QString &key, const QVariant &value) override;
|
||||
bool get(const QString &key, QVariant *value) const override;
|
||||
std::optional<QVariant> get(const QString &key) const override;
|
||||
|
||||
QStringList children(const QString &prefix, ChildSpec spec) const override;
|
||||
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
const QString &application);
|
||||
~QWasmSettingsPrivate();
|
||||
|
||||
bool get(const QString &key, QVariant *value) const override;
|
||||
std::optional<QVariant> get(const QString &key) const override;
|
||||
QStringList children(const QString &prefix, ChildSpec spec) const override;
|
||||
void clear() override;
|
||||
void sync() override;
|
||||
@ -169,12 +169,12 @@ QWasmSettingsPrivate::~QWasmSettingsPrivate()
|
||||
QConfFileSettingsPrivate::initAccess();
|
||||
}
|
||||
|
||||
bool QWasmSettingsPrivate::get(const QString &key, QVariant *value) const
|
||||
std::optional<QVariant> QWasmSettingsPrivate::get(const QString &key) const
|
||||
{
|
||||
if (isReadReady)
|
||||
return QConfFileSettingsPrivate::get(key, value);
|
||||
return QConfFileSettingsPrivate::get(key);
|
||||
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QStringList QWasmSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
|
||||
|
@ -387,7 +387,7 @@ public:
|
||||
|
||||
void remove(const QString &uKey) override;
|
||||
void set(const QString &uKey, const QVariant &value) override;
|
||||
bool get(const QString &uKey, QVariant *value) const override;
|
||||
std::optional<QVariant> get(const QString &uKey) const override;
|
||||
QStringList children(const QString &uKey, ChildSpec spec) const override;
|
||||
void clear() override;
|
||||
void sync() override;
|
||||
@ -747,20 +747,22 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value)
|
||||
RegCloseKey(handle);
|
||||
}
|
||||
|
||||
bool QWinSettingsPrivate::get(const QString &uKey, QVariant *value) const
|
||||
std::optional<QVariant> QWinSettingsPrivate::get(const QString &uKey) const
|
||||
{
|
||||
QString rKey = escapedKey(uKey);
|
||||
|
||||
QVariant value;
|
||||
|
||||
for (const RegistryKey &r : regList) {
|
||||
HKEY handle = r.handle();
|
||||
if (handle != 0 && readKey(handle, rKey, value))
|
||||
return true;
|
||||
if (handle != 0 && readKey(handle, rKey, &value))
|
||||
return value;
|
||||
|
||||
if (!fallbacks)
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QStringList QWinSettingsPrivate::children(const QString &uKey, ChildSpec spec) const
|
||||
|
Loading…
Reference in New Issue
Block a user