ACF $AcfVersion:0$
IChangeable.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QString>
7#include <QtCore/QSet>
8#include <QtCore/QVariant>
9#include <QtCore/QMap>
10
11// ACF includes
12#include <istd/IPolymorphic.h>
13#include <istd/TInterfacePtr.h>
14
15
16namespace istd
17{
18
19
27class IChangeable: virtual public IPolymorphic
28{
29public:
30 typedef QMultiMap<QByteArray,QVariant> ChangeInfoMap;
31
36 {
37 public:
39 explicit ChangeSet(const QString& description);
40 explicit ChangeSet(int id1, const QString& description = "");
41 ChangeSet(int id1, int id2, const QString& description = "");
42 ChangeSet(int id1, int id2, int id3, const QString& description = "");
43 ChangeSet(int id1, int id2, int id3, int id4, const QString& description = "");
44 ChangeSet(int id1, int id2, int id3, int id4, int id5, const QString& description = "");
45 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, const QString& description = "");
46 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, const QString& description = "");
47 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, const QString& description = "");
48 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, const QString& description = "");
49 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, int id10, const QString& description = "");
50
54 void Reset();
55
59 bool IsEmpty() const;
63 bool Contains(int changeId) const;
70 bool ContainsExplicit(int changeId, bool singleOnly = false) const;
74 bool ContainsAny(const ChangeSet& changeSet) const;
75
79 void MaskOut(const ChangeSet& changeSet);
80
84 const QString& GetDescription() const;
85
90 QSet<int> GetIds() const;
91
96
100 void SetChangeInfoMap(const ChangeInfoMap& infoMap);
101
105 QVariant GetChangeInfo(const QByteArray& key) const;
106
110 void SetChangeInfo(const QByteArray& key, const QVariant& value);
111
115 ChangeSet operator+(const ChangeSet& changeSet) const;
116
120 ChangeSet& operator+=(int changeId);
121
125 ChangeSet& operator+=(const QSet<int>& ids);
126
130 ChangeSet& operator+=(const ChangeSet& changeSet);
131
132 private:
133 QSet<int> m_ids;
134
135 ChangeInfoMap m_infoMap;
136
137 QString m_description;
138 };
139
176
182 {
187
191 SO_OBSERVE = 1 << 0,
192
196 SO_COPY = 1 << 1,
197
201 SO_CLONE = 1 << 2,
202
206 SO_COMPARE = 1 << 3,
207
211 SO_RESET = 1 << 4
212 };
213
242
247 virtual int GetSupportedOperations() const;
248
253 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
254
260 virtual bool IsEqual(const IChangeable& object) const;
261
267
273 virtual bool ResetData(CompatibilityMode mode = CM_WITHOUT_REFS);
274
280 virtual void BeginChanges(const ChangeSet& changeSet);
281
289 virtual void EndChanges(const ChangeSet& changeSet);
290
297 virtual void BeginChangeGroup(const ChangeSet& changeSet);
298
305 virtual void EndChangeGroup(const ChangeSet& changeSet);
306
307 // static methods
311 static const ChangeSet& GetNoChanges();
312
316 static const ChangeSet& GetAnyChange();
317
321 static const ChangeSet& GetAllChanges();
322
326 static const ChangeSet& GetDelegatedChanges();
327
328protected:
333 virtual void OnBeginChanges();
334
338 virtual void OnEndChanges(const ChangeSet& changeSet);
339
340private:
341 // static attributes
342 static const ChangeSet s_emptyChanges;
343 static const ChangeSet s_anyChanges;
344 static const ChangeSet s_allChanges;
345 static const ChangeSet s_delegatedChanges;
346};
347
348
349// public inline methods
350
352{
353 return SO_NONE;
354}
355
356
357inline bool IChangeable::CopyFrom(const IChangeable& /*object*/, CompatibilityMode /*mode*/)
358{
359 return false;
360}
361
362
363inline bool IChangeable::IsEqual(const IChangeable& /*object*/) const
364{
365 return false;
366}
367
368
373
374
376{
377 return false;
378}
379
380
381inline void IChangeable::BeginChanges(const ChangeSet& /*changeSet*/)
382{
384}
385
386
387inline void IChangeable::EndChanges(const ChangeSet& changeSet)
388{
389 OnEndChanges(changeSet);
390}
391
392
393inline void IChangeable::BeginChangeGroup(const ChangeSet& /*changeSet*/)
394{
395}
396
397
398inline void IChangeable::EndChangeGroup(const ChangeSet& /*changeSet*/)
399{
400}
401
402
403// public static inline methods
408{
409 return s_emptyChanges;
410}
411
412
414{
415 return s_anyChanges;
416}
417
418
420{
421 return s_allChanges;
422}
423
424
426{
427 return s_delegatedChanges;
428}
429
430
431// protected inline methods
432
434{
435}
436
437
438inline void IChangeable::OnEndChanges(const ChangeSet& /*changeSet*/)
439{
440}
441
442
445
446
447bool AreObjectsEqual(const IChangeable* a, const IChangeable* b);
448
449
450} // namespace istd
451
452
Set of change flags (its IDs).
Definition IChangeable.h:36
ChangeSet(int id1, int id2, int id3, int id4, const QString &description="")
QSet< int > GetIds() const
Get set of all stored IDs.
ChangeSet operator+(const ChangeSet &changeSet) const
Get the union of two change sets.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, const QString &description="")
void SetChangeInfoMap(const ChangeInfoMap &infoMap)
Set map of all stored info.
bool IsEmpty() const
Check if there is any change in the set.
ChangeSet(const QString &description)
ChangeSet & operator+=(int changeId)
Add some change flag.
ChangeSet(int id1, int id2, const QString &description="")
void MaskOut(const ChangeSet &changeSet)
Remove the IDs from the second set.
ChangeSet(int id1, const QString &description="")
QVariant GetChangeInfo(const QByteArray &key) const
Get change info by a key.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, const QString &description="")
bool ContainsExplicit(int changeId, bool singleOnly=false) const
Check if there is specific change flag in the set explicit set by user.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, const QString &description="")
void Reset()
Remove all IDs.
ChangeSet & operator+=(const ChangeSet &changeSet)
Add some change set.
bool Contains(int changeId) const
Check if there is specific change flag in the set.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, int id10, const QString &description="")
const ChangeInfoMap & GetChangeInfoMap() const
Get information about the changes.
bool ContainsAny(const ChangeSet &changeSet) const
Check if any of IDs is changed.
ChangeSet(int id1, int id2, int id3, int id4, int id5, const QString &description="")
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, const QString &description="")
void SetChangeInfo(const QByteArray &key, const QVariant &value)
Set change info for a defined key.
ChangeSet(int id1, int id2, int id3, const QString &description="")
ChangeSet & operator+=(const QSet< int > &ids)
Add some change flags.
const QString & GetDescription() const
Get textual description of this change set.
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
static const ChangeSet & GetAllChanges()
Get anonymous change set.
virtual void BeginChanges(const ChangeSet &changeSet)
Starts the change transaction.
virtual bool ResetData(CompatibilityMode mode=CM_WITHOUT_REFS)
Reset data to its default state.
virtual bool IsEqual(const IChangeable &object) const
Compare this object with another object.
static const ChangeSet & GetNoChanges()
Get empty set of changes.
virtual void EndChangeGroup(const ChangeSet &changeSet)
Ends group of changes.
virtual void BeginChangeGroup(const ChangeSet &changeSet)
Starts group of changes.
virtual void EndChanges(const ChangeSet &changeSet)
Ends the change transaction.
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
@ CM_WITH_REFS
External references are part of object integrity.
@ CM_STRICT
If external references are different this object are not compatible and cannot be compared or copied.
@ CM_CONVERT
Data of object are interpreted in context of external references.
QMultiMap< QByteArray, QVariant > ChangeInfoMap
Definition IChangeable.h:30
static const ChangeSet & GetDelegatedChanges()
Get delegated change set.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
Copy this object from another one.
virtual int GetSupportedOperations() const
Get set of flags for supported operations.
virtual void OnBeginChanges()
Callback function for begin change event.
ChangeFlags
Data model change notification flags.
@ CF_ALL_DATA
All object data are changed.
@ CF_ACF_INTERNAL
Internal ACF flag.
@ CF_NO_UNDO
Used to avoid adding of changes to undo list.
@ CF_ANY
Indicate anonymous change.
@ CF_DESTROYING
Change flag indicate that model is during destruction.
@ CF_DELEGATED
Change flag indicate that this change was delegated (is indirect) for example from aggregated object.
virtual istd::TUniqueInterfacePtr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const
Make a copy of this object.
SupportedOperations
Flags for supported operations.
@ SO_COPY
Copying from other object.
@ SO_RESET
Resetting of object state.
@ SO_NONE
No operations are supported.
@ SO_CLONE
Creating of copy of this object.
@ SO_COMPARE
Comparison with another object.
@ SO_OBSERVE
Observing of this object via observer-observable pattern.
virtual void OnEndChanges(const ChangeSet &changeSet)
Callback function for end change event.
static const ChangeSet & GetAnyChange()
Get anonymous change set.
Base interface for all used interfaces and implementations.
Shared ownership smart pointer for interface types.
Unique ownership smart pointer for interface types.
Standard library.
Definition IComponent.h:17
istd::TSharedInterfacePtr< istd::IChangeable > IChangeableSharedPtr
bool AreObjectsEqual(const IChangeable *a, const IChangeable *b)
istd::TUniqueInterfacePtr< istd::IChangeable > IChangeableUniquePtr