src/documentmanager.cpp

changeset 338
719b909a7d2b
parent 335
c5830bce1c23
child 374
75efc3ba5a56
equal deleted inserted replaced
337:5bb26aa33ad5 338:719b909a7d2b
52 this->makePolygonCacheForModel(modelId); 52 this->makePolygonCacheForModel(modelId);
53 Q_EMIT this->message(logInfo(tr("New model %1 created").arg(modelId.value))); 53 Q_EMIT this->message(logInfo(tr("New model %1 created").arg(modelId.value)));
54 return modelId; 54 return modelId;
55 } 55 }
56 56
57 Model* DocumentManager::findDependencyByName(const ModelId modelId, const QString& name) 57 QTextDocument* DocumentManager::findDependencyByName(const ModelId modelId, const QString& name)
58 { 58 {
59 const auto modelsIterator = this->openModels.find(modelId); 59 const auto modelsIterator = this->openModels.find(modelId);
60 if (modelsIterator != std::end(this->openModels)) { 60 if (modelsIterator != std::end(this->openModels)) {
61 const auto& dependencies = modelsIterator->second.dependencies; 61 const auto& dependencies = modelsIterator->second.dependencies;
62 const auto dependenciesIterator = dependencies.find(name); 62 const auto dependenciesIterator = dependencies.find(name);
76 /** 76 /**
77 * @brief Gets a model pointer by id or nullptr if not found 77 * @brief Gets a model pointer by id or nullptr if not found
78 * @param modelId id of model to find 78 * @param modelId id of model to find
79 * @returns model pointer or null 79 * @returns model pointer or null
80 */ 80 */
81 Model *DocumentManager::getModelById(ModelId modelId) 81 QTextDocument *DocumentManager::getModelById(ModelId modelId)
82 { 82 {
83 const auto iterator = this->openModels.find(modelId); 83 const auto iterator = this->openModels.find(modelId);
84 if (iterator != this->openModels.end()) 84 if (iterator != this->openModels.end())
85 { 85 {
86 return iterator->second.model.get(); 86 return iterator->second.model.get();
226 /** 226 /**
227 * @brief Searches the open models for the specified model and returns its id if found 227 * @brief Searches the open models for the specified model and returns its id if found
228 * @param model model to look for 228 * @param model model to look for
229 * @return id or no value if not found 229 * @return id or no value if not found
230 */ 230 */
231 std::optional<ModelId> DocumentManager::findIdForModel(const Model *model) const 231 std::optional<ModelId> DocumentManager::findIdForModel(const QTextDocument *model) const
232 { 232 {
233 std::optional<ModelId> result; 233 std::optional<ModelId> result;
234 for (auto it = this->openModels.begin(); it != this->openModels.end(); ++it) 234 for (auto it = this->openModels.begin(); it != this->openModels.end(); ++it)
235 { 235 {
236 if (it->second.model.get() == model) 236 if (it->second.model.get() == model)
323 } 323 }
324 } 324 }
325 325
326 void DocumentManager::makePolygonCacheForModel(const ModelId modelId) 326 void DocumentManager::makePolygonCacheForModel(const ModelId modelId)
327 { 327 {
328 Model* model = this->getModelById(modelId); 328 QTextDocument* model = this->getModelById(modelId);
329 if (model != nullptr) 329 if (model != nullptr)
330 { 330 {
331 const auto modelModified = [this, model]{ 331 const auto modelModified = [this, model]{
332 const std::optional<ModelId> modelId = this->findIdForModel(model); 332 const std::optional<ModelId> modelId = this->findIdForModel(model);
333 if (modelId.has_value()) { 333 if (modelId.has_value()) {
356 referencedFilePath = libraries.findFile(referenceName); 356 referencedFilePath = libraries.findFile(referenceName);
357 } 357 }
358 return referencedFilePath; 358 return referencedFilePath;
359 } 359 }
360 360
361 static std::set<QString> referenceNames(const Model* model) 361 static std::set<QString> referenceNames(const QTextDocument* model)
362 { 362 {
363 std::set<QString> result; 363 std::set<QString> result;
364 for (const QString& line : model->toPlainText().split("\n")) { 364 for (const QString& line : model->toPlainText().split("\n")) {
365 const opt<ParsedLine> parsed = parse(line); 365 const opt<ParsedLine> parsed = parse(line);
366 if (parsed.has_value() and std::holds_alternative<LineType1>(*parsed)) { 366 if (parsed.has_value() and std::holds_alternative<LineType1>(*parsed)) {

mercurial