Skip to content

Commit

Permalink
settings.*: revert from QAnyStringView back to QString
Browse files Browse the repository at this point in the history
QAnyStringView (and any string view, in fact) cannot be used in
invocations from QML - meaning that anything Q_INVOKABLE in these files
cannot use string views.
  • Loading branch information
KitsuneRal committed Sep 1, 2024
1 parent 631922c commit a80a6f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions Quotient/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ void Settings::setLegacyNames(const QString& organizationName,
Settings::Settings(QObject* parent) : QSettings(parent)
{}

void Settings::setValue(QAnyStringView key, const QVariant& value)
void Settings::setValue(const QString& key, const QVariant& value)
{
QSettings::setValue(key, value);
if (legacySettings.contains(key))
legacySettings.remove(key);
}

void Settings::remove(QAnyStringView key)
void Settings::remove(const QString& key)
{
QSettings::remove(key);
if (legacySettings.contains(key))
legacySettings.remove(key);
}

QVariant Settings::value(QAnyStringView key, const QVariant& defaultValue) const
QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
{
auto value = QSettings::value(key, legacySettings.value(key, defaultValue));
// QML's Qt.labs.Settings stores boolean values as strings, which, if loaded
Expand All @@ -45,7 +45,7 @@ QVariant Settings::value(QAnyStringView key, const QVariant& defaultValue) const
return value.toString() == "false"_L1 ? QVariant(false) : value;
}

bool Settings::contains(QAnyStringView key) const
bool Settings::contains(const QString& key) const
{
return QSettings::contains(key) || legacySettings.contains(key);
}
Expand All @@ -60,14 +60,14 @@ QStringList Settings::childGroups() const
return groups;
}

void SettingsGroup::setValue(QAnyStringView key, const QVariant& value)
void SettingsGroup::setValue(const QString& key, const QVariant& value)
{
Settings::setValue(fullPath(key), value);
}

bool SettingsGroup::contains(QAnyStringView key) const { return Settings::contains(fullPath(key)); }
bool SettingsGroup::contains(const QString& key) const { return Settings::contains(fullPath(key)); }

QVariant SettingsGroup::value(QAnyStringView key, const QVariant& defaultValue) const
QVariant SettingsGroup::value(const QString& key, const QVariant& defaultValue) const
{
return Settings::value(fullPath(key), defaultValue);
}
Expand Down
22 changes: 11 additions & 11 deletions Quotient/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class QUOTIENT_API Settings : public QSettings {

/// Set the value for a given key
/*! If the key exists in the legacy location, it is removed. */
Q_INVOKABLE void setValue(QAnyStringView key, const QVariant& value);
Q_INVOKABLE void setValue(const QString& key, const QVariant& value);

/// Remove the value from both the primary and legacy locations
Q_INVOKABLE void remove(QAnyStringView key);
Q_INVOKABLE void remove(const QString& key);

/// Obtain a value for a given key
/*!
Expand All @@ -47,7 +47,7 @@ class QUOTIENT_API Settings : public QSettings {
*
* \sa setLegacyNames, get
*/
Q_INVOKABLE QVariant value(QAnyStringView key, const QVariant& defaultValue = {}) const;
Q_INVOKABLE QVariant value(const QString& key, const QVariant& defaultValue = {}) const;

/// Obtain a value for a given key, coerced to the given type
/*!
Expand All @@ -62,11 +62,11 @@ class QUOTIENT_API Settings : public QSettings {
template <typename T>
T get(const QString& key, const T& defaultValue = {}) const
{
const auto qv = value(key, QVariant());
const auto qv = value(key);
return qv.isValid() && qv.canConvert<T>() ? qv.value<T>() : defaultValue;
}

Q_INVOKABLE bool contains(QAnyStringView key) const;
Q_INVOKABLE bool contains(const QString& key) const;
Q_INVOKABLE QStringList childGroups() const;

private:
Expand All @@ -84,19 +84,19 @@ class QUOTIENT_API SettingsGroup : public Settings {
, groupPath(std::move(path))
{}

Q_INVOKABLE bool contains(QAnyStringView key) const;
Q_INVOKABLE QVariant value(QAnyStringView key, const QVariant& defaultValue = {}) const;
Q_INVOKABLE bool contains(const QString& key) const;
Q_INVOKABLE QVariant value(const QString& key, const QVariant& defaultValue = {}) const;

template <typename T>
T get(auto key, const T& defaultValue = {}) const
T get(const QString& key, const T& defaultValue = {}) const
{
const auto qv = value(key, QVariant());
return qv.isValid() && qv.template canConvert<T>() ? qv.template value<T>() : defaultValue;
const auto qv = value(key);
return qv.isValid() && qv.canConvert<T>() ? qv.value<T>() : defaultValue;
}

Q_INVOKABLE QString group() const;
Q_INVOKABLE QStringList childGroups() const;
Q_INVOKABLE void setValue(QAnyStringView key, const QVariant& value);
Q_INVOKABLE void setValue(const QString& key, const QVariant& value);

Q_INVOKABLE void remove(const QString& key);

Expand Down

0 comments on commit a80a6f8

Please sign in to comment.