diff -r ee5758ddb6d2 -r 8e1fe64ce4e3 src/documentmanager.h --- 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 dependencies = {}; - PolygonCache polygonCache; + PolygonCache polygonCache = {}; + QObject* payload; }; using MissingDependencies = std::map; - 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 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 + T* findPayload(ModelId modelId) const + { + const ModelInfo* info = this->find(modelId); + return info ? qobject_cast(info->payload) : nullptr; + } private: int modelIdCounter = 0; std::map openModels;