QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RTransaction.h
Go to the documentation of this file.
1 
20 #ifndef RTRANSACTION_H
21 #define RTRANSACTION_H
22 
23 #include "core_global.h"
24 
25 #include <QList>
26 #include <QMap>
27 #include <QSet>
28 #include <QSharedPointer>
29 
30 #include "RObject.h"
31 #include "REntity.h"
32 #include "RPropertyTypeId.h"
33 #include "RPropertyChange.h"
34 
35 class RStorage;
36 class RExporter;
37 class RDocument;
38 
39 #define RDEFAULT_QSET_RPROPERTYTYPEID QSet<RPropertyTypeId> ()
40 
72 public:
73  RTransaction();
74 
75  RTransaction(RStorage& storage);
76 
77  RTransaction(RStorage& storage, int transactionId, const QString& text,
78  const QList<RObject::Id>& affectedObjectIds,
79  //const QSet<RObject::Id>& affectedEntities,
80  const QMap<RObject::Id, QList<RPropertyChange> >& propertyChanges);
81  //RTransaction* parent = NULL);
82 
83  RTransaction(RStorage& storage, const QString& text, bool undoable = true);
84  //RTransaction* parent = NULL);
85 
86  virtual ~RTransaction();
87 
88  void setRecordAffectedObjects(bool on) {
89  recordAffectedObjects = on;
90  }
91 
92  void setAllowAll(bool on) {
93  allowAll = on;
94  }
95 
96  void setAllowInvisible(bool on) {
97  allowInvisible = on;
98  }
99 
100  void setSpatialIndexDisabled(bool on) {
101  spatialIndexDisabled = on;
102  }
103 
105  existingBlockDetectionDisabled = on;
106  }
107 
109  existingLayerDetectionDisabled = on;
110  }
111 
113  blockRecursionDetectionDisabled = on;
114  }
115 
116  void setKeepHandles(bool on) {
117  keepHandles = on;
118  }
119 
120 // void setUndoing(bool on) {
121 // undoing = on;
122 // }
123 
124  bool isUndoing() {
125  return undoing;
126  }
127 
128 // void setRedoing(bool on) {
129 // redoing = on;
130 // }
131 
132  bool isRedoing() {
133  return redoing;
134  }
135 
140  bool isUndoable() const {
141  return undoable;
142  }
143 
144  bool isFailed() const {
145  return failed;
146  }
147 
151  virtual void redo(RDocument* document = NULL);
152 
157  virtual void undo(RDocument* document = NULL);
158 
159  void end(RDocument* document);
160 
161  void updateAffectedBlockReferences();
162 
167  void setId(int id) {
168  transactionId = id;
169  }
170 
174  int getId() const {
175  return transactionId;
176  }
177 
181  QString getText() const {
182  return text;
183  }
184 
185  bool overwriteBlock(QSharedPointer<RBlock> block);
186 
187  bool addObject(QSharedPointer<RObject> obj,
188  bool useCurrentAttributes = true,
189  bool forceNew = false,
190  const QSet<RPropertyTypeId>& modifiedPropertyTypeIds = RDEFAULT_QSET_RPROPERTYTYPEID);
191 
192  void addAffectedObject(RObject::Id objectId);
193  void addAffectedObjects(const QSet<RObject::Id>& objectIds);
194  void addAffectedObject(QSharedPointer<RObject> object);
195 
196  void deleteObject(RObject::Id objectId, RDocument* document);
197  void deleteObject(QSharedPointer<RObject> object, RDocument* document);
198 
203  QList<RObject::Id> getAffectedObjects() const {
204  return affectedObjectIds;
205  }
206 
211  QSet<RObject::Id> getStatusChanges() const {
212  return statusChanges;
213  }
214 
218  QMap<RObject::Id, QList<RPropertyChange> > getPropertyChanges() const {
219  return propertyChanges;
220  }
221 
222  bool hasOnlyChanges() const {
223  return onlyChanges;
224  }
225 
226  void fail();
227 
228  void endCycle();
229 
230 protected:
231  bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
232  //void appendChild(RTransaction& t);
233 
234  void commit(RDocument* document);
235  void rollback();
236 
237 protected:
242 
247 
251  QString text;
252 
256  QList<RObject::Id> affectedObjectIds;
257 
261  QSet<RObject::Id> affectedBlockReferenceIds;
262 
268  QMap<RObject::Id, QList<RPropertyChange> > propertyChanges;
269 
274  QSet<RObject::Id> statusChanges;
275 
279  //QList<RTransaction> childTransactions;
280 
284  bool undoable;
285 
289  bool failed;
290 
295 
301 
306  bool allowAll;
307 
314 
320 
325 
330 
335 
340 
341  QMap<RObject::Id, RObject::Id> cloneIds;
342 
343  bool undoing;
344  bool redoing;
345 };
346 
347 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
348 
351 
352 #endif