QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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 "RPropertyTypeId.h"
32#include "RPropertyChange.h"
33
34class RBlock;
35class RStorage;
36
37#define RDEFAULT_QSET_RPROPERTYTYPEID QSet<RPropertyTypeId> ()
38
74public:
78 enum Type {
79 Generic = 0x0000,
80 CurrentLayerChange = 0x0001,
81 CurrentLayerSelectionChange = 0x0002,
82 LayerLockStatusChange = 0x0004,
83 LayerVisibilityStatusChange = 0x0008,
84 SaveWorkingSet = 0x0010,
85 ChangeDocumentSetting = 0x0020,
86 Undo = 0x0040,
87 Redo = 0x0080
88 };
89 Q_DECLARE_FLAGS(Types, Type)
90
91public:
93
94 RTransaction(RStorage& storage);
95
96 RTransaction(RStorage& storage, int transactionId, const QString& text,
97 const QList<RObject::Id>& affectedObjectIds,
98 //const QSet<RObject::Id>& affectedEntities,
99 const QMap<RObject::Id, QList<RPropertyChange> >& propertyChanges);
100 //RTransaction* parent = NULL);
101
102 RTransaction(RStorage& storage, const QString& text, bool undoable = true);
103 //RTransaction* parent = NULL);
104
105 virtual ~RTransaction();
106
108 recordAffectedObjects = on;
109 }
110
111 void setAllowAll(bool on) {
112 allowAll = on;
113 }
114
115 void setAllowInvisible(bool on) {
116 allowInvisible = on;
117 }
118
120 spatialIndexDisabled = on;
121 }
122
124 existingBlockDetectionDisabled = on;
125 }
126
128 existingLayerDetectionDisabled = on;
129 }
130
132 existingLinetypeDetectionDisabled = on;
133 }
134
136 blockRecursionDetectionDisabled = on;
137 }
138
139 void setKeepHandles(bool on) {
140 keepHandles = on;
141 }
142
146 void setKeepChildren(bool on) {
147 keepChildren = on;
148 }
149
150// void setUndoing(bool on) {
151// undoing = on;
152// }
153
154 bool isUndoing() {
155 return undoing;
156 }
157
158// void setRedoing(bool on) {
159// redoing = on;
160// }
161
162 bool isRedoing() {
163 return redoing;
164 }
165
170 bool isUndoable() const {
171 return undoable;
172 }
173
174 bool isFailed() const {
175 return failed;
176 }
177
181 virtual void redo();
182
187 virtual void undo();
188
189 void end();
190
191 void updateAffectedBlockReferences();
192
197 void setId(int id) {
198 transactionId = id;
199 }
200
204 int getId() const {
205 return transactionId;
206 }
207
211 void setGroup(int group) {
212 transactionGroup = group;
213 }
214
218 int getGroup() const {
219 return transactionGroup;
220 }
221
225 QString getText() const {
226 return text;
227 }
228
229 bool overwriteBlock(QSharedPointer<RBlock> block);
230
231 bool addObject(QSharedPointer<RObject> obj,
232 bool useCurrentAttributes = true,
233 bool forceNew = false,
234 const QSet<RPropertyTypeId>& modifiedPropertyTypeIds = RDEFAULT_QSET_RPROPERTYTYPEID);
235
236 void addAffectedObject(RObject::Id objectId);
237 void addAffectedObjects(const QSet<RObject::Id>& objectIds);
238 void addAffectedObject(QSharedPointer<RObject> object);
239
240 void deleteObject(RObject::Id objectId, bool force = false);
241 void deleteObject(QSharedPointer<RObject> object, bool force = false);
242
247 QList<RObject::Id> getAffectedObjects() const {
248 return affectedObjectIds;
249 }
250
255 QSet<RObject::Id> getStatusChanges() const {
256 return statusChanges;
257 }
258
260 return statusChanges.contains(id);
261 }
262
267 return propertyChanges;
268 }
269
270 RObject::Id getNewObjectId(RObject::Id oldId) const;
271
272 QList<RPropertyChange> getPropertyChanges(RObject::Id id) const;
273
274 bool hasOnlyChanges() const {
275 return onlyChanges;
276 }
277
278 void fail();
279
280 void endCycle();
281
282 bool isPreview() const;
283
284 void setTypes(RTransaction::Types t) {
285 types = t;
286 }
287 RTransaction::Types getTypes() const {
288 return types;
289 }
290 void setType(RTransaction::Type type, bool on = true);
291 bool isType(RTransaction::Type type) const;
292
293protected:
294 bool addPropertyChange(RObject::Id objectId, const RPropertyChange& propertyChange);
295 //void appendChild(RTransaction& t);
296
297 void commit();
298 void rollback();
299
300protected:
301 RTransaction::Types types;
302
307
312
317
321 QString text;
322
327 QList<RObject::Id> affectedObjectIds;
328 QSet<RObject::Id> affectedObjectIdsSet;
329
333 QSet<RObject::Id> affectedBlockReferenceIds;
334
341
346 QSet<RObject::Id> statusChanges;
347
351 //QList<RTransaction> childTransactions;
352
357
361 bool failed;
362
367
373
379
386
392
397
402
407
412
417
421 QStringList usedBlockNames;
422
427
432
434
437};
438
439QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction& t);
440
441Q_DECLARE_OPERATORS_FOR_FLAGS(RTransaction::Types)
446Q_DECLARE_METATYPE(QFlags<RTransaction::Type>)
447Q_DECLARE_METATYPE(QFlags<RTransaction::Type>*)
448
449#endif
Q_DECLARE_METATYPE(RMath *)
#define RDEFAULT_QSET_RPROPERTYTYPEID
Definition RTransaction.h:37
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RTransaction &t)
Stream operator for QDebug.
Definition RTransaction.cpp:1289
Definition RDebug.h:38
Represents a block definition in a drawing.
Definition RBlock.h:42
int Id
Definition RObject.h:69
Stores the change that was made to a property of an object.
Definition RPropertyChange.h:38
This is the abstract base class for all storage implementations.
Definition RStorage.h:67
Transaction implementation.
Definition RTransaction.h:73
void setBlockRecursionDetectionDisabled(bool on)
Definition RTransaction.h:135
bool isUndoable() const
Definition RTransaction.h:170
void setGroup(int group)
Set group.
Definition RTransaction.h:211
void setExistingLinetypeDetectionDisabled(bool on)
Definition RTransaction.h:131
bool recordAffectedObjects
True if caller is interested in list of objects that are affected by this transaction.
Definition RTransaction.h:372
QStringList usedBlockNames
List of block names that have been already used in this transaction.
Definition RTransaction.h:421
bool deletingBlock
True if a block is being deleted to prevent recursion in deleteObject.
Definition RTransaction.h:416
QSet< RObject::Id > affectedBlockReferenceIds
List of IDs of all block references that need to be updated.
Definition RTransaction.h:333
QSet< RObject::Id > affectedObjectIdsSet
Definition RTransaction.h:328
void setTypes(RTransaction::Types t)
Definition RTransaction.h:284
int transactionGroup
Transaction group or -1.
Definition RTransaction.h:316
bool spatialIndexDisabled
True to ignore spatial index.
Definition RTransaction.h:391
RTransaction::Types types
Definition RTransaction.h:301
QList< RObject::Id > getAffectedObjects() const
Definition RTransaction.h:247
bool onlyChanges
True if this transaction only changed objects, no additions, no deletes.
Definition RTransaction.h:366
void setId(int id)
Sets the ID of this transaction.
Definition RTransaction.h:197
void setSpatialIndexDisabled(bool on)
Definition RTransaction.h:119
bool isRedoing()
Definition RTransaction.h:162
bool redoing
Definition RTransaction.h:436
int getId() const
Definition RTransaction.h:204
bool allowInvisible
True if all transactions on invisible entities are allowed, typically transactions on invisible layer...
Definition RTransaction.h:385
bool existingBlockDetectionDisabled
True to disable detection of existing blocks (performance gain).
Definition RTransaction.h:396
QMap< RObject::Id, QList< RPropertyChange > > getPropertyChanges() const
Definition RTransaction.h:266
QString getText() const
Definition RTransaction.h:225
void setRecordAffectedObjects(bool on)
Definition RTransaction.h:107
bool allowAll
True if all transactions are allowed, even transactions on locked or invisible layers.
Definition RTransaction.h:378
bool isUndoing()
Definition RTransaction.h:154
bool hasStatusChange(RObject::Id id) const
Definition RTransaction.h:259
QList< RObject::Id > affectedObjectIds
List of IDs of all objects that are affected by this transaction.
Definition RTransaction.h:327
bool hasOnlyChanges() const
Definition RTransaction.h:274
bool undoing
Definition RTransaction.h:435
bool keepHandles
True to keep existing object handles (importers).
Definition RTransaction.h:426
void setAllowAll(bool on)
Definition RTransaction.h:111
RStorage * storage
A transaction always belongs to the storage of a document.
Definition RTransaction.h:306
bool existingLayerDetectionDisabled
True to disable detection of existing layers (performance gain).
Definition RTransaction.h:401
bool blockRecursionDetectionDisabled
True to disable block recursion detection (performance gain for loading).
Definition RTransaction.h:411
QString text
Log entry for this transaction.
Definition RTransaction.h:321
int transactionId
Unique ID of this transaction.
Definition RTransaction.h:311
void setKeepChildren(bool on)
Keep child entities (e.g.
Definition RTransaction.h:146
QSet< RObject::Id > statusChanges
Contains affected objects that have been created or deleted in this transaction.
Definition RTransaction.h:346
Type
Transaction type for optimizations.
Definition RTransaction.h:78
bool keepChildren
True to keep and not delete child entities (block attributes for block references).
Definition RTransaction.h:431
bool existingLinetypeDetectionDisabled
True to disable detection of existing linetypes (performance gain).
Definition RTransaction.h:406
void setExistingLayerDetectionDisabled(bool on)
Definition RTransaction.h:127
bool undoable
Child transactions of this transaction.
Definition RTransaction.h:356
QMap< RObject::Id, QList< RPropertyChange > > propertyChanges
Map of properties that are changed by this transaction.
Definition RTransaction.h:340
QMap< RObject::Id, RObject::Id > cloneIds
Definition RTransaction.h:433
void setKeepHandles(bool on)
Definition RTransaction.h:139
void setExistingBlockDetectionDisabled(bool on)
Definition RTransaction.h:123
void setAllowInvisible(bool on)
Definition RTransaction.h:115
QSet< RObject::Id > getStatusChanges() const
Definition RTransaction.h:255
int getGroup() const
Definition RTransaction.h:218
RTransaction::Types getTypes() const
Definition RTransaction.h:287
bool failed
True if this transaction failed.
Definition RTransaction.h:361
bool isFailed() const
Definition RTransaction.h:174
Redoes the last undone transaction of the current document.
Definition Redo.js:11
Undoes the last transaction of the current document.
Definition Undo.js:11
#define QCADCORE_EXPORT
Definition core_global.h:10
void deleteObject(void obj)
Deletes the given RObject from the drawing.
Definition simple_create.js:216
void addObject(void obj)
Adds the given RObject to the drawing.
Definition simple_create.js:97