Files
qt-creator/src/libs/utils/qtcsettings.cpp
hjk d6fe357d81 Utils: Use a proper class as Key
The Key encapsulates now a QByteArray.

Plan is to use QByteArray::fromRawData on literals, but that's not
active yet due to an unclear ASAN report, see the gerrit discussion.

For now we also paddle back when interfacing QSettings, instead of mimicing
writing a QVariantMap (and fail in some corners), always convert
the Store. This is meant to go away in the future when code paths
are better controled.

Change-Id: Id1206a434d511f8003903d5322c7c9bd5f5fb859
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
2023-09-27 09:41:44 +00:00

44 lines
1.3 KiB
C++

// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qtcsettings.h"
#include "store.h"
namespace Utils {
/*!
\class Utils::QtcSettings
\inheaderfile utils/qtcsettings.h
\inmodule QtCreator
\brief The QtcSettings class is an extension of the QSettings class.
Use Utils::QtcSettings::setValueWithDefault() to write values with a
default.
*/
/*!
\fn template<typename T> void setValueWithDefault(const QString &key, const T &val, const T &defaultValue)
Sets the value of setting \a key to \a val. If \a val is the same as the \a
defaultValue, the settings key is removed instead. This makes sure that
settings are only written if actually necessary, namely when the user
changed them from the default. It also makes a new default value for a
setting in a new version of the application take effect, if the user did
not change the setting before.
\sa QSettings::setValue()
*/
QVariant QtcSettings::value(const Key &key, const QVariant &def) const
{
return QSettings::value(stringFromKey(key), def);
}
void QtcSettings::setValue(const Key &key, const QVariant &value)
{
QSettings::setValue(stringFromKey(key), mapEntryFromStoreEntry(value));
}
} // namespace Utils