QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RDimStyleData.h
Go to the documentation of this file.
1
20#ifndef RDIMSTYLEDATA_H
21#define RDIMSTYLEDATA_H
22
23#include "core_global.h"
24
25#include "RS.h"
26#include "RColor.h"
27
28#include <QDebug>
29#include <QVariant>
30
39
40public:
41 RDimStyleData(bool override = false);
42 virtual ~RDimStyleData();
43
44 static void init();
45 static void initDefaults();
46 static QVariant getVariantDefault(RS::KnownVariable key);
47 static double getDoubleDefault(RS::KnownVariable key);
48 static int getIntDefault(RS::KnownVariable key);
49 static bool getBoolDefault(RS::KnownVariable key);
50 static RColor getColorDefault(RS::KnownVariable key);
51
52 void initFromSettings();
53
55 return mapBool.contains(key) || mapDouble.contains(key) || mapInt.contains(key) || mapColor.contains(key);
56 }
57
58 bool isValid() const {
59 return !mapBool.isEmpty() || !mapDouble.isEmpty() || !mapInt.isEmpty() || !mapColor.isEmpty();
60 }
61
62 void clear() {
63 mapBool.clear();
64 mapInt.clear();
65 mapDouble.clear();
66 mapColor.clear();
67 }
68
70 if (dimXTypes.contains(key)) {
71 return dimXTypes[key];
72 }
73 else {
74 return RS::VarTypeUnknown;
75 }
76 }
77
78 QVariant getVariant(RS::KnownVariable key) const {
79 if (mapDouble.contains(key)) {
80 return mapDouble[key];
81 }
82 else if (mapInt.contains(key)) {
83 return mapInt[key];
84 }
85 else if (mapBool.contains(key)) {
86 return mapBool[key];
87 }
88 else if (mapColor.contains(key)) {
89 QVariant v;
90 v.setValue<RColor>(mapColor[key]);
91 return v;
92 }
93 else {
94 return getVariantDefault(key);
95 }
96 }
97
98 void setVariant(RS::KnownVariable key, const QVariant& val) {
99 if (!dimXTypes.contains(key)) {
100 qWarning() << "unregistered dim x type:" << key;
101 return;
102 }
103
104 RS::KnownVariableType type = dimXTypes[key];
105 switch (type) {
107 setDouble(key, val.toDouble());
108 break;
109
110 case RS::VarTypeInt:
111 setInt(key, val.toInt());
112 break;
113
114 case RS::VarTypeBool:
115 setBool(key, val.toBool());
116 break;
117
118 case RS::VarTypeColor:
119 {
120 RColor col = val.value<RColor>();
121 setColor(key, col);
122 }
123 break;
124
125 default:
126 qWarning() << "unknown type:" << type;
127 break;
128 }
129 }
130
131 double getDouble(RS::KnownVariable key) const {
132 if (mapDouble.contains(key)) {
133 return mapDouble[key];
134 }
135 else {
136 return getDoubleDefault(key);
137 }
138 }
139
140 virtual void setDouble(RS::KnownVariable key, double val) {
141 mapDouble[key] = val;
142 }
143
145 mapDouble.remove(key);
146 }
147
148 int getInt(RS::KnownVariable key) const {
149 if (mapInt.contains(key)) {
150 return mapInt[key];
151 }
152 else {
153 return getIntDefault(key);
154 }
155 }
156
157 virtual void setInt(RS::KnownVariable key, int val) {
158 mapInt[key] = val;
159 }
160
162 mapInt.remove(key);
163 }
164
165 bool getBool(RS::KnownVariable key) const {
166 if (mapBool.contains(key)) {
167 return mapBool[key];
168 }
169 else {
170 return getBoolDefault(key);
171 }
172 }
173
174 virtual void setBool(RS::KnownVariable key, bool val) {
175 mapBool[key] = val;
176 }
177
179 mapBool.remove(key);
180 }
181
183 if (mapColor.contains(key)) {
184 return mapColor[key];
185 }
186 else {
187 return getColorDefault(key);
188 }
189 }
190
191 virtual void setColor(RS::KnownVariable key, const RColor& val) {
192 mapColor[key] = val;
193 }
194
196 mapColor.remove(key);
197 }
198
199public:
201
202 friend QDebug operator<<(QDebug dbg, const RDimStyleData& d) {
203 dbg.nospace() << "RDimSyleData(";
204 dbg.nospace() << d.mapBool;
205 dbg.nospace() << d.mapInt;
206 dbg.nospace() << d.mapDouble;
207 dbg.nospace() << d.mapColor;
208 dbg.nospace() << ")";
209 return dbg;
210 }
211
212protected:
217
219};
220
223typedef QMap<RS::KnownVariable, RS::KnownVariableType> _QMapRSKnownVariableRSKnownVariableType;
225
226#endif
void init(void basePath)
Definition AddBlockInit.js:2
Q_DECLARE_METATYPE(RMath *)
Definition RDebug.h:38
Color.
Definition RColor.h:43
Copyright (c) 2011-2021 by Andrew Mustun.
Definition RDimStyleData.h:38
QMap< RS::KnownVariable, RColor > mapColor
Definition RDimStyleData.h:216
virtual void setColor(RS::KnownVariable key, const RColor &val)
Definition RDimStyleData.h:191
RColor getColor(RS::KnownVariable key) const
Definition RDimStyleData.h:182
void setVariant(RS::KnownVariable key, const QVariant &val)
Definition RDimStyleData.h:98
QMap< RS::KnownVariable, int > mapInt
Definition RDimStyleData.h:214
QMap< RS::KnownVariable, bool > mapBool
Definition RDimStyleData.h:215
int getInt(RS::KnownVariable key) const
Definition RDimStyleData.h:148
void removeDouble(RS::KnownVariable key)
Definition RDimStyleData.h:144
static QMap< RS::KnownVariable, QVariant > mapDefaults
Copyright (c) 2011-2021 by Andrew Mustun.
Definition RDimStyleData.h:218
static QMap< RS::KnownVariable, RS::KnownVariableType > dimXTypes
Definition RDimStyleData.h:200
friend QDebug operator<<(QDebug dbg, const RDimStyleData &d)
Definition RDimStyleData.h:202
double getDouble(RS::KnownVariable key) const
Definition RDimStyleData.h:131
void clear()
Definition RDimStyleData.h:62
QMap< RS::KnownVariable, double > mapDouble
Definition RDimStyleData.h:213
void removeBool(RS::KnownVariable key)
Definition RDimStyleData.h:178
virtual void setBool(RS::KnownVariable key, bool val)
Definition RDimStyleData.h:174
void removeColor(RS::KnownVariable key)
Definition RDimStyleData.h:195
bool getBool(RS::KnownVariable key) const
Definition RDimStyleData.h:165
virtual void setInt(RS::KnownVariable key, int val)
Definition RDimStyleData.h:157
void removeInt(RS::KnownVariable key)
Definition RDimStyleData.h:161
bool isValid() const
Definition RDimStyleData.h:58
bool hasOverride(RS::KnownVariable key) const
Definition RDimStyleData.h:54
virtual void setDouble(RS::KnownVariable key, double val)
Definition RDimStyleData.h:140
static RS::KnownVariableType getVariableType(RS::KnownVariable key)
Definition RDimStyleData.h:69
QVariant getVariant(RS::KnownVariable key) const
Definition RDimStyleData.h:78
Class namespace for various global enums.
Definition RS.h:149
KnownVariableType
Definition RS.h:678
@ VarTypeInt
Definition RS.h:680
@ VarTypeUnknown
Definition RS.h:683
@ VarTypeColor
Definition RS.h:682
@ VarTypeDouble
Definition RS.h:681
@ VarTypeBool
Definition RS.h:679
KnownVariable
Well established document variables.
Definition RS.h:501
#define QCADCORE_EXPORT
Definition core_global.h:10