From da449098ca45bfa2a945fcf29d3f74849403b6a3 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de> Date: Sat, 6 Nov 2021 22:57:54 +0100 Subject: [PATCH] simplify logic --- GUI/Model/Project/ProjectDocument.cpp | 7 +++++++ GUI/Model/Project/ProjectDocument.h | 1 + GUI/View/Main/ProjectManager.cpp | 18 +++++++----------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp index f7098615ca9..ef1cd2d186d 100644 --- a/GUI/Model/Project/ProjectDocument.cpp +++ b/GUI/Model/Project/ProjectDocument.cpp @@ -72,6 +72,13 @@ QString ProjectDocument::projectDir() const return m_project_dir; } +QString ProjectDocument::validProjectDir() const +{ + if (m_project_name.isEmpty()) + return ""; + return m_project_dir; +} + void ProjectDocument::setProjectDir(const QString& text) { m_project_dir = text; diff --git a/GUI/Model/Project/ProjectDocument.h b/GUI/Model/Project/ProjectDocument.h index 6c2380f34d2..0668cc7cdeb 100644 --- a/GUI/Model/Project/ProjectDocument.h +++ b/GUI/Model/Project/ProjectDocument.h @@ -62,6 +62,7 @@ public: void setProjectName(const QString& text); QString projectDir() const; + QString validProjectDir() const; void setProjectDir(const QString& text); QString projectFileName() const; diff --git a/GUI/View/Main/ProjectManager.cpp b/GUI/View/Main/ProjectManager.cpp index e0b06c66b19..91bae5efd1a 100644 --- a/GUI/View/Main/ProjectManager.cpp +++ b/GUI/View/Main/ProjectManager.cpp @@ -123,11 +123,9 @@ void ProjectManager::writeSettings() QStringList ProjectManager::recentProjects() { QStringList updatedList; - for (QString fileName : m_recentProjects) { - QFile fin(fileName); - if (fin.exists()) + for (QString fileName : m_recentProjects) + if (QFile fin(fileName); fin.exists()) updatedList.append(fileName); - } m_recentProjects = updatedList; return m_recentProjects; } @@ -136,8 +134,8 @@ QStringList ProjectManager::recentProjects() QString ProjectManager::projectDir() const { - if (gSessionData->projectDocument && gSessionData->projectDocument->hasValidNameAndPath()) - return gSessionData->projectDocument->projectDir(); + if (gSessionData->projectDocument) + return gSessionData->projectDocument->validProjectDir(); return ""; } @@ -146,11 +144,9 @@ QString ProjectManager::projectDir() const QString ProjectManager::userExportDir() const { - QString result = projectDir(); - if (result.isEmpty()) - result = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); - - return result; + if (QString dir = projectDir(); !dir.isEmpty()) + return dir; + return QStandardPaths::writableLocation(QStandardPaths::HomeLocation); } //! Returns directory name which was used by the user to import files. -- GitLab