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  void setGroup(int group) {
185  transactionGroup = group;
186  }
187 
191  int getGroup() const {
192  return transactionGroup;
193  }
194 
198  QString getText() const {
199  return text;
200  }
201 
202  bool overwriteBlock(QSharedPointer<RBlock> block);
203 
204  bool addObject(QSharedPointer<RObject> obj,
205  bool useCurrentAttributes = true,
206  bool forceNew = false,
207  const QSet<RPropertyTypeId>& modifiedPropertyTypeIds = RDEFAULT_QSET_RPROPERTYTYPEID);
208 
209  void addAffectedObject(RObject::Id objectId);
210  void addAffectedObjects(const QSet<RObject::Id>& objectIds);
211  void addAffectedObject(QSharedPointer<RObject> object);
212 
213  void deleteObject(RObject::Id objectId);
214  void deleteObject(QSharedPointer<RObject> object);
215 
220  QList<RObject::Id> getAffectedObjects() const {
221  return affectedObjectIds;
222  }
223 
228  QSet<RObject::Id> getStatusChanges() const {
229  return statusChanges;
230  }
231 
235  QMap<RObject::Id, QList<RPropertyChange> > getPropertyChanges() const {
236  return propertyChanges;
237  }
238 
239  bool hasOnlyChanges() const {
240  return onlyChanges;
241  }
242 
243  void fail();
244 
245  void endCycle();
246 
247  bool isPreview() const;
248 
249 protected:
250  bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
251  //void appendChild(RTransaction& t);
252 
253  void commit();
254  void rollback();
255 
256 protected:
261 
266 
271 
275  QString text;
276 
280  QList<RObject::Id> affectedObjectIds;
281 
285  QSet<RObject::Id> affectedBlockReferenceIds;
286 
292  QMap<RObject::Id, QList<RPropertyChange> > propertyChanges;
293 
298  QSet<RObject::Id> statusChanges;
299 
303  //QList<RTransaction> childTransactions;
304 
308  bool undoable;
309 
313  bool failed;
314 
319 
325 
330  bool allowAll;
331 
338 
344 
349 
354 
359 
364 
369 
370  QMap<RObject::Id, RObject::Id> cloneIds;
371 
372  bool undoing;
373  bool redoing;
374 };
375 
376 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
377 
380 
381 #endif