src/ldDocument.cpp

changeset 1015
92c6ec099075
parent 1014
f0a8ecb6a357
child 1017
fc1c13db9618
--- a/src/ldDocument.cpp	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/ldDocument.cpp	Sat Feb 13 04:06:49 2016 +0200
@@ -41,14 +41,14 @@
 	m_isCache (true),
 	m_verticesOutdated (true),
 	m_needVertexMerge (true),
+	m_needsReCache(true),
 	m_beingDestroyed (false),
+	m_needRecount(false),
+	m_savePosition(-1),
+	m_tabIndex(-1),
+	m_triangleCount(0),
 	m_gldata (new LDGLData),
-	m_manager (parent)
-{
-	setSavePosition (-1);
-	setTabIndex (-1);
-	m_needsReCache = true;
-}
+	m_manager (parent) {}
 
 LDDocument::~LDDocument()
 {
@@ -126,6 +126,21 @@
 	m_defaultName = value;
 }
 
+int LDDocument::triangleCount()
+{
+	if (m_needRecount)
+	{
+		m_triangleCount = 0;
+
+		for (LDObject* obj : m_objects)
+			m_triangleCount += obj->triangleCount();
+
+		m_needRecount = false;
+	}
+
+	return m_triangleCount;
+}
+
 void LDDocument::openForEditing()
 {
 	if (m_isCache)
@@ -599,6 +614,7 @@
 	m_objects << obj;
 	addKnownVertices (obj);
 	obj->setDocument (this);
+	m_needRecount = true;
 	m_window->renderer()->compileObject (obj);
 	return getObjectCount() - 1;
 }
@@ -621,6 +637,7 @@
 	history()->add (new AddHistoryEntry (pos, obj));
 	m_objects.insert (pos, obj);
 	obj->setDocument (this);
+	m_needRecount = true;
 	m_window->renderer()->compileObject (obj);
 	
 
@@ -662,6 +679,7 @@
 		}
 
 		m_objects.removeAt (idx);
+		m_needRecount = true;
 		obj->setDocument (nullptr);
 	}
 }
@@ -909,4 +927,9 @@
 void LDDocument::needVertexMerge()
 {
 	m_needVertexMerge = true;
-}
\ No newline at end of file
+}
+
+void LDDocument::needRecount()
+{
+	m_needRecount = true;
+}

mercurial