119 QFile file{path}; |
119 QFile file{path}; |
120 const QString name = pathToName(QFileInfo{path}); |
120 const QString name = pathToName(QFileInfo{path}); |
121 file.open(QFile::ReadOnly | QFile::Text); |
121 file.open(QFile::ReadOnly | QFile::Text); |
122 std::unique_ptr<Model> newModel = std::make_unique<Model>(nullptr); |
122 std::unique_ptr<Model> newModel = std::make_unique<Model>(nullptr); |
123 QTextStream textStream{&file}; |
123 QTextStream textStream{&file}; |
124 Parser parser{file}; |
124 Parser parser{textStream}; |
125 parser.parseBody(*newModel); |
125 parser.parseBody(*newModel); |
126 std::optional<ModelId> result; |
126 std::optional<ModelId> result; |
127 if (file.error() == QFile::NoError) |
127 if (file.error() == QFile::NoError) |
128 { |
128 { |
129 const ModelId modelId{++this->modelIdCounter}; |
129 const ModelId modelId{++this->modelIdCounter}; |
193 if (info != nullptr) |
193 if (info != nullptr) |
194 { |
194 { |
195 QSaveFile file{info->path}; |
195 QSaveFile file{info->path}; |
196 file.setDirectWriteFallback(true); |
196 file.setDirectWriteFallback(true); |
197 if (file.open(QSaveFile::WriteOnly)) { |
197 if (file.open(QSaveFile::WriteOnly)) { |
198 ::save(*info->model.get(), &file); |
198 QTextStream stream{&file}; |
|
199 ::save(*info->model.get(), &stream); |
199 const bool commitSucceeded = file.commit(); |
200 const bool commitSucceeded = file.commit(); |
200 if (not commitSucceeded) { |
201 if (not commitSucceeded) { |
201 errors << QObject::tr("Could not save: %1").arg(file.errorString()); |
202 errors << QObject::tr("Could not save: %1").arg(file.errorString()); |
202 return false; |
203 return false; |
203 } |
204 } |