QCAD
Open Source 2D CAD
RLayer.h
Go to the documentation of this file.
1 
20 #ifndef RLAYER_H
21 #define RLAYER_H
22 
23 #include "core_global.h"
24 
25 #include <QString>
26 #include <QColor>
27 #include <QDebug>
28 
29 #include "RGlobal.h"
30 #include "RObject.h"
31 #include "RVector.h"
32 #include "RPropertyTypeId.h"
33 #include "RLayerProxy.h"
34 #include "RLinetype.h"
35 #include "RColor.h"
36 #include "RLineweight.h"
37 #include "RPropertyAttributes.h"
38 
39 class RDocument;
40 
49 public:
54 
66 
67 
68 public:
69  enum LayerFlag {
70  Off = 0x010,
71  Frozen = 0x020,
72  Locked = 0x040,
73  Collapsed = 0x080,
74  Plottable = 0x100,
75  Snappable = 0x200,
76  OffIsFreeze = 0x400
77  };
78  Q_DECLARE_FLAGS(Flags, LayerFlag)
79 
80 public:
81  RLayer();
82 
83  RLayer(RDocument* document, const QString& name, bool frozen = false,
84  bool locked = false, const RColor& color = Qt::black,
85  RLinetype::Id linetypeId = RLinetype::INVALID_ID,
86  RLineweight::Lineweight lineweight = RLineweight::Weight000,
87  bool off = false);
88 
89  RLayer(const RLayer& other);
90  virtual ~RLayer();
91 
92  static void init();
93 
94  virtual RS::EntityType getType() const {
95  return RS::ObjectLayer;
96  }
97 
98  virtual RLayer* clone() const;
99 
100  RLayer::Id getParentLayerId() const;
101 
102  QString getName() const {
103  return name;
104  }
105 
106  void setName(const QString& n);
107 
108  bool isOffOrFrozen() const {
109  return isOff() || isFrozen();
110  }
111 
112  bool isOff() const {
113  return getFlag(RLayer::Off);
114  }
115 
116  void setOff(bool on) {
117  setFlag(RLayer::Off, on);
118  }
119 
120  bool isFrozen() const {
121  return getFlag(RLayer::Frozen);
122  }
123 
124  void setFrozen(bool on) {
125  setFlag(RLayer::Frozen, on);
126  }
127 
128  bool isLocked() const {
129  return getFlag(RLayer::Locked);
130  }
131 
132  void setLocked(bool on) {
133  setFlag(RLayer::Locked, on);
134  }
135 
136  bool isCollapsed() const {
137  return getFlag(RLayer::Collapsed);
138  }
139 
140  void setCollapsed(bool on) {
142  }
143 
144  bool isPlottable() const {
145  return getFlag(RLayer::Plottable);
146  }
147 
148  void setPlottable(bool on) {
149  if (name.toLower()!="defpoints") {
151  }
152  }
153 
154  bool isSnappable() const {
155  return getFlag(RLayer::Snappable);
156  }
157 
158  void setSnappable(bool on) {
160  }
161 
162  bool isOffIsFreeze() const {
164  }
165 
166  void setOffIsFreeze(bool on) {
168  }
169 
170  RColor getColor() const {
171  return color;
172  }
173 
174  void setColor(const RColor& c) {
175  color = c;
176  }
177 
179  return linetypeId;
180  }
181 
183  linetypeId = lt;
184  }
185 
187  return lineweight;
188  }
189 
191  lineweight = lw;
192  }
193 
194  virtual QPair<QVariant, RPropertyAttributes> getProperty(
195  RPropertyTypeId& propertyTypeId,
196  bool humanReadable = false, bool noAttributes = false, bool showOnRequest = false);
197  virtual bool setProperty(RPropertyTypeId propertyTypeId,
198  const QVariant& value, RTransaction* transaction=NULL);
199 
200  virtual bool isSelectedForPropertyEditing();
201 
202  bool hasChildLayers() const {
203  const RDocument* doc = getDocument();
204  if (doc==NULL) {
205  return false;
206  }
207  return RLayer::hasChildLayersStatic(doc, name);
208  }
209 
210  QList<QString> getChildLayerNames(bool recursive = true) const {
211  const RDocument* doc = getDocument();
212  if (doc==NULL) {
213  return QList<QString>();
214  }
215  return RLayer::getChildLayerNamesStatic(doc, name, recursive);
216  }
217 
218  QString getParentLayerName() const {
220  }
221 
222  QString getShortLayerName() const {
223  return RLayer::getShortLayerNameStatic(name);
224  }
225 
226  QList<QString> getLayerNameHierarchy() const {
228  }
229 
230  bool isChildLayerOf(const QString& layerName) const {
231  return RLayer::isChildLayerOfStatic(name, layerName);
232  }
233 
234  static QString getHierarchySeparator() {
235  if (layerProxy!=NULL) {
236  return layerProxy->getHierarchySeparator();
237  }
238  return "";
239  }
240 
241  static bool hasChildLayersStatic(const RDocument* doc, const QString& layerName) {
242  if (layerProxy!=NULL) {
243  return layerProxy->hasChildLayers(doc, layerName);
244  }
245  return false;
246  }
247 
248  static QList<QString> getChildLayerNamesStatic(const RDocument* doc, const QString& layerName, bool recursive = true) {
249  if (layerProxy!=NULL) {
250  return layerProxy->getChildLayerNames(doc, layerName, recursive);
251  }
252  return QList<QString>();
253  }
254 
255  static QString getParentLayerNameStatic(const QString& layerName) {
256  if (layerProxy!=NULL) {
257  return layerProxy->getParentLayerName(layerName);
258  }
259  return QString();
260  }
261 
262  static QString getShortLayerNameStatic(const QString& layerName) {
263  if (layerProxy!=NULL) {
264  return layerProxy->getShortLayerName(layerName);
265  }
266  return QString();
267  }
268 
269  static QList<QString> getLayerNameHierarchyStatic(const QString& layerName) {
270  if (layerProxy!=NULL) {
271  return layerProxy->getLayerNameHierarchy(layerName);
272  }
273  return QList<QString>();
274  }
275 
276  static bool isChildLayerOfStatic(const QString& layerName, const QString& parentLayerName) {
277  if (layerProxy!=NULL) {
278  return layerProxy->isChildLayerOf(layerName, parentLayerName);
279  }
280  return false;
281  }
282 
283  static bool hasProxy() {
284  return layerProxy!=NULL;
285  }
286 
290  static void setLayerProxy(RLayerProxy* p) {
291  if (layerProxy!=NULL) {
292  delete layerProxy;
293  }
294  layerProxy = p;
295  }
296 
301  return layerProxy;
302  }
303 
304 private:
305  QString name;
306  Flags flags;
310 
312 };
313 
314 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLayer& l);
315 
316 Q_DECLARE_METATYPE(QSharedPointer<RLayer>)
317 Q_DECLARE_METATYPE(QSharedPointer<RLayer>*)
320 Q_DECLARE_METATYPE(RLayer::LayerFlag)
321 Q_DECLARE_METATYPE(QFlags<RLayer::LayerFlag>)
322 
323 #endif
QString name
Definition: RLayer.h:305
bool isOff() const
Definition: RLayer.h:112
static QString getParentLayerNameStatic(const QString &layerName)
Definition: RLayer.h:255
bool isOffIsFreeze() const
Definition: RLayer.h:162
bool isFrozen() const
Definition: RLayer.h:120
static QList< QString > getChildLayerNamesStatic(const RDocument *doc, const QString &layerName, bool recursive=true)
Definition: RLayer.h:248
static RPropertyTypeId PropertyLinetype
Definition: RLayer.h:64
static RPropertyTypeId PropertyName
Definition: RLayer.h:55
void setCollapsed(bool on)
Definition: RLayer.h:140
static RPropertyTypeId PropertyCollapsed
Definition: RLayer.h:59
layer is frozen
Definition: RLayer.h:71
virtual bool setProperty(RPropertyTypeId propertyTypeId, const QVariant &value, RTransaction *transaction=NULL)
Sets the given property to the given value.
Definition: RObject.cpp:132
static RPropertyTypeId PropertyPlottable
Definition: RLayer.h:60
static RPropertyTypeId PropertyHandle
Definition: RLayer.h:52
Abstract base class for all objects.
Definition: RObject.h:61
bool isOffOrFrozen() const
Definition: RLayer.h:108
void setFrozen(bool on)
Definition: RLayer.h:124
bool hasChildLayers() const
Definition: RLayer.h:202
static bool isChildLayerOfStatic(const QString &layerName, const QString &parentLayerName)
Definition: RLayer.h:276
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RPropertyTypeId.h:58
Flags flags
Definition: RLayer.h:306
static QString getHierarchySeparator()
Definition: RLayer.h:234
#define QCADCORE_EXPORT
Definition: core_global.h:10
Definition: RS.h:81
void setPlottable(bool on)
Definition: RLayer.h:148
off means freeze for this layer
Definition: RLayer.h:76
RLinetype::Id linetypeId
Definition: RLayer.h:308
static bool hasProxy()
Definition: RLayer.h:283
bool isSnappable() const
Definition: RLayer.h:154
int Id
Definition: RObject.h:66
Transaction implementation.
Definition: RTransaction.h:74
static RPropertyTypeId PropertyLocked
Definition: RLayer.h:58
bool isCollapsed() const
Definition: RLayer.h:136
QList< QString > getChildLayerNames(bool recursive=true) const
Definition: RLayer.h:210
RLineweight::Lineweight lineweight
Definition: RLayer.h:309
static RPropertyTypeId PropertyOff
Definition: RLayer.h:56
QList< QString > getLayerNameHierarchy() const
Definition: RLayer.h:226
virtual QPair< QVariant, RPropertyAttributes > getProperty(RPropertyTypeId &propertyTypeId, bool humanReadable=false, bool noAttributes=false, bool showOnRequest=false)
Definition: RObject.cpp:96
Lineweight
Definition: RLineweight.h:42
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RLineweight.h:37
static RLayerProxy * getLayerProxy()
Definition: RLayer.h:300
void setLocked(bool on)
Definition: RLayer.h:132
Color.
Definition: RColor.h:42
bool isLocked() const
Definition: RLayer.h:128
QString getShortLayerName() const
Definition: RLayer.h:222
RColor color
Definition: RLayer.h:307
void setOff(bool on)
Definition: RLayer.h:116
static QList< QString > getLayerNameHierarchyStatic(const QString &layerName)
Definition: RLayer.h:269
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLayerProxy.h:34
static RPropertyTypeId PropertyCustom
Definition: RLayer.h:50
static RLayerProxy * layerProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RLayer.h:311
void setOffIsFreeze(bool on)
Definition: RLayer.h:166
bool isChildLayerOf(const QString &layerName) const
Definition: RLayer.h:230
static RPropertyTypeId PropertySnappable
Definition: RLayer.h:61
static void setLayerProxy(RLayerProxy *p)
Definition: RLayer.h:290
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
static RPropertyTypeId PropertyOffIsFreeze
Definition: RLayer.h:62
Q_DECLARE_METATYPE(RMath *)
void setSnappable(bool on)
Definition: RLayer.h:158
void setLinetypeId(RLinetype::Id lt)
Definition: RLayer.h:182
static RPropertyTypeId PropertyLineweight
Definition: RLayer.h:65
QString getParentLayerName() const
Definition: RLayer.h:218
void setColor(const RColor &c)
Definition: RLayer.h:174
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLayer &l)
Stream operator for QDebug.
Definition: RLayer.cpp:249
layer is locked
Definition: RLayer.h:72
RColor getColor() const
Definition: RLayer.h:170
printing disabled for this layer
Definition: RLayer.h:74
void setFlag(int flag, bool on=true)
Definition: RObject.h:111
LayerFlag
Definition: RLayer.h:69
static RPropertyTypeId PropertyProtected
Definition: RLayer.h:53
RDocument * getDocument()
Definition: RObject.h:99
Represents a linetype in a drawing.
Definition: RLinetype.h:50
RLinetype::Id getLinetypeId() const
Definition: RLayer.h:178
void setLineweight(RLineweight::Lineweight lw)
Definition: RLayer.h:190
static RPropertyTypeId PropertyType
Definition: RLayer.h:51
layer is off
Definition: RLayer.h:70
void init(void basePath)
Definition: AddBlockInit.js:2
Represents a layer in a drawing.
Definition: RLayer.h:48
virtual bool isSelectedForPropertyEditing()=0
bool getFlag(int flag) const
Definition: RObject.h:118
static RPropertyTypeId PropertyFrozen
Definition: RLayer.h:57
RLineweight::Lineweight getLineweight() const
Definition: RLayer.h:186
QString getName() const
Definition: RLayer.h:102
static QString getShortLayerNameStatic(const QString &layerName)
Definition: RLayer.h:262
static RPropertyTypeId PropertyColor
Definition: RLayer.h:63
bool isPlottable() const
Definition: RLayer.h:144
Class namespace for various global enums.
Definition: RS.h:58
virtual RObject * clone() const =0
snap disabled for this layer
Definition: RLayer.h:75
layer is collapsed
Definition: RLayer.h:73
static bool hasChildLayersStatic(const RDocument *doc, const QString &layerName)
Definition: RLayer.h:241