src/model.cpp

changeset 21
0133e565e072
parent 13
6e838748867b
child 24
1a0faaaceb84
--- a/src/model.cpp	Sat Dec 14 23:00:01 2019 +0200
+++ b/src/model.cpp	Wed Jan 01 17:45:56 2020 +0200
@@ -3,10 +3,8 @@
 #include "model.h"
 #include "modeleditcontext.h"
 
-Model::Model()
-{
-
-}
+Model::Model(QObject* parent) :
+	QAbstractListModel{parent} {}
 
 int Model::size() const
 {
@@ -59,6 +57,30 @@
 	return object->getProperty(property);
 }
 
+std::vector<gl::Polygon> Model::getPolygons(DocumentManager* documents) const
+{
+	if (this->needRecache)
+	{
+		this->cachedPolygons.clear();
+		linetypes::GetPolygonsContext context{documents};
+		for (int i = 0; i < this->size(); i += 1)
+		{
+			this->getObjectPolygons(i, this->cachedPolygons, &context);
+		}
+		this->needRecache = false;
+	}
+	return this->cachedPolygons;
+}
+
+void Model::getObjectPolygons(
+	const int index,
+	std::vector<gl::Polygon>& polygons_out,
+	linetypes::GetPolygonsContext* context) const
+{
+	const linetypes::Object* object = this->body[index].get();
+	object->getPolygons(polygons_out, context);
+}
+
 void Model::append(ModelObjectPointer&& object)
 {
 	this->body.push_back(std::move(object));

mercurial