libquentier 0.8.0
The library for rich desktop clients of Evernote service
Loading...
Searching...
No Matches
ApplicationSettings.h
1/*
2 * Copyright 2016-2025 Dmitry Ivanov
3 *
4 * This file is part of libquentier
5 *
6 * libquentier is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, version 3 of the License.
9 *
10 * libquentier is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <quentier/types/Account.h>
22
23#include <QSettings>
24
25#include <string_view>
26
27namespace quentier::utility {
28
34class QUENTIER_EXPORT ApplicationSettings :
35 public QSettings,
37{
38 Q_OBJECT
39public:
49 explicit ApplicationSettings(const QString & settingsName = {});
50
63 const Account & account, const QString & settingsName = {});
64
82 const Account & account, const char * settingsName,
83 int settingsNameSize = -1);
84
98 ApplicationSettings(const Account & account, std::string_view settingsName);
99
104
109 struct ArrayCloser
110 {
111 ArrayCloser(ApplicationSettings & settings) : m_settings(settings) {}
112
113 ~ArrayCloser()
114 {
115 m_settings.endArray();
116 m_settings.sync();
117 }
118
119 ApplicationSettings & m_settings;
120 };
121
126 struct GroupCloser
127 {
128 GroupCloser(ApplicationSettings & settings) : m_settings(settings) {}
129
130 ~GroupCloser()
131 {
132 m_settings.endGroup();
133 m_settings.sync();
134 }
135
136 ApplicationSettings & m_settings;
137 };
138
145 void beginGroup(const QString & prefix);
146
157 void beginGroup(const char * prefix, int size = -1);
158
168 void beginGroup(std::string_view prefix);
169
177 [[nodiscard]] int beginReadArray(const QString & prefix);
178
189 [[nodiscard]] int beginReadArray(const char * prefix, int size = -1);
190
198 [[nodiscard]] int beginReadArray(std::string_view prefix);
199
210 void beginWriteArray(const QString & prefix, int arraySize = -1);
211
227 const char * prefix, int arraySize = -1, int prefixSize = -1);
228
240 void beginWriteArray(std::string_view prefix, int arraySize = -1);
241
249 [[nodiscard]] bool contains(const QString & key) const;
250
262 [[nodiscard]] bool contains(const char * key, int size = -1) const;
263
272 [[nodiscard]] bool contains(std::string_view key) const;
273
280 void remove(const QString & key);
281
292 void remove(const char * key, int size = -1);
293
301 void remove(std::string_view key);
302
310 void setValue(const QString & key, const QVariant & value);
311
323 void setValue(const char * key, const QVariant & value, int keySize = -1);
324
333 void setValue(std::string_view key, const QVariant & value);
334
345 [[nodiscard]] QVariant value(
346 const QString & key, const QVariant & defaultValue = {}) const;
347
362 [[nodiscard]] QVariant value(
363 const char * key, const QVariant & defaultValue = {},
364 int keySize = -1) const;
365
377 [[nodiscard]] QVariant value(
378 std::string_view key, const QVariant & defaultValue = {}) const;
379
380 // utility::Printable
381 QTextStream & print(QTextStream & strm) const override;
382
383private:
384 Q_DISABLE_COPY(ApplicationSettings)
385};
386
387} // namespace quentier::utility
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition Account.h:38
The ApplicationSettings class enhances the functionality of QSettings, in particular it simplifies th...
Definition ApplicationSettings.h:37
void setValue(std::string_view key, const QVariant &value)
void beginGroup(const char *prefix, int size=-1)
int beginReadArray(const QString &prefix)
void remove(const char *key, int size=-1)
bool contains(const QString &key) const
QVariant value(const QString &key, const QVariant &defaultValue={}) const
ApplicationSettings(const QString &settingsName={})
void setValue(const char *key, const QVariant &value, int keySize=-1)
void beginWriteArray(const QString &prefix, int arraySize=-1)
void setValue(const QString &key, const QVariant &value)
ApplicationSettings(const Account &account, const QString &settingsName={})
void beginWriteArray(std::string_view prefix, int arraySize=-1)
ApplicationSettings(const Account &account, std::string_view settingsName)
bool contains(const char *key, int size=-1) const
void remove(const QString &key)
int beginReadArray(std::string_view prefix)
bool contains(std::string_view key) const
void beginWriteArray(const char *prefix, int arraySize=-1, int prefixSize=-1)
QVariant value(const char *key, const QVariant &defaultValue={}, int keySize=-1) const
ApplicationSettings(const Account &account, const char *settingsName, int settingsNameSize=-1)
void remove(std::string_view key)
int beginReadArray(const char *prefix, int size=-1)
void beginGroup(std::string_view prefix)
QVariant value(std::string_view key, const QVariant &defaultValue={}) const
void beginGroup(const QString &prefix)
The Printable class is the interface for Quentier's internal classes which should be able to write th...
Definition Printable.h:38