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 
124  bool isUndoable() const {
125  return undoable;
126  }
127 
128  bool isFailed() const {
129  return failed;
130  }
131 
135  virtual void redo(RDocument* objectContainer = NULL);
136 
141  virtual void undo(RDocument* objectContainer = NULL);
142 
148  //virtual void preview(RExporter& /*exporter*/) const {}
149 
150  void end();
151 
152  void updateOverwrittenBlockReferences();
153 
158  void setId(int id) {
159  transactionId = id;
160  }
161 
165  int getId() const {
166  return transactionId;
167  }
168 
172  QString getText() const {
173  return text;
174  }
175 
176  bool overwriteBlock(QSharedPointer<RBlock> block);
177 
178  bool addObject(QSharedPointer<RObject> obj,
179  bool useCurrentAttributes = true,
180  bool forceNew = false,
181  const QSet<RPropertyTypeId>& modifiedPropertyTypeIds = RDEFAULT_QSET_RPROPERTYTYPEID);
182 
183  void addAffectedObject(RObject::Id objectId);
184  void addAffectedObjects(const QSet<RObject::Id>& objectIds);
185  void addAffectedObject(QSharedPointer<RObject> object);
186 
187  void deleteObject(RObject::Id objectId, RDocument* document);
188  void deleteObject(QSharedPointer<RObject> object, RDocument* document);
189 
194  QList<RObject::Id> getAffectedObjects() const {
195  return affectedObjectIds;
196  }
197 
202  QSet<RObject::Id> getStatusChanges() const {
203  return statusChanges;
204  }
205 
209  QMap<RObject::Id, QList<RPropertyChange> > getPropertyChanges() const {
210  return propertyChanges;
211  }
212 
213  bool hasOnlyChanges() const {
214  return onlyChanges;
215  }
216 
217  void fail();
218 
219  void endCycle();
220 
221 protected:
222  bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
223  //void appendChild(RTransaction& t);
224 
225  void commit();
226  void rollback();
227 
228 protected:
233 
238 
242  QString text;
243 
247  QList<RObject::Id> affectedObjectIds;
248 
252  QList<RObject::Id> overwrittenBlockReferences;
253 
259  QMap<RObject::Id, QList<RPropertyChange> > propertyChanges;
260 
265  QSet<RObject::Id> statusChanges;
266 
270  //QList<RTransaction> childTransactions;
271 
275  bool undoable;
276 
280  bool failed;
281 
286 
292 
297  bool allowAll;
298 
305 
311 
316 
321 
326 
331 
332  QMap<RObject::Id, RObject::Id> cloneIds;
333 };
334 
335 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
336 
339 
340 #endif