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 , swatchBookPage(QStringLiteral("colordialog/swatchbookpage"), this)
43 , tab(QStringLiteral("colordialog/tab"), this)
44 , tabExpanded(QStringLiteral("colordialog/tabexpanded"), this)
45{
46}
47
48/** @brief Destructor. */
49PerceptualSettings::~PerceptualSettings()
50{
51}
52
53/** @brief Get a reference to the singleton instance.
54 *
55 * @pre There exists a QCoreApplication object. (Otherwise, this
56 * function will throw an exception.)
57 *
58 * @returns A reference to the instance.
59 *
60 * To use it, assign the return value to a reference (not a normal variable):
61 *
62 * @snippet testperceptualsettings.cpp PerceptualSettings Instance */
63PerceptualSettings &PerceptualSettings::instance()
64{
65 if (QCoreApplication::instance() == nullptr) {
66 // A QCoreApplication object is required because otherwise
67 // the QFileSystemWatcher will not do anything and print the
68 // highly confusing warning “QSocketNotifier: Can only be used
69 // with threads started with QThread”. It's better to give clear
70 // feedback:
71 throw 0;
72 }
73 static PerceptualSettings myInstance;
74 return myInstance;
75}
76
77} // 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 Nov 22 2024 12:00:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.