From cded0429c87cf46ab8d6d1cab5e3a2eb6d3d5742 Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <svechnikovmv@gmail.com> Date: Thu, 19 Jan 2023 14:39:12 +0100 Subject: [PATCH] rnm saveProjectFile --> saveProjectFileWithData --- GUI/Model/Project/ProjectDocument.cpp | 11 ++++------- GUI/Model/Project/ProjectDocument.h | 4 ++-- GUI/View/Project/ProjectManager.cpp | 20 +++++++++----------- Tests/Unit/GUI/TestProjectDocument.cpp | 6 +++--- Tests/Unit/GUI/TestSaveService.cpp | 4 ++-- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp index 0aad02528fc..0b6e95abb01 100644 --- a/GUI/Model/Project/ProjectDocument.cpp +++ b/GUI/Model/Project/ProjectDocument.cpp @@ -154,13 +154,12 @@ InstrumentsEditController* ProjectDocument::instrumentsEditController() return &m_instrumentEditController; } -void ProjectDocument::saveProjectFile(const QString& projectPullPath) +void ProjectDocument::saveProjectFileWithData(const QString& projectPullPath) { QFile file(projectPullPath); if (!file.open(QFile::ReadWrite | QIODevice::Truncate | QFile::Text)) throw Error("ProjectDocument::save_project_file() -> Error. Cannot open " - "file '" - + projectPullPath + "' for writing."); + "file '" + projectPullPath + "' for writing."); const bool autoSave = GUI::Project::Utils::isAutosave(projectPullPath); // QString mainDir = projectDir(); @@ -179,10 +178,10 @@ void ProjectDocument::saveProjectFile(const QString& projectPullPath) } } -ProjectDocument::ReadResult ProjectDocument::loadProjectFile(const QString& project_file_name, +ProjectDocument::ReadResult ProjectDocument::loadProjectFileWithData(const QString& projectPullPath, MessageService& messageService) { - setProjectFullPath(project_file_name); + setProjectFullPath(projectPullPath); QFile file(projectFullPath()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -197,8 +196,6 @@ ProjectDocument::ReadResult ProjectDocument::loadProjectFile(const QString& proj file.close(); if (result == ReadResult::error) return result; - - // m_dataService->loadDataFiles(projectDir(), &messageService); connectModels(); if (!messageService.warnings().empty()) diff --git a/GUI/Model/Project/ProjectDocument.h b/GUI/Model/Project/ProjectDocument.h index f8d342eb972..841965dd9ca 100644 --- a/GUI/Model/Project/ProjectDocument.h +++ b/GUI/Model/Project/ProjectDocument.h @@ -87,9 +87,9 @@ public: //! \sa InstrumentsEditController for more information InstrumentsEditController* instrumentsEditController(); - void saveProjectFile(const QString& projectPullPath); + void saveProjectFileWithData(const QString& projectPullPath); - ReadResult loadProjectFile(const QString& project_file_name, MessageService& messageService); + ReadResult loadProjectFileWithData(const QString& projectPullPath, MessageService& messageService); bool hasValidNameAndPath(); diff --git a/GUI/View/Project/ProjectManager.cpp b/GUI/View/Project/ProjectManager.cpp index 407bcea2175..759ef264349 100644 --- a/GUI/View/Project/ProjectManager.cpp +++ b/GUI/View/Project/ProjectManager.cpp @@ -253,7 +253,7 @@ bool ProjectManager::closeCurrentProject() bool ProjectManager::saveProject(QString projectPullPath) { -// qInfo() << "INPUT" << projectPullPath; + qInfo() << "INPUT" << projectPullPath; if (projectPullPath.isEmpty()) { if (gProjectDocument.value()->hasValidNameAndPath()) projectPullPath = gProjectDocument.value()->projectFullPath(); @@ -267,12 +267,12 @@ bool ProjectManager::saveProject(QString projectPullPath) gProjectDocument.value()->setProjectName(GUI::Project::Utils::projectName(projectPullPath)); gProjectDocument.value()->setProjectDir(GUI::Project::Utils::projectDir(projectPullPath)); -// qInfo() << "dir" <<gProjectDocument.value()->projectDir(); -// qInfo() << "name" <<gProjectDocument.value()->projectName(); -// qInfo() << "full" <<gProjectDocument.value()->projectFullPath(); + qInfo() << "dir" <<gProjectDocument.value()->projectDir(); + qInfo() << "name" <<gProjectDocument.value()->projectName(); + qInfo() << "full" <<gProjectDocument.value()->projectFullPath(); try { - gProjectDocument.value()->saveProjectFile(projectPullPath); + gProjectDocument.value()->saveProjectFileWithData(projectPullPath); } catch (const std::exception& ex) { QString message = QString("Failed to save project under '%1'. \n\n").arg(projectPullPath); message.append("Exception was thrown.\n\n"); @@ -281,9 +281,7 @@ bool ProjectManager::saveProject(QString projectPullPath) QMessageBox::warning(GUI::Global::mainWindow, "Error while saving project", message); return false; } - addToRecentProjects(); - return true; } @@ -373,16 +371,16 @@ ProjectDocument::ReadResult ProjectManager::loadProject(const QString& fullPathA auto readResult = ProjectDocument::ReadResult::ok; const bool useAutosave = GUI::Project::Utils::hasAutosavedData(fullPathAndName); - const QString autosaveName = GUI::Project::Utils::autosaveFullPath(fullPathAndName); - if (useAutosave && restoreProjectDialog(fullPathAndName, autosaveName)) { + const QString autosaveFullPath = GUI::Project::Utils::autosaveFullPath(fullPathAndName); + if (useAutosave && restoreProjectDialog(fullPathAndName, autosaveFullPath)) { QApplication::setOverrideCursor(Qt::WaitCursor); - readResult = gProjectDocument.value()->loadProjectFile(autosaveName, messageService); + readResult = gProjectDocument.value()->loadProjectFileWithData(autosaveFullPath, messageService); gProjectDocument.value()->setProjectFullPath(fullPathAndName); // restored project should be marked by '*' gProjectDocument.value()->setModified(); } else { QApplication::setOverrideCursor(Qt::WaitCursor); - readResult = gProjectDocument.value()->loadProjectFile(fullPathAndName, messageService); + readResult = gProjectDocument.value()->loadProjectFileWithData(fullPathAndName, messageService); } QApplication::restoreOverrideCursor(); return readResult; diff --git a/Tests/Unit/GUI/TestProjectDocument.cpp b/Tests/Unit/GUI/TestProjectDocument.cpp index 09b47e9786f..40714f1ae2c 100644 --- a/Tests/Unit/GUI/TestProjectDocument.cpp +++ b/Tests/Unit/GUI/TestProjectDocument.cpp @@ -40,7 +40,7 @@ TEST_F(TestProjectDocument, projectDocument) instrument->setInstrumentName("GISAS"); // Checking document name and isModified status after project save - document.saveProjectFile(projectFileName); + document.saveProjectFileWithData(projectFileName); EXPECT_TRUE(document.hasValidNameAndPath()); EXPECT_EQ(document.projectDir(), projectDir); EXPECT_EQ(document.projectName(), "document"); @@ -56,7 +56,7 @@ TEST_F(TestProjectDocument, projectDocument) EXPECT_EQ(spyDocument.count(), 1); // Saving document - document.saveProjectFile(projectFileName); + document.saveProjectFileWithData(projectFileName); EXPECT_FALSE(document.isModified()); EXPECT_EQ(spyDocument.count(), 2); @@ -80,7 +80,7 @@ TEST_F(TestProjectDocument, projectDocumentWithData) intensityItem->setSaveInBackground(false); document.setProjectDir(projectDir); - document.saveProjectFile(projectDir + "/untitled.pro"); + document.saveProjectFileWithData(projectDir + "/untitled.pro"); QFileInfo info(projectDir + "/untitled.pro"); EXPECT_TRUE(info.exists()); diff --git a/Tests/Unit/GUI/TestSaveService.cpp b/Tests/Unit/GUI/TestSaveService.cpp index fefaffaa9a3..fdabd6711a2 100644 --- a/Tests/Unit/GUI/TestSaveService.cpp +++ b/Tests/Unit/GUI/TestSaveService.cpp @@ -39,7 +39,7 @@ TEST_F(TestSaveService, autoSaveController) std::unique_ptr<ProjectDocument> document(new ProjectDocument); auto* instrument = document->instrumentModel()->addInstrumentItem<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); - document->saveProjectFile(projectFileName); + document->saveProjectFileWithData(projectFileName); // setting up autosave AutosaveController autosave; @@ -60,7 +60,7 @@ TEST_F(TestSaveService, autoSaveController) EXPECT_TRUE(QFile::exists(autosave.autosaveDir())); // saving document and checking that autosave is not triggered - document->saveProjectFile(projectFileName); + document->saveProjectFileWithData(projectFileName); EXPECT_FALSE(document->isModified()); EXPECT_EQ(spyAutosave.count(), 1); -- GitLab