QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RObject.h
Go to the documentation of this file.
1 #ifndef ROBJECT_H
2 #define ROBJECT_H
3 
4 #include "RPropertyAttributes.h"
5 #include "RPropertyTypeId.h"
6 
7 class RDocument;
8 
9 #ifndef RDEFAULT_QVARIANT
10 #define RDEFAULT_QVARIANT QVariant()
11 #endif
12 
13 
26 class RObject {
27 
28  friend class RStorage;
29 
30 public:
31  typedef int Id;
32  const static Id INVALID_ID;
33  typedef int Handle;
34  const static Handle INVALID_HANDLE;
35 
38 
39  enum XYZ {
40  X, Y, Z
41  };
42 
43 public:
44 
47  }
48  virtual ~RObject() {
49  }
50 
51  static void init();
52 
53  virtual RObject* clone() const = 0;
54 
56  return document;
57  }
58 
59  const RDocument* getDocument() const {
60  return document;
61  }
62 
64  this->document = document;
65  }
66 
67  // static double variantToDouble(const QVariant& v, double defaultValue,
68  // bool ignoreError = true);
69  // static int variantToInt(const QVariant& v, int defaultValue,
70  // bool ignoreError = true);
71 
75  template<class T>
76  static bool setMember(T& variable, const QVariant& value,
77  bool condition = true) {
78 
79  if (!condition) {
80  return false;
81  }
82  variable = value.value<T> ();
83  return true;
84  }
85 
91  RObject::Id getId() const {
92  return objectId;
93  }
94 
96  return handle;
97  }
98 
99  bool isUndone() const {
100  return undone;
101  }
102 
103  virtual void setUndone(bool on);
104 
105  virtual QSet<RPropertyTypeId> getPropertyTypeIds() const;
106 
111  virtual QPair<QVariant, RPropertyAttributes>
112  getProperty(RPropertyTypeId propertyTypeId,
113  bool humanReadable = false,
114  bool noAttributes = false);
115 
124  virtual bool setProperty(RPropertyTypeId propertyTypeId, const QVariant& value);
125 
130  virtual bool hasPropertyType(RPropertyTypeId propertyTypeId) {
131  return RPropertyTypeId::hasPropertyType(typeid(*this), propertyTypeId);
132  }
133 
139  virtual bool isSelectedForPropertyEditing() = 0;
140 
141  QVariant getCustomProperty(const QString& key, const QVariant& defaultValue = RDEFAULT_QVARIANT);
142  void setCustomProperty(const QString& key, const QVariant& value);
143  void removeCustomProperty(const QString& key);
144  QMap<QString, QVariant> getCustomProperties() const;
145 
146  virtual int getComplexity() const {
147  return 0;
148  }
149 
153  // RPropertyTypeId getPropertyId(const QString& propertyGroupTitle, const QString& propertyTitle) {
154  // if (propertyTypeIdMap.count(propertyGroupTitle)==0 ||
155  // propertyTypeIdMap[propertyGroupTitle].count(propertyTitle)==0) {
156  //
157  // return -1;
158  // }
159  // else {
160  // return propertyTypeIdMap[propertyGroupTitle][propertyTitle];
161  // }
162  // }
163 
168  // static RPropertyTypeId getPropertyTypeId(const QString& propertyGroupTitle, const QString& propertyTitle) {
169  // if (propertyTypeIdMap.count(propertyGroupTitle)==0) {
170  // return -1;
171  // }
172  // if (propertyTypeIdMap[propertyGroupTitle].count(propertyTitle)==0) {
173  // return -1;
174  // }
175  //
176  // return propertyTypeIdMap[propertyGroupTitle][propertyTitle];
177  // }
178 
182  friend QDebug operator<<(QDebug dbg, const RObject& o) {
183  o.print(dbg);
184  return dbg;
185  }
186 
187 protected:
188  virtual void print(QDebug dbg) const;
189 
190  void setId(RObject::Id id) {
191  objectId = id;
192  }
193 
195  handle = h;
196  }
197 
201  static bool setMember(QString& variable, const QVariant& value,
202  bool condition = true);
206  static bool setMember(double& variable, const QVariant& value,
207  bool condition = true);
211  static bool setMember(int& variable, const QVariant& value,
212  bool condition = true);
216  static bool setMember(bool& variable, const QVariant& value,
217  bool condition = true);
221  bool setMember(QList<double>& variable, const QVariant& value,
222  bool condition);
226  static bool setMemberX(QList<RVector>& variable, const QVariant& value,
227  bool condition = true);
231  static bool setMemberY(QList<RVector>& variable, const QVariant& value,
232  bool condition = true);
236  static bool setMemberZ(QList<RVector>& variable, const QVariant& value,
237  bool condition = true);
238 
242  static bool setMemberVector(QList<RVector>& variable, const QVariant& value,
243  RObject::XYZ xyz);
244 
245 private:
252  bool undone;
253  QMap<QString, QVariant> customProperties;
254 };
255 
258 Q_DECLARE_METATYPE(QList<QSharedPointer<RObject> >)
259 Q_DECLARE_METATYPE(QSharedPointer<RObject>)
260 Q_DECLARE_METATYPE(QSharedPointer<RObject>*)
261 typedef QMap<int, QSharedPointer<RObject> > _RMapIntObjectPointer;
262 Q_DECLARE_METATYPE(_RMapIntObjectPointer)
264 
265 #endif