src/model.cpp

changeset 21
0133e565e072
parent 13
6e838748867b
child 24
1a0faaaceb84
equal deleted inserted replaced
20:cef43609a374 21:0133e565e072
1 #include <QBrush> 1 #include <QBrush>
2 #include <QFont> 2 #include <QFont>
3 #include "model.h" 3 #include "model.h"
4 #include "modeleditcontext.h" 4 #include "modeleditcontext.h"
5 5
6 Model::Model() 6 Model::Model(QObject* parent) :
7 { 7 QAbstractListModel{parent} {}
8
9 }
10 8
11 int Model::size() const 9 int Model::size() const
12 { 10 {
13 return this->body.size(); 11 return this->body.size();
14 } 12 }
57 { 55 {
58 const linetypes::Object* object = this->body[index].get(); 56 const linetypes::Object* object = this->body[index].get();
59 return object->getProperty(property); 57 return object->getProperty(property);
60 } 58 }
61 59
60 std::vector<gl::Polygon> Model::getPolygons(DocumentManager* documents) const
61 {
62 if (this->needRecache)
63 {
64 this->cachedPolygons.clear();
65 linetypes::GetPolygonsContext context{documents};
66 for (int i = 0; i < this->size(); i += 1)
67 {
68 this->getObjectPolygons(i, this->cachedPolygons, &context);
69 }
70 this->needRecache = false;
71 }
72 return this->cachedPolygons;
73 }
74
75 void Model::getObjectPolygons(
76 const int index,
77 std::vector<gl::Polygon>& polygons_out,
78 linetypes::GetPolygonsContext* context) const
79 {
80 const linetypes::Object* object = this->body[index].get();
81 object->getPolygons(polygons_out, context);
82 }
83
62 void Model::append(ModelObjectPointer&& object) 84 void Model::append(ModelObjectPointer&& object)
63 { 85 {
64 this->body.push_back(std::move(object)); 86 this->body.push_back(std::move(object));
65 } 87 }

mercurial