| 30 int Model::size() const |
30 int Model::size() const |
| 31 { |
31 { |
| 32 return static_cast<int>(this->body.size()); |
32 return static_cast<int>(this->body.size()); |
| 33 } |
33 } |
| 34 |
34 |
| |
35 /** |
| |
36 * @brief Looks up the object ID at the specified index. If out of bounds, returns NULL_ID. |
| |
37 * @param index Index of object to look up |
| |
38 * @return object ID |
| |
39 */ |
| |
40 ldraw::id_t Model::at(int index) const |
| |
41 { |
| |
42 if (index >= 0 and index < this->size()) |
| |
43 { |
| |
44 return this->body[index]->id; |
| |
45 } |
| |
46 else |
| |
47 { |
| |
48 return ldraw::NULL_ID; |
| |
49 } |
| |
50 } |
| |
51 |
| 35 Model::EditContext Model::edit() |
52 Model::EditContext Model::edit() |
| 36 { |
53 { |
| |
54 this->editCounter += 1; |
| 37 return {*this}; |
55 return {*this}; |
| 38 } |
56 } |
| 39 |
57 |
| 40 int Model::rowCount(const QModelIndex&) const |
58 int Model::rowCount(const QModelIndex&) const |
| 41 { |
59 { |
| 116 { |
134 { |
| 117 const ldraw::Object* object = this->body[unsigned_cast(index)].get(); |
135 const ldraw::Object* object = this->body[unsigned_cast(index)].get(); |
| 118 object->getPolygons(polygons_out, context); |
136 object->getPolygons(polygons_out, context); |
| 119 } |
137 } |
| 120 |
138 |
| |
139 void Model::editFinished() |
| |
140 { |
| |
141 this->editCounter -= 1; |
| |
142 } |
| |
143 |
| |
144 void Model::objectModified(ldraw::id_t id) |
| |
145 { |
| |
146 const QModelIndex index = this->lookup(id); |
| |
147 Q_EMIT this->dataChanged(index, index); |
| |
148 } |
| |
149 |
| 121 void Model::append(ModelObjectPointer&& object) |
150 void Model::append(ModelObjectPointer&& object) |
| 122 { |
151 { |
| 123 const int position = static_cast<int>(this->body.size()); |
152 const int position = static_cast<int>(this->body.size()); |
| 124 Q_EMIT beginInsertRows({}, position, position); |
153 Q_EMIT beginInsertRows({}, position, position); |
| 125 this->body.push_back(std::move(object)); |
154 this->body.push_back(std::move(object)); |