diff -r b27b90fb993f -r 27259810da6d src/documentmanager.h --- a/src/documentmanager.h Thu Jun 09 19:11:27 2022 +0300 +++ b/src/documentmanager.h Sat Jun 11 14:30:30 2022 +0300 @@ -21,32 +21,33 @@ #include "model.h" #include "polygoncache.h" -class DocumentManager : public QObject +enum OpenType { - Q_OBJECT + //! \brief Document was opened manually by the user + ManuallyOpened, + //! \brief Document was opened automatically in order to resolve subfile references + AutomaticallyOpened, +}; + +class DocumentManager +{ public: - enum OpenType + struct ModelInfo { - /** - * Document was opened manually by the user - */ - ManuallyOpened, - /** - * Document was opened automatically in order to resolve subfile references - */ - AutomaticallyOpened, + std::unique_ptr model; + ModelId id; + QString path; + OpenType opentype; + std::map dependencies = {}; + PolygonCache polygonCache; }; - DocumentManager(QObject* parent = nullptr); + using MissingDependencies = std::map; + DocumentManager(); ModelId newModel(); Model* findDependencyByName(const ModelId modelId, const QString& name); Model* getModelById(ModelId modelId); std::optional openModel(const QString& path, QTextStream& errorStream, const OpenType openType); - QString makeNewModelName(); - void loadDependenciesForAllModels(const LibraryManager &libraries, QTextStream &errorStream); - void loadDependenciesForModel(const ModelId modelId, - const QString& path, - const LibraryManager& libraries, - QTextStream& errorStream); + std::map loadDependenciesForAllModels(const LibraryManager &libraries); void closeDocument(const ModelId modelId); const QString* modelPath(ModelId modelId) const; void setModelPath( @@ -57,27 +58,16 @@ bool saveModel(const ModelId modelId, QTextStream& errors); std::optional findIdForModel(const Model* model) const; PolygonCache* getPolygonCacheForModel(ModelId modelId); + const ModelInfo* infoForModel(ModelId modelId) const; private: - struct ModelInfo - { - std::unique_ptr model; - ModelId id; - QString path; - OpenType opentype; - std::map dependencies = {}; - }; - struct LoadDepedenciesBag; int modelIdCounter = 0; - int untitledNameCounter = 0; std::map openModels; - std::map polygonCaches; - void loadDependenciesForModel(const ModelId modelId, const QString& path, LoadDepedenciesBag& bag); void collectReferences(QSet &referenced, const QString& name, const Model* model); void updateDependencies(ModelInfo* model); void prune(); - Q_SLOT void modelModified(); bool isReferencedByAnything(const ModelId modelId) const; void makePolygonCacheForModel(const ModelId modelId); }; +QString errorStringFromMissingDependencies(const DocumentManager::MissingDependencies& missing); QString pathToName(const QFileInfo& path);