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 
62 
63 public:
64  RLayer();
65 
66  RLayer(RDocument* document, const QString& name, bool frozen = false,
67  bool locked = false, const RColor& color = Qt::black,
70  bool off = false);
71 
72  RLayer(const RLayer& other);
73  virtual ~RLayer();
74 
75  static void init();
76 
77  virtual RS::EntityType getType() const {
78  return RS::ObjectLayer;
79  }
80 
81  virtual RLayer* clone() const;
82 
83  RLayer::Id getParentLayerId() const;
84 
85  QString getName() const {
86  return name;
87  }
88 
89  void setName(const QString& n);
90 
91  bool isOffOrFrozen() const {
92  return isOff() || isFrozen();
93  }
94 
95  bool isOff() const {
96  return off;
97  }
98 
99  void setOff(bool on) {
100  off = on;
101  }
102 
103  bool isFrozen() const {
104  return frozen;
105  }
106 
107  void setFrozen(bool on) {
108  frozen = on;
109  }
110 
111  bool isLocked() const {
112  return locked;
113  }
114 
115  void setLocked(bool on) {
116  locked = on;
117  }
118 
119  RColor getColor() const {
120  return color;
121  }
122 
123  void setColor(const RColor& c) {
124  color = c;
125  }
126 
128  return linetypeId;
129  }
130 
132  linetypeId = lt;
133  }
134 
136  return lineweight;
137  }
138 
140  lineweight = lw;
141  }
142 
143  virtual QPair<QVariant, RPropertyAttributes> getProperty(
144  RPropertyTypeId& propertyTypeId,
145  bool humanReadable = false, bool noAttributes = false);
146  virtual bool setProperty(RPropertyTypeId propertyTypeId,
147  const QVariant& value, RTransaction* transaction=NULL);
148 
149  virtual bool isSelectedForPropertyEditing();
150 
151  bool hasChildLayers() const {
152  const RDocument* doc = getDocument();
153  if (doc==NULL) {
154  return false;
155  }
156  return RLayer::hasChildLayersStatic(doc, name);
157  }
158 
159  QList<QString> getChildLayerNames(bool recursive = true) const {
160  const RDocument* doc = getDocument();
161  if (doc==NULL) {
162  return QList<QString>();
163  }
164  return RLayer::getChildLayerNamesStatic(doc, name, recursive);
165  }
166 
167  QString getParentLayerName() const {
169  }
170 
171  QString getShortLayerName() const {
172  return RLayer::getShortLayerNameStatic(name);
173  }
174 
175  QList<QString> getLayerNameHierarchy() const {
177  }
178 
179  bool isChildLayerOf(const QString& layerName) const {
180  return RLayer::isChildLayerOfStatic(name, layerName);
181  }
182 
183  static QString getHierarchySeparator() {
184  if (layerProxy!=NULL) {
185  return layerProxy->getHierarchySeparator();
186  }
187  return "";
188  }
189 
190  static bool hasChildLayersStatic(const RDocument* doc, const QString& layerName) {
191  if (layerProxy!=NULL) {
192  return layerProxy->hasChildLayers(doc, layerName);
193  }
194  return false;
195  }
196 
197  static QList<QString> getChildLayerNamesStatic(const RDocument* doc, const QString& layerName, bool recursive = true) {
198  if (layerProxy!=NULL) {
199  return layerProxy->getChildLayerNames(doc, layerName, recursive);
200  }
201  return QList<QString>();
202  }
203 
204  static QString getParentLayerNameStatic(const QString& layerName) {
205  if (layerProxy!=NULL) {
206  return layerProxy->getParentLayerName(layerName);
207  }
208  return QString();
209  }
210 
211  static QString getShortLayerNameStatic(const QString& layerName) {
212  if (layerProxy!=NULL) {
213  return layerProxy->getShortLayerName(layerName);
214  }
215  return QString();
216  }
217 
218  static QList<QString> getLayerNameHierarchyStatic(const QString& layerName) {
219  if (layerProxy!=NULL) {
220  return layerProxy->getLayerNameHierarchy(layerName);
221  }
222  return QList<QString>();
223  }
224 
225  static bool isChildLayerOfStatic(const QString& layerName, const QString& parentLayerName) {
226  if (layerProxy!=NULL) {
227  return layerProxy->isChildLayerOf(layerName, parentLayerName);
228  }
229  return false;
230  }
231 
232  static bool hasProxy() {
233  return layerProxy!=NULL;
234  }
235 
239  static void setLayerProxy(RLayerProxy* p) {
240  if (layerProxy!=NULL) {
241  delete layerProxy;
242  }
243  layerProxy = p;
244  }
245 
250  return layerProxy;
251  }
252 
253 private:
254  QString name;
255  bool off;
256  bool frozen;
257  bool locked;
261 
263 };
264 
265 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLayer& l);
266 
267 Q_DECLARE_METATYPE(QSharedPointer<RLayer>)
268 Q_DECLARE_METATYPE(QSharedPointer<RLayer>*)
271 
272 #endif
QString name
Definition: RLayer.h:254
bool isOff() const
Definition: RLayer.h:95
static QString getParentLayerNameStatic(const QString &layerName)
Definition: RLayer.h:204
bool isFrozen() const
Definition: RLayer.h:103
static QList< QString > getChildLayerNamesStatic(const RDocument *doc, const QString &layerName, bool recursive=true)
Definition: RLayer.h:197
static RPropertyTypeId PropertyLinetype
Definition: RLayer.h:60
static RPropertyTypeId PropertyName
Definition: RLayer.h:55
bool off
Definition: RLayer.h:255
virtual bool setProperty(RPropertyTypeId propertyTypeId, const QVariant &value, RTransaction *transaction=NULL)
Sets the given property to the given value.
Definition: RObject.cpp:129
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:76
static RPropertyTypeId PropertyHandle
Definition: RLayer.h:52
Abstract base class for all objects.
Definition: RObject.h:52
bool isOffOrFrozen() const
Definition: RLayer.h:91
void setFrozen(bool on)
Definition: RLayer.h:107
bool hasChildLayers() const
Definition: RLayer.h:151
static bool isChildLayerOfStatic(const QString &layerName, const QString &parentLayerName)
Definition: RLayer.h:225
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPropertyTypeId.h:58
static QString getHierarchySeparator()
Definition: RLayer.h:183
#define QCADCORE_EXPORT
Definition: core_global.h:10
Definition: RS.h:81
RLinetype::Id linetypeId
Definition: RLayer.h:259
virtual QPair< QVariant, RPropertyAttributes > getProperty(RPropertyTypeId &propertyTypeId, bool humanReadable=false, bool noAttributes=false)
Definition: RObject.cpp:94
static bool hasProxy()
Definition: RLayer.h:232
int Id
Definition: RObject.h:57
Transaction implementation.
Definition: RTransaction.h:74
static RPropertyTypeId PropertyLocked
Definition: RLayer.h:58
QList< QString > getChildLayerNames(bool recursive=true) const
Definition: RLayer.h:159
RLineweight::Lineweight lineweight
Definition: RLayer.h:260
static RPropertyTypeId PropertyOff
Definition: RLayer.h:56
static const Id INVALID_ID
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RObject.h:58
QList< QString > getLayerNameHierarchy() const
Definition: RLayer.h:175
bool locked
Definition: RLayer.h:257
Lineweight
Definition: RLineweight.h:42
static RLayerProxy * getLayerProxy()
Definition: RLayer.h:249
void setLocked(bool on)
Definition: RLayer.h:115
Color.
Definition: RColor.h:42
bool isLocked() const
Definition: RLayer.h:111
QString getShortLayerName() const
Definition: RLayer.h:171
RColor color
Definition: RLayer.h:258
void setOff(bool on)
Definition: RLayer.h:99
static QList< QString > getLayerNameHierarchyStatic(const QString &layerName)
Definition: RLayer.h:218
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLayerProxy.h:34
static RPropertyTypeId PropertyCustom
Definition: RLayer.h:50
static RLayerProxy * layerProxy
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RLayer.h:262
bool isChildLayerOf(const QString &layerName) const
Definition: RLayer.h:179
static void setLayerProxy(RLayerProxy *p)
Definition: RLayer.h:239
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Q_DECLARE_METATYPE(RMath *)
virtual RS::EntityType getType() const
Definition: RLayer.h:77
void setLinetypeId(RLinetype::Id lt)
Definition: RLayer.h:131
static RPropertyTypeId PropertyLineweight
Definition: RLayer.h:61
QString getParentLayerName() const
Definition: RLayer.h:167
void setColor(const RColor &c)
Definition: RLayer.h:123
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RLayer &l)
Stream operator for QDebug.
Definition: RLayer.cpp:221
RColor getColor() const
Definition: RLayer.h:119
bool frozen
Definition: RLayer.h:256
static RPropertyTypeId PropertyProtected
Definition: RLayer.h:53
RDocument * getDocument()
Definition: RObject.h:82
RLinetype::Id getLinetypeId() const
Definition: RLayer.h:127
void setLineweight(RLineweight::Lineweight lw)
Definition: RLayer.h:139
static RPropertyTypeId PropertyType
Definition: RLayer.h:51
static void init()
Definition: RObject.cpp:61
Definition: RLineweight.h:43
Represents a layer in a drawing.
Definition: RLayer.h:48
virtual bool isSelectedForPropertyEditing()=0
static RPropertyTypeId PropertyFrozen
Definition: RLayer.h:57
RLineweight::Lineweight getLineweight() const
Definition: RLayer.h:135
QString getName() const
Definition: RLayer.h:85
static QString getShortLayerNameStatic(const QString &layerName)
Definition: RLayer.h:211
static RPropertyTypeId PropertyColor
Definition: RLayer.h:59
virtual RObject * clone() const =0
static bool hasChildLayersStatic(const RDocument *doc, const QString &layerName)
Definition: RLayer.h:190