ProjectSerialiser.h 5.58 KB
Newer Older
1
2
#ifndef PROJECT_SERIALISER_H
#define PROJECT_SERIALISER_H
3
4
5
6
7
8
9
10
11
12

#include <string>

#include <QFile>
#include <QFileInfo>
#include <QMessageBox>
#include <QStringList>
#include <QDir>
#include <QApplication>

Roman Tolchenov's avatar
Roman Tolchenov committed
13
#include "MantidQtWidgets/Common/TSVSerialiser.h"
14

15
16
#include "qstring.h"
#include "Folder.h"
17
18
#include "Graph3D.h"
#include "Mantid/MantidMatrix.h"
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

// Forward declare Mantid classes.
class ApplicationWindow;

/** Manages saving and loading Mantid project files.

  @author Samuel Jackson, ISIS, RAL
  @date 21/06/2016

  Copyright &copy; 2007-2014 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
  National Laboratory & European Spallation Source

  This file is part of Mantid.

  Mantid is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  Mantid is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

  File change history is stored at: <https://github.com/mantidproject/mantid>
*/

namespace MantidQt {
50
namespace API {
51

52
53
class ProjectSerialiser : public QObject {
  Q_OBJECT
54
55
public:
  /// Create a new serialiser with the current application window
Samuel Jackson's avatar
Samuel Jackson committed
56
  explicit ProjectSerialiser(ApplicationWindow *window);
57
58
  explicit ProjectSerialiser(ApplicationWindow *window, Folder *folder);

59
  /// Save the current state of the project to disk
60
61
62
63
  void save(const QString &projectName, const std::vector<std::string> &wsNames,
            const std::vector<std::string> &windowNames, bool compress = false);
  void save(const QString &projectName, bool compress = false,
            bool saveAll = true);
64
65
66
67
68
69
  /// Load a project file from disk
  void load(std::string lines, const int fileVersion,
            const bool isTopLevel = true);
  /// Open the script window and load scripts from string
  void openScriptWindow(const QStringList &files);

70
71
72
73
74
75
76
77
signals:
  /// Set the curret progress of serialisation
  void setProgressBarRange(int min, int max);
  /// Set the forcasted range of things to do when saving
  void setProgressBarValue(int value);
  /// Set what is currently happening to listening progress bars
  void setProgressBarText(QString text);

78
79
80
81
82
private:
  // Instance Variables

  /// Store a reference to the caller application window instance
  ApplicationWindow *window;
83
  /// Store a reference to the current folder
84
  Folder *m_currentFolder;
85
86
87
88
  /// Vector of names of windows to save to file
  std::vector<std::string> m_windowNames;
  /// Vector of names of workspaces to save to file
  std::vector<std::string> m_workspaceNames;
89
90
  /// Store a count of the number of windows during saving
  int m_windowCount;
91
92
  /// Flag to check if e should save all workspaces
  bool m_saveAll;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

  // Saving Functions

  /// Attempt to backup files before save
  bool canBackupProjectFiles(QFile *fileHandle, const QString &projectName);
  /// Check that the project is writable
  bool canWriteToProject(QFile *fileHandle, const QString &projectName);
  /// Convert the current state of the application to a project file
  QString serialiseProjectState(Folder *folder);
  /// Save the project file to disk
  void saveProjectFile(QFile *fileHandle, const QString &projectName,
                       QString &text, bool compress);
  /// Save the state of a folder
  QString saveFolderState(Folder *folder, const bool isTopLevel = false);
  /// Save the header information about a folder
  QString saveFolderHeader(Folder *folder, bool isCurrentFolder);
  /// Save sub-windows for a folder
  QString saveFolderSubWindows(Folder *folder);
  /// Save the footer contents of a folder
  QString saveFolderFooter();
  /// Save any currently loaded workspaces
  QString saveWorkspaces();
115
116
  /// Save additional windows
  QString saveAdditionalWindows();
117
118
119
120
121
122

  // Loading Functions

  /// Load sections of the folder
  void loadProjectSections(const std::string &lines, const int fileVersion,
                           const bool isTopLevel);
123
124
  /// Load workspaces from the project file
  void loadWorkspaces(const TSVSerialiser &tsv);
125
126
  /// Load project windows from the project file
  void loadWindows(const TSVSerialiser &tsv, const int fileVersion);
127
128
129
130
131
132
133
134
  /// Load all subfolders of the current folder
  void loadSubFolders(const TSVSerialiser &tsv, const int fileVersion);
  /// Load scripts into the script window
  void loadScriptWindow(const TSVSerialiser &tsv, const int fileVersion);
  /// Load saved log data into the log
  void loadLogData(const TSVSerialiser &tsv);
  /// Load information about the current folder
  void loadCurrentFolder(const TSVSerialiser &tsv);
135
136
137
138
139
140
  /// Open the script window and load scripts from string
  void openScriptWindow(const std::string &files, const int fileVersion);
  /// Load Nexus files and add workspaces to the ADS
  void populateMantidTreeWidget(const QString &lines);
  /// Load a single workspaces to the ADS
  void loadWsToMantidTree(const std::string &wsName);
141
142
  /// Load additional windows (e.g. slice viewer)
  void loadAdditionalWindows(const std::string &lines, const int fileVersion);
143
144
145
146
147

  // Misc functions

  /// Create a handle to a new QMdiSubWindow instance
  QMdiSubWindow *setupQMdiSubWindow() const;
148
  /// Check if a vector of strings contains a string
149
  bool contains(const std::vector<std::string> &vec, const std::string &value);
150
151
};
}
152
153
}

154
#endif // PROJECT_SERIALISER_H