QCAD
Open Source 2D CAD
RPropertyAttributes.h
Go to the documentation of this file.
1 
20 #ifndef RPROPERTYATTRIBUTES_H
21 #define RPROPERTYATTRIBUTES_H
22 
23 #include "core_global.h"
24 
25 #include <QString>
26 #include <QSet>
27 #include <QMap>
28 #include <QPair>
29 #include <QVariant>
30 
31 #include "RDebug.h"
32 #include "RMath.h"
33 #include "RPropertyTypeId.h"
34 
48 public:
49  enum Option {
50  NoOptions = 0x0,
51  ReadOnly = 0x1,
52  Invisible = 0x2,
53  Angle = 0x4,
54  AffectsOtherProperties = 0x8,
55  IgnoreCase = 0x10,
56  AllowMixedValue = 0x20,
57  List = 0x40,
58  Mixed = 0x80,
59  RichText = 0x100,
60  Style = 0x200,
61  DimensionLabel = 0x400,
62  Label = 0x800,
63  Pattern = 0x1000,
64  Custom = 0x2000,
65  Integer = 0x4000,
66  Redundant = 0x8000,
67  VisibleToParent = 0x10000,
68  KnownVariable = 0x20000,
69  NumericallySorted = 0x40000,
70  Percentage = 0x80000 | Integer,
71  Sum = 0x100000 | ReadOnly
72  };
73  Q_DECLARE_FLAGS(Options, Option)
74 
75 public:
76  RPropertyAttributes() : options(NoOptions) {}
77 
78  RPropertyAttributes(RPropertyAttributes::Options options) :
79  options(options) {
80  }
81 
82  void setOption(RPropertyAttributes::Option option, bool on);
83 
84  bool isReadOnly() const {
85  return options.testFlag(ReadOnly);
86  }
87 
88  void setReadOnly(bool readOnly) {
89  setOption(ReadOnly, readOnly);
90  }
91 
92  bool isInvisible() const {
93  return options.testFlag(Invisible);
94  }
95 
96  void setInvisible(bool invisible) {
97  setOption(Invisible, invisible);
98  }
99 
100  bool isList() const {
101  return options.testFlag(List);
102  }
103 
104  void setList(bool on) {
105  setOption(List, on);
106  }
107 
108  bool isAngleType() const {
109  return options.testFlag(Angle);
110  }
111 
112  void setAngleType(bool angle) {
113  setOption(Angle, angle);
114  }
115 
116  bool getIgnoreCase() const {
117  return options.testFlag(IgnoreCase);
118  }
119 
120  void setIgnoreCase(bool ignoreCase) {
121  setOption(IgnoreCase, ignoreCase);
122  }
123 
124  bool affectsOtherProperties() const {
125  return options.testFlag(AffectsOtherProperties);
126  }
127 
128  void setAffectsOtherProperties(bool affectsOtherProperties) {
129  setOption(AffectsOtherProperties, affectsOtherProperties);
130  }
131 
132  void setAllowMixedValue(bool allowMixedValue) {
133  setOption(AllowMixedValue, allowMixedValue);
134  }
135 
137  return options.testFlag(AllowMixedValue);
138  }
139 
140  QSet<QString> getChoices() const {
141  return choices;
142  }
143 
144  void setChoices(QSet<QString> choices) {
145  this->choices = choices;
146  }
147 
148  bool hasChoices() {
149  return !choices.isEmpty();
150  }
151 
152 // QList<QVariant> getEnumChoices() const {
153 // return enumChoices;
154 // }
155 
156 // void setEnumChoices(QList<QVariant> ec) {
157 // enumChoices = ec;
158 // }
159 
160 // bool hasEnumChoices() const {
161 // return !enumChoices.isEmpty();
162 // }
163 
164  bool isRichText() const {
165  return options.testFlag(RichText);
166  }
167 
168  void setRichText(bool on) {
169  setOption(RichText, on);
170  }
171 
172  bool isStyle() const {
173  return options.testFlag(Style);
174  }
175 
176  void setStyle(bool on) {
177  setOption(Style, on);
178  }
179 
180  void mixWith(const RPropertyAttributes & other);
181 
182  bool isMixed() const {
183  return options.testFlag(Mixed);
184  }
185 
186  void setMixed(bool mixed) {
187  setOption(Mixed, mixed);
188  }
189 
190  bool isSum() const {
191  return options.testFlag(Sum);
192  }
193 
194  void setSum(bool sum) {
195  setOption(Sum, sum);
196  }
197 
198  bool isLabel() const {
199  return options.testFlag(Label);
200  }
201 
202  bool isDimensionLabel() const {
203  return options.testFlag(DimensionLabel);
204  }
205 
206  bool isInteger() const {
207  return options.testFlag(Integer);
208  }
209 
210  bool isRedundant() const {
211  return options.testFlag(Redundant);
212  }
213 
214  void setRedundant(bool on) {
215  setOption(Redundant, on);
216  }
217 
218  bool isVisibleToParent() const {
219  return options.testFlag(VisibleToParent);
220  }
221 
222  bool isNumericallySorted() const {
223  return options.testFlag(NumericallySorted);
224  }
225 
226  void setNumericallySorted(bool on) {
227  setOption(NumericallySorted, on);
228  }
229 
231  return propertyTypeId;
232  }
233 
235  propertyTypeId = pid;
236  }
237 
238  bool operator == (const RPropertyAttributes& other) const {
239  if (isInvisible() != other.isInvisible()) {
240  return false;
241  }
242  if (isAngleType() != other.isAngleType()) {
243  return false;
244  }
245  if (affectsOtherProperties() != other.affectsOtherProperties()) {
246  return false;
247  }
248  if (isList() != other.isList()) {
249  return false;
250  }
251  if (choices != other.choices) {
252  return false;
253  }
254  if (propertyTypeId != other.propertyTypeId) {
255  return false;
256  }
257 
258  return true;
259  }
260 
261  bool operator !=(const RPropertyAttributes& other) const {
262  return !operator ==(other);
263  }
264 
265 
266 private:
267  RPropertyAttributes::Options options;
268  QSet<QString> choices;
269  //QList<QVariant> enumChoices;
271 };
272 
273 Q_DECLARE_OPERATORS_FOR_FLAGS(RPropertyAttributes::Options)
274 
278 Q_DECLARE_METATYPE(QFlags<RPropertyAttributes::Option>*)
281 Q_DECLARE_METATYPE(_RPairVariantPropertyAttributes*)
282 Q_DECLARE_METATYPE(_RPairVariantPropertyAttributes)
283 
284 #endif
bool isReadOnly() const
Definition: RPropertyAttributes.h:84
void setMixed(bool mixed)
Definition: RPropertyAttributes.h:186
bool isVisibleToParent() const
Definition: RPropertyAttributes.h:218
RPropertyAttributes::Options options
Definition: RPropertyAttributes.h:267
bool getAllowMixedValue()
Definition: RPropertyAttributes.h:136
bool isAngleType() const
Definition: RPropertyAttributes.h:108
QSet< QString > getChoices() const
Definition: RPropertyAttributes.h:140
bool affectsOtherProperties() const
Definition: RPropertyAttributes.h:124
void setSum(bool sum)
Definition: RPropertyAttributes.h:194
bool getIgnoreCase() const
Definition: RPropertyAttributes.h:116
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPropertyTypeId.h:58
RPropertyAttributes(RPropertyAttributes::Options options)
Definition: RPropertyAttributes.h:78
#define QCADCORE_EXPORT
Definition: core_global.h:10
bool isLabel() const
Definition: RPropertyAttributes.h:198
void setAffectsOtherProperties(bool affectsOtherProperties)
Definition: RPropertyAttributes.h:128
bool isDimensionLabel() const
Definition: RPropertyAttributes.h:202
bool isSum() const
Definition: RPropertyAttributes.h:190
void setIgnoreCase(bool ignoreCase)
Definition: RPropertyAttributes.h:120
bool isInteger() const
Definition: RPropertyAttributes.h:206
bool isNumericallySorted() const
Definition: RPropertyAttributes.h:222
bool isInvisible() const
Definition: RPropertyAttributes.h:92
Q_DECLARE_METATYPE(RMath *)
void setPropertyTypeId(RPropertyTypeId pid)
Definition: RPropertyAttributes.h:234
QPair< QVariant, RPropertyAttributes > _RPairVariantPropertyAttributes
Definition: RPropertyAttributes.h:275
void setInvisible(bool invisible)
Definition: RPropertyAttributes.h:96
void setRedundant(bool on)
Definition: RPropertyAttributes.h:214
Option
Definition: RPropertyAttributes.h:49
void setAngleType(bool angle)
Definition: RPropertyAttributes.h:112
void setStyle(bool on)
Definition: RPropertyAttributes.h:176
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPropertyAttributes.h:47
void setChoices(QSet< QString > choices)
Definition: RPropertyAttributes.h:144
bool isRedundant() const
Definition: RPropertyAttributes.h:210
QSet< QString > choices
Definition: RPropertyAttributes.h:268
bool isStyle() const
Definition: RPropertyAttributes.h:172
void setRichText(bool on)
Definition: RPropertyAttributes.h:168
bool hasChoices()
Definition: RPropertyAttributes.h:148
void setNumericallySorted(bool on)
Definition: RPropertyAttributes.h:226
bool isRichText() const
Definition: RPropertyAttributes.h:164
void setAllowMixedValue(bool allowMixedValue)
Definition: RPropertyAttributes.h:132
bool isMixed() const
Definition: RPropertyAttributes.h:182
void setList(bool on)
Definition: RPropertyAttributes.h:104
void setReadOnly(bool readOnly)
Definition: RPropertyAttributes.h:88
RPropertyTypeId propertyTypeId
Definition: RPropertyAttributes.h:270
bool isList() const
Definition: RPropertyAttributes.h:100
RPropertyTypeId getPropertyTypeId()
Definition: RPropertyAttributes.h:230