src/linetypes/object.cpp

changeset 200
ca23936b455b
parent 199
6988973515d2
child 201
5d201ee4a9c3
equal deleted inserted replaced
199:6988973515d2 200:ca23936b455b
1 #include <QBrush>
2 #include <QFont>
3 #include "object.h"
4 #include "widgets/vec3editor.h"
5 #include "modeleditor.h"
6
7 static std::int32_t getIdForNewObject()
8 {
9 static std::int32_t id = 0;
10 id += 1;
11 return id;
12 }
13
14 ldraw::Object::Object() :
15 id {getIdForNewObject()}
16 {
17 }
18
19 ldraw::Object::~Object()
20 {
21 }
22
23 bool ldraw::Object::hasColor() const
24 {
25 return false;
26 }
27
28 QVariant ldraw::Object::getProperty(Property id) const
29 {
30 Q_UNUSED(id);
31 return {};
32 }
33
34 void ldraw::Object::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
35 {
36 Q_UNUSED(result)
37 Q_UNUSED(pair)
38 }
39
40 /**
41 * @brief public interface to setProperty
42 */
43 ldraw::Object::SetPropertyResult ldraw::Object::setProperty(const PropertyKeyValue& pair)
44 {
45 SetPropertyResult result;
46 this->setProperty(&result, pair);
47 return result;
48 }
49
50 QBrush ldraw::Object::textRepresentationForeground() const
51 {
52 return {};
53 }
54
55 QBrush ldraw::Object::textRepresentationBackground() const
56 {
57 return {};
58 }
59
60 QFont ldraw::Object::textRepresentationFont() const
61 {
62 return {};
63 }
64
65 void ldraw::Object::getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const
66 {
67 Q_UNUSED(polygons)
68 Q_UNUSED(context)
69 }
70
71 const glm::vec3& ldraw::Object::getPoint(int index) const
72 {
73 Q_UNUSED(index);
74 throw BadPointIndex{};
75 }
76
77 /**
78 * @brief Serializes the object into a stream of bytes for internal storage.
79 * @param stream Data stream to serialize into
80 */
81 QDataStream& ldraw::Object::serialize(QDataStream &stream) const
82 {
83 return stream << static_cast<int>(this->typeIdentifier());
84 }
85
86 /**
87 * @brief Deserializes the object from a stream of bytes coming from internal storage.
88 * @param stream Data stream to serialize from.
89 * @note @c ldraw::Object::serialize will insert a type enumerator. Before calling this function,
90 * this enumerator is assumed to have been handled as the object class needs to be initialized based
91 * on the value of this enumerator.
92 */
93 QDataStream& ldraw::Object::deserialize(QDataStream &stream)
94 {
95 return stream;
96 }
97
98 QString ldraw::Object::iconName() const
99 {
100 return "";
101 }
102
103 ldraw::ColoredObject::ColoredObject(const Color color_index) :
104 colorIndex{color_index}
105 {
106 }
107
108 bool ldraw::ColoredObject::hasColor() const
109 {
110 return true;
111 }
112
113 QVariant ldraw::ColoredObject::getProperty(Property id) const
114 {
115 switch (id)
116 {
117 case Property::Color:
118 return QVariant::fromValue<Color>(colorIndex);
119 default:
120 return Object::getProperty(id);
121 }
122 }
123
124 void ldraw::ColoredObject::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
125 {
126 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Color, {colorIndex = value;});
127 Object::setProperty(result, pair);
128 }
129
130 /**
131 * @brief @overload @c ldraw::Object::serialize
132 * @param stream
133 * @return stream
134 */
135 QDataStream& ldraw::ColoredObject::serialize(QDataStream& stream) const
136 {
137 return Object::serialize(stream) << this->colorIndex;
138 }
139
140 /**
141 * @brief @overload @c ldraw::Object::deserialize
142 * @param stream
143 * @return stream
144 */
145 QDataStream& ldraw::ColoredObject::deserialize(QDataStream& stream)
146 {
147 return Object::deserialize(stream) >> this->colorIndex;
148 }
149
150 QString ldraw::Empty::textRepresentation() const
151 {
152 return "";
153 }
154
155 ldraw::Object::Type ldraw::Empty::typeIdentifier() const
156 {
157 return Type::Empty;
158 }
159
160 QString ldraw::Empty::toLDrawCode() const
161 {
162 return "";
163 }
164
165 QString ldraw::Empty::typeName() const
166 {
167 return QObject::tr("empty");
168 }

mercurial