From abcabba88ef7f983450a932c7c0b6c671dfc7c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Jul 2017 13:42:34 +0200 Subject: [PATCH] GUI: When loading project, try to load last results --- gui/mainwindow.cpp | 36 +++++++++++++++++++++++------------- gui/mainwindow.h | 6 ++++++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 912a5ba21..1584f5f7e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -318,19 +318,12 @@ void MainWindow::loadSettings() msgBox.exec(); } - const QString project = mSettings->value(SETTINGS_OPEN_PROJECT, QString()).toString(); - if (!project.isEmpty() && QCoreApplication::arguments().size()==1) { - QFileInfo inf(project); + const QString projectFile = mSettings->value(SETTINGS_OPEN_PROJECT, QString()).toString(); + if (!projectFile.isEmpty() && QCoreApplication::arguments().size()==1) { + QFileInfo inf(projectFile); if (inf.exists() && inf.isReadable()) { - delete mProject; - mProject = new Project(project, this); - mProject->open(); - if (!mProject->getProjectFile()->getBuildDir().isEmpty()) { - const QString buildDir = QFileInfo(project).absolutePath() + '/' + mProject->getProjectFile()->getBuildDir(); - const QString lastResults = buildDir + "/lastResults.xml"; - if (QFileInfo(lastResults).exists()) - mUI.mResults->readErrorsXml(lastResults); - } + mProject = new Project(projectFile, this); + loadLastResults(); } } } @@ -1333,7 +1326,24 @@ void MainWindow::loadProjectFile(const QString &filePath) mUI.mActionEditProjectFile->setEnabled(true); delete mProject; mProject = new Project(filePath, this); - analyzeProject(mProject); + if (!loadLastResults()) + analyzeProject(mProject); +} + +bool MainWindow::loadLastResults() +{ + if (!mProject) + return false; + if (!mProject->isOpen() && !mProject->open()) + return false; + if (mProject->getProjectFile()->getBuildDir().isEmpty()) + return false; + const QString buildDir = QFileInfo(mProject->getFilename()).absolutePath() + '/' + mProject->getProjectFile()->getBuildDir(); + const QString lastResults = buildDir + "/lastResults.xml"; + if (!QFileInfo(lastResults).exists()) + return false; + mUI.mResults->readErrorsXml(lastResults); + return true; } void MainWindow::analyzeProject(Project *project) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index a283158a3..be9f114f6 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -343,6 +343,12 @@ private: */ void loadResults(const QString selectedFile, const QString sourceDirectory); + /** + * @brief Load last project results to the GUI. + * @return Returns true if last results was loaded + */ + bool loadLastResults(); + /** * @brief Load project file to the GUI. * @param filePath Filename (inc. path) of project file to load.