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<RUcs::Id> queryAllUcs();
56  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false);
57  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false);
58  virtual QSet<RView::Id> queryAllViews(bool undone = false);
59  virtual QSet<RLinetype::Id> queryAllLinetypes();
60  virtual QSet<REntity::Id> queryInfiniteEntities();
61  virtual QSet<REntity::Id> querySelectedEntities() const;
62 
63  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false);
64  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId);
65  virtual QSet<REntity::Id> queryLayerBlockEntities(RLayer::Id layerId, RBlock::Id blockId);
66  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll);
67  virtual bool hasChildEntities(REntity::Id parentId);
68  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId);
69  virtual QSet<REntity::Id> queryAllBlockReferences();
70  //virtual QSet<REntity::Id> queryViewEntities(RView::Id viewId);
71 
72  virtual QSharedPointer<RDocumentVariables> queryDocumentVariables() const;
73  virtual QSharedPointer<RDocumentVariables> queryDocumentVariablesDirect() const;
74  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
75  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const;
76  virtual QSharedPointer<RObject> queryObjectByHandleDirect(RObject::Handle objectHandle) const;
77  virtual QSharedPointer<REntity> queryEntity(REntity::Id objectId) const;
78  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
79  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
80  virtual QSharedPointer<RLayout> queryLayout(RLayout::Id layoutId) const;
81  virtual QSharedPointer<RLayout> queryLayout(const QString& layoutName) const;
82  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
83  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
84  virtual QSharedPointer<RView> queryView(RView::Id viewId) const;
85  virtual QSharedPointer<RView> queryView(const QString& viewName) const;
86  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
87  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
88  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const;
89  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
90  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
91 
92  void clearSelectionCache();
93  void updateSelectedEntityMap() const;
94 
95  virtual int countSelectedEntities() const;
96  virtual void clearEntitySelection(QSet<REntity::Id>* affectedEntities = NULL);
97  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
98  virtual void selectEntity(REntity::Id entityId, bool add = false,
99  QSet<REntity::Id>* affectedEntities = NULL);
100  virtual void deselectEntity(REntity::Id entityId,
101  QSet<REntity::Id>* affectedEntities=NULL);
102  virtual void selectEntities(const QSet<REntity::Id>& entityIds,
103  bool add = false,
104  QSet<REntity::Id>* affectedEntities = NULL);
105  virtual bool deselectEntities(const QSet<REntity::Id>& entityIds,
106  QSet<REntity::Id>* affectedEntities = NULL);
107  void setEntitySelected(QSharedPointer<REntity> entity, bool on,
108  QSet<REntity::Id>* affectedEntities = NULL, bool onlyDescend = false);
109  virtual bool isSelected(REntity::Id entityId);
110 
111  virtual bool hasSelection() const;
112 
113  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty=false) const;
114  virtual RBox getSelectionBox() const;
115 
116  virtual bool removeObject(QSharedPointer<RObject> object);
117  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false);
118  bool checkRecursion(
119  RBlock::Id blockId, RBlock::Id potentialChildBlockId
120  );
121  virtual bool deleteObject(RObject::Id objectId);
122  virtual void saveTransaction(RTransaction& transaction);
123  virtual void deleteTransactionsFrom(int transactionId);
124  virtual RTransaction getTransaction(int transactionId);
125 
126  virtual void resetTransactionStack();
127 
128  virtual void toggleUndoStatus(QSet<RObject::Id>& objects);
129  virtual void toggleUndoStatus(RObject::Id object);
130  virtual bool setUndoStatus(RObject::Id objectId, bool status);
131  virtual void setUndoStatus(RObject& object, bool status);
132  //virtual bool getUndoStatus(RObject::Id objectId) const;
133  virtual int getMaxTransactionId();
134 
135  virtual QStringList getVariables() const;
136  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite = true);
137  virtual QVariant getVariable(const QString& key) const;
138  virtual void removeVariable(const QString& key);
139 
140  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL);
141  virtual QVariant getKnownVariable(RS::KnownVariable key) const;
142 
143  virtual QString getLayerName(RLayer::Id layerId) const;
144  virtual QSet<QString> getLayerNames(const QString& rxStr = RDEFAULT_QSTRING) const;
145  virtual RLayer::Id getLayerId(const QString& layerName) const;
146 
147  virtual QString getLayoutName(RLayout::Id layoutId) const;
148  virtual QSet<QString> getLayoutNames(const QString& rxStr = RDEFAULT_QSTRING) const;
149  virtual RLayout::Id getLayoutId(const QString& layoutName) const;
150 
151  virtual QString getBlockName(RBlock::Id blockId) const;
152  virtual QSet<QString> getBlockNames(const QString& rxStr = RDEFAULT_QSTRING) const;
153  virtual RBlock::Id getBlockId(const QString& blockName) const;
154 
155  virtual QString getViewName(RView::Id viewId) const;
156  virtual QSet<QString> getViewNames() const;
157  virtual RView::Id getViewId(const QString& viewName) const;
158 
159  virtual QString getLinetypeName(RLinetype::Id linetypeId) const;
160  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const;
161  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const;
162  virtual QSet<QString> getLinetypeNames() const;
163  virtual QList<RLinetypePattern> getLinetypePatterns() const;
164  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const;
165 
166  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
167  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id objectId) const;
168  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const;
169  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
170  virtual QSharedPointer<RLayout> queryLayoutDirect(RLayout::Id layoutId) const;
171  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
172 
173  virtual void setLastTransactionId(int transactionId);
174 
176 
177  virtual void update();
178 
179  //virtual void setUnit(RS::Unit unit, RTransaction* transaction = NULL);
180  //virtual RS::Unit getUnit() const;
181 
182 // virtual void setDimensionFont(const QString& f);
183 // virtual QString getDimensionFont() const;
184 
185 // virtual void setLinetypeScale(double v, RTransaction* transaction);
186 // virtual double getLinetypeScale() const;
187 
188 protected:
190 
191  mutable RBox boundingBox[2][2];
192  mutable bool boundingBoxDirty;
193  //mutable bool boundingBoxIgnoreHiddenLayers;
194  //mutable bool boundingBoxIgnoreEmpty;
195 
197  QHash<RObject::Id, QSharedPointer<RObject> > objectMap;
198  QHash<RObject::Handle, QSharedPointer<RObject> > objectHandleMap;
199  QHash<REntity::Id, QSharedPointer<REntity> > entityMap;
200  mutable QHash<REntity::Id, QSharedPointer<REntity> > selectedEntityMap;
202  QMultiHash<RBlock::Id, QSharedPointer<REntity> > blockEntityMap;
203  QHash<RBlock::Id, QSharedPointer<RBlock> > blockMap;
204  QHash<RLayer::Id, QSharedPointer<RLayer> > layerMap;
205  QHash<RLayout::Id, QSharedPointer<RLayout> > layoutMap;
206  QHash<RLinetype::Id, QSharedPointer<RLinetype> > linetypeMap;
207  QHash<int, RTransaction> transactionMap;
208 
209  // document wide variables are stored as custom properties in this object:
210  QSharedPointer<RDocumentVariables> documentVariables;
211 
212  QHash<QString, QVariant> variables;
213  QMap<QString, QString> variableCaseMap;
214  //QHash<RS::KnownVariable, QVariant> knownVariables;
215  //RS::Unit unit;
216  //QString dimensionFont;
217  //double linetypeScale;
218 };
219 
221 
222 #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:194
virtual bool removeObject(QSharedPointer< RObject > object)=0
virtual QSet< REntity::Id > queryAllBlockReferences()=0
bool boundingBoxDirty
Definition: RMemoryStorage.h:192
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:200
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:549
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:215
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:213
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:231
Transaction implementation.
Definition: RTransaction.h:70
virtual void resetTransactionStack()=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:203
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:210
virtual RBox getBoundingBox(bool ignoreHiddenLayers=true, bool ignoreEmpty=false) const =0
QHash< RObject::Handle, QSharedPointer< RObject > > objectHandleMap
Definition: RMemoryStorage.h:198
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 RLayout::Id getLayoutId(const QString &layoutName) const =0
QHash< QString, QVariant > variables
Definition: RMemoryStorage.h:212
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:205
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:197
KnownVariable
Well established document variables.
Definition: RS.h:304
virtual QSharedPointer< REntity > queryEntity(REntity::Id entityId) const =0
virtual void update()
Clear caches:
Definition: RStorage.h:649
virtual void setCurrentBlock(RBlock::Id blockId)
Definition: RStorage.h:303
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:205
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:202
virtual QSet< REntity::Id > queryAllEntities(bool undone=false, bool allBlocks=false, RS::EntityType type=RS::EntityAll)=0
bool selectedEntityMapDirty
Definition: RMemoryStorage.h:201
#define RDEFAULT_QSTRING
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDebug.h:48
QHash< RLinetype::Id, QSharedPointer< RLinetype > > linetypeMap
Definition: RMemoryStorage.h:206
virtual int countSelectedEntities() const
Definition: RStorage.h:402
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:472
QHash< int, RTransaction > transactionMap
Definition: RMemoryStorage.h:207
QHash< REntity::Id, QSharedPointer< REntity > > entityMap
Definition: RMemoryStorage.h:199
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:251
RLineweight::Lineweight maxLineweight
Definition: RMemoryStorage.h:189
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:204
virtual QVariant getVariable(const QString &key) const =0
virtual void setUndoStatus(RObject &object, bool status)
Definition: RStorage.cpp:65
bool inTransaction
Definition: RMemoryStorage.h:196
virtual bool deselectEntities(const QSet< REntity::Id > &entityIds, QSet< REntity::Id > *affectedEntities=NULL)=0
Deselects all entities with the given IDs.