Perceptual Color

perceptualsettings.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4// Own headers
5// First the interface, which forces the header to be self-contained.
6#include "perceptualsettings.h"
7
8#include <qcoreapplication.h>
9#include <qsettings.h>
10#include <qstringliteral.h>
11
12#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
13#else
14#include <qdatastream.h>
15#endif
16
17namespace PerceptualColor
18{
19
20/** @brief Private constructor to prevent instantiation. */
21PerceptualSettings::PerceptualSettings()
22 : Settings(QSettings::UserScope, QStringLiteral("kde.org"), QStringLiteral("libperceptualcolor"))
23 // For maximum portability:
24 // - No upper case should ever be used.
25 // (Some systems, like the INI that we are using, are case-insensitive.
26 // And even if we always use INI, having both capital and small letters
27 // is error-prone because typos are not checked by the compiler.)
28 // - Only the letters a-z should be used.
29 // (Also, some characters like the backslash are not allowed on some
30 // platforms.)
31 // - “group/key”: Each key has exactly one group. Don't use subgroups.
32 // Use the class name as group name.
33 // (This makes the settings file well readable for humans. Missing
34 // groups are confusing because the system generates a “General”
35 // group which is not easy to understand. And using class identifiers
36 // helps to understand the structure of the settings file.)
37 // - In C++, use “const” variables to define key strings, instead of
38 // manually typing the key strings.
39 // (This avoids typing errors.)
40 , customColors(QStringLiteral("colordialog/customcolors"), this)
41 , history(QStringLiteral("colordialog/history"), this)
42 , tab(QStringLiteral("colordialog/tab"), this)
43 , tabExpanded(QStringLiteral("colordialog/tabexpanded"), this)
44{
45}
46
47/** @brief Destructor. */
48PerceptualSettings::~PerceptualSettings()
49{
50}
51
52/** @brief Get a reference to the singleton instance.
53 *
54 * @pre There exists a QCoreApplication object. (Otherwise, this
55 * function will throw an exception.)
56 *
57 * @returns A reference to the instance.
58 *
59 * To use it, assign the return value to a reference (not a normal variable):
60 *
61 * @snippet testperceptualsettings.cpp PerceptualSettings Instance */
62PerceptualSettings &PerceptualSettings::instance()
63{
64 if (QCoreApplication::instance() == nullptr) {
65 // A QCoreApplication object is required because otherwise
66 // the QFileSystemWatcher will not do anything and print the
67 // highly confusing warning “QSocketNotifier: Can only be used
68 // with threads started with QThread”. It's better to give clear
69 // feedback:
70 throw 0;
71 }
72 static PerceptualSettings myInstance;
73 return myInstance;
74}
75
76} // namespace PerceptualColor
The namespace of this library.
QCoreApplication * instance()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:51:26 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.