diff --git a/src/app/qt/element/QtMainWindow.cpp b/src/app/qt/element/QtMainWindow.cpp index e4a56b10..e492bcf8 100644 --- a/src/app/qt/element/QtMainWindow.cpp +++ b/src/app/qt/element/QtMainWindow.cpp @@ -14,6 +14,7 @@ #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageLoadSource.h" #include "utility/messaging/type/MessageRefresh.h" +#include "utility/messaging/type/MessageSaveProject.h" QtMainWindow::QtMainWindow() { @@ -71,6 +72,22 @@ void QtMainWindow::openProject(const QString &path) } } +void QtMainWindow::saveProject() +{ + MessageSaveProject("").dispatch(); +} + +void QtMainWindow::saveAsProject() +{ + QString filename = ""; + filename = QFileDialog::getSaveFileName(this, "Save File as", "", "XML Files(*.xml)"); + + if(!filename.isEmpty()) + { + MessageSaveProject(filename.toStdString()).dispatch(); + } +} + void QtMainWindow::find() { MessageFind().dispatch(); @@ -184,6 +201,8 @@ void QtMainWindow::setupProjectMenu() menu->addAction(tr("&New"), this, SLOT(newProject()), QKeySequence::New); menu->addAction(tr("&Open..."), this, SLOT(openProject()), QKeySequence::Open); + menu->addAction(tr("&Save"), this, SLOT(saveProject()), QKeySequence::Save); + menu->addAction(tr("Save as"), this, SLOT(saveAsProject()), QKeySequence::SaveAs); menu->addAction(tr("E&xit"), QCoreApplication::instance(), SLOT(quit()), QKeySequence::Quit); } diff --git a/src/app/qt/element/QtMainWindow.h b/src/app/qt/element/QtMainWindow.h index 4fee06a9..acdcdf57 100644 --- a/src/app/qt/element/QtMainWindow.h +++ b/src/app/qt/element/QtMainWindow.h @@ -33,6 +33,8 @@ public slots: void find(); void closeWindow(); void refresh(); + void saveProject(); + void saveAsProject(); private: void setupProjectMenu(); diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 2a7ea527..0e9342dd 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -5,6 +5,7 @@ #include "component/view/ViewFactory.h" #include "data/access/GraphAccessProxy.h" #include "data/access/LocationAccessProxy.h" +#include "utility/logging/logging.h" #include "utility/messaging/MessageQueue.h" #include "utility/messaging/type/MessageActivateToken.h" @@ -67,6 +68,14 @@ void Application::reloadProject() MessageActivateToken(1).dispatch(); } +void Application::saveProject(const std::string& projectSettingsFilePath) +{ + if(!m_project->saveProjectSettings(projectSettingsFilePath)) + { + LOG_ERROR("No Project Settings File defined"); + } +} + void Application::handleMessage(MessageLoadProject* message) { loadProject(message->projectSettingsFilePath); @@ -81,3 +90,8 @@ void Application::handleMessage(MessageRefresh* message) { reloadProject(); } + +void Application::handleMessage(MessageSaveProject* message) +{ + saveProject(message->projectSettingsFilePath); +} diff --git a/src/lib/Application.h b/src/lib/Application.h index e505e39b..70b1d2d5 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -8,6 +8,7 @@ #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageLoadSource.h" +#include "utility/messaging/type/MessageSaveProject.h" #include "utility/messaging/type/MessageRefresh.h" class ViewFactory; @@ -19,6 +20,7 @@ class Application : public MessageListener , public MessageListener , public MessageListener + , public MessageListener { public: static std::shared_ptr create(ViewFactory* viewFactory); @@ -27,6 +29,7 @@ public: void loadProject(const std::string& projectSettingsFilePath); void loadSource(const std::string& sourceDirectoryPath); + void saveProject(const std::string& projectSettingsFilePath); void reloadProject(); private: @@ -35,6 +38,7 @@ private: virtual void handleMessage(MessageLoadProject* message); virtual void handleMessage(MessageLoadSource* message); virtual void handleMessage(MessageRefresh* message); + virtual void handleMessage(MessageSaveProject* message); std::shared_ptr m_project; std::shared_ptr m_graphAccessProxy; diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 39b3bf2c..02aab432 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -10,6 +10,7 @@ #include "data/parser/cxx/CxxParser.h" #include "utility/FileSystem.h" #include "utility/messaging/type/MessageFinishedParsing.h" +#include "utility/logging/logging.h" std::shared_ptr Project::create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy) { @@ -24,16 +25,42 @@ Project::~Project() bool Project::loadProjectSettings(const std::string& projectSettingsFile) { - return ProjectSettings::getInstance()->load(projectSettingsFile); + bool success = ProjectSettings::getInstance()->load(projectSettingsFile); + if(success) + { + m_projectSettingsFilepath = projectSettingsFile; + } + return success; +} + +bool Project::saveProjectSettings( const std::string& projectSettingsFile ) +{ + if(!projectSettingsFile.empty()) + { + m_projectSettingsFilepath = projectSettingsFile; + ProjectSettings::getInstance()->save(projectSettingsFile); + } + else if (!m_projectSettingsFilepath.empty()) + { + ProjectSettings::getInstance()->save(m_projectSettingsFilepath); + } + else + { + return false; + } + LOG_INFO_STREAM(<< "Projectsettings saved in File: " << m_projectSettingsFilepath); + return true; } void Project::clearProjectSettings() { + m_projectSettingsFilepath.clear(); ProjectSettings::getInstance()->clear(); } bool Project::setSourceDirectoryPath(const std::string& sourceDirectoryPath) { + m_projectSettingsFilepath = sourceDirectoryPath + "/ProjectSettings.xml"; return ProjectSettings::getInstance()->setSourcePath(sourceDirectoryPath); } diff --git a/src/lib/Project.h b/src/lib/Project.h index 6bc90890..dfe2c666 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -17,6 +17,7 @@ public: ~Project(); bool loadProjectSettings(const std::string& projectSettingsFile); + bool saveProjectSettings(const std::string& projectSettingsFile); void clearProjectSettings(); bool setSourceDirectoryPath(const std::string& sourceDirectoryPath); @@ -29,6 +30,8 @@ private: Project(const Project&); Project operator=(const Project&); + std::string m_projectSettingsFilepath; + GraphAccessProxy* const m_graphAccessProxy; LocationAccessProxy* const m_locationAccessProxy; diff --git a/src/lib/utility/messaging/type/MessageSaveProject.h b/src/lib/utility/messaging/type/MessageSaveProject.h new file mode 100644 index 00000000..a2dc3c52 --- /dev/null +++ b/src/lib/utility/messaging/type/MessageSaveProject.h @@ -0,0 +1,22 @@ +#ifndef MESSAGE_SAVE_PROJECT_H +#define MESSAGE_SAVE_PROJECT_H + +#include "utility/messaging/Message.h" + +class MessageSaveProject: public Message +{ +public: + MessageSaveProject(const std::string& filePath) + : projectSettingsFilePath(filePath) + { + } + + static const std::string getStaticType() + { + return "MessageSaveProject"; + } + + const std::string projectSettingsFilePath; +}; + +#endif // MESSAGE_SAVE_PROJECT_H