File indexing completed on 2024-05-12 04:44:35

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 // Own headers
0005 // First the interface, which forces the header to be self-contained.
0006 #include "settingbase.h"
0007 
0008 #include "settings.h"
0009 
0010 class QSettings;
0011 
0012 namespace PerceptualColor
0013 {
0014 
0015 // // Example stream operator
0016 // QDataStream& operator<<(QDataStream& out, const Settings::ColorList& colorList)
0017 // {
0018 //     out << static_cast<qint32>(colorList.size());
0019 //     for (const QColor& color : colorList) {
0020 //         out << color;
0021 //     }
0022 //     return out;
0023 // }
0024 //
0025 // // Example stream operator
0026 // QDataStream& operator>>(QDataStream& in, Settings::ColorList& colorList)
0027 // {
0028 //     colorList.clear();
0029 //     qint32 size;
0030 //     in >> size;
0031 //     for (int i = 0; i < size; ++i) {
0032 //         QColor color;
0033 //         in >> color;
0034 //         colorList.append(color);
0035 //     }
0036 //     return in;
0037 // }
0038 
0039 /** @brief Constructor.
0040  *
0041  * @param key <tt>QSettings</tt> key for the value.
0042  * For maximum portability:
0043  * - No upper case should ever be used.
0044  *   (Some systems, like the INI that we are using, are case-insensitive.
0045  *   And even if we always use INI, having both capital and small letters
0046  *   is error-prone because typos are not checked by the compiler.)
0047  * - Only the letters a-z should be used.
0048  *   (Also, some characters like the backslash are not allowed on some
0049  *   platforms.)
0050  * - “group/key”: Each key has exactly one group. Don't use subgroups.
0051  *   Use the class name as group name.
0052  *   (This makes the settings file well readable for humans. Missing
0053  *   groups are confusing because the system generates a “General”
0054  *   group which is not easy to understand. And using class identifiers
0055  *   helps to understand the structure of the settings file.)
0056  * - In C++, use “const” variables to define key strings, instead of
0057  *   manually typing the key strings.
0058  *   (This avoids typing errors.)
0059  * @param settings Corresponding @ref Settings object.
0060  * @param parent The parent object (if any). */
0061 SettingBase::SettingBase(const QString &key, Settings *settings, QObject *parent)
0062     : QObject(parent)
0063     , m_key(key)
0064     , m_settings(settings)
0065 {
0066 }
0067 
0068 /** @brief Destructor. */
0069 SettingBase::~SettingBase()
0070 {
0071 }
0072 
0073 /** @brief The underlying <tt>QSettings</tt> object of @ref m_settings.
0074  *
0075  * @returns the underlying <tt>QSettings</tt> object of @ref m_settings. */
0076 QSettings *SettingBase::underlyingQSettings()
0077 {
0078     return &(m_settings->m_qSettings);
0079 }
0080 
0081 } // namespace PerceptualColor