forked from qt-creator/qt-creator
Utils: Use new settings API
Avoid writing defaults to the settings. Task-number: QTCREATORBUG-24430 Change-Id: I57193c0c07c02faf95753378bb1c8d86d18fd131 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "basetreeview.h"
|
||||
|
||||
#include "progressindicator.h"
|
||||
#include "qtcsettings.h"
|
||||
#include "treemodel.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
@@ -159,7 +160,7 @@ public:
|
||||
l.append(column);
|
||||
l.append(width);
|
||||
}
|
||||
m_settings->setValue(QLatin1String(ColumnKey), l);
|
||||
QtcSettings::setValueWithDefault(m_settings, ColumnKey, l);
|
||||
m_settings->endGroup();
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "checkablemessagebox.h"
|
||||
|
||||
#include "qtcassert.h"
|
||||
#include "qtcsettings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
|
@@ -24,14 +24,13 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "historycompleter.h"
|
||||
|
||||
#include "fancylineedit.h"
|
||||
#include "qtcassert.h"
|
||||
#include "qtcsettings.h"
|
||||
#include "theme/theme.h"
|
||||
#include "utilsicons.h"
|
||||
|
||||
#include "qtcassert.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QKeyEvent>
|
||||
#include <QListView>
|
||||
@@ -41,7 +40,8 @@
|
||||
namespace Utils {
|
||||
namespace Internal {
|
||||
|
||||
static QSettings *theSettings = nullptr;
|
||||
static QtcSettings *theSettings = nullptr;
|
||||
const bool isLastItemEmptyDefault = false;
|
||||
|
||||
class HistoryCompleterPrivate : public QAbstractListModel
|
||||
{
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
QString historyKey;
|
||||
QString historyKeyIsLastItemEmpty;
|
||||
int maxLines = 6;
|
||||
bool isLastItemEmpty = false;
|
||||
bool isLastItemEmpty = isLastItemEmptyDefault;
|
||||
};
|
||||
|
||||
class HistoryLineDelegate : public QItemDelegate
|
||||
@@ -157,7 +157,7 @@ bool HistoryCompleterPrivate::removeRows(int row, int count, const QModelIndex &
|
||||
beginRemoveRows(parent, row, row + count -1);
|
||||
for (int i = 0; i < count; ++i)
|
||||
list.removeAt(row);
|
||||
theSettings->setValue(historyKey, list);
|
||||
theSettings->setValueWithDefault(historyKey, list);
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
@@ -175,7 +175,9 @@ void HistoryCompleterPrivate::addEntry(const QString &str)
|
||||
const QString entry = str.trimmed();
|
||||
if (entry.isEmpty()) {
|
||||
isLastItemEmpty = true;
|
||||
theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
|
||||
theSettings->setValueWithDefault(historyKeyIsLastItemEmpty,
|
||||
isLastItemEmpty,
|
||||
isLastItemEmptyDefault);
|
||||
return;
|
||||
}
|
||||
int removeIndex = list.indexOf(entry);
|
||||
@@ -185,9 +187,11 @@ void HistoryCompleterPrivate::addEntry(const QString &str)
|
||||
list.prepend(entry);
|
||||
list = list.mid(0, maxLines - 1);
|
||||
endResetModel();
|
||||
theSettings->setValue(historyKey, list);
|
||||
theSettings->setValueWithDefault(historyKey, list);
|
||||
isLastItemEmpty = false;
|
||||
theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
|
||||
theSettings->setValueWithDefault(historyKeyIsLastItemEmpty,
|
||||
isLastItemEmpty,
|
||||
isLastItemEmptyDefault);
|
||||
}
|
||||
|
||||
HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
|
||||
@@ -201,7 +205,8 @@ HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
|
||||
d->list = theSettings->value(d->historyKey).toStringList();
|
||||
d->historyKeyIsLastItemEmpty = QLatin1String("CompleterHistory/")
|
||||
+ historyKey + QLatin1String(".IsLastItemEmpty");
|
||||
d->isLastItemEmpty = theSettings->value(d->historyKeyIsLastItemEmpty, false).toBool();
|
||||
d->isLastItemEmpty = theSettings->value(d->historyKeyIsLastItemEmpty, isLastItemEmptyDefault)
|
||||
.toBool();
|
||||
|
||||
setModel(d);
|
||||
auto popup = new HistoryLineView(d);
|
||||
@@ -260,7 +265,7 @@ void HistoryCompleter::addEntry(const QString &str)
|
||||
d->addEntry(str);
|
||||
}
|
||||
|
||||
void HistoryCompleter::setSettings(QSettings *settings)
|
||||
void HistoryCompleter::setSettings(QtcSettings *settings)
|
||||
{
|
||||
Internal::theSettings = settings;
|
||||
}
|
||||
|
@@ -29,12 +29,10 @@
|
||||
|
||||
#include <QCompleter>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class QtcSettings;
|
||||
|
||||
namespace Internal { class HistoryCompleterPrivate; }
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
|
||||
@@ -42,7 +40,7 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static void setSettings(QSettings *settings);
|
||||
static void setSettings(QtcSettings *settings);
|
||||
HistoryCompleter(const QString &historyKey, QObject *parent = nullptr);
|
||||
bool removeHistoryItem(int index);
|
||||
QString historyItem() const;
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "algorithm.h"
|
||||
#include "qtcassert.h"
|
||||
#include "qtcsettings.h"
|
||||
#include "theme/theme.h"
|
||||
#include "utilsicons.h"
|
||||
|
||||
@@ -192,7 +193,7 @@ void InfoBar::clearGloballySuppressed()
|
||||
{
|
||||
globallySuppressed.clear();
|
||||
if (m_settings)
|
||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), QStringList());
|
||||
m_settings->remove(C_SUPPRESSED_WARNINGS);
|
||||
}
|
||||
|
||||
bool InfoBar::anyGloballySuppressed()
|
||||
@@ -205,7 +206,7 @@ void InfoBar::writeGloballySuppressedToSettings()
|
||||
if (!m_settings)
|
||||
return;
|
||||
const QStringList list = Utils::transform<QList>(globallySuppressed, &Id::toString);
|
||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list);
|
||||
QtcSettings::setValueWithDefault(m_settings, C_SUPPRESSED_WARNINGS, list);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -40,24 +40,46 @@ public:
|
||||
void setValueWithDefault(const QString &key, const T &val, const T &defaultValue);
|
||||
template<typename T>
|
||||
void setValueWithDefault(const QString &key, const T &val);
|
||||
|
||||
template<typename T>
|
||||
static void setValueWithDefault(QSettings *settings,
|
||||
const QString &key,
|
||||
const T &val,
|
||||
const T &defaultValue);
|
||||
template<typename T>
|
||||
static void setValueWithDefault(QSettings *settings, const QString &key, const T &val);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(const QString &key, const T &val, const T &defaultValue)
|
||||
{
|
||||
if (val == defaultValue)
|
||||
remove(key);
|
||||
else
|
||||
setValue(key, QVariant::fromValue(val));
|
||||
setValueWithDefault(this, key, val, defaultValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(const QString &key, const T &val)
|
||||
{
|
||||
if (val == T())
|
||||
remove(key);
|
||||
else
|
||||
setValue(key, QVariant::fromValue(val));
|
||||
setValueWithDefault(this, key, val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(QSettings *settings,
|
||||
const QString &key,
|
||||
const T &val,
|
||||
const T &defaultValue)
|
||||
{
|
||||
if (val == defaultValue)
|
||||
settings->remove(key);
|
||||
else
|
||||
settings->setValue(key, QVariant::fromValue(val));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(QSettings *settings, const QString &key, const T &val)
|
||||
{
|
||||
if (val == T())
|
||||
settings->remove(key);
|
||||
else
|
||||
settings->setValue(key, QVariant::fromValue(val));
|
||||
}
|
||||
} // namespace Utils
|
||||
|
@@ -25,9 +25,10 @@
|
||||
|
||||
#include <utils/savedaction.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/pathlisteditor.h>
|
||||
#include "pathchooser.h"
|
||||
#include "pathlisteditor.h"
|
||||
#include "qtcassert.h"
|
||||
#include "qtcsettings.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <QCheckBox>
|
||||
@@ -147,7 +148,7 @@ void SavedAction::writeSettings(QSettings *settings)
|
||||
{
|
||||
if (settingsKey().isEmpty())
|
||||
return;
|
||||
settings->setValue(settingsKey(), m_value);
|
||||
QtcSettings::setValueWithDefault(settings, settingsKey(), m_value, m_defaultValue);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -24,7 +24,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "unixutils.h"
|
||||
|
||||
#include "fileutils.h"
|
||||
#include "qtcsettings.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QFileInfo>
|
||||
@@ -47,7 +49,7 @@ QString UnixUtils::fileBrowser(const QSettings *settings)
|
||||
|
||||
void UnixUtils::setFileBrowser(QSettings *settings, const QString &term)
|
||||
{
|
||||
settings->setValue(QLatin1String("General/FileBrowser"), term);
|
||||
QtcSettings::setValueWithDefault(settings, "General/FileBrowser", term, defaultFileBrowser());
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user