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  virtual QSharedPointer<RLayer> queryLayerDirect(const QString& layerName) const {
248  return queryLayerDirect(getLayerId(layerName));
249  }
250 
255  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
256 
257  virtual QSharedPointer<RLayer> queryCurrentLayer() {
258  return queryLayer(getCurrentLayerId());
259  }
260 
265  virtual QSharedPointer<RLayout> queryLayout(RLayout::Id layoutId) const = 0;
266 
267  virtual QSharedPointer<RLayout> queryLayoutDirect(RLayout::Id layoutId) const {
268  return queryLayout(layoutId);
269  }
270 
275  virtual QSharedPointer<RLayout> queryLayout(const QString& layoutName) const = 0;
276 
277  virtual QSharedPointer<RView> queryCurrentView() {
278  return queryView(getCurrentViewId());
279  }
280 
281  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const = 0;
282  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
283  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
284 
285  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
286  virtual QSharedPointer<RBlock> queryBlockDirect(const QString& blockName) const {
287  return queryBlockDirect(getBlockId(blockName));
288  }
289  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
290  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
291 
292  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
293  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
294 
295  void setCurrentLayer(RLayer::Id layerId, RTransaction* transaction=NULL);
296  void setCurrentLayer(const QString& layerName, RTransaction* transaction=NULL);
297 
298  virtual RLayer::Id getCurrentLayerId() const;
299  virtual RView::Id getCurrentViewId() const {
300  return currentViewId;
301  }
302 
303  virtual void setCurrentColor(const RColor& color);
304  virtual RColor getCurrentColor() const;
305 
306  void setCurrentLineweight(RLineweight::Lineweight lw);
307  virtual RLineweight::Lineweight getCurrentLineweight() const;
308 
309  void setCurrentLinetype(RLinetype::Id ltId);
310  void setCurrentLinetype(const QString& name);
311  void setCurrentLinetypePattern(const RLinetypePattern& p);
312  virtual RLinetype::Id getCurrentLinetypeId() const;
313  virtual RLinetypePattern getCurrentLinetypePattern() const;
314  virtual QSharedPointer<RLinetype> queryCurrentLinetype() const {
315  return queryLinetype(getCurrentLinetypeId());
316  }
317 
318  virtual QSharedPointer<RBlock> queryCurrentBlock() {
319  return queryBlock(getCurrentBlockId());
320  }
321 
322  virtual void setCurrentBlock(RBlock::Id blockId) {
323  currentBlockId = blockId;
324  }
325 
326  void setCurrentBlock(const QString& blockName) {
327  RBlock::Id id = getBlockId(blockName);
328  if (id == RBlock::INVALID_ID) {
329  return;
330  }
331  setCurrentBlock(id);
332  }
333 
334  virtual RBlock::Id getCurrentBlockId() const {
335  return currentBlockId;
336  }
337 
338  virtual void setModelSpaceBlockId(RBlock::Id id) {
339  modelSpaceBlockId = id;
340  }
342  return modelSpaceBlockId;
343  }
344 
345  void setCurrentView(RView::Id viewId) {
346  currentViewId = viewId;
347  }
348 
349  void setCurrentView(const QString& viewName) {
350  RView::Id id = getViewId(viewName);
351  // unlike blocks and layers, the current view can be invalid:
352  setCurrentView(id);
353  }
354 
355  QSharedPointer<RDocumentVariables> startDocumentVariablesTransaction(RTransaction*& transaction, bool& useLocalTransaction);
356  void endDocumentVariablesTransaction(RTransaction* transaction, bool useLocalTransaction, QSharedPointer<RDocumentVariables> docVars);
357 
358  void setUnit(RS::Unit unit, RTransaction* transaction=NULL);
359  RS::Unit getUnit() const;
360 
361  void setMeasurement(RS::Measurement m, RTransaction* transaction=NULL);
362  RS::Measurement getMeasurement() const;
363 
364  virtual void setDimensionFont(const QString& f, RTransaction* transaction=NULL);
365  virtual QString getDimensionFont() const;
366 
367  virtual void setLinetypeScale(double v, RTransaction* transaction=NULL);
368  virtual double getLinetypeScale() const;
369 
370  virtual QString getBlockName(RBlock::Id blockId) const = 0;
371  virtual QSet<QString> getBlockNames(const QString& rxStr = RDEFAULT_QSTRING) const = 0;
372  virtual RBlock::Id getBlockId(const QString& blockName) const = 0;
373  virtual bool hasBlock(const QString& blockName) const;
374 
375  virtual QString getViewName(RView::Id viewId) const = 0;
376  virtual QSet<QString> getViewNames() const = 0;
377  virtual RView::Id getViewId(const QString& viewName) const = 0;
378  virtual bool hasView(const QString& viewName) const;
379 
380  virtual QString getLayerName(RLayer::Id layerId) const = 0;
381  virtual QSet<QString> getLayerNames(const QString& rxStr = RDEFAULT_QSTRING) const = 0;
382  virtual RLayer::Id getLayerId(const QString& layerName) const = 0;
383  virtual bool hasLayer(const QString& layerName) const;
384 
385  virtual QString getLayoutName(RLayout::Id layoutId) const = 0;
386  virtual QSet<QString> getLayoutNames(const QString& rxStr = RDEFAULT_QSTRING) const = 0;
387  virtual RLayout::Id getLayoutId(const QString& layoutName) const = 0;
388  virtual bool hasLayout(const QString& layoutName) const;
389 
393  virtual QString getLinetypeName(RLinetype::Id linetypeId) const = 0;
397  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const = 0;
401  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const = 0;
405  virtual QSet<QString> getLinetypeNames() const = 0;
409  virtual QList<RLinetypePattern> getLinetypePatterns() const = 0;
413  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const = 0;
414  virtual bool hasLinetype(const QString& linetypeName) const;
415 
419  virtual QStringList getVariables() const = 0;
427  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite=true) = 0;
431  virtual void removeVariable(const QString& key) = 0;
436  virtual QVariant getVariable(const QString& key) const = 0;
437 
441  virtual bool hasVariable(const QString& key) const {
442  QVariant value = getVariable(key);
443  return value.isValid();
444  }
445 
453  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL) = 0;
454 
458  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
459 
463  virtual int countSelectedEntities() const {
464  return querySelectedEntities().size();
465  }
466 
470  virtual void clearEntitySelection(
471  QSet<REntity::Id>* affectedEntities=NULL
472  ) = 0;
473 
477  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
478 
488  virtual void selectEntity(
489  REntity::Id entityId,
490  bool add=false,
491  QSet<REntity::Id>* affectedEntities=NULL
492  ) = 0;
493 
503  virtual void selectEntities(
504  const QSet<REntity::Id>& entityIds,
505  bool add=false,
506  QSet<REntity::Id>* affectedEntities=NULL
507  ) = 0;
508 
516  virtual void deselectEntity(
517  REntity::Id entityId,
518  QSet<REntity::Id>* affectedEntities=NULL
519  ) = 0;
520 
528  virtual bool deselectEntities(
529  const QSet<REntity::Id>& entityIds,
530  QSet<REntity::Id>* affectedEntities=NULL
531  ) = 0;
532 
533  virtual bool isSelected(REntity::Id entityId) {
534  QSharedPointer<REntity> e = queryEntityDirect(entityId);
535  return (!e.isNull() && e->isSelected());
536  }
537 
538  virtual bool isEntity(RObject::Id objectId) {
539  QSharedPointer<REntity> e = queryEntityDirect(objectId);
540  return !e.isNull();
541  }
542 
543  virtual bool isLayerLocked(RLayer::Id layerId) const;
544  virtual bool isParentLayerLocked(RLayer::Id layerId) const;
545  virtual bool isLayerFrozen(RLayer::Id layerId) const;
546  virtual bool isParentLayerFrozen(RLayer::Id layerId) const;
547 
548  virtual bool isBlockFrozen(RBlock::Id blockId) const {
549  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
550  if (b.isNull()) {
551  return false;
552  }
553  return b->isFrozen();
554  }
555 
556  virtual void setObjectId(RObject& object, RObject::Id objectId) const;
557  virtual void setObjectHandle(RObject& object, RObject::Handle objectHandle);
558 
559  virtual void setEntityParentId(REntity& entity, REntity::Id parentId) {
560  entity.setParentId(parentId);
561  }
562 
563  virtual void setUndoStatus(RObject& object, bool status);
564 
568  virtual bool hasSelection() const = 0;
569 
573  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty = false) const = 0;
574 
575  virtual RBox getSelectionBox() const = 0;
576 
577  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
578 
582  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
583 
587  virtual bool deleteObject(RObject::Id objectId) = 0;
588 
593  virtual int getLastTransactionId() {
594  return lastTransactionId;
595  }
596 
603  virtual void setLastTransactionId(int transactionId) {
604  lastTransactionId = transactionId;
605 
606  setModified(true);
607  }
608 
609  virtual void startTransactionGroup() {
610  lastTransactionGroup++;
611  }
612 
613  virtual int getTransactionGroup() const {
614  return lastTransactionGroup;
615  }
616 
621  virtual void saveTransaction(RTransaction& transaction) = 0;
622 
629  virtual void deleteTransactionsFrom(int transactionId) = 0;
630 
631  virtual void resetTransactionStack() = 0;
632 
636  virtual RTransaction getTransaction(int transactionId) = 0;
637 
643  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
644 
648  virtual void toggleUndoStatus(RObject::Id object) = 0;
649 
650  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
651 
652  //virtual bool getUndoStatus(RObject::Id object) const = 0;
653 
658  virtual int getMaxTransactionId() = 0;
659 
660  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
661 
662  virtual RObject::Id getNewObjectId();
663  virtual RObject::Id getMaxObjectId();
664  virtual RObject::Handle getNewObjectHandle();
665  virtual RObject::Handle getMaxObjectHandle();
666 
667  virtual void setMaxDrawOrder(int m) {
668  maxDrawOrder = m;
669  }
670 
671  virtual int getMaxDrawOrder() {
672  return maxDrawOrder;
673  }
674 
675  virtual int getMinDrawOrder();
676 
681  virtual bool isInBackStorage(RObject::Id /*object*/) {
682  return false;
683  }
684 
685  static QString getKnownVariableName(RS::KnownVariable n);
686 
690  friend QDebug operator<<(QDebug dbg, RStorage& s);
691 
695  void setModified(bool m);
696 
700  bool isModified() const {
701  return modified;
702  }
703 
707  QDateTime getLastModifiedDateTime() const {
708  return lastModified;
709  }
710 
711  QString getLastModified() const {
712  return lastModified.toString("yyyyMMddHHmmsszzz");
713  }
714 
715  void addModifiedListener(RModifiedListener* l);
716 
720  virtual void update() {}
721 
722 protected:
723  QDateTime lastModified;
724  bool modified;
725 
726 private:
737 
740 
741  QList<RModifiedListener*> modifiedListeners;
742 };
743 
746 
747 #endif
Represents a box e.g.
Definition: RBox.h:43
int Handle
Definition: RObject.h:59
RColor currentColor
Definition: RStorage.h:731
virtual QSharedPointer< RView > queryCurrentView()
Definition: RStorage.h:277
virtual QSharedPointer< RLinetype > queryCurrentLinetype() const
Definition: RStorage.h:314
virtual QSharedPointer< RObject > queryObjectDirect(RObject::Id objectId) const
Definition: RStorage.h:207
virtual RBlock::Id getModelSpaceBlockId() const
Definition: RStorage.h:341
RObject::Handle handleCounter
Definition: RStorage.h:730
RDocument * document
Definition: RStorage.h:727
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:52
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RNonCopyable.h:32
virtual int getMaxDrawOrder()
Definition: RStorage.h:671
virtual QSharedPointer< RBlock > queryCurrentBlock()
Definition: RStorage.h:318
RBlock::Id currentBlockId
Definition: RStorage.h:735
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 QSharedPointer< RLayer > queryLayerDirect(const QString &layerName) const
Definition: RStorage.h:247
virtual void setLastTransactionId(int transactionId)
Sets the ID of the last created transaction.
Definition: RStorage.h:603
RView::Id currentViewId
Definition: RStorage.h:734
RLinetype::Id currentLinetypeId
Definition: RStorage.h:733
virtual QSharedPointer< RUcs > queryUcsDirect(RUcs::Id ucsId) const
Definition: RStorage.h:228
int Id
Definition: RObject.h:57
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:728
void setCurrentBlock(const QString &blockName)
Definition: RStorage.h:326
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:338
Measurement
Enum of supported measurement systems.
Definition: RS.h:222
virtual int getTransactionGroup() const
Definition: RStorage.h:613
virtual bool isEntity(RObject::Id objectId)
Definition: RStorage.h:538
virtual RBlock::Id getCurrentBlockId() const
Definition: RStorage.h:334
QDateTime getLastModifiedDateTime() const
Definition: RStorage.h:707
virtual RView::Id getCurrentViewId() const
Definition: RStorage.h:299
static const Id INVALID_ID
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RObject.h:58
Lineweight
Definition: RLineweight.h:42
Color.
Definition: RColor.h:42
int lastTransactionId
Definition: RStorage.h:738
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:681
virtual void setEntityParentId(REntity &entity, REntity::Id parentId)
Definition: RStorage.h:559
Base class for all entity classes.
Definition: REntity.h:64
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
QDateTime lastModified
Definition: RStorage.h:723
Q_DECLARE_METATYPE(RMath *)
QList< RModifiedListener * > modifiedListeners
Definition: RStorage.h:741
void setCurrentView(const QString &viewName)
Definition: RStorage.h:349
int lastTransactionGroup
Definition: RStorage.h:739
KnownVariable
Well established document variables.
Definition: RS.h:307
virtual void update()
Clear caches:
Definition: RStorage.h:720
virtual void setCurrentBlock(RBlock::Id blockId)
Definition: RStorage.h:322
bool modified
Definition: RStorage.h:724
virtual QSharedPointer< RLayer > queryCurrentLayer()
Definition: RStorage.h:257
RObject::Id idCounter
Definition: RStorage.h:729
bool isModified() const
Definition: RStorage.h:700
virtual ~RStorage()
Definition: RStorage.h:65
virtual QSharedPointer< RBlock > queryBlockDirect(const QString &blockName) const
Definition: RStorage.h:286
All entities (for filters)
Definition: RS.h:88
virtual QSharedPointer< REntity > queryEntityDirect(REntity::Id entityId) const
Definition: RStorage.h:218
virtual void startTransactionGroup()
Definition: RStorage.h:609
void setCurrentView(RView::Id viewId)
Definition: RStorage.h:345
RLineweight::Lineweight currentLineweight
Definition: RStorage.h:732
#define RDEFAULT_QSTRING
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDebug.h:48
virtual int countSelectedEntities() const
Definition: RStorage.h:463
Unit
Enum of supported units (values correspond to DXF spec).
Definition: RS.h:231
RBlock::Id modelSpaceBlockId
Definition: RStorage.h:736
virtual bool isSelected(REntity::Id entityId)
Definition: RStorage.h:533
virtual void setMaxDrawOrder(int m)
Definition: RStorage.h:667
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RRequireHeap.h:30
QString getLastModified() const
Definition: RStorage.h:711
void setParentId(REntity::Id parentId)
Definition: REntity.h:222
virtual QSharedPointer< RLayout > queryLayoutDirect(RLayout::Id layoutId) const
Definition: RStorage.h:267
virtual int getLastTransactionId()
Definition: RStorage.h:593
virtual bool isBlockFrozen(RBlock::Id blockId) const
Definition: RStorage.h:548
virtual bool hasVariable(const QString &key) const
Definition: RStorage.h:441