QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RObject.h
Go to the documentation of this file.
1
20#ifndef ROBJECT_H
21#define ROBJECT_H
22
23#include "core_global.h"
24
25#include <QDebug>
26
27#include "RPropertyAttributes.h"
28#include "RPropertyTypeId.h"
29
30class RDocument;
31class RTransaction;
32class RVector;
33
34#ifndef RQMapQStringQString
36#endif
37
38#ifndef RDEFAULT_QVARIANT
39#define RDEFAULT_QVARIANT QVariant()
40#endif
41
42#ifndef RDEFAULT_QSTRING
43#define RDEFAULT_QSTRING QString()
44#endif
45
46#ifndef RDEFAULT_QSTRINGLIST
47#define RDEFAULT_QSTRINGLIST QStringList()
48#endif
49
50
51
65
66 friend class RStorage;
67
68public:
69 typedef int Id;
70 const static Id INVALID_ID;
71 typedef int Handle;
72 const static Handle INVALID_HANDLE;
73
81
82 enum XYZ {
83 X, Y, Z
84 };
85
86public:
88 NoFlags = 0x000,
89 Undone = 0x001,
90 Protect = 0x002,
91 Selected = 0x004,
92 Invisible = 0x008,
93 WorkingSet = 0x010
94 };
95 Q_DECLARE_FLAGS(Flags, ObjectFlag)
96
97public:
98 RObject(RDocument* document=NULL);
99 RObject(const RObject& other);
100 virtual ~RObject();
101
102 static void init();
103
105 return RS::ObjectUnknown;
106 }
107
111 virtual bool isOfType(RS::EntityType t) const {
112 return getType()==t;
113 }
114
118 virtual RS::EntityType getType() const {
119 return RS::ObjectUnknown;
120 }
121
122 virtual QSharedPointer<RObject> clone() const = 0;
123
128 virtual bool mustAlwaysClone() const {
129 return false;
130 }
131
133 return document;
134 }
135
136 const RDocument* getDocument() const {
137 return document;
138 }
139
140 void setDocument(RDocument* document);
141
142 void setFlag(int flag, bool on = true) {
143 if (on) {
144 flags |= (ObjectFlag)flag;
145 } else {
146 flags &= ~(ObjectFlag)flag;
147 }
148 }
149 bool getFlag(int flag) const {
150 return (int)(flags & flag) == flag;
151 }
152
156 template<class T>
157 static bool setMember(T& variable, const QVariant& value, bool condition = true) {
158 if (!condition) {
159 return false;
160 }
161 variable = value.value<T> ();
162 return true;
163 }
164
171 return objectId;
172 }
173
175 return handle;
176 }
177
178 bool isProtected() const {
179 return getFlag(RObject::Protect);
180 }
181
182 void setProtected(bool on) {
183 setFlag(RObject::Protect, on);
184 }
185
186 bool isInvisible() const {
187 return getFlag(RObject::Invisible);
188 }
189
190 void setInvisible(bool on) {
191 setFlag(RObject::Invisible, on);
192 }
193
194 virtual bool isSelected() const {
195 return getFlag(RObject::Selected);
196 }
197
198 virtual void setSelected(bool on) {
199 setFlag(RObject::Selected, on);
200 }
201
202 bool isUndone() const {
203 return getFlag(RObject::Undone);
204 }
205
206 virtual bool isWorkingSet() const {
207 return getFlag(RObject::WorkingSet);
208 }
209
210 virtual void setWorkingSet(bool on) {
211 setFlag(RObject::WorkingSet, on);
212 }
213
214 virtual QSet<RPropertyTypeId> getPropertyTypeIds(RPropertyAttributes::Option option = RPropertyAttributes::NoOptions) const;
215 virtual QSet<RPropertyTypeId> getCustomPropertyTypeIds() const;
216
221 virtual QPair<QVariant, RPropertyAttributes> getProperty(RPropertyTypeId& propertyTypeId,
222 bool humanReadable = false, bool noAttributes = false, bool showOnRequest = false);
223
232 virtual bool setProperty(RPropertyTypeId propertyTypeId,
233 const QVariant& value, RTransaction* transaction=NULL);
234
239 virtual bool hasPropertyType(RPropertyTypeId propertyTypeId) {
240 return RPropertyTypeId::hasPropertyType(getType(), propertyTypeId);
241 }
242
243 bool hasCustomProperties() const;
244 bool hasCustomProperty(const QString& title, const QString& key) const;
245
249 bool hasCustomProperty(const QString& title, const QRegularExpression& key) const;
250
251 virtual QVariant getCustomProperty(const QString& title, const QString& key, const QVariant& defaultValue = RDEFAULT_QVARIANT) const;
252 virtual double getCustomDoubleProperty(const QString& title, const QString& key, double defaultValue) const;
253 virtual int getCustomIntProperty(const QString& title, const QString& key, int defaultValue) const;
254 virtual bool getCustomBoolProperty(const QString& title, const QString& key, bool defaultValue) const;
255 virtual void setCustomProperty(const QString& title, const QString& key, const QVariant& value);
256
260 virtual void setCustomProperties(const RQMapQStringQString& properties);
261 virtual void removeCustomProperty(const QString& title, const QString& key);
262 QStringList getCustomPropertyTitles() const;
263 QStringList getCustomPropertyKeys(const QString& title) const;
264 void copyCustomPropertiesFrom(const RObject *other,
265 const QString& title = RDEFAULT_QSTRING,
266 bool overwrite = false,
267 const QStringList& ignoreList = RDEFAULT_QSTRINGLIST,
268 const QString& mapKeyFrom = RDEFAULT_QSTRING,
269 const QString& mapKeyTo = RDEFAULT_QSTRING);
270
271 static void setCustomPropertyAttributes(const QString& title, const QString& key, const RPropertyAttributes& att);
272 static RPropertyAttributes getCustomPropertyAttributes(const QString& title, const QString& key);
273
277 QMap<QString, QVariantMap> getCustomProperties() const;
278
279 virtual int getComplexity() const {
280 return 0;
281 }
282
283 virtual void setAutoUpdatesBlocked(bool on) {
284 Q_UNUSED(on)
285 }
286
287 void dump() const {
288 qDebug() << *this;
289 }
290
291 virtual bool validate() {
292 return true;
293 }
294
298 friend QDebug operator<<(QDebug dbg, const RObject& o) {
299 o.print(dbg);
300 return dbg;
301 }
302
303protected:
304 virtual void print(QDebug dbg) const;
305
306 void setUndone(bool on);
307
309 objectId = id;
310 }
311
313 handle = h;
314 }
315
319 static bool setMember(QString& variable, const QVariant& value, bool condition = true);
323 static bool setMember(double& variable, const QVariant& value, bool condition = true);
327 static bool setMember(int& variable, const QVariant& value, bool condition = true);
331 static bool setMember(bool& variable, const QVariant& value, bool condition = true);
335 bool setMemberFlag(int flag, const QVariant& value, bool condition = true);
339 static bool setMember(QList<double>& variable, const QVariant& value, bool condition);
343 static bool setMember(QList<int>& variable, const QVariant& value, bool condition);
347 static bool setMemberX(QList<RVector>& variable, const QVariant& value, bool condition = true);
351 static bool setMemberY(QList<RVector>& variable, const QVariant& value, bool condition = true);
355 static bool setMemberZ(QList<RVector>& variable, const QVariant& value, bool condition = true);
356
360 static bool setMemberVector(QList<RVector>& variable, const QVariant& value, RObject::XYZ xyz);
361
362private:
375 Flags flags;
384
389};
390
394Q_DECLARE_METATYPE(QList<QSharedPointer<RObject> >)
395Q_DECLARE_METATYPE(QSharedPointer<RObject>)
396Q_DECLARE_METATYPE(QSharedPointer<RObject>*)
397typedef QMap<int, QSharedPointer<RObject> > _RMapIntObjectPointer;
400Q_DECLARE_METATYPE(RObject::ObjectFlag)
401Q_DECLARE_METATYPE(QFlags<RObject::ObjectFlag>)
402
403#endif
void init(void basePath)
Definition AddBlockInit.js:2
#define RDEFAULT_QSTRING
Definition RDebug.h:41
Q_DECLARE_METATYPE(RMath *)
QMap< QString, QString > RQMapQStringQString
Definition RObject.h:35
#define RDEFAULT_QSTRINGLIST
Definition RObject.h:47
#define QRegularExpression
Definition RS.h:53
#define RDEFAULT_QVARIANT
Definition RTextLabel.h:32
Definition RDebug.h:38
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition RDocument.h:78
Abstract base class for all objects.
Definition RObject.h:64
virtual void setAutoUpdatesBlocked(bool on)
Definition RObject.h:283
virtual RS::EntityType getType() const
Definition RObject.h:118
Flags flags
Object flags (undone, protected, ...)
Definition RObject.h:375
static const Id INVALID_ID
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RObject.h:70
bool getFlag(int flag) const
Definition RObject.h:149
virtual QSharedPointer< RObject > clone() const =0
static RPropertyTypeId PropertyInvisible
Definition RObject.h:80
virtual bool isSelected() const
Definition RObject.h:194
void setInvisible(bool on)
Definition RObject.h:190
Id objectId
Unique ID of this object.
Definition RObject.h:367
static RPropertyTypeId PropertyHandle
Definition RObject.h:76
virtual bool isWorkingSet() const
Definition RObject.h:206
virtual void setSelected(bool on)
Definition RObject.h:198
static RPropertyTypeId PropertyProtected
Definition RObject.h:77
const RDocument * getDocument() const
Definition RObject.h:136
bool isProtected() const
Definition RObject.h:178
ObjectFlag
Definition RObject.h:87
@ Invisible
object is invisible
Definition RObject.h:92
@ Protect
object is protected
Definition RObject.h:90
@ Undone
object is undone
Definition RObject.h:89
@ WorkingSet
object is part of the current working set
Definition RObject.h:93
@ Selected
object is selected
Definition RObject.h:91
XYZ
Definition RObject.h:82
@ X
Definition RObject.h:83
int Handle
Definition RObject.h:71
RObject::Handle getHandle() const
Definition RObject.h:174
virtual bool isOfType(RS::EntityType t) const
Override to indicate that this entity is of a certain type, e.g.
Definition RObject.h:111
RObject::Id getId() const
Definition RObject.h:170
int Id
Definition RObject.h:69
void setHandle(RObject::Handle h)
Definition RObject.h:312
Handle handle
Handle of this object (from DXF / DWG).
Definition RObject.h:371
virtual void setWorkingSet(bool on)
Definition RObject.h:210
void setId(RObject::Id id)
Definition RObject.h:308
void setFlag(int flag, bool on=true)
Definition RObject.h:142
friend QDebug operator<<(QDebug dbg, const RObject &o)
Definition RObject.h:298
static RPropertyTypeId PropertySelected
Definition RObject.h:79
static RS::EntityType getRtti()
Definition RObject.h:104
bool isUndone() const
Definition RObject.h:202
static RPropertyTypeId PropertyCustom
Definition RObject.h:74
RDocument * getDocument()
Definition RObject.h:132
virtual bool mustAlwaysClone() const
Definition RObject.h:128
void dump() const
Definition RObject.h:287
static const Handle INVALID_HANDLE
Definition RObject.h:72
virtual void print(QDebug dbg) const
Stream operator for QDebug.
Definition RObject.cpp:719
QMap< QString, QVariantMap > customProperties
AppID -> key -> value e.g.
Definition RObject.h:383
static bool setMember(T &variable, const QVariant &value, bool condition=true)
Definition RObject.h:157
bool isInvisible() const
Definition RObject.h:186
virtual bool validate()
Definition RObject.h:291
RDocument * document
Definition RObject.h:363
static RPropertyTypeId PropertyWorkingSet
Definition RObject.h:78
static QMap< QString, QMap< QString, RPropertyAttributes > > customPropertyAttributes
Attributes of custom properties (read-only, invisible, ...).
Definition RObject.h:388
void setProtected(bool on)
Definition RObject.h:182
virtual bool hasPropertyType(RPropertyTypeId propertyTypeId)
Definition RObject.h:239
virtual int getComplexity() const
Definition RObject.h:279
static RPropertyTypeId PropertyType
Definition RObject.h:75
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RPropertyAttributes.h:42
Option
Definition RPropertyAttributes.h:44
@ NoOptions
Definition RPropertyAttributes.h:45
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RPropertyTypeId.h:54
static bool hasPropertyType(RS::EntityType type, RPropertyTypeId propertyTypeId)
Definition RPropertyTypeId.cpp:265
EntityType
Entity types used for property handling / filtering.
Definition RS.h:227
@ ObjectUnknown
Unknown object.
Definition RS.h:229
This is the abstract base class for all storage implementations.
Definition RStorage.h:67
Transaction implementation.
Definition RTransaction.h:73
Represents a 3d vector (x/y/z).
Definition RVector.h:47
#define QCADCORE_EXPORT
Definition core_global.h:10
#define NULL
Definition opennurbs_system.h:256