QCAD
Open Source 2D CAD
RStorage.h
Go to the documentation of this file.
1 
20 #ifndef RSTORAGE_H
21 #define RSTORAGE_H
22 
23 #include "core_global.h"
24 
25 #include <QString>
26 #include <QSharedPointer>
27 
28 #include "RBlock.h"
29 #include "RBlockReferenceEntity.h"
30 #include "RBox.h"
31 #include "RDocumentVariables.h"
32 #include "REntity.h"
33 #include "RLayer.h"
34 #include "RLinetype.h"
35 #include "RLinetypePattern.h"
36 #include "RModifiedListener.h"
37 #include "RNonCopyable.h"
38 #include "RRequireHeap.h"
39 #include "RTransaction.h"
40 #include "RUcs.h"
41 #include "RView.h"
42 
43 class RDocument;
44 
45 #ifndef RDEFAULT_QSTRING
46 #define RDEFAULT_QSTRING QString()
47 #endif
48 
49 
50 
63 public:
64  RStorage();
65  virtual ~RStorage() { }
66 
67  void setDocument(RDocument* doc) {
68  document = doc;
69  }
70 
72  return document;
73  }
74 
78  virtual void clear();
79 
85  virtual void beginTransaction() = 0;
86 
92  virtual void commitTransaction() = 0;
93 
98  virtual void rollbackTransaction() = 0;
99 
103  virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds) const;
104 
108  virtual QSet<RObject::Id> queryAllObjects() = 0;
109 
110  virtual QSet<REntity::Id> queryAllVisibleEntities() = 0;
111 
115  virtual QSet<REntity::Id> queryAllEntities(bool undone = false,
116  bool allBlocks = false, RS::EntityType type = RS::EntityAll) = 0;
117 
118  virtual QSet<REntity::Id> queryAllEntities(bool undone,
119  bool allBlocks, QList<RS::EntityType> types) = 0;
120 
124  virtual QSet<RUcs::Id> queryAllUcs() = 0;
125 
129  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false) = 0;
130 
134  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false) = 0;
135 
139  virtual QSet<RBlock::Id> queryAllLayoutBlocks(bool undone = false) = 0;
140 
144  virtual QSet<RView::Id> queryAllViews(bool undone = false) = 0;
145 
149  virtual QSet<RLinetype::Id> queryAllLinetypes() = 0;
150 
154  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false) = 0;
155 
159  virtual bool hasBlockEntities(RBlock::Id blockId) const = 0;
160 
164  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) = 0;
165 
166  virtual QSet<REntity::Id> queryLayerBlockEntities(RLayer::Id layerId, RBlock::Id blockId) = 0;
167 
173  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll) = 0;
174 
175  virtual bool hasChildEntities(REntity::Id parentId) = 0;
176 
181  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) = 0;
182 
186  virtual QSet<REntity::Id> queryAllBlockReferences() = 0;
187 
191  virtual QSet<REntity::Id> querySelectedEntities() const = 0;
192 
196  virtual QSet<REntity::Id> queryInfiniteEntities() = 0;
197 
198  virtual QSharedPointer<RDocumentVariables> queryDocumentVariables() const = 0;
199  virtual QSharedPointer<RDocumentVariables> queryDocumentVariablesDirect() const = 0;
200 
205  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const = 0;
206 
207  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const {
208  return queryObject(objectId);
209  }
210  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const = 0;
211 
216  virtual QSharedPointer<REntity> queryEntity(REntity::Id entityId) const = 0;
217 
218  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const {
219  return queryEntity(entityId);
220  }
221 
226  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const = 0;
227 
228  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const {
229  return queryUcs(ucsId);
230  }
231 
236  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const = 0;
237 
242  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const = 0;
243 
244  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const {
245  return queryLayer(layerId);
246  }
247 
252  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
253 
254  virtual QSharedPointer<RLayer> queryCurrentLayer() {
255  return queryLayer(getCurrentLayerId());
256  }
257 
262  virtual QSharedPointer<RLayout> queryLayout(RLayout::Id layoutId) const = 0;
263 
264  virtual QSharedPointer<RLayout> queryLayoutDirect(RLayout::Id layoutId) const {
265  return queryLayout(layoutId);
266  }
267 
272  virtual QSharedPointer<RLayout> queryLayout(const QString& layoutName) const = 0;
273 
274  virtual QSharedPointer<RView> queryCurrentView() {
275  return queryView(getCurrentViewId());
276  }
277 
278  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const = 0;
279  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
280  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
281 
282  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
283  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
284  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
285 
286  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
287  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
288 
289  void setCurrentLayer(RLayer::Id layerId, RTransaction* transaction=NULL);
290  void setCurrentLayer(const QString& layerName, RTransaction* transaction=NULL);
291 
292  virtual RLayer::Id getCurrentLayerId() const;
293  virtual RView::Id getCurrentViewId() const {
294  return currentViewId;
295  }
296 
297  virtual void setCurrentColor(const RColor& color);
298  virtual RColor getCurrentColor() const;
299 
300  void setCurrentLineweight(RLineweight::Lineweight lw);
301  virtual RLineweight::Lineweight getCurrentLineweight() const;
302 
303  void setCurrentLinetype(RLinetype::Id ltId);
304  void setCurrentLinetype(const QString& name);
305  void setCurrentLinetypePattern(const RLinetypePattern& p);
306  virtual RLinetype::Id getCurrentLinetypeId() const;
307  virtual RLinetypePattern getCurrentLinetypePattern() const;
308  virtual QSharedPointer<RLinetype> queryCurrentLinetype() const {
309  return queryLinetype(getCurrentLinetypeId());
310  }
311 
312  virtual QSharedPointer<RBlock> queryCurrentBlock() {
313  return queryBlock(getCurrentBlockId());
314  }
315 
316  virtual void setCurrentBlock(RBlock::Id blockId) {
317  currentBlockId = blockId;
318  }
319 
320  void setCurrentBlock(const QString& blockName) {
321  RBlock::Id id = getBlockId(blockName);
322  if (id == RBlock::INVALID_ID) {
323  return;
324  }
325  setCurrentBlock(id);
326  }
327 
328  virtual RBlock::Id getCurrentBlockId() const {
329  return currentBlockId;
330  }
331 
332  virtual void setModelSpaceBlockId(RBlock::Id id) {
333  modelSpaceBlockId = id;
334  }
336  return modelSpaceBlockId;
337  }
338 
339  void setCurrentView(RView::Id viewId) {
340  currentViewId = viewId;
341  }
342 
343  void setCurrentView(const QString& viewName) {
344  RView::Id id = getViewId(viewName);
345  // unlike blocks and layers, the current view can be invalid:
346  setCurrentView(id);
347  }
348 
349  QSharedPointer<RDocumentVariables> startDocumentVariablesTransaction(RTransaction*& transaction, bool& useLocalTransaction);
350  void endDocumentVariablesTransaction(RTransaction* transaction, bool useLocalTransaction, QSharedPointer<RDocumentVariables> docVars);
351 
352  void setUnit(RS::Unit unit, RTransaction* transaction=NULL);
353  RS::Unit getUnit() const;
354 
355  void setMeasurement(RS::Measurement m, RTransaction* transaction=NULL);
356  RS::Measurement getMeasurement() const;
357 
358  virtual void setDimensionFont(const QString& f, RTransaction* transaction=NULL);
359  virtual QString getDimensionFont() const;
360 
361  virtual void setLinetypeScale(double v, RTransaction* transaction=NULL);
362  virtual double getLinetypeScale() const;
363 
364  virtual QString getBlockName(RBlock::Id blockId) const = 0;
365  virtual QSet<QString> getBlockNames(const QString& rxStr = RDEFAULT_QSTRING) const = 0;
366  virtual RBlock::Id getBlockId(const QString& blockName) const = 0;
367  virtual bool hasBlock(const QString& blockName) const;
368 
369  virtual QString getViewName(RView::Id viewId) const = 0;
370  virtual QSet<QString> getViewNames() const = 0;
371  virtual RView::Id getViewId(const QString& viewName) const = 0;
372  virtual bool hasView(const QString& viewName) const;
373 
374  virtual QString getLayerName(RLayer::Id layerId) const = 0;
375  virtual QSet<QString> getLayerNames(const QString& rxStr = RDEFAULT_QSTRING) const = 0;
376  virtual RLayer::Id getLayerId(const QString& layerName) const = 0;
377  virtual bool hasLayer(const QString& layerName) const;
378 
379  virtual QString getLayoutName(RLayout::Id layoutId) const = 0;
380  virtual QSet<QString> getLayoutNames(const QString& rxStr = RDEFAULT_QSTRING) const = 0;
381  virtual RLayout::Id getLayoutId(const QString& layoutName) const = 0;
382  virtual bool hasLayout(const QString& layoutName) const;
383 
384  virtual QString getLinetypeName(RLinetype::Id linetypeId) const = 0;
385  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const = 0;
386  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const = 0;
387  virtual QSet<QString> getLinetypeNames() const = 0;
388  virtual QList<RLinetypePattern> getLinetypePatterns() const = 0;
389  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const = 0;
390  virtual bool hasLinetype(const QString& linetypeName) const;
391 
395  virtual QStringList getVariables() const = 0;
403  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite=true) = 0;
407  virtual void removeVariable(const QString& key) = 0;
412  virtual QVariant getVariable(const QString& key) const = 0;
413 
417  virtual bool hasVariable(const QString& key) const {
418  QVariant value = getVariable(key);
419  return value.isValid();
420  }
421 
429  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL) = 0;
430 
434  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
435 
439  virtual int countSelectedEntities() const {
440  return querySelectedEntities().size();
441  }
442 
446  virtual void clearEntitySelection(
447  QSet<REntity::Id>* affectedEntities=NULL
448  ) = 0;
449 
453  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
454 
464  virtual void selectEntity(
465  REntity::Id entityId,
466  bool add=false,
467  QSet<REntity::Id>* affectedEntities=NULL
468  ) = 0;
469 
479  virtual void selectEntities(
480  const QSet<REntity::Id>& entityIds,
481  bool add=false,
482  QSet<REntity::Id>* affectedEntities=NULL
483  ) = 0;
484 
492  virtual void deselectEntity(
493  REntity::Id entityId,
494  QSet<REntity::Id>* affectedEntities=NULL
495  ) = 0;
496 
504  virtual bool deselectEntities(
505  const QSet<REntity::Id>& entityIds,
506  QSet<REntity::Id>* affectedEntities=NULL
507  ) = 0;
508 
509  virtual bool isSelected(REntity::Id entityId) {
510  QSharedPointer<REntity> e = queryEntityDirect(entityId);
511  return (!e.isNull() && e->isSelected());
512  }
513 
514  virtual bool isEntity(RObject::Id objectId) {
515  QSharedPointer<REntity> e = queryEntityDirect(objectId);
516  return !e.isNull();
517  }
518 
519  virtual bool isLayerLocked(RLayer::Id layerId) const {
520  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
521  if (l.isNull()) {
522  return false;
523  }
524  return l->isLocked();
525  }
526 
527  virtual bool isLayerFrozen(RLayer::Id layerId) const {
528  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
529  if (l.isNull()) {
530  return false;
531  }
532  return l->isFrozen();
533  }
534 
535  virtual bool isBlockFrozen(RBlock::Id blockId) const {
536  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
537  if (b.isNull()) {
538  return false;
539  }
540  return b->isFrozen();
541  }
542 
543  virtual void setObjectId(RObject& object, RObject::Id objectId) const;
544  virtual void setObjectHandle(RObject& object, RObject::Handle objectHandle);
545 
546  virtual void setUndoStatus(RObject& object, bool status);
547 
551  virtual bool hasSelection() const = 0;
552 
556  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty = false) const = 0;
557 
558  virtual RBox getSelectionBox() const = 0;
559 
560  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
561 
565  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
566 
570  virtual bool deleteObject(RObject::Id objectId) = 0;
571 
576  virtual int getLastTransactionId() {
577  return lastTransactionId;
578  }
579 
586  virtual void setLastTransactionId(int transactionId) {
587  lastTransactionId = transactionId;
588 
589  setModified(true);
590  }
591 
592  virtual void startTransactionGroup() {
593  lastTransactionGroup++;
594  }
595 
596  virtual int getTransactionGroup() const {
597  return lastTransactionGroup;
598  }
599 
604  virtual void saveTransaction(RTransaction& transaction) = 0;
605 
612  virtual void deleteTransactionsFrom(int transactionId) = 0;
613 
614  virtual void resetTransactionStack() = 0;
615 
619  virtual RTransaction getTransaction(int transactionId) = 0;
620 
626  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
627 
631  virtual void toggleUndoStatus(RObject::Id object) = 0;
632 
633  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
634 
635  //virtual bool getUndoStatus(RObject::Id object) const = 0;
636 
641  virtual int getMaxTransactionId() = 0;
642 
643  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
644 
645  virtual RObject::Id getNewObjectId();
646  virtual RObject::Id getMaxObjectId();
647  virtual RObject::Handle getNewObjectHandle();
648  virtual RObject::Handle getMaxObjectHandle();
649 
650  virtual void setMaxDrawOrder(int m) {
651  maxDrawOrder = m;
652  }
653 
654  virtual int getMaxDrawOrder() {
655  return maxDrawOrder;
656  }
657 
658  virtual int getMinDrawOrder();
659 
664  virtual bool isInBackStorage(RObject::Id /*object*/) {
665  return false;
666  }
667 
668  static QString getKnownVariableName(RS::KnownVariable n);
669 
673  friend QDebug operator<<(QDebug dbg, RStorage& s);
674 
675  void setModified(bool m);
676 
677  bool isModified() const {
678  return modified;
679  }
680 
681  void addModifiedListener(RModifiedListener* l);
682 
686  virtual void update() {}
687 
688 protected:
689  bool modified;
690 
691 private:
702 
705 
706  QList<RModifiedListener*> modifiedListeners;
707 };
708 
711 
712 #endif
Represents a box e.g.
Definition: RBox.h:43
int Handle
Definition: RObject.h:55
RColor currentColor
Definition: RStorage.h:696
virtual QSharedPointer< RView > queryCurrentView()
Definition: RStorage.h:274
virtual QSharedPointer< RLinetype > queryCurrentLinetype() const
Definition: RStorage.h:308
virtual QSharedPointer< RObject > queryObjectDirect(RObject::Id objectId) const
Definition: RStorage.h:207
virtual RBlock::Id getModelSpaceBlockId() const
Definition: RStorage.h:335
RObject::Handle handleCounter
Definition: RStorage.h:695
RDocument * document
Definition: RStorage.h:692
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:76
RDocument * getDocument() const
Definition: RStorage.h:71
Abstract base class for all objects.
Definition: RObject.h:48
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RNonCopyable.h:32
virtual int getMaxDrawOrder()
Definition: RStorage.h:654
virtual QSharedPointer< RBlock > queryCurrentBlock()
Definition: RStorage.h:312
RBlock::Id currentBlockId
Definition: RStorage.h:700
Abstract base class for classes that are interested in the current state of a storage (modified or un...
Definition: RModifiedListener.h:34
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual void setLastTransactionId(int transactionId)
Sets the ID of the last created transaction.
Definition: RStorage.h:586
RView::Id currentViewId
Definition: RStorage.h:699
RLinetype::Id currentLinetypeId
Definition: RStorage.h:698
virtual QSharedPointer< RUcs > queryUcsDirect(RUcs::Id ucsId) const
Definition: RStorage.h:228
int Id
Definition: RObject.h:53
This is the abstract base class for all storage implementations.
Definition: RStorage.h:62
virtual QSharedPointer< RLayer > queryLayerDirect(RLayer::Id layerId) const
Definition: RStorage.h:244
int maxDrawOrder
Definition: RStorage.h:693
void setCurrentBlock(const QString &blockName)
Definition: RStorage.h:320
Transaction implementation.
Definition: RTransaction.h:74
void setDocument(RDocument *doc)
Definition: RStorage.h:67
QDebug operator<<(QDebug dbg, const RBox &b)
Stream operator for QDebug.
Definition: RBox.cpp:447
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLinetypePattern.h:45
virtual void setModelSpaceBlockId(RBlock::Id id)
Definition: RStorage.h:332
Measurement
Enum of supported measurement systems.
Definition: RS.h:220
virtual int getTransactionGroup() const
Definition: RStorage.h:596
virtual bool isEntity(RObject::Id objectId)
Definition: RStorage.h:514
virtual RBlock::Id getCurrentBlockId() const
Definition: RStorage.h:328
virtual RView::Id getCurrentViewId() const
Definition: RStorage.h:293
static const Id INVALID_ID
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RObject.h:54
Lineweight
Definition: RLineweight.h:42
Color.
Definition: RColor.h:42
virtual bool isLayerLocked(RLayer::Id layerId) const
Definition: RStorage.h:519
int lastTransactionId
Definition: RStorage.h:703
virtual bool isInBackStorage(RObject::Id)
Linked storages should return true if the given object is stored in the storage the linked storage li...
Definition: RStorage.h:664
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
virtual bool isLayerFrozen(RLayer::Id layerId) const
Definition: RStorage.h:527
Q_DECLARE_METATYPE(RMath *)
QList< RModifiedListener * > modifiedListeners
Definition: RStorage.h:706
void setCurrentView(const QString &viewName)
Definition: RStorage.h:343
int lastTransactionGroup
Definition: RStorage.h:704
KnownVariable
Well established document variables.
Definition: RS.h:305
virtual void update()
Clear caches:
Definition: RStorage.h:686
virtual void setCurrentBlock(RBlock::Id blockId)
Definition: RStorage.h:316
bool modified
Definition: RStorage.h:689
virtual QSharedPointer< RLayer > queryCurrentLayer()
Definition: RStorage.h:254
RObject::Id idCounter
Definition: RStorage.h:694
bool isModified() const
Definition: RStorage.h:677
virtual ~RStorage()
Definition: RStorage.h:65
All entities (for filters)
Definition: RS.h:86
virtual QSharedPointer< REntity > queryEntityDirect(REntity::Id entityId) const
Definition: RStorage.h:218
virtual void startTransactionGroup()
Definition: RStorage.h:592
void setCurrentView(RView::Id viewId)
Definition: RStorage.h:339
RLineweight::Lineweight currentLineweight
Definition: RStorage.h:697
#define RDEFAULT_QSTRING
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDebug.h:48
virtual int countSelectedEntities() const
Definition: RStorage.h:439
Unit
Enum of supported units (values correspond to DXF spec).
Definition: RS.h:229
RBlock::Id modelSpaceBlockId
Definition: RStorage.h:701
virtual bool isSelected(REntity::Id entityId)
Definition: RStorage.h:509
virtual void setMaxDrawOrder(int m)
Definition: RStorage.h:650
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RRequireHeap.h:30
virtual QSharedPointer< RLayout > queryLayoutDirect(RLayout::Id layoutId) const
Definition: RStorage.h:264
virtual int getLastTransactionId()
Definition: RStorage.h:576
virtual bool isBlockFrozen(RBlock::Id blockId) const
Definition: RStorage.h:535
virtual bool hasVariable(const QString &key) const
Definition: RStorage.h:417