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:
55 
67 
68 
69 public:
70  enum LayerFlag {
71  // these complement the RObject flags
72  Off = 0x010,
73  Frozen = 0x020,
74  Locked = 0x040,
75  Collapsed = 0x080,
76  Plottable = 0x100,
77  Snappable = 0x200,
78  OffIsFreeze = 0x400
79  };
80  Q_DECLARE_FLAGS(LayerFlags, LayerFlag)
81 
82 public:
83  RLayer();
84 
85  RLayer(RDocument* document, const QString& name, bool frozen = false,
86  bool locked = false, const RColor& color = Qt::black,
89  bool off = false);
90 
91  RLayer(const RLayer& other);
92  virtual ~RLayer();
93 
94  static void init();
95 
96  virtual RS::EntityType getType() const {
97  return RS::ObjectLayer;
98  }
99 
100  virtual RLayer* clone() const;
101 
102  RLayer::Id getParentLayerId() const;
103 
104  QString getName() const {
105  return name;
106  }
107 
108  void setName(const QString& n);
109 
110  bool isOffOrFrozen() const {
111  return isOff() || isFrozen();
112  }
113 
114  bool isOff() const {
115  return getFlag(RLayer::Off);
116  }
117 
118  void setOff(bool on) {
119  setFlag(RLayer::Off, on);
120  }
121 
122  bool isFrozen() const {
123  return getFlag(RLayer::Frozen);
124  }
125 
126  void setFrozen(bool on) {
127  setFlag(RLayer::Frozen, on);
128  }
129 
130  bool isLocked() const {
131  return getFlag(RLayer::Locked);
132  }
133 
134  void setLocked(bool on) {
135  setFlag(RLayer::Locked, on);
136  }
137 
138  bool isCollapsed() const {
139  return getFlag(RLayer::Collapsed);
140  }
141 
142  void setCollapsed(bool on) {
144  }
145 
146  bool isPlottable() const {
147  return getFlag(RLayer::Plottable);
148  }
149 
150  void setPlottable(bool on) {
151  if (name.toLower()!="defpoints") {
153  }
154  }
155 
156  bool isSnappable() const {
157  return getFlag(RLayer::Snappable);
158  }
159 
160  void setSnappable(bool on) {
162  }
163 
164  bool isOffIsFreeze() const {
166  }
167 
168  void setOffIsFreeze(bool on) {
170  }
171 
172  RColor getColor() const {
173  return color;
174  }
175 
176  void setColor(const RColor& c) {
177  color = c;
178  }
179 
181  return linetypeId;
182  }
183 
185  linetypeId = lt;
186  }
187 
189  return lineweight;
190  }
191 
193  lineweight = lw;
194  }
195 
196  virtual QPair<QVariant, RPropertyAttributes> getProperty(
197  RPropertyTypeId& propertyTypeId,
198  bool humanReadable = false, bool noAttributes = false, bool showOnRequest = false);
199  virtual bool setProperty(RPropertyTypeId propertyTypeId,
200  const QVariant& value, RTransaction* transaction=NULL);
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  LayerFlags 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>*)
321 Q_DECLARE_METATYPE(QFlags<RLayer::LayerFlag>)
322 
323 #endif
RLayer::PropertyCollapsed
static RPropertyTypeId PropertyCollapsed
Definition: RLayer.h:60
RLayer::PropertyType
static RPropertyTypeId PropertyType
Definition: RLayer.h:51
RLayer::Collapsed
@ Collapsed
layer is collapsed
Definition: RLayer.h:75
RLayer::OffIsFreeze
@ OffIsFreeze
off means freeze for this layer
Definition: RLayer.h:78
RS::ObjectLayer
@ ObjectLayer
Definition: RS.h:130
RLayer::getLayerNameHierarchy
QList< QString > getLayerNameHierarchy() const
Definition: RLayer.h:226
RLayer::getChildLayerNames
QList< QString > getChildLayerNames(bool recursive=true) const
Definition: RLayer.h:210
RLayer::flags
LayerFlags flags
Definition: RLayer.h:306
RObject::INVALID_ID
static const Id INVALID_ID
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RObject.h:67
RLayer::PropertyName
static RPropertyTypeId PropertyName
Definition: RLayer.h:56
RObject::clone
virtual RObject * clone() const =0
RLayer::hasChildLayersStatic
static bool hasChildLayersStatic(const RDocument *doc, const QString &layerName)
Definition: RLayer.h:241
RLayer::PropertyLinetype
static RPropertyTypeId PropertyLinetype
Definition: RLayer.h:65
RLayer::hasProxy
static bool hasProxy()
Definition: RLayer.h:283
RLayer::getParentLayerNameStatic
static QString getParentLayerNameStatic(const QString &layerName)
Definition: RLayer.h:255
RObject::setFlag
void setFlag(int flag, bool on=true)
Definition: RObject.h:123
RLineweight.h
RLayer::Snappable
@ Snappable
snap disabled for this layer
Definition: RLayer.h:77
RLineweight::Weight000
@ Weight000
Definition: RLineweight.h:47
RLayer::Plottable
@ Plottable
printing disabled for this layer
Definition: RLayer.h:76
RLayer::getHierarchySeparator
static QString getHierarchySeparator()
Definition: RLayer.h:234
RLayer::isOffOrFrozen
bool isOffOrFrozen() const
Definition: RLayer.h:110
RLayer::PropertyLocked
static RPropertyTypeId PropertyLocked
Definition: RLayer.h:59
RLayer::getShortLayerName
QString getShortLayerName() const
Definition: RLayer.h:222
RObject
Abstract base class for all objects.
Definition: RObject.h:61
RLayer::getParentLayerName
QString getParentLayerName() const
Definition: RLayer.h:218
RLayer::setPlottable
void setPlottable(bool on)
Definition: RLayer.h:150
RLayer::setCollapsed
void setCollapsed(bool on)
Definition: RLayer.h:142
RLayer::isPlottable
bool isPlottable() const
Definition: RLayer.h:146
RLayer::isLocked
bool isLocked() const
Definition: RLayer.h:130
RS::EntityType
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:125
RLayer::hasChildLayers
bool hasChildLayers() const
Definition: RLayer.h:202
RLayer::PropertyHandle
static RPropertyTypeId PropertyHandle
Definition: RLayer.h:52
RObject::getProperty
virtual QPair< QVariant, RPropertyAttributes > getProperty(RPropertyTypeId &propertyTypeId, bool humanReadable=false, bool noAttributes=false, bool showOnRequest=false)
Definition: RObject.cpp:106
RLayer::setLayerProxy
static void setLayerProxy(RLayerProxy *p)
Definition: RLayer.h:290
RLayer::setFrozen
void setFrozen(bool on)
Definition: RLayer.h:126
RLayer::getLinetypeId
RLinetype::Id getLinetypeId() const
Definition: RLayer.h:180
RLayer::isOff
bool isOff() const
Definition: RLayer.h:114
RLayerProxy.h
RLayer::linetypeId
RLinetype::Id linetypeId
Definition: RLayer.h:308
RLayer::PropertyCustom
static RPropertyTypeId PropertyCustom
Definition: RLayer.h:50
RLayer::setLocked
void setLocked(bool on)
Definition: RLayer.h:134
RLayer::layerProxy
static RLayerProxy * layerProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RLayer.h:311
RLayer::setOffIsFreeze
void setOffIsFreeze(bool on)
Definition: RLayer.h:168
RLayer
Represents a layer in a drawing.
Definition: RLayer.h:48
RLayer::isChildLayerOf
bool isChildLayerOf(const QString &layerName) const
Definition: RLayer.h:230
RLayer::getLayerNameHierarchyStatic
static QList< QString > getLayerNameHierarchyStatic(const QString &layerName)
Definition: RLayer.h:269
operator<<
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLayer &l)
Stream operator for QDebug.
Definition: RLayer.cpp:247
RLayer::PropertySnappable
static RPropertyTypeId PropertySnappable
Definition: RLayer.h:62
RLayer::PropertySelected
static RPropertyTypeId PropertySelected
Definition: RLayer.h:54
RLayer::LayerFlag
LayerFlag
Definition: RLayer.h:70
RObject::setProperty
virtual bool setProperty(RPropertyTypeId propertyTypeId, const QVariant &value, RTransaction *transaction=NULL)
Sets the given property to the given value.
Definition: RObject.cpp:151
RLayer::PropertyLineweight
static RPropertyTypeId PropertyLineweight
Definition: RLayer.h:66
RVector.h
RLayer::color
RColor color
Definition: RLayer.h:307
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
RLinetype.h
RObject::getFlag
bool getFlag(int flag) const
Definition: RObject.h:130
RLayer::Off
@ Off
layer is off
Definition: RLayer.h:72
RLayer::getLayerProxy
static RLayerProxy * getLayerProxy()
Definition: RLayer.h:300
RObject::init
static void init()
Definition: RObject.cpp:67
RLayer::setLineweight
void setLineweight(RLineweight::Lineweight lw)
Definition: RLayer.h:192
RPropertyTypeId
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RPropertyTypeId.h:59
RPropertyAttributes.h
RObject::Id
int Id
Definition: RObject.h:66
RLayer::isOffIsFreeze
bool isOffIsFreeze() const
Definition: RLayer.h:164
RLayer::setColor
void setColor(const RColor &c)
Definition: RLayer.h:176
RLayer::setOff
void setOff(bool on)
Definition: RLayer.h:118
core_global.h
RLayer::lineweight
RLineweight::Lineweight lineweight
Definition: RLayer.h:309
RLayer::PropertyOff
static RPropertyTypeId PropertyOff
Definition: RLayer.h:57
RLayer::PropertyOffIsFreeze
static RPropertyTypeId PropertyOffIsFreeze
Definition: RLayer.h:63
RLayer::setLinetypeId
void setLinetypeId(RLinetype::Id lt)
Definition: RLayer.h:184
RGlobal.h
RDocument
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition: RDocument.h:72
RLayer::isCollapsed
bool isCollapsed() const
Definition: RLayer.h:138
RLayer::setSnappable
void setSnappable(bool on)
Definition: RLayer.h:160
RColor.h
RLineweight::Lineweight
Lineweight
Definition: RLineweight.h:46
RObject.h
RPropertyTypeId.h
RLayer::isFrozen
bool isFrozen() const
Definition: RLayer.h:122
RLayer::getName
QString getName() const
Definition: RLayer.h:104
RLayer::Locked
@ Locked
layer is locked
Definition: RLayer.h:74
RLayer::PropertyColor
static RPropertyTypeId PropertyColor
Definition: RLayer.h:64
RTransaction
Transaction implementation.
Definition: RTransaction.h:74
RLayer::getType
virtual RS::EntityType getType() const
Definition: RLayer.h:96
RObject::getDocument
RDocument * getDocument()
Definition: RObject.h:113
RLayer::isSnappable
bool isSnappable() const
Definition: RLayer.h:156
RLayer::getShortLayerNameStatic
static QString getShortLayerNameStatic(const QString &layerName)
Definition: RLayer.h:262
RLayer::getLineweight
RLineweight::Lineweight getLineweight() const
Definition: RLayer.h:188
RLayer::Frozen
@ Frozen
layer is frozen
Definition: RLayer.h:73
RLayerProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLayerProxy.h:34
RLayer::PropertyPlottable
static RPropertyTypeId PropertyPlottable
Definition: RLayer.h:61
RLayer::PropertyProtected
static RPropertyTypeId PropertyProtected
Definition: RLayer.h:53
RLayer::getColor
RColor getColor() const
Definition: RLayer.h:172
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RLayer::getChildLayerNamesStatic
static QList< QString > getChildLayerNamesStatic(const RDocument *doc, const QString &layerName, bool recursive=true)
Definition: RLayer.h:248
RLayer::PropertyFrozen
static RPropertyTypeId PropertyFrozen
Definition: RLayer.h:58
RColor
Color.
Definition: RColor.h:44
RLayer::isChildLayerOfStatic
static bool isChildLayerOfStatic(const QString &layerName, const QString &parentLayerName)
Definition: RLayer.h:276
RLayer::name
QString name
Definition: RLayer.h:305