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 #ifndef SETTINGBASE_H 0005 #define SETTINGBASE_H 0006 0007 #include <qglobal.h> 0008 #include <qobject.h> 0009 #include <qpointer.h> 0010 #include <qstring.h> 0011 0012 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0013 #include <qtmetamacros.h> 0014 #else 0015 #include <qobjectdefs.h> 0016 #endif 0017 0018 class QSettings; 0019 0020 namespace PerceptualColor 0021 { 0022 0023 class Settings; 0024 0025 /** @internal 0026 * 0027 * @brief Base class for @ref Setting. 0028 * 0029 * @internal 0030 * 0031 * @note <a href="https://stackoverflow.com/a/63021891">The <tt>Q_OBJECT</tt> 0032 * macro and templates cannot be combined.</a> Therefore, 0033 * @ref SettingBase serves as a base class to provide 0034 * signals for @ref Setting. */ 0035 class SettingBase : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 virtual ~SettingBase() override; 0041 0042 Q_SIGNALS: 0043 /** @brief Notify signal for the value. */ 0044 void valueChanged(); 0045 0046 protected: 0047 SettingBase(const QString &key, Settings *settings, QObject *parent = nullptr); 0048 0049 /** @brief <tt>QSettings</tt> key for the value. */ 0050 const QString m_key; 0051 0052 /** @brief Corresponding @ref Settings object. */ 0053 QPointer<Settings> m_settings; 0054 0055 QSettings *underlyingQSettings(); 0056 0057 private: 0058 /** @internal @brief Only for unit tests. */ 0059 friend class TestSettingBase; 0060 }; 0061 0062 } // namespace PerceptualColor 0063 0064 #endif // SETTINGBASE_H