C++: define Duration as a metatype in Qt to be able to parse it in
[smartapi.git] / Common / C++ / SmartAPI / smartapi / model / TemporalContext.h
1 #ifndef _TEMPORALCONTEXT_H_
2 #define _TEMPORALCONTEXT_H_
3
4 #include <QString>
5 #include <QDateTime>
6
7 #include "smartapi/common/PROPERTY.h"
8 #include "smartapi/common/Duration.h"
9 #include "smartapi/model/Obj.h"
10 #include "smartapi/rdf/Variant.h"
11
12 class Model;
13 class Resource;
14 class Statement;
15
16 class TemporalContext : public Obj
17 {
18 public:
19         TemporalContext();
20         TemporalContext(QString uri);
21         TemporalContext(QDateTime mStart, QDateTime mEnd);
22         TemporalContext(QDateTime mStart, QDateTime mEnd, QString mDuring);
23         TemporalContext(QDateTime mStart);
24         TemporalContext(QTime mStart, QTime mEnd);
25         TemporalContext(QTime mStart, QTime mEnd, QString mDuring);
26         TemporalContext(QTime mStart);
27         TemporalContext(TemporalContext* t);
28         ~TemporalContext();
29
30         Resource* serialize(Model* model);
31         void parse(Statement* statement);
32         void clearReferences(QSet<GraphItem*>* trash);
33         
34         bool hasStart()                                         { return (mStart != nullptr); }
35         QDateTime getStart()                            { PROPERTYVAL(mStart, asDateTime, QDateTime()); }
36         QTime getStartTime()                            { PROPERTYVAL(mStart, asTime, QTime()); }
37         void setStart(Variant* s)                       { add(PROPERTY__START, s); mStart = s; }
38         void setStart(QDateTime _start)         { setStart(new Variant(_start)); }
39         void setStart(QTime _start)                     { setStart(new Variant(_start)); }
40
41         bool hasEnd()                                           { return (mEnd != nullptr); }
42         QDateTime getEnd()                                      { PROPERTYVAL(mEnd, asDateTime, QDateTime()); }
43         QTime getEndTime()                                      { PROPERTYVAL(mEnd, asTime, QTime()); }
44         void setEnd(Variant* e)                         { add(PROPERTY__END, e); mEnd = e; }
45         void setEnd(QDateTime _end)                     { setEnd(new Variant(_end)); }
46         void setEnd(QTime _end)                         { setEnd(new Variant(_end)); }
47
48         bool hasCount()                                         { return mCount != nullptr; }
49         int getCount()                                          { PROPERTYVAL(mCount, asInt, -1); }
50         void setCount(Variant* c)                       { add(PROPERTY__COUNT, c); mCount = c; }
51         void setCount(int _count)                       { setCount(new Variant(_count)); }
52
53         bool hasDuration()                                      { return mDuration != nullptr; }
54         QString getDuration()                           { return (mDuration != nullptr ? mDuration->asDuration()->toString() : QString()); }
55         Duration* getDurationObject()           { return (mDuration != nullptr ? mDuration->asDuration() : nullptr); }
56         void setDuration(Variant* d)            { add(PROPERTY__DURATION, d); mDuration = d; }
57         void setDuration(Duration* d)           { setDuration(new Variant(d)); }
58         void setDuration(QString _duration)     { setDuration(new Duration(_duration)); }
59
60         bool hasDuring()                                        { return mDuring != nullptr; }
61         QString getDuring()                                     { PROPERTYVAL(mDuring, asString, QString()); }
62         void setDuring(Variant* d)                      { add(PROPERTY__DURING, d); mDuring = d; }
63         void setDuring(QString _during)         { setDuring(new Variant(_during)); }
64
65 private:
66         Variant* mStart;
67         Variant* mEnd;
68         Variant* mCount;
69         Variant* mDuring;
70         Variant* mDuration;
71 };
72
73 #endif // _TEMPORALCONTEXT_H_