Changeset View
Standalone View
kcmkwin/kwinrules/ruleitem.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2020 Ismael Asensio <isma.af@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef KWIN_RULEITEM_H | ||||
22 | #define KWIN_RULEITEM_H | ||||
23 | | ||||
24 | #include "optionsmodel.h" | ||||
25 | | ||||
26 | #include <QFlag> | ||||
27 | #include <QIcon> | ||||
28 | | ||||
29 | | ||||
30 | namespace KWin | ||||
31 | { | ||||
32 | | ||||
33 | class RuleItem : public QObject | ||||
broulik: Since none of these classes are exported, I think you can save yourself the trouble of using… | |||||
It helped me at the beginning to set-up the model items... but you're probably right now it's just an inconvenience iasensio: It helped me at the beginning to set-up the model items... but you're probably right now it's… | |||||
34 | { | ||||
35 | Q_OBJECT | ||||
36 | | ||||
37 | public: | ||||
38 | enum Type { | ||||
39 | Undefined, | ||||
40 | Boolean, | ||||
I /think/ if you based your class on QMetaObject::Type you can generalize it a lot without putting switch statements for your types in it? However, there's also Coordinate and Shortcut, so maybe not. broulik: I /think/ if you based your class on `QMetaObject::Type` you can generalize it a lot without… | |||||
I definitely want to go with a nicer approach for this thing, but for now is the simplest way I found. @hchain suggested to use a template, ideally, using the type on the KConfigXT schema. Currently RuleItem::Type has a double meaning: it sets the stored type and the edit field in the UI. And anyway, Coordinate just maps to a QPoint or QSize, and Shortcut a QKeySequence. iasensio: I definitely want to go with a nicer approach for this thing, but for now is the simplest way I… | |||||
41 | String, | ||||
42 | Integer, | ||||
43 | Option, | ||||
44 | FlagsOption, | ||||
45 | Percentage, | ||||
46 | Coordinate, | ||||
47 | Shortcut | ||||
48 | }; | ||||
49 | Q_ENUM(Type) | ||||
50 | | ||||
51 | enum Flags { | ||||
52 | NoFlags = 0, | ||||
53 | AlwaysEnabled = 1u << 0, | ||||
54 | StartEnabled = 1u << 1, | ||||
55 | AffectsWarning = 1u << 2, | ||||
56 | AffectsDescription = 1u << 3, | ||||
57 | AllFlags = 0b1111 | ||||
58 | }; | ||||
59 | | ||||
60 | public: | ||||
61 | RuleItem() {}; | ||||
62 | RuleItem(const QString &key, | ||||
63 | const RulePolicy::Type policyType, | ||||
64 | const Type type, | ||||
65 | const QString &name, | ||||
66 | const QString §ion, | ||||
67 | const QIcon &icon = QIcon::fromTheme("window"), | ||||
68 | const QString &description = QString("") | ||||
69 | ); | ||||
70 | ~RuleItem(); | ||||
71 | | ||||
72 | QString key() const; | ||||
73 | QString name() const; | ||||
74 | QString section() const; | ||||
75 | QIcon icon() const; | ||||
76 | QString iconName() const; | ||||
77 | QString description() const; | ||||
78 | | ||||
79 | bool isEnabled() const; | ||||
80 | void setEnabled(bool enabled); | ||||
81 | | ||||
82 | bool hasFlag(RuleItem::Flags flag) const; | ||||
83 | void setFlag(RuleItem::Flags flag, bool active=true); | ||||
84 | | ||||
85 | Type type() const; | ||||
86 | QVariant value() const; | ||||
87 | void setValue(QVariant value); | ||||
88 | QVariant suggestedValue() const; | ||||
89 | void setSuggestedValue(QVariant value, bool forceValue = false); | ||||
90 | | ||||
91 | QVariant options() const; | ||||
92 | void setOptionsData(const QList<OptionsModel::Data> &data); | ||||
93 | | ||||
94 | RulePolicy::Type policyType() const; | ||||
95 | int policy() const; // int belongs to anonymous enum in Rules:: | ||||
96 | void setPolicy(int policy); // int belongs to anonymous enum in Rules:: | ||||
97 | QVariant policyModel() const; | ||||
98 | QString policyKey() const; | ||||
99 | | ||||
100 | | ||||
101 | | ||||
102 | void reset(); | ||||
103 | | ||||
104 | private: | ||||
105 | static QVariant typedValue(const QVariant &value, const Type type); | ||||
106 | | ||||
107 | private: | ||||
108 | QString m_key; | ||||
109 | RuleItem::Type m_type; | ||||
Generally we want to have speaking names, i.e. name this policy. broulik: Generally we want to have speaking names, i.e. name this `policy`.
`d` pointer is an exception. | |||||
110 | QString m_name; | ||||
111 | QString m_section; | ||||
112 | QIcon m_icon; | ||||
113 | QString m_description; | ||||
114 | QFlags<Flags> m_flags; | ||||
115 | | ||||
116 | bool m_enabled; | ||||
117 | | ||||
118 | QVariant m_value; | ||||
119 | QVariant m_suggestedValue; | ||||
120 | | ||||
121 | RulePolicy *m_policy; | ||||
122 | OptionsModel *m_options; | ||||
123 | }; | ||||
124 | | ||||
125 | } //namespace | ||||
126 | | ||||
127 | #endif //KWIN_RULEITEM_H |
Since none of these classes are exported, I think you can save yourself the trouble of using private data classes