src/model.h

changeset 173
8a3047468994
parent 152
03f8e6d42e13
child 200
ca23936b455b
--- a/src/model.h	Wed Mar 09 12:42:45 2022 +0200
+++ b/src/model.h	Wed Mar 09 13:01:50 2022 +0200
@@ -68,7 +68,8 @@
 private:
 	bool modified = false;
 	std::vector<ModelObjectPointer> body;
-	std::map<ldraw::id_t, ldraw::Object*> objectsById;
+	mutable std::map<ldraw::id_t, std::size_t> objectsById;
+	mutable bool needObjectsByIdRebuild = false;
 };
 
 void save(const Model& model, QIODevice *device);
@@ -99,7 +100,7 @@
 	Q_EMIT beginInsertRows({}, position, position);
 	this->body.push_back(std::make_unique<T>(args...));
 	ldraw::Object* pointer = this->body.back().get();
-	this->objectsById[pointer->id] = pointer;
+	this->objectsById[pointer->id] = this->body.size() - 1;
 	Q_EMIT endInsertRows();
 	return ldraw::Id<T>{pointer->id.value};
 }
@@ -110,7 +111,7 @@
 	Q_EMIT beginInsertRows({}, position, position);
 	this->body.insert(std::begin(this->body) + position, std::make_unique<T>(args...));
 	ldraw::Object* pointer = this->body[position].get();
-	this->objectsById[pointer->id] = pointer;
+	this->objectsById[pointer->id] = position;
 	Q_EMIT endInsertRows();
 	return ldraw::Id<T>{pointer->id.value};
 }

mercurial