diff options
Diffstat (limited to 'common/domain')
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 45 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 60 | ||||
-rw-r--r-- | common/domain/event.cpp | 2 |
3 files changed, 86 insertions, 21 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index b0433be..df10327 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -64,6 +64,12 @@ ApplicationDomainType::~ApplicationDomainType() | |||
64 | { | 64 | { |
65 | } | 65 | } |
66 | 66 | ||
67 | bool ApplicationDomainType::hasProperty(const QByteArray &key) const | ||
68 | { | ||
69 | Q_ASSERT(mAdaptor); | ||
70 | return mAdaptor->availableProperties().contains(key); | ||
71 | } | ||
72 | |||
67 | QVariant ApplicationDomainType::getProperty(const QByteArray &key) const | 73 | QVariant ApplicationDomainType::getProperty(const QByteArray &key) const |
68 | { | 74 | { |
69 | Q_ASSERT(mAdaptor); | 75 | Q_ASSERT(mAdaptor); |
@@ -76,13 +82,18 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const | |||
76 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) | 82 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) |
77 | { | 83 | { |
78 | Q_ASSERT(mAdaptor); | 84 | Q_ASSERT(mAdaptor); |
79 | mChangeSet.insert(key, value); | 85 | mChangeSet.insert(key); |
80 | mAdaptor->setProperty(key, value); | 86 | mAdaptor->setProperty(key, value); |
81 | } | 87 | } |
82 | 88 | ||
89 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) | ||
90 | { | ||
91 | mChangeSet = changeset; | ||
92 | } | ||
93 | |||
83 | QByteArrayList ApplicationDomainType::changedProperties() const | 94 | QByteArrayList ApplicationDomainType::changedProperties() const |
84 | { | 95 | { |
85 | return mChangeSet.keys(); | 96 | return mChangeSet.toList(); |
86 | } | 97 | } |
87 | 98 | ||
88 | qint64 ApplicationDomainType::revision() const | 99 | qint64 ApplicationDomainType::revision() const |
@@ -100,6 +111,36 @@ QByteArray ApplicationDomainType::identifier() const | |||
100 | return mIdentifier; | 111 | return mIdentifier; |
101 | } | 112 | } |
102 | 113 | ||
114 | Entity::~Entity() | ||
115 | { | ||
116 | |||
117 | } | ||
118 | |||
119 | Event::~Event() | ||
120 | { | ||
121 | |||
122 | } | ||
123 | |||
124 | Todo::~Todo() | ||
125 | { | ||
126 | |||
127 | } | ||
128 | |||
129 | Mail::~Mail() | ||
130 | { | ||
131 | |||
132 | } | ||
133 | |||
134 | Folder::~Folder() | ||
135 | { | ||
136 | |||
137 | } | ||
138 | |||
139 | SinkResource::~SinkResource() | ||
140 | { | ||
141 | |||
142 | } | ||
143 | |||
103 | template<> | 144 | template<> |
104 | QByteArray getTypeName<Event>() | 145 | QByteArray getTypeName<Event>() |
105 | { | 146 | { |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 63f030c..32d8999 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -19,9 +19,11 @@ | |||
19 | */ | 19 | */ |
20 | #pragma once | 20 | #pragma once |
21 | 21 | ||
22 | #include "sink_export.h" | ||
22 | #include <QSharedPointer> | 23 | #include <QSharedPointer> |
23 | #include <QVariant> | 24 | #include <QVariant> |
24 | #include <QByteArray> | 25 | #include <QByteArray> |
26 | #include <QDebug> | ||
25 | #include "bufferadaptor.h" | 27 | #include "bufferadaptor.h" |
26 | 28 | ||
27 | namespace Sink { | 29 | namespace Sink { |
@@ -35,7 +37,7 @@ namespace ApplicationDomain { | |||
35 | * | 37 | * |
36 | * ApplicationDomainTypes don't adhere to any standard and are meant to be extended frequently (hence the non-typesafe interface). | 38 | * ApplicationDomainTypes don't adhere to any standard and are meant to be extended frequently (hence the non-typesafe interface). |
37 | */ | 39 | */ |
38 | class ApplicationDomainType { | 40 | class SINK_EXPORT ApplicationDomainType { |
39 | public: | 41 | public: |
40 | typedef QSharedPointer<ApplicationDomainType> Ptr; | 42 | typedef QSharedPointer<ApplicationDomainType> Ptr; |
41 | 43 | ||
@@ -55,16 +57,19 @@ public: | |||
55 | 57 | ||
56 | virtual ~ApplicationDomainType(); | 58 | virtual ~ApplicationDomainType(); |
57 | 59 | ||
58 | virtual QVariant getProperty(const QByteArray &key) const; | 60 | bool hasProperty(const QByteArray &key) const; |
59 | virtual void setProperty(const QByteArray &key, const QVariant &value); | 61 | QVariant getProperty(const QByteArray &key) const; |
60 | virtual QByteArrayList changedProperties() const; | 62 | void setProperty(const QByteArray &key, const QVariant &value); |
63 | void setChangedProperties(const QSet<QByteArray> &changeset); | ||
64 | QByteArrayList changedProperties() const; | ||
61 | qint64 revision() const; | 65 | qint64 revision() const; |
62 | QByteArray resourceInstanceIdentifier() const; | 66 | QByteArray resourceInstanceIdentifier() const; |
63 | QByteArray identifier() const; | 67 | QByteArray identifier() const; |
64 | 68 | ||
65 | private: | 69 | private: |
70 | friend QDebug operator<<(QDebug, const ApplicationDomainType &); | ||
66 | QSharedPointer<BufferAdaptor> mAdaptor; | 71 | QSharedPointer<BufferAdaptor> mAdaptor; |
67 | QHash<QByteArray, QVariant> mChangeSet; | 72 | QSet<QByteArray> mChangeSet; |
68 | /* | 73 | /* |
69 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. | 74 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. |
70 | */ | 75 | */ |
@@ -82,34 +87,50 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain | |||
82 | && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier(); | 87 | && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier(); |
83 | } | 88 | } |
84 | 89 | ||
85 | struct Entity : public ApplicationDomainType { | 90 | inline QDebug operator<< (QDebug d, const ApplicationDomainType &type) |
91 | { | ||
92 | d << "ApplicationDomainType(\n"; | ||
93 | for (const auto &property : type.mAdaptor->availableProperties()) { | ||
94 | d << " " << property << "\t" << type.getProperty(property) << "\n"; | ||
95 | } | ||
96 | d << ")"; | ||
97 | return d; | ||
98 | } | ||
99 | |||
100 | struct SINK_EXPORT Entity : public ApplicationDomainType { | ||
86 | typedef QSharedPointer<Entity> Ptr; | 101 | typedef QSharedPointer<Entity> Ptr; |
87 | using ApplicationDomainType::ApplicationDomainType; | 102 | using ApplicationDomainType::ApplicationDomainType; |
103 | virtual ~Entity(); | ||
88 | }; | 104 | }; |
89 | 105 | ||
90 | struct Event : public Entity { | 106 | struct SINK_EXPORT Event : public Entity { |
91 | typedef QSharedPointer<Event> Ptr; | 107 | typedef QSharedPointer<Event> Ptr; |
92 | using Entity::Entity; | 108 | using Entity::Entity; |
109 | virtual ~Event(); | ||
93 | }; | 110 | }; |
94 | 111 | ||
95 | struct Todo : public Entity { | 112 | struct SINK_EXPORT Todo : public Entity { |
96 | typedef QSharedPointer<Todo> Ptr; | 113 | typedef QSharedPointer<Todo> Ptr; |
97 | using Entity::Entity; | 114 | using Entity::Entity; |
115 | virtual ~Todo(); | ||
98 | }; | 116 | }; |
99 | 117 | ||
100 | struct Calendar : public Entity { | 118 | struct SINK_EXPORT Calendar : public Entity { |
101 | typedef QSharedPointer<Calendar> Ptr; | 119 | typedef QSharedPointer<Calendar> Ptr; |
102 | using Entity::Entity; | 120 | using Entity::Entity; |
121 | virtual ~Calendar(); | ||
103 | }; | 122 | }; |
104 | 123 | ||
105 | struct Mail : public Entity { | 124 | struct SINK_EXPORT Mail : public Entity { |
106 | typedef QSharedPointer<Mail> Ptr; | 125 | typedef QSharedPointer<Mail> Ptr; |
107 | using Entity::Entity; | 126 | using Entity::Entity; |
127 | virtual ~Mail(); | ||
108 | }; | 128 | }; |
109 | 129 | ||
110 | struct Folder : public Entity { | 130 | struct SINK_EXPORT Folder : public Entity { |
111 | typedef QSharedPointer<Folder> Ptr; | 131 | typedef QSharedPointer<Folder> Ptr; |
112 | using Entity::Entity; | 132 | using Entity::Entity; |
133 | virtual ~Folder(); | ||
113 | }; | 134 | }; |
114 | 135 | ||
115 | /** | 136 | /** |
@@ -118,9 +139,10 @@ struct Folder : public Entity { | |||
118 | * This type is used for configuration of resources, | 139 | * This type is used for configuration of resources, |
119 | * and for creating and removing resource instances. | 140 | * and for creating and removing resource instances. |
120 | */ | 141 | */ |
121 | struct SinkResource : public ApplicationDomainType { | 142 | struct SINK_EXPORT SinkResource : public ApplicationDomainType { |
122 | typedef QSharedPointer<SinkResource> Ptr; | 143 | typedef QSharedPointer<SinkResource> Ptr; |
123 | using ApplicationDomainType::ApplicationDomainType; | 144 | using ApplicationDomainType::ApplicationDomainType; |
145 | virtual ~SinkResource(); | ||
124 | }; | 146 | }; |
125 | 147 | ||
126 | /** | 148 | /** |
@@ -129,22 +151,22 @@ struct SinkResource : public ApplicationDomainType { | |||
129 | * Do not store these types to disk, they may change over time. | 151 | * Do not store these types to disk, they may change over time. |
130 | */ | 152 | */ |
131 | template<class DomainType> | 153 | template<class DomainType> |
132 | QByteArray getTypeName(); | 154 | QByteArray SINK_EXPORT getTypeName(); |
133 | 155 | ||
134 | template<> | 156 | template<> |
135 | QByteArray getTypeName<Event>(); | 157 | QByteArray SINK_EXPORT getTypeName<Event>(); |
136 | 158 | ||
137 | template<> | 159 | template<> |
138 | QByteArray getTypeName<Todo>(); | 160 | QByteArray SINK_EXPORT getTypeName<Todo>(); |
139 | 161 | ||
140 | template<> | 162 | template<> |
141 | QByteArray getTypeName<SinkResource>(); | 163 | QByteArray SINK_EXPORT getTypeName<SinkResource>(); |
142 | 164 | ||
143 | template<> | 165 | template<> |
144 | QByteArray getTypeName<Mail>(); | 166 | QByteArray SINK_EXPORT getTypeName<Mail>(); |
145 | 167 | ||
146 | template<> | 168 | template<> |
147 | QByteArray getTypeName<Folder>(); | 169 | QByteArray SINK_EXPORT getTypeName<Folder>(); |
148 | 170 | ||
149 | /** | 171 | /** |
150 | * Type implementation. | 172 | * Type implementation. |
@@ -153,7 +175,7 @@ QByteArray getTypeName<Folder>(); | |||
153 | * Contains all non-resource specific, but type-specific code. | 175 | * Contains all non-resource specific, but type-specific code. |
154 | */ | 176 | */ |
155 | template<typename DomainType> | 177 | template<typename DomainType> |
156 | class TypeImplementation; | 178 | class SINK_EXPORT TypeImplementation; |
157 | 179 | ||
158 | } | 180 | } |
159 | } | 181 | } |
diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 9f81eb8..4210125 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp | |||
@@ -69,6 +69,7 @@ QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImple | |||
69 | { | 69 | { |
70 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | 70 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |
71 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); | 71 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); |
72 | propertyMapper->addMapping<QString, Buffer>("description", &Buffer::description); | ||
72 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); | 73 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); |
73 | propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment); | 74 | propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment); |
74 | return propertyMapper; | 75 | return propertyMapper; |
@@ -78,6 +79,7 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > T | |||
78 | { | 79 | { |
79 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); | 80 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); |
80 | propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); | 81 | propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); |
82 | propertyMapper->addMapping<QString>("description", &BufferBuilder::add_description); | ||
81 | propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); | 83 | propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); |
82 | propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment); | 84 | propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment); |
83 | return propertyMapper; | 85 | return propertyMapper; |