QCAD
Open Source 2D CAD
RMemoryStorage.h
Go to the documentation of this file.
1 
20 #ifndef RMEMORYSTORAGE_H_
21 #define RMEMORYSTORAGE_H_
22 
23 #include "core_global.h"
24 
25 #include <QSharedPointer>
26 
27 #include "RStorage.h"
28 #include "RBlockReferenceEntity.h"
29 #include "RDocumentVariables.h"
30 
38 public:
40  virtual ~RMemoryStorage();
41 
42  virtual void clear();
43 
44  virtual void setCurrentBlock(RBlock::Id blockId);
45 
46  virtual void beginTransaction();
47  virtual void commitTransaction();
48  virtual void rollbackTransaction();
49 
50  //virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds);
51 
52  virtual QSet<RObject::Id> queryAllObjects();
53  virtual QSet<REntity::Id> queryAllVisibleEntities();
54  virtual QSet<REntity::Id> queryAllEntities(bool undone = false, bool allBlocks = false, RS::EntityType type = RS::EntityAll);
55  virtual QSet<REntity::Id> queryAllEntities(bool undone, bool allBlocks, QList<RS::EntityType> types);
56  virtual QSet<RUcs::Id> queryAllUcs();
57  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false);
58  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false);
59  virtual QSet<RBlock::Id> queryAllLayoutBlocks(bool undone = false);
60  virtual QSet<RView::Id> queryAllViews(bool undone = false);
61  virtual QSet<RLinetype::Id> queryAllLinetypes();
62  virtual QSet<REntity::Id> queryInfiniteEntities();
63  virtual QSet<REntity::Id> querySelectedEntities() const;
64 
65  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false);
66  virtual bool hasBlockEntities(RBlock::Id blockId) const;
67  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId);
68  virtual QSet<REntity::Id> queryLayerBlockEntities(RLayer::Id layerId, RBlock::Id blockId);
69  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll);
70  virtual bool hasChildEntities(REntity::Id parentId);
71  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId);
72  virtual QSet<REntity::Id> queryAllBlockReferences();
73  //virtual QSet<REntity::Id> queryViewEntities(RView::Id viewId);
74 
75  virtual QSharedPointer<RDocumentVariables> queryDocumentVariables() const;
76  virtual QSharedPointer<RDocumentVariables> queryDocumentVariablesDirect() const;
77  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
78  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const;
79  virtual QSharedPointer<RObject> queryObjectByHandleDirect(RObject::Handle objectHandle) const;
80  virtual QSharedPointer<REntity> queryEntity(REntity::Id objectId) const;
81  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
82  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
83  virtual QSharedPointer<RLayout> queryLayout(RLayout::Id layoutId) const;
84  virtual QSharedPointer<RLayout> queryLayout(const QString& layoutName) const;
85  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
86  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
87  virtual QSharedPointer<RView> queryView(RView::Id viewId) const;
88  virtual QSharedPointer<RView> queryView(const QString& viewName) const;
89  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
90  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
91  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const;
92  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
93  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
94 
95  void clearSelectionCache();
96  void updateSelectedEntityMap() const;
97 
98  virtual int countSelectedEntities() const;
99  virtual void clearEntitySelection(QSet<REntity::Id>* affectedEntities = NULL);
100  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
101  virtual void selectEntity(REntity::Id entityId, bool add = false,
102  QSet<REntity::Id>* affectedEntities = NULL);
103  virtual void deselectEntity(REntity::Id entityId,
104  QSet<REntity::Id>* affectedEntities=NULL);
105  virtual void selectEntities(const QSet<REntity::Id>& entityIds,
106  bool add = false,
107  QSet<REntity::Id>* affectedEntities = NULL);
108  virtual bool deselectEntities(const QSet<REntity::Id>& entityIds,
109  QSet<REntity::Id>* affectedEntities = NULL);
110  void setEntitySelected(QSharedPointer<REntity> entity, bool on,
111  QSet<REntity::Id>* affectedEntities = NULL, bool onlyDescend = false);
112  virtual bool isSelected(REntity::Id entityId);
113 
114  virtual bool hasSelection() const;
115 
116  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty=false) const;
117  virtual RBox getSelectionBox() const;
118 
119  virtual bool removeObject(QSharedPointer<RObject> object);
120  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false);
121  bool checkRecursion(
122  RBlock::Id blockId, RBlock::Id potentialChildBlockId
123  );
124  virtual bool deleteObject(RObject::Id objectId);
125  virtual void saveTransaction(RTransaction& transaction);
126  virtual void deleteTransactionsFrom(int transactionId);
127  virtual RTransaction getTransaction(int transactionId);
128 
129  virtual void resetTransactionStack();
130 
131  virtual void toggleUndoStatus(QSet<RObject::Id>& objects);
132  virtual void toggleUndoStatus(RObject::Id object);
133  virtual bool setUndoStatus(RObject::Id objectId, bool status);
134  virtual void setUndoStatus(RObject& object, bool status);
135  //virtual bool getUndoStatus(RObject::Id objectId) const;
136  virtual int getMaxTransactionId();
137 
138  virtual QStringList getVariables() const;
139  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite = true);
140  virtual QVariant getVariable(const QString& key) const;
141  virtual void removeVariable(const QString& key);
142 
143  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL);
144  virtual QVariant getKnownVariable(RS::KnownVariable key) const;
145 
146  virtual QString getLayerName(RLayer::Id layerId) const;
147  virtual QSet<QString> getLayerNames(const QString& rxStr = RDEFAULT_QSTRING) const;
148  virtual RLayer::Id getLayerId(const QString& layerName) const;
149 
150  virtual QString getLayoutName(RLayout::Id layoutId) const;
151  virtual QSet<QString> getLayoutNames(const QString& rxStr = RDEFAULT_QSTRING) const;
152  virtual RLayout::Id getLayoutId(const QString& layoutName) const;
153 
154  virtual QString getBlockName(RBlock::Id blockId) const;
155  virtual QSet<QString> getBlockNames(const QString& rxStr = RDEFAULT_QSTRING) const;
156  virtual RBlock::Id getBlockId(const QString& blockName) const;
157 
158  virtual QString getViewName(RView::Id viewId) const;
159  virtual QSet<QString> getViewNames() const;
160  virtual RView::Id getViewId(const QString& viewName) const;
161 
162  virtual QString getLinetypeName(RLinetype::Id linetypeId) const;
163  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const;
164  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const;
165  virtual QSet<QString> getLinetypeNames() const;
166  virtual QList<RLinetypePattern> getLinetypePatterns() const;
167  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const;
168 
169  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
170  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id objectId) const;
171  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const;
172  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
173  virtual QSharedPointer<RLayout> queryLayoutDirect(RLayout::Id layoutId) const;
174  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
175 
176  virtual void setLastTransactionId(int transactionId);
177 
179 
180  virtual void update();
181 
182  //virtual void setUnit(RS::Unit unit, RTransaction* transaction = NULL);
183  //virtual RS::Unit getUnit() const;
184 
185 // virtual void setDimensionFont(const QString& f);
186 // virtual QString getDimensionFont() const;
187 
188 // virtual void setLinetypeScale(double v, RTransaction* transaction);
189 // virtual double getLinetypeScale() const;
190 
191 protected:
193 
194  mutable RBox boundingBox[2][2];
195  mutable bool boundingBoxDirty;
196  //mutable bool boundingBoxIgnoreHiddenLayers;
197  //mutable bool boundingBoxIgnoreEmpty;
198 
200  QHash<RObject::Id, QSharedPointer<RObject> > objectMap;
201  QHash<RObject::Handle, QSharedPointer<RObject> > objectHandleMap;
202  QHash<REntity::Id, QSharedPointer<REntity> > entityMap;
203  mutable QHash<REntity::Id, QSharedPointer<REntity> > selectedEntityMap;
205  QMultiHash<RBlock::Id, QSharedPointer<REntity> > blockEntityMap;
206  QHash<RBlock::Id, QSharedPointer<RBlock> > blockMap;
207  QHash<RLayer::Id, QSharedPointer<RLayer> > layerMap;
208  QHash<RLayout::Id, QSharedPointer<RLayout> > layoutMap;
209  QHash<RLinetype::Id, QSharedPointer<RLinetype> > linetypeMap;
210  QHash<int, RTransaction> transactionMap;
211 
212  // document wide variables are stored as custom properties in this object:
213  QSharedPointer<RDocumentVariables> documentVariables;
214 
215  QHash<QString, QVariant> variables;
216  QMap<QString, QString> variableCaseMap;
217  //QHash<RS::KnownVariable, QVariant> knownVariables;
218  //RS::Unit unit;
219  //QString dimensionFont;
220  //double linetypeScale;
221 };
222 
224 
225 #endif /* RMEMORYSTOARGE_H_ */
virtual RLineweight::Lineweight getMaxLineweight() const =0
Represents a box e.g.
Definition: RBox.h:43
virtual void setVariable(const QString &key, const QVariant &value, bool overwrite=true)=0
virtual RBox getSelectionBox() const =0
virtual void saveTransaction(RTransaction &transaction)=0
Saves the given transaction.
int Handle
Definition: RObject.h:55
virtual QSet< REntity::Id > queryInfiniteEntities()=0
virtual QSet< REntity::Id > queryLayerBlockEntities(RLayer::Id layerId, RBlock::Id blockId)=0
virtual bool hasSelection() const =0
virtual QSharedPointer< RObject > queryObjectDirect(RObject::Id objectId) const
Definition: RStorage.h:207
virtual bool removeObject(QSharedPointer< RObject > object)=0
virtual QSet< REntity::Id > queryAllBlockReferences()=0
bool boundingBoxDirty
Definition: RMemoryStorage.h:195
virtual void selectEntities(const QSet< REntity::Id > &entityIds, bool add=false, QSet< REntity::Id > *affectedEntities=NULL)=0
Selects all entities with the given IDs.
virtual QSet< RLayer::Id > queryAllLayers(bool undone=false)=0
virtual RLinetype::Id getLinetypeId(const QString &linetypeName) const =0
virtual QList< RLinetypePattern > getLinetypePatterns() const =0
virtual QSet< RObject::Id > queryAllObjects()=0
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:76
virtual RBlock::Id getBlockId(const QString &blockName) const =0
virtual QSet< REntity::Id > queryBlockEntities(RBlock::Id blockId)=0
QHash< REntity::Id, QSharedPointer< REntity > > selectedEntityMap
Definition: RMemoryStorage.h:203
virtual RTransaction getTransaction(int transactionId)=0
Abstract base class for all objects.
Definition: RObject.h:48
virtual QVariant getKnownVariable(RS::KnownVariable key) const =0
virtual bool hasChildEntities(REntity::Id parentId)=0
virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const =0
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const =0
virtual void setLastTransactionId(int transactionId)
Sets the ID of the last created transaction.
Definition: RStorage.h:562
virtual QSharedPointer< RUcs > queryUcs(RUcs::Id ucsId) const =0
virtual QSet< QString > getViewNames() const =0
virtual void deselectEntity(REntity::Id entityId, QSet< REntity::Id > *affectedEntities=NULL)=0
Deselects the entity with the given ID.
virtual QSharedPointer< RUcs > queryUcsDirect(RUcs::Id ucsId) const
Definition: RStorage.h:228
int Id
Definition: RObject.h:53
virtual QSet< REntity::Id > queryLayerEntities(RLayer::Id layerId, bool allBlocks=false)=0
QMap< QString, QString > variableCaseMap
Definition: RMemoryStorage.h:216
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
Transaction implementation.
Definition: RTransaction.h:74
virtual void resetTransactionStack()=0
virtual QSet< RBlock::Id > queryAllLayoutBlocks(bool undone=false)=0
virtual void rollbackTransaction()=0
Rolls the current transaction back in order to cancel it.
virtual QSet< RUcs::Id > queryAllUcs()=0
virtual QSharedPointer< RObject > queryObject(RObject::Id objectId) const =0
QHash< RBlock::Id, QSharedPointer< RBlock > > blockMap
Definition: RMemoryStorage.h:206
virtual bool deleteObject(RObject::Id objectId)=0
Deletes the object with the given ID.
Lineweight
Definition: RLineweight.h:42
QSharedPointer< RDocumentVariables > documentVariables
Definition: RMemoryStorage.h:213
virtual RBox getBoundingBox(bool ignoreHiddenLayers=true, bool ignoreEmpty=false) const =0
QHash< RObject::Handle, QSharedPointer< RObject > > objectHandleMap
Definition: RMemoryStorage.h:201
virtual QStringList getVariables() const =0
virtual QString getLinetypeName(RLinetype::Id linetypeId) const =0
virtual int getMaxTransactionId()=0
virtual QSet< QString > getLayerNames(const QString &rxStr=RDEFAULT_QSTRING) const =0
virtual QSharedPointer< RLayout > queryLayout(RLayout::Id layoutId) const =0
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RMemoryStorage.h:37
virtual QSet< REntity::Id > querySelectedEntities() const =0
virtual bool hasBlockEntities(RBlock::Id blockId) const =0
virtual RLayout::Id getLayoutId(const QString &layoutName) const =0
QHash< QString, QVariant > variables
Definition: RMemoryStorage.h:215
Q_DECLARE_METATYPE(RMath *)
virtual void setKnownVariable(RS::KnownVariable key, const QVariant &value, RTransaction *transaction=NULL)=0
virtual void clear()
Resets this storage to its initial, empty state.
Definition: RStorage.cpp:40
virtual QSharedPointer< RObject > queryObjectByHandle(RObject::Handle objectHandle) const =0
virtual QString getLayoutName(RLayout::Id layoutId) const =0
virtual QSharedPointer< RView > queryView(RView::Id viewId) const =0
virtual QSharedPointer< RDocumentVariables > queryDocumentVariables() const =0
virtual void removeVariable(const QString &key)=0
virtual bool saveObject(QSharedPointer< RObject > object, bool checkBlockRecursion=true, bool keepHandles=false)=0
Saves the given object to the storage.
QHash< RLayout::Id, QSharedPointer< RLayout > > layoutMap
Definition: RMemoryStorage.h:208
virtual QSharedPointer< RBlock > queryBlock(RBlock::Id blockId) const =0
virtual void commitTransaction()=0
Commits the current transaction.
virtual QString getBlockName(RBlock::Id blockId) const =0
QHash< RObject::Id, QSharedPointer< RObject > > objectMap
Definition: RMemoryStorage.h:200
KnownVariable
Well established document variables.
Definition: RS.h:305
virtual QSharedPointer< REntity > queryEntity(REntity::Id entityId) const =0
virtual void update()
Clear caches:
Definition: RStorage.h:662
virtual void setCurrentBlock(RBlock::Id blockId)
Definition: RStorage.h:316
virtual QSharedPointer< RDocumentVariables > queryDocumentVariablesDirect() const =0
virtual RLayer::Id getLayerId(const QString &layerName) const =0
virtual QSet< QString > getLayoutNames(const QString &rxStr=RDEFAULT_QSTRING) const =0
virtual QSharedPointer< RLayer > queryLayer(RLayer::Id layerId) const =0
virtual void selectEntity(REntity::Id entityId, bool add=false, QSet< REntity::Id > *affectedEntities=NULL)=0
Selects the entity with the given ID.
virtual void toggleUndoStatus(QSet< RObject::Id > &objects)=0
Toggles the current undo status of all given objects.
virtual QSet< RLinetype::Id > queryAllLinetypes()=0
All entities (for filters)
Definition: RS.h:86
virtual QSharedPointer< REntity > queryEntityDirect(REntity::Id entityId) const
Definition: RStorage.h:218
virtual QSharedPointer< RBlock > queryBlockDirect(RBlock::Id blockId) const =0
virtual QString getViewName(RView::Id viewId) const =0
virtual QSet< REntity::Id > queryChildEntities(REntity::Id parentId, RS::EntityType type=RS::EntityAll)=0
virtual QSet< RView::Id > queryAllViews(bool undone=false)=0
virtual void clearEntitySelection(QSet< REntity::Id > *affectedEntities=NULL)=0
Clears the selection status of all entities.
virtual QSharedPointer< RLinetype > queryLinetypeDirect(RLinetype::Id linetypeId) const =0
QMultiHash< RBlock::Id, QSharedPointer< REntity > > blockEntityMap
Definition: RMemoryStorage.h:205
virtual QSet< REntity::Id > queryAllEntities(bool undone=false, bool allBlocks=false, RS::EntityType type=RS::EntityAll)=0
bool selectedEntityMapDirty
Definition: RMemoryStorage.h:204
#define RDEFAULT_QSTRING
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDebug.h:48
QHash< RLinetype::Id, QSharedPointer< RLinetype > > linetypeMap
Definition: RMemoryStorage.h:209
virtual int countSelectedEntities() const
Definition: RStorage.h:415
virtual QSet< QString > getLinetypeNames() const =0
virtual QSet< QString > getBlockNames(const QString &rxStr=RDEFAULT_QSTRING) const =0
virtual QSet< REntity::Id > queryAllVisibleEntities()=0
virtual QSet< RBlock::Id > queryAllBlocks(bool undone=false)=0
virtual QString getLayerName(RLayer::Id layerId) const =0
virtual void beginTransaction()=0
Starts a new transaction.
virtual bool isSelected(REntity::Id entityId)
Definition: RStorage.h:485
QHash< int, RTransaction > transactionMap
Definition: RMemoryStorage.h:210
QHash< REntity::Id, QSharedPointer< REntity > > entityMap
Definition: RMemoryStorage.h:202
virtual void deleteTransactionsFrom(int transactionId)=0
Deletes all transactions with IDs from transactionId (inclusive) to the maximum transaction ID...
virtual QSharedPointer< RLayout > queryLayoutDirect(RLayout::Id layoutId) const
Definition: RStorage.h:264
RLineweight::Lineweight maxLineweight
Definition: RMemoryStorage.h:192
virtual QSharedPointer< RLinetype > queryLinetype(RLinetype::Id linetypeId) const =0
virtual void selectAllEntites(QSet< REntity::Id > *affectedEntities=NULL)=0
Sets the selection status of all entities.
virtual QSet< REntity::Id > queryBlockReferences(RBlock::Id blockId)=0
virtual RView::Id getViewId(const QString &viewName) const =0
QHash< RLayer::Id, QSharedPointer< RLayer > > layerMap
Definition: RMemoryStorage.h:207
virtual QVariant getVariable(const QString &key) const =0
virtual void setUndoStatus(RObject &object, bool status)
Definition: RStorage.cpp:65
bool inTransaction
Definition: RMemoryStorage.h:199
virtual bool deselectEntities(const QSet< REntity::Id > &entityIds, QSet< REntity::Id > *affectedEntities=NULL)=0
Deselects all entities with the given IDs.