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 
38 #define RDEFAULT_QSET_RPROPERTYTYPEID QSet<RPropertyTypeId> ()
39 
71 public:
72  RTransaction();
73 
74  RTransaction(RStorage& storage);
75 
76  RTransaction(RStorage& storage, int transactionId, const QString& text,
77  const QList<RObject::Id>& affectedObjectIds,
78  //const QSet<RObject::Id>& affectedEntities,
79  const QMap<RObject::Id, QList<RPropertyChange> >& propertyChanges);
80  //RTransaction* parent = NULL);
81 
82  RTransaction(RStorage& storage, const QString& text, bool undoable = true);
83  //RTransaction* parent = NULL);
84 
85  virtual ~RTransaction();
86 
87  void setRecordAffectedObjects(bool on) {
88  recordAffectedObjects = on;
89  }
90 
91  void setAllowAll(bool on) {
92  allowAll = on;
93  }
94 
95  void setAllowInvisible(bool on) {
96  allowInvisible = on;
97  }
98 
99  void setSpatialIndexDisabled(bool on) {
100  spatialIndexDisabled = on;
101  }
102 
104  existingBlockDetectionDisabled = on;
105  }
106 
108  existingLayerDetectionDisabled = on;
109  }
110 
112  existingLinetypeDetectionDisabled = on;
113  }
114 
116  blockRecursionDetectionDisabled = on;
117  }
118 
119  void setKeepHandles(bool on) {
120  keepHandles = on;
121  }
122 
123 // void setUndoing(bool on) {
124 // undoing = on;
125 // }
126 
127  bool isUndoing() {
128  return undoing;
129  }
130 
131 // void setRedoing(bool on) {
132 // redoing = on;
133 // }
134 
135  bool isRedoing() {
136  return redoing;
137  }
138 
143  bool isUndoable() const {
144  return undoable;
145  }
146 
147  bool isFailed() const {
148  return failed;
149  }
150 
154  virtual void redo();
155 
160  virtual void undo();
161 
162  void end();
163 
164  void updateAffectedBlockReferences();
165 
170  void setId(int id) {
171  transactionId = id;
172  }
173 
177  int getId() const {
178  return transactionId;
179  }
180 
184  QString getText() const {
185  return text;
186  }
187 
188  bool overwriteBlock(QSharedPointer<RBlock> block);
189 
190  bool addObject(QSharedPointer<RObject> obj,
191  bool useCurrentAttributes = true,
192  bool forceNew = false,
193  const QSet<RPropertyTypeId>& modifiedPropertyTypeIds = RDEFAULT_QSET_RPROPERTYTYPEID);
194 
195  void addAffectedObject(RObject::Id objectId);
196  void addAffectedObjects(const QSet<RObject::Id>& objectIds);
197  void addAffectedObject(QSharedPointer<RObject> object);
198 
199  void deleteObject(RObject::Id objectId);
200  void deleteObject(QSharedPointer<RObject> object);
201 
206  QList<RObject::Id> getAffectedObjects() const {
207  return affectedObjectIds;
208  }
209 
214  QSet<RObject::Id> getStatusChanges() const {
215  return statusChanges;
216  }
217 
221  QMap<RObject::Id, QList<RPropertyChange> > getPropertyChanges() const {
222  return propertyChanges;
223  }
224 
225  bool hasOnlyChanges() const {
226  return onlyChanges;
227  }
228 
229  void fail();
230 
231  void endCycle();
232 
233  bool isPreview() const;
234 
235 protected:
236  bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
237  //void appendChild(RTransaction& t);
238 
239  void commit();
240  void rollback();
241 
242 protected:
247 
252 
256  QString text;
257 
261  QList<RObject::Id> affectedObjectIds;
262 
266  QSet<RObject::Id> affectedBlockReferenceIds;
267 
273  QMap<RObject::Id, QList<RPropertyChange> > propertyChanges;
274 
279  QSet<RObject::Id> statusChanges;
280 
284  //QList<RTransaction> childTransactions;
285 
289  bool undoable;
290 
294  bool failed;
295 
300 
306 
311  bool allowAll;
312 
319 
325 
330 
335 
340 
345 
350 
351  QMap<RObject::Id, RObject::Id> cloneIds;
352 
353  bool undoing;
354  bool redoing;
355 };
356 
357 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
358 
361 
362 #endif