src/documentmanager.h

changeset 214
8e1fe64ce4e3
parent 213
ee5758ddb6d2
child 230
a1f3f7d9078b
--- a/src/documentmanager.h	Sat Jun 11 15:20:24 2022 +0300
+++ b/src/documentmanager.h	Sun Jun 12 20:47:04 2022 +0300
@@ -29,8 +29,9 @@
 	AutomaticallyOpened,
 };
 
-class DocumentManager
+class DocumentManager : public QObject
 {
+	Q_OBJECT
 public:
 	struct ModelInfo
 	{
@@ -39,10 +40,13 @@
 		QString path;
 		OpenType opentype;
 		std::map<QString, ModelId> dependencies = {};
-		PolygonCache polygonCache;
+		PolygonCache polygonCache = {};
+		QObject* payload;
 	};
 	using MissingDependencies = std::map<QString, QString>;
-	DocumentManager();
+	DocumentManager(QObject* parent = nullptr);
+	auto begin() const { return this->openModels.begin(); }
+	auto end() const { return this->openModels.end(); }
 	ModelId newModel();
 	Model* findDependencyByName(const ModelId modelId, const QString& name);
 	Model* getModelById(ModelId modelId);
@@ -58,7 +62,14 @@
 	bool saveModel(const ModelId modelId, QTextStream& errors);
 	std::optional<ModelId> findIdForModel(const Model* model) const;
 	PolygonCache* getPolygonCacheForModel(ModelId modelId);
-	const ModelInfo* infoForModel(ModelId modelId) const;
+	const ModelInfo* find(ModelId modelId) const;
+	void setModelPayload(ModelId modelId, QObject* object);
+	template<typename T>
+	T* findPayload(ModelId modelId) const
+	{
+		const ModelInfo* info = this->find(modelId);
+		return info ? qobject_cast<T*>(info->payload) : nullptr;
+	}
 private:
 	int modelIdCounter = 0;
 	std::map<ModelId, ModelInfo> openModels;

mercurial