Mantid
Loading...
Searching...
No Matches
ProjectSavePresenter.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11#include <QApplication>
12#include <QDir>
13#include <QFileInfo>
14
15#include <algorithm>
16#include <iterator>
17#include <vector>
18
19using namespace MantidQt::MantidWidgets;
20using namespace Mantid::API;
21
27 : m_view(view), m_model(m_view->getWindows(), m_view->getAllPythonInterfaces()) {
28 auto workspaceNames = m_model.getWorkspaceNames();
29 auto info = m_model.getWorkspaceInformation();
30 auto winInfo = m_model.getWindowInformation(workspaceNames, true);
34}
35
41 switch (notification) {
44 break;
47 break;
50 }
51}
52
60bool ProjectSavePresenter::needsSizeWarning(const std::vector<std::string> &wsNames) {
61 if (!wsNames.empty()) {
62 return m_model.needsSizeWarning(wsNames);
63 }
64 return false;
65}
66
72 auto wsNames = m_view->getCheckedWorkspaceNames();
73 auto names = m_model.getWindowNames(wsNames);
74 // true flag gets windows unattached to workspaces as well
75 auto info = m_model.getWindowInformation(wsNames, true);
78}
79
85 auto wsNames = m_view->getUncheckedWorkspaceNames();
86 auto names = m_model.getWindowNames(wsNames);
87 auto info = m_model.getWindowInformation(wsNames);
90}
91
98 auto path = m_view->getProjectPath();
99
100 QFileInfo fileInfo(path);
101 bool isFile = fileInfo.filePath().endsWith(".mantid") || fileInfo.filePath().endsWith(".mantid.gz");
102
103 if (!isFile) {
104 QDir directory(path);
105 if (!directory.exists()) {
106 // Make the directory
107 directory.mkdir(path);
108 }
109
110 auto projectFileName = directory.dirName();
111 projectFileName.append(".mantid");
112 path = directory.absoluteFilePath(projectFileName);
113 } else {
114 path = fileInfo.absoluteFilePath();
115 }
116
117 m_view->setProjectPath(path);
118}
IProjectSaveView is the interface for defining the functions that the project save view needs to impl...
virtual void updateInterfacesList(const std::vector< std::string > &interfaces)=0
Update the list of interfaces.
virtual void updateExcludedWindowsList(const std::vector< WindowInfo > &windows)=0
Update the excluded windows list with a collection of window info items.
virtual void removeFromIncludedWindowsList(const std::vector< std::string > &windows)=0
Remove items from the included window list.
virtual void updateWorkspacesList(const std::vector< WorkspaceInfo > &workspaces)=0
Update the workspaces list with a collection of workspace info items.
virtual void removeFromExcludedWindowsList(const std::vector< std::string > &windows)=0
Remove items from the excluded window list.
virtual QString getProjectPath()=0
Get the project path.
virtual void updateIncludedWindowsList(const std::vector< WindowInfo > &windows)=0
Update the included windows list with a collection of window info items.
virtual std::vector< std::string > getCheckedWorkspaceNames()=0
Get the names of all checked workspaces.
virtual void setProjectPath(const QString &path)=0
Set the project path.
virtual std::vector< std::string > getUncheckedWorkspaceNames()=0
Get the names of all unchecked workspaces.
std::vector< std::string > getWorkspaceNames() const
Get all workspace names.
std::vector< WorkspaceInfo > getWorkspaceInformation() const
Get all workspace information.
std::vector< WindowInfo > getWindowInformation(const std::vector< std::string > &wsNames, bool includeUnattached=false) const
Get all window information for a collection of workspaces.
std::vector< std::string > getAllPythonInterfaces() const
Return the list of python interfaces that can be saved.
bool needsSizeWarning(const std::vector< std::string > &wsNames)
Check if the size of the project is > than the warning size.
std::vector< std::string > getWindowNames(const std::vector< std::string > &wsNames) const
Get all window names for a collection of workspace names.
void includeWindowsForCheckedWorkspace()
Update the view to add included windows for a workspace.
ProjectSaveModel m_model
Hold an instance of the model.
IProjectSaveView * m_view
Handle to the view for this presenter.
ProjectSavePresenter(IProjectSaveView *view)
Construct a new presenter with a view.
void notify(Notification notification)
Notify the presenter to do something.
void prepareProjectFolder()
Prepare a project folder given the path.
void excludeWindowsForUncheckedWorkspace()
Update the view to add excluded windows for a workspace.
bool needsSizeWarning(const std::vector< std::string > &wsNames)
Find out if a project needs a save warning.