Messagelib

optionset.h
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 *
7 *******************************************************************************/
8
9#pragma once
10
11#include <QString>
12
13class QDataStream;
14
15namespace MessageList
16{
17namespace Core
18{
19/**
20 * A set of options that can be applied to the MessageList in one shot.
21 * In the sources and in the user interface you can find this set of options
22 * referred also as "View Mode" or "Preset".
23 *
24 * The option set has a name and an unique id that identifies it. The name
25 * is shown to the user in the combo box above the message list view.
26 * The set has also a description that is shown as tooltip and should explain
27 * the purpose, the best usage cases, eventually the advantages and disadvantages.
28 *
29 * The option set can be "packed" to a string and "unpacked" from a string. This
30 * is basically for storing it in a configuration file.
31 */
33{
34public:
35 explicit OptionSet();
36 explicit OptionSet(const OptionSet &src);
37 explicit OptionSet(const QString &name, const QString &description, bool readOnly = false);
38 virtual ~OptionSet();
39
40protected:
41 QString mId;
42 QString mName;
43 QString mDescription;
44 bool mReadOnly = false;
45
46public:
47 /**
48 * Returns the unique id of this OptionSet.
49 * The id can't be set. It's either automatically generated or loaded from configuration.
50 */
51 const QString &id() const
52 {
53 return mId;
54 }
55
56 /**
57 * Returns the name of this OptionSet
58 */
59 const QString &name() const
60 {
61 return mName;
62 }
63
64 /**
65 * Sets the name of this OptionSet. You must take care
66 * of specifying an _unique_ name in order for the Manager to
67 * store the sets properly.
68 */
69 void setName(const QString &name)
70 {
71 mName = name;
72 }
73
74 /**
75 * Returns a description of this option set. Ideally it should contain
76 * its purpose and what to expect from it. But in the end we'll show
77 * whatever the user will put in here.
78 */
79 const QString &description() const
80 {
81 return mDescription;
82 }
83
84 /**
85 * Sets the description for this option set.
86 */
88 {
89 mDescription = description;
90 }
91
92 /**
93 * Packs this configuration object into a string suitable for storing
94 * in a config file.
95 */
96 [[nodiscard]] QString saveToString() const;
97
98 /**
99 * Attempts to unpack this configuration object from a string (that is
100 * likely to come out from a config file). Returns true if the string
101 * was in a valid format and the load operation succeeded, false otherwise.
102 */
103 bool loadFromString(const QString &data);
104
105 /**
106 * (Re)generates a (hopefully) unique identifier for this option set.
107 * Please note that this function is reserved to this class and to
108 * Configure*Dialog instances which need it for cloning option sets.
109 * You shouldn't need to call it.
110 */
111 void generateUniqueId();
112
113 [[nodiscard]] bool readOnly() const
114 {
115 return mReadOnly;
116 }
117
118 void setReadOnly(bool b)
119 {
120 mReadOnly = b;
121 }
122
123protected:
124 /**
125 * Saves the inner contents of this option set to the specified data stream.
126 * The implementation of this method MUST be provided by derived classes.
127 */
128 virtual void save(QDataStream &s) const = 0;
129
130 /**
131 * Loads the inner contents of this option set from the specified data stream.
132 * The implementation of this method MUST be provided by derived classes
133 * and must return true in case of success and false in case of load failure.
134 */
135 virtual bool load(QDataStream &s) = 0;
136};
137} // namespace Core
138} // namespace MessageList
A set of options that can be applied to the MessageList in one shot.
Definition optionset.h:33
const QString & id() const
Returns the unique id of this OptionSet.
Definition optionset.h:51
const QString & description() const
Returns a description of this option set.
Definition optionset.h:79
virtual void save(QDataStream &s) const =0
Saves the inner contents of this option set to the specified data stream.
QString saveToString() const
Packs this configuration object into a string suitable for storing in a config file.
Definition optionset.cpp:47
void generateUniqueId()
(Re)generates a (hopefully) unique identifier for this option set.
Definition optionset.cpp:40
void setName(const QString &name)
Sets the name of this OptionSet.
Definition optionset.h:69
const QString & name() const
Returns the name of this OptionSet.
Definition optionset.h:59
virtual bool load(QDataStream &s)=0
Loads the inner contents of this option set from the specified data stream.
void setDescription(const QString &description)
Sets the description for this option set.
Definition optionset.h:87
bool loadFromString(const QString &data)
Attempts to unpack this configuration object from a string (that is likely to come out from a config ...
Definition optionset.cpp:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.