|
1 #include "modelobject.h" |
|
2 |
|
3 static Uuid &getUuidForNewObject() |
|
4 { |
|
5 static Uuid running_uuid {0, 0}; |
|
6 incrementUuid(running_uuid); |
|
7 return running_uuid; |
|
8 } |
|
9 |
|
10 modelobjects::BaseObject::BaseObject() : |
|
11 id {getUuidForNewObject()} |
|
12 { |
|
13 } |
|
14 |
|
15 modelobjects::BaseObject::~BaseObject() |
|
16 { |
|
17 } |
|
18 |
|
19 bool modelobjects::BaseObject::hasColor() const |
|
20 { |
|
21 return false; |
|
22 } |
|
23 |
|
24 QVariant modelobjects::BaseObject::getProperty(Property id) const |
|
25 { |
|
26 Q_UNUSED(id); |
|
27 return {}; |
|
28 } |
|
29 |
|
30 auto modelobjects::BaseObject::setProperty(Property id, const QVariant& value) |
|
31 -> SetPropertyResult |
|
32 { |
|
33 Q_UNUSED(id) |
|
34 Q_UNUSED(value) |
|
35 return SetPropertyResult::PropertyNotHandled; |
|
36 } |
|
37 |
|
38 modelobjects::ColoredBaseObject::ColoredBaseObject(const Color color_index) : |
|
39 color_index{color_index} |
|
40 { |
|
41 } |
|
42 |
|
43 bool modelobjects::ColoredBaseObject::hasColor() const |
|
44 { |
|
45 return true; |
|
46 } |
|
47 |
|
48 QVariant modelobjects::ColoredBaseObject::getProperty(Property id) const |
|
49 { |
|
50 switch (id) |
|
51 { |
|
52 case Property::Color: |
|
53 return color_index.index; |
|
54 default: |
|
55 return BaseObject::getProperty(id); |
|
56 } |
|
57 } |
|
58 |
|
59 auto modelobjects::ColoredBaseObject::setProperty(Property id, const QVariant& value) |
|
60 -> SetPropertyResult |
|
61 { |
|
62 switch (id) |
|
63 { |
|
64 case Property::Color: |
|
65 { |
|
66 bool ok; |
|
67 const int value_int = value.toInt(&ok); |
|
68 if (ok) |
|
69 { |
|
70 color_index.index = value_int; |
|
71 return SetPropertyResult::Success; |
|
72 } |
|
73 else |
|
74 { |
|
75 return SetPropertyResult::InvalidValue; |
|
76 } |
|
77 } |
|
78 default: |
|
79 return BaseObject::setProperty(id, value); |
|
80 } |
|
81 } |