QCAD
Open Source 2D CAD
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 
75 public:
76  RTransaction();
77 
78  RTransaction(RStorage& storage);
79 
80  RTransaction(RStorage& storage, int transactionId, const QString& text,
81  const QList<RObject::Id>& affectedObjectIds,
82  //const QSet<RObject::Id>& affectedEntities,
83  const QMap<RObject::Id, QList<RPropertyChange> >& propertyChanges);
84  //RTransaction* parent = NULL);
85 
86  RTransaction(RStorage& storage, const QString& text, bool undoable = true);
87  //RTransaction* parent = NULL);
88 
89  virtual ~RTransaction();
90 
91  void setRecordAffectedObjects(bool on) {
92  recordAffectedObjects = on;
93  }
94 
95  void setAllowAll(bool on) {
96  allowAll = on;
97  }
98 
99  void setAllowInvisible(bool on) {
100  allowInvisible = on;
101  }
102 
103  void setSpatialIndexDisabled(bool on) {
104  spatialIndexDisabled = on;
105  }
106 
108  existingBlockDetectionDisabled = on;
109  }
110 
112  existingLayerDetectionDisabled = on;
113  }
114 
116  existingLinetypeDetectionDisabled = on;
117  }
118 
120  blockRecursionDetectionDisabled = on;
121  }
122 
123  void setKeepHandles(bool on) {
124  keepHandles = on;
125  }
126 
127 // void setUndoing(bool on) {
128 // undoing = on;
129 // }
130 
131  bool isUndoing() {
132  return undoing;
133  }
134 
135 // void setRedoing(bool on) {
136 // redoing = on;
137 // }
138 
139  bool isRedoing() {
140  return redoing;
141  }
142 
147  bool isUndoable() const {
148  return undoable;
149  }
150 
151  bool isFailed() const {
152  return failed;
153  }
154 
158  virtual void redo();
159 
164  virtual void undo();
165 
166  void end();
167 
168  void updateAffectedBlockReferences();
169 
174  void setId(int id) {
175  transactionId = id;
176  }
177 
181  int getId() const {
182  return transactionId;
183  }
184 
188  void setGroup(int group) {
189  transactionGroup = group;
190  }
191 
195  int getGroup() const {
196  return transactionGroup;
197  }
198 
202  QString getText() const {
203  return text;
204  }
205 
206  bool overwriteBlock(QSharedPointer<RBlock> block);
207 
208  bool addObject(QSharedPointer<RObject> obj,
209  bool useCurrentAttributes = true,
210  bool forceNew = false,
211  const QSet<RPropertyTypeId>& modifiedPropertyTypeIds = RDEFAULT_QSET_RPROPERTYTYPEID);
212 
213  void addAffectedObject(RObject::Id objectId);
214  void addAffectedObjects(const QSet<RObject::Id>& objectIds);
215  void addAffectedObject(QSharedPointer<RObject> object);
216 
217  void deleteObject(RObject::Id objectId);
218  void deleteObject(QSharedPointer<RObject> object);
219 
224  QList<RObject::Id> getAffectedObjects() const {
225  return affectedObjectIds;
226  }
227 
232  QSet<RObject::Id> getStatusChanges() const {
233  return statusChanges;
234  }
235 
236  bool hasStatusChange(RObject::Id id) const {
237  return statusChanges.contains(id);
238  }
239 
243  QMap<RObject::Id, QList<RPropertyChange> > getPropertyChanges() const {
244  return propertyChanges;
245  }
246 
247  QList<RPropertyChange> getPropertyChanges(RObject::Id id) const;
248 
249  bool hasOnlyChanges() const {
250  return onlyChanges;
251  }
252 
253  void fail();
254 
255  void endCycle();
256 
257  bool isPreview() const;
258 
259 protected:
260  bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
261  //void appendChild(RTransaction& t);
262 
263  void commit();
264  void rollback();
265 
266 protected:
271 
276 
281 
285  QString text;
286 
290  QList<RObject::Id> affectedObjectIds;
291 
295  QSet<RObject::Id> affectedBlockReferenceIds;
296 
302  QMap<RObject::Id, QList<RPropertyChange> > propertyChanges;
303 
308  QSet<RObject::Id> statusChanges;
309 
313  //QList<RTransaction> childTransactions;
314 
318  bool undoable;
319 
323  bool failed;
324 
329 
335 
340  bool allowAll;
341 
348 
354 
359 
364 
369 
374 
379 
380  QMap<RObject::Id, RObject::Id> cloneIds;
381 
382  bool undoing;
383  bool redoing;
384 };
385 
386 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
387 
390 
391 #endif
bool hasOnlyChanges() const
Definition: RTransaction.h:249
QList< RObject::Id > affectedObjectIds
List of IDs of all objects that are affected by this transaction.
Definition: RTransaction.h:290
int transactionGroup
Transaction group or -1.
Definition: RTransaction.h:280
void setExistingLinetypeDetectionDisabled(bool on)
Definition: RTransaction.h:115
bool existingBlockDetectionDisabled
True to disable detection of existing blocks (performance gain).
Definition: RTransaction.h:358
QMap< RObject::Id, QList< RPropertyChange > > propertyChanges
Map of properties that are changed by this transaction.
Definition: RTransaction.h:302
QList< RObject::Id > getAffectedObjects() const
Definition: RTransaction.h:224
int getGroup() const
Definition: RTransaction.h:195
bool failed
True if this transaction failed.
Definition: RTransaction.h:323
bool keepHandles
True to keep existing object handles (importers).
Definition: RTransaction.h:378
void setRecordAffectedObjects(bool on)
Definition: RTransaction.h:91
Stores the change that was made to a property of an object.
Definition: RPropertyChange.h:39
#define QCADCORE_EXPORT
Definition: core_global.h:10
bool undoing
Definition: RTransaction.h:382
#define RDEFAULT_QSET_RPROPERTYTYPEID
Definition: RTransaction.h:38
bool recordAffectedObjects
True if caller is intereseted in list of objects that are affected by this transaction.
Definition: RTransaction.h:334
void setKeepHandles(bool on)
Definition: RTransaction.h:123
int Id
Definition: RObject.h:53
bool undoable
Child transactions of this transaction.
Definition: RTransaction.h:318
QString text
Log entry for this transaction.
Definition: RTransaction.h:285
void setGroup(int group)
Set group.
Definition: RTransaction.h:188
This is the abstract base class for all storage implementations.
Definition: RStorage.h:62
QMap< RObject::Id, QList< RPropertyChange > > getPropertyChanges() const
Definition: RTransaction.h:243
Transaction implementation.
Definition: RTransaction.h:74
bool allowInvisible
True if all transactions on invisible entities are allowed, typically transactions on invisible layer...
Definition: RTransaction.h:347
bool isRedoing()
Definition: RTransaction.h:139
bool isUndoing()
Definition: RTransaction.h:131
void setBlockRecursionDetectionDisabled(bool on)
Definition: RTransaction.h:119
bool onlyChanges
True if this transaction only changed objects, no additions, no deletes.
Definition: RTransaction.h:328
QString getText() const
Definition: RTransaction.h:202
bool redoing
Definition: RTransaction.h:383
Q_DECLARE_METATYPE(RMath *)
QSet< RObject::Id > statusChanges
Contains affected objects that have been created or deleted in this transaction.
Definition: RTransaction.h:308
QMap< RObject::Id, RObject::Id > cloneIds
Definition: RTransaction.h:380
int transactionId
Unique ID of this transaction.
Definition: RTransaction.h:275
bool existingLinetypeDetectionDisabled
True to disable detection of existing linetypes (performance gain).
Definition: RTransaction.h:368
bool isUndoable() const
Definition: RTransaction.h:147
QSet< RObject::Id > getStatusChanges() const
Definition: RTransaction.h:232
bool blockRecursionDetectionDisabled
True to disable block recursion detection (performance gain for loading).
Definition: RTransaction.h:373
void setAllowInvisible(bool on)
Definition: RTransaction.h:99
int getId() const
Definition: RTransaction.h:181
bool spatialIndexDisabled
True to ignore spatial index.
Definition: RTransaction.h:353
Abstract base class for exporters.
Definition: RExporter.h:71
void setId(int id)
Sets the ID of this transaction.
Definition: RTransaction.h:174
void setAllowAll(bool on)
Definition: RTransaction.h:95
bool allowAll
True if all transactions are allowed, even transactions on locked or invisible layers.
Definition: RTransaction.h:340
bool hasStatusChange(RObject::Id id) const
Definition: RTransaction.h:236
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction &t)
Stream operator for QDebug.
Definition: RTransaction.cpp:1069
bool isFailed() const
Definition: RTransaction.h:151
void setExistingLayerDetectionDisabled(bool on)
Definition: RTransaction.h:111
void setSpatialIndexDisabled(bool on)
Definition: RTransaction.h:103
QSet< RObject::Id > affectedBlockReferenceIds
List of IDs of all block references that need to be updated.
Definition: RTransaction.h:295
void setExistingBlockDetectionDisabled(bool on)
Definition: RTransaction.h:107
bool existingLayerDetectionDisabled
True to disable detection of existing layers (performance gain).
Definition: RTransaction.h:363
RStorage * storage
A transaction always belongs to the storage of a document.
Definition: RTransaction.h:270