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 
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  QList<RPropertyChange> getPropertyChanges(RObject::Id id) const;
240 
241  bool hasOnlyChanges() const {
242  return onlyChanges;
243  }
244 
245  void fail();
246 
247  void endCycle();
248 
249  bool isPreview() const;
250 
251 protected:
252  bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
253  //void appendChild(RTransaction& t);
254 
255  void commit();
256  void rollback();
257 
258 protected:
263 
268 
273 
277  QString text;
278 
282  QList<RObject::Id> affectedObjectIds;
283 
287  QSet<RObject::Id> affectedBlockReferenceIds;
288 
294  QMap<RObject::Id, QList<RPropertyChange> > propertyChanges;
295 
300  QSet<RObject::Id> statusChanges;
301 
305  //QList<RTransaction> childTransactions;
306 
310  bool undoable;
311 
315  bool failed;
316 
321 
327 
332  bool allowAll;
333 
340 
346 
351 
356 
361 
366 
371 
372  QMap<RObject::Id, RObject::Id> cloneIds;
373 
374  bool undoing;
375  bool redoing;
376 };
377 
378 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
379 
382 
383 #endif
bool hasOnlyChanges() const
Definition: RTransaction.h:241
QList< RObject::Id > affectedObjectIds
List of IDs of all objects that are affected by this transaction.
Definition: RTransaction.h:282
int transactionGroup
Transaction group or -1.
Definition: RTransaction.h:272
void setExistingLinetypeDetectionDisabled(bool on)
Definition: RTransaction.h:111
bool existingBlockDetectionDisabled
True to disable detection of existing blocks (performance gain).
Definition: RTransaction.h:350
QMap< RObject::Id, QList< RPropertyChange > > propertyChanges
Map of properties that are changed by this transaction.
Definition: RTransaction.h:294
QList< RObject::Id > getAffectedObjects() const
Definition: RTransaction.h:220
int getGroup() const
Definition: RTransaction.h:191
bool failed
True if this transaction failed.
Definition: RTransaction.h:315
bool keepHandles
True to keep existing object handles (importers).
Definition: RTransaction.h:370
void setRecordAffectedObjects(bool on)
Definition: RTransaction.h:87
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:374
#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:326
void setKeepHandles(bool on)
Definition: RTransaction.h:119
int Id
Definition: RObject.h:53
bool undoable
Child transactions of this transaction.
Definition: RTransaction.h:310
QString text
Log entry for this transaction.
Definition: RTransaction.h:277
void setGroup(int group)
Set group.
Definition: RTransaction.h:184
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RStorage.h:55
QMap< RObject::Id, QList< RPropertyChange > > getPropertyChanges() const
Definition: RTransaction.h:235
Transaction implementation.
Definition: RTransaction.h:70
bool allowInvisible
True if all transactions on invisible entities are allowed, typically transactions on invisible layer...
Definition: RTransaction.h:339
bool isRedoing()
Definition: RTransaction.h:135
bool isUndoing()
Definition: RTransaction.h:127
void setBlockRecursionDetectionDisabled(bool on)
Definition: RTransaction.h:115
bool onlyChanges
True if this transaction only changed objects, no additions, no deletes.
Definition: RTransaction.h:320
QString getText() const
Definition: RTransaction.h:198
bool redoing
Definition: RTransaction.h:375
Q_DECLARE_METATYPE(RMath *)
QSet< RObject::Id > statusChanges
Contains affected objects that have been created or deleted in this transaction.
Definition: RTransaction.h:300
QMap< RObject::Id, RObject::Id > cloneIds
Definition: RTransaction.h:372
int transactionId
Unique ID of this transaction.
Definition: RTransaction.h:267
bool existingLinetypeDetectionDisabled
True to disable detection of existing linetypes (performance gain).
Definition: RTransaction.h:360
bool isUndoable() const
Definition: RTransaction.h:143
QSet< RObject::Id > getStatusChanges() const
Definition: RTransaction.h:228
bool blockRecursionDetectionDisabled
True to disable block recursion detection (performance gain for loading).
Definition: RTransaction.h:365
void setAllowInvisible(bool on)
Definition: RTransaction.h:95
int getId() const
Definition: RTransaction.h:177
bool spatialIndexDisabled
True to ignore spatial index.
Definition: RTransaction.h:345
Abstract base class for exporters.
Definition: RExporter.h:63
void setId(int id)
Sets the ID of this transaction.
Definition: RTransaction.h:170
void setAllowAll(bool on)
Definition: RTransaction.h:91
bool allowAll
True if all transactions are allowed, even transactions on locked or invisible layers.
Definition: RTransaction.h:332
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction &t)
Stream operator for QDebug.
Definition: RTransaction.cpp:1029
bool isFailed() const
Definition: RTransaction.h:147
void setExistingLayerDetectionDisabled(bool on)
Definition: RTransaction.h:107
void setSpatialIndexDisabled(bool on)
Definition: RTransaction.h:99
QSet< RObject::Id > affectedBlockReferenceIds
List of IDs of all block references that need to be updated.
Definition: RTransaction.h:287
void setExistingBlockDetectionDisabled(bool on)
Definition: RTransaction.h:103
bool existingLayerDetectionDisabled
True to disable detection of existing layers (performance gain).
Definition: RTransaction.h:355
RStorage * storage
A transaction always belongs to the storage of a document.
Definition: RTransaction.h:262