Mercurial > hg > classical
comparison common/Objects.h @ 0:e8f4c2b55fd8 classical-rdf
* reorganise
author | Chris Cannam |
---|---|
date | Tue, 01 Dec 2009 17:50:41 +0000 |
parents | |
children | 29ca5974905d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e8f4c2b55fd8 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 #ifndef _CLASSICAL_DATA_OBJECTS_H_ | |
4 #define _CLASSICAL_DATA_OBJECTS_H_ | |
5 | |
6 #include <QObject> | |
7 #include <QMetaType> | |
8 #include <QString> | |
9 #include <QStringList> | |
10 #include <QSharedPointer> | |
11 #include <QUrl> | |
12 #include <QSet> | |
13 #include <QMutex> | |
14 #include <QMutexLocker> | |
15 #include <QMap> | |
16 | |
17 namespace ClassicalData { | |
18 | |
19 class HistoricalEvent : public QObject | |
20 { | |
21 Q_OBJECT | |
22 | |
23 Q_PROPERTY(int year READ year WRITE setYear STORED true) | |
24 Q_PROPERTY(QString place READ place WRITE setPlace STORED true) | |
25 Q_PROPERTY(bool approximate READ approximate WRITE setApproximate STORED true) | |
26 | |
27 public: | |
28 HistoricalEvent() : m_year(0), m_place(), m_approximate(false) { } | |
29 HistoricalEvent(int y) : m_year(y), m_approximate(false) { } | |
30 HistoricalEvent(int y, QString p) : m_year(y), m_place(p), m_approximate(false) { } | |
31 | |
32 int year() const { return m_year; } | |
33 void setYear(int y) { m_year = y; } | |
34 QString place() const { return m_place; } | |
35 void setPlace(QString p) { m_place = p; } | |
36 bool approximate() const { return m_approximate; } | |
37 void setApproximate(bool a) { m_approximate = a; } | |
38 | |
39 private: | |
40 int m_year; | |
41 QString m_place; | |
42 bool m_approximate; | |
43 }; | |
44 | |
45 class Birth : public HistoricalEvent | |
46 { | |
47 Q_OBJECT | |
48 | |
49 public: | |
50 Birth() : HistoricalEvent() { } | |
51 Birth(int y) : HistoricalEvent(y) { } | |
52 Birth(int y, QString p) : HistoricalEvent(y, p) { } | |
53 }; | |
54 | |
55 class Death : public HistoricalEvent | |
56 { | |
57 Q_OBJECT | |
58 | |
59 public: | |
60 Death() : HistoricalEvent() { } | |
61 Death(int y) : HistoricalEvent(y) { } | |
62 Death(int y, QString p) : HistoricalEvent(y, p) { } | |
63 }; | |
64 | |
65 class Composer; | |
66 class Work; | |
67 | |
68 class Composition : public HistoricalEvent | |
69 { | |
70 Q_OBJECT | |
71 | |
72 Q_PROPERTY(ClassicalData::Composer *composer READ composer WRITE setComposer STORED true) | |
73 Q_PROPERTY(QSet<ClassicalData::Work *> works READ works WRITE setWorks STORED true) | |
74 Q_PROPERTY(QString composerName READ composerName WRITE setComposerName STORED false) | |
75 | |
76 public: | |
77 Composition() : HistoricalEvent(), m_composer(0) { } | |
78 Composition(int y) : HistoricalEvent(y), m_composer(0) { } | |
79 Composition(int y, QString p) : HistoricalEvent(y, p), m_composer(0) { } | |
80 | |
81 Composer *composer() { return m_composer; } | |
82 void setComposer(Composer *c) { m_composer = c; } | |
83 | |
84 QSet<Work *> works() { return m_works; } | |
85 void setWorks(QSet<Work *> c) { m_works = c; } | |
86 void addWork(Work *w) { m_works.insert(w); } | |
87 | |
88 // Not a storable property, set temporarily while composer record is found | |
89 QString composerName() const { return m_cname; } | |
90 void setComposerName(QString n) { m_cname = n; } | |
91 | |
92 private: | |
93 Composer *m_composer; | |
94 QSet<Work *> m_works; | |
95 QString m_cname; | |
96 }; | |
97 | |
98 class Document : public QObject | |
99 { | |
100 Q_OBJECT | |
101 | |
102 Q_PROPERTY(QUrl uri READ uri WRITE setUri STORED true) | |
103 Q_PROPERTY(QString siteName READ siteName WRITE setSiteName STORED true) | |
104 Q_PROPERTY(QObject *topic READ topic WRITE setTopic STORED true) | |
105 | |
106 public: | |
107 Document(QObject *parent = 0) : QObject(parent), m_topic(0) { } | |
108 | |
109 QUrl uri() const { return m_uri; } | |
110 void setUri(QUrl uri) { m_uri = uri; } | |
111 | |
112 QString siteName() const { return m_siteName; } | |
113 void setSiteName(QString n) { m_siteName = n; } | |
114 | |
115 QObject *topic() const { return m_topic; } | |
116 void setTopic(QObject *t) { m_topic = t; } | |
117 | |
118 private: | |
119 QUrl m_uri; | |
120 QString m_siteName; | |
121 QObject *m_topic; | |
122 }; | |
123 | |
124 | |
125 class NamedEntity : public QObject | |
126 { | |
127 Q_OBJECT | |
128 | |
129 Q_PROPERTY(QString name READ name WRITE setName STORED true) | |
130 Q_PROPERTY(QSet<QString> aliases READ aliases WRITE setAliases STORED true) | |
131 Q_PROPERTY(QString remarks READ remarks WRITE setRemarks STORED true) | |
132 Q_PROPERTY(QSet<ClassicalData::Document*> pages READ pages WRITE setPages STORED true) | |
133 | |
134 public: | |
135 NamedEntity(QObject *parent = 0) : QObject(parent) { } | |
136 | |
137 QString name() const { return m_name; } | |
138 void setName(QString n) { m_name = n; } | |
139 | |
140 QString remarks() const { return m_remarks; } | |
141 void setRemarks(QString n) { m_remarks = n; } | |
142 | |
143 QSet<QString> aliases() const { return m_aliases; } | |
144 void setAliases(QSet<QString> l) { m_aliases = l; } | |
145 void addAlias(QString a) { m_aliases.insert(a); } | |
146 | |
147 QSet<Document *> pages() const { return m_pages; } | |
148 void addPage(Document *p) { m_pages.insert(p); } | |
149 void setPages(QSet<Document *> p) { m_pages = p; } //!!! destroy old ones? do we own? | |
150 | |
151 private: | |
152 QString m_name; | |
153 QString m_remarks; | |
154 QSet<QString> m_aliases; | |
155 QSet<Document *> m_pages; | |
156 }; | |
157 | |
158 class Movement; | |
159 | |
160 class Form; | |
161 | |
162 class Work : public NamedEntity | |
163 { | |
164 Q_OBJECT | |
165 | |
166 Q_PROPERTY(QString key READ key WRITE setKey STORED true) | |
167 Q_PROPERTY(QString opus READ opus WRITE setOpus STORED true) | |
168 Q_PROPERTY(QString catalogue READ catalogue WRITE setCatalogue STORED true) | |
169 Q_PROPERTY(QString number READ number WRITE setNumber STORED true) | |
170 Q_PROPERTY(QSet<ClassicalData::Form*> forms READ forms WRITE setForms STORED true) | |
171 Q_PROPERTY(ClassicalData::Work* partOf READ partOf WRITE setPartOf STORED true) | |
172 Q_PROPERTY(QSet<ClassicalData::Work*> parts READ parts WRITE setParts STORED true) | |
173 Q_PROPERTY(QSet<ClassicalData::Movement*> movements READ movements WRITE setMovements STORED true) | |
174 Q_PROPERTY(ClassicalData::Composition *composition READ composition WRITE setComposition STORED true) | |
175 | |
176 public: | |
177 Work(QObject *parent = 0) : NamedEntity(parent), m_partOf(0), m_composition(0) { } | |
178 | |
179 QString key() const { return m_key; } | |
180 void setKey(QString n) { m_key = n; } | |
181 | |
182 QString opus() const { return m_opus; } | |
183 void setOpus(QString n) { m_opus = n; } | |
184 | |
185 QString catalogue() const { return m_catalogue; } | |
186 void setCatalogue(QString n) { m_catalogue = n; } | |
187 | |
188 QString number() const { return m_number; } | |
189 void setNumber(QString n) { m_number = n; } | |
190 | |
191 QSet<Form *> forms() const { return m_forms; } | |
192 void setForms(QSet<Form *> f) { m_forms = f; } | |
193 void addForm(Form *f) { m_forms.insert(f); } | |
194 | |
195 Work *partOf() const { return m_partOf; } | |
196 void setPartOf(Work *w) { m_partOf = w; } | |
197 | |
198 QSet<Work *> parts() const { return m_parts; } | |
199 void setParts(QSet<Work *> l) { m_parts = l; } | |
200 void addPart(Work *w) { m_parts.insert(w); } | |
201 | |
202 QSet<Movement *> movements() const { return m_movements; } | |
203 void setMovements(QSet<Movement *> l) { m_movements = l; } | |
204 void addMovement(Movement *w) { m_movements.insert(w); } | |
205 | |
206 Composition *composition() { return m_composition; } | |
207 const Composition *composition() const { return m_composition; } | |
208 void setComposition(Composition *c) { m_composition = c; } | |
209 | |
210 struct Ordering { | |
211 bool operator()(Work *, Work *); | |
212 }; | |
213 | |
214 private: | |
215 QString m_key; | |
216 QString m_opus; | |
217 QString m_catalogue; | |
218 QString m_number; | |
219 QSet<Form *> m_forms; | |
220 Work *m_partOf; | |
221 QSet<Work *> m_parts; | |
222 QSet<Movement *> m_movements; | |
223 Composition *m_composition; | |
224 }; | |
225 | |
226 class Movement : public NamedEntity | |
227 { | |
228 Q_OBJECT | |
229 | |
230 Q_PROPERTY(QString key READ key WRITE setKey STORED true) | |
231 Q_PROPERTY(QString number READ number WRITE setNumber STORED true) | |
232 Q_PROPERTY(ClassicalData::Work* partOf READ partOf WRITE setPartOf STORED true) | |
233 Q_PROPERTY(QSet<ClassicalData::Movement*> parts READ parts WRITE setParts STORED true) // movements can be nested | |
234 Q_PROPERTY(ClassicalData::Composition *composition READ composition WRITE setComposition STORED true) | |
235 | |
236 public: | |
237 Movement(QObject *parent = 0) : NamedEntity(parent), m_partOf(0), m_composition(0) { } | |
238 | |
239 QString key() const { return m_key; } | |
240 void setKey(QString n) { m_key = n; } | |
241 | |
242 QString number() const { return m_number; } | |
243 void setNumber(QString n) { m_number = n; } | |
244 | |
245 Work *partOf() const { return m_partOf; } | |
246 void setPartOf(Work *w) { m_partOf = w; } | |
247 | |
248 QSet<Movement *> parts() const { return m_parts; } | |
249 void setParts(QSet<Movement *> l) { m_parts = l; } | |
250 void addPart(Movement *w) { m_parts.insert(w); } | |
251 | |
252 Composition *composition() { return m_composition; } | |
253 const Composition *composition() const { return m_composition; } | |
254 void setComposition(Composition *c) { m_composition = c; } | |
255 | |
256 private: | |
257 QString m_key; | |
258 QString m_number; | |
259 Work *m_partOf; | |
260 QSet<Movement *> m_parts; | |
261 Composition *m_composition; | |
262 }; | |
263 | |
264 class Composer : public NamedEntity | |
265 { | |
266 Q_OBJECT | |
267 | |
268 Q_PROPERTY(QString gender READ gender WRITE setGender STORED true) | |
269 Q_PROPERTY(QString nationality READ nationality WRITE setNationality STORED true) | |
270 Q_PROPERTY(QString period READ period WRITE setPeriod STORED true) | |
271 Q_PROPERTY(ClassicalData::Birth *birth READ birth WRITE setBirth STORED true) | |
272 Q_PROPERTY(ClassicalData::Death *death READ death WRITE setDeath STORED true) | |
273 | |
274 public: | |
275 Composer(QObject *parent = 0) : NamedEntity(parent), m_birth(0), m_death(0) { } | |
276 | |
277 QString gender() const { return m_gender; } | |
278 void setGender(QString n) { m_gender = n; } | |
279 | |
280 QString nationality() const { return m_nationality; } | |
281 void setNationality(QString n) { m_nationality = n; } | |
282 | |
283 QString period() const { return m_period; } | |
284 void setPeriod(QString n) { m_period = n; } | |
285 | |
286 Birth *birth() { return m_birth; } | |
287 const Birth *birth() const { return m_birth; } | |
288 void setBirth(Birth *b) { m_birth = b; } | |
289 | |
290 Death *death() { return m_death; } | |
291 const Death *death() const { return m_death; } | |
292 void setDeath(Death *d) { m_death = d; } | |
293 | |
294 QString getSortName(bool caps) const; | |
295 QString getDisplayDates() const; | |
296 | |
297 private: | |
298 QString m_gender; | |
299 QString m_nationality; | |
300 QString m_period; | |
301 Birth *m_birth; | |
302 Death *m_death; | |
303 }; | |
304 | |
305 class Form : public NamedEntity | |
306 { | |
307 Q_OBJECT | |
308 | |
309 Q_PROPERTY(QString uri READ uri) | |
310 | |
311 public: | |
312 Form(QObject *parent = 0) : NamedEntity(parent) { } | |
313 | |
314 static Form *getFormByName(QString name) { | |
315 QMutexLocker locker(&m_mutex); | |
316 if (!m_map.contains(name)) { | |
317 Form *f = new Form(); | |
318 f->setName(name); | |
319 m_map[name] = f; | |
320 } | |
321 return m_map[name]; | |
322 } | |
323 | |
324 QString uri() const { | |
325 return QString(":form_%1").arg(name()).toLower().replace(' ', '_'); | |
326 } | |
327 | |
328 private: | |
329 static QMap<QString, Form *> m_map; | |
330 static QMutex m_mutex; | |
331 }; | |
332 | |
333 } | |
334 | |
335 Q_DECLARE_METATYPE(ClassicalData::HistoricalEvent*); | |
336 Q_DECLARE_METATYPE(ClassicalData::Birth*); | |
337 Q_DECLARE_METATYPE(ClassicalData::Death*); | |
338 Q_DECLARE_METATYPE(ClassicalData::Composition*); | |
339 Q_DECLARE_METATYPE(ClassicalData::Work*); | |
340 Q_DECLARE_METATYPE(ClassicalData::Movement*); | |
341 Q_DECLARE_METATYPE(ClassicalData::Document*); | |
342 Q_DECLARE_METATYPE(QSet<QString>); | |
343 Q_DECLARE_METATYPE(QSet<ClassicalData::Work*>); | |
344 Q_DECLARE_METATYPE(QSet<ClassicalData::Movement*>); | |
345 Q_DECLARE_METATYPE(QSet<ClassicalData::Document*>); | |
346 Q_DECLARE_METATYPE(ClassicalData::Composer*); | |
347 Q_DECLARE_METATYPE(ClassicalData::Form*); | |
348 Q_DECLARE_METATYPE(QSet<ClassicalData::Form*>); | |
349 | |
350 #endif |