28 #include <QApplication>
30 #include <QFileDialog>
31 #include <QMessageBox>
33 #include <QStandardPaths>
36 const QString S_PROJECTMANAGER =
"ProjectManager";
37 const QString S_AUTOSAVE =
"EnableAutosave";
38 const QString S_DEFAULTPROJECTPATH =
"DefaultProjectPath";
39 const QString S_RECENTPROJECTS =
"RecentProjects";
40 const QString S_LASTUSEDIMPORTDIR =
"LastUsedImportDir";
41 const QString S_LASTUSEDIMPORFILTER1D =
"LastUsedImportFilter1D";
42 const QString S_LASTUSEDIMPORFILTER2D =
"LastUsedImportFilter2D";
46 : m_mainWindow(parent)
47 , m_project_document(nullptr)
69 if (settings.childGroups().contains(S_PROJECTMANAGER)) {
70 settings.beginGroup(S_PROJECTMANAGER);
72 if (!settings.contains(S_AUTOSAVE))
73 settings.setValue(S_AUTOSAVE,
true);
78 if (settings.contains(S_LASTUSEDIMPORTDIR))
95 settings.beginGroup(S_PROJECTMANAGER);
116 QStringList updatedList;
120 updatedList.append(fileName);
141 if (result.isEmpty())
142 result = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
197 settings.setValue(S_PROJECTMANAGER +
"/" + S_AUTOSAVE, value);
229 if (!projectFileName.isEmpty())
241 bool projectWasClosed(
true);
245 msgBox.setText(
"The project has been modified.");
246 msgBox.setInformativeText(
"Do you want to save your changes?");
247 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
248 msgBox.setDefaultButton(QMessageBox::Save);
249 int ret = msgBox.exec();
252 case QMessageBox::Save:
254 projectWasClosed =
false;
256 case QMessageBox::Discard:
258 case QMessageBox::Cancel:
259 projectWasClosed =
false;
266 if (projectWasClosed)
269 return projectWasClosed;
276 if (projectFileName.isEmpty()) {
283 if (projectFileName.isEmpty())
288 }
catch (
const std::exception& ex) {
289 QString message = QString(
"Failed to save project under '%1'. \n\n").arg(projectFileName);
290 message.append(
"Exception was thrown.\n\n");
291 message.append(ex.what());
309 if (projectFileName.isEmpty())
324 if (fileName.isEmpty()) {
327 "BornAgain project Files (*.pro)");
328 if (fileName.isEmpty())
352 throw GUIHelpers::Error(
"ProjectManager::createNewProject() -> Project already exists");
382 QApplication::setOverrideCursor(Qt::WaitCursor);
387 QApplication::setOverrideCursor(Qt::WaitCursor);
390 QApplication::restoreOverrideCursor();
401 if (dialog.exec() != QDialog::Accepted)
432 QString result =
"Untitled";
435 for (
size_t i = 1; i < 99; ++i) {
436 result = QString(
"Untitled") + QString::number(i);
437 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
455 message.append(details +
"\n");
466 warningDialog->show();
467 warningDialog->raise();
474 QString title(
"Recover project");
477 QString(
"Project '%1' contains autosaved data.\n\n"
478 "Project saved at %2\nAutosave from %3")
484 "\nDo you want to restore from autosave?\n",
"Yes, please restore.",
485 "No, keep loading original");
Defines class holding all application models.
Defines the macro ASSERT.
#define ASSERT(condition)
Defines class GUIHelpers functions.
Defines class MainWindow.
Defines class ProjectManager.
Defines MessageService class.
Defines class ProjectLoadWarningDialog.
Defines ProjectUtils namespace.
Defines class SaveService.
static void unsubscribe(ProjectManager *projectManager)
static void subscribe(ProjectManager *projectManager)
void resetModels()
reset all models to initial state
ApplicationModels * models()
The service to collect messages from different senders.
QStringList errorDescriptionList(const QObject *sender=0) const
Returns multi-line string representing error messages of given sender.
new project dialog window
QString getWorkingDirectory() const
QString getProjectFileName() const
Project document class handles all data related to the opened project (sample, jobModel,...
void setApplicationModels(ApplicationModels *applicationModels)
QString projectFileName() const
QString documentVersion() const
QString projectName() const
bool hasValidNameAndPath()
void load(const QString &project_file_name)
void setProjectName(const QString &text)
void setLogger(MessageService *messageService)
QString projectDir() const
void setProjectFileName(const QString &text)
void setModified(bool flag)
The dialog to inform user about encountered problems during the loading of old project.
bool saveProject(QString projectFileName="")
Processes save project request.
void setRecentlyUsedImportFilter1D(const QString &filter)
MainWindow * m_mainWindow
void riseProjectLoadFailedDialog()
void createNewProject()
Calls dialog window to define project path and name.
void deleteCurrentProject()
ProjectManager(MainWindow *parent)
QString userExportDir() const
Returns directory name suitable for saving plots.
ProjectDocument * document()
QString untitledProjectName()
Will return 'Untitled' if the directory with such name doesn't exist in project path.
void loadProject(const QString &projectFileName)
Load project data from file name. If autosave info exists, opens dialog for project restore.
QString m_importFilter2D
Recently used import filter for 2D files.
QStringList m_recentProjects
void clearRecentProjects()
Clears list of recent projects.
void onDocumentModified()
Updates title of main window when the project was modified.
void setAutosaveEnabled(bool value)
void setImportDirFromFilePath(const QString &filePath)
Sets user import directory in system settings.
QString recentlyUsedImportFilter2D() const
SaveService * m_saveService
void addToRecentProjects()
Add name of the current project to the name of recent projects.
QString m_importDirectory
QString acquireProjectFileName(bool forSaveAs)
Returns project file name from dialog. Returns empty string if dialog was canceled.
void setRecentlyUsedImportFilter2D(const QString &filter)
bool closeCurrentProject()
Processes close current project request.
void readSettings()
Reads settings of ProjectManager from global settings.
QString m_workingDirectory
Name of directory from there user prefer to import files.
void openProject(QString fileName="")
Opens existing project. If fileName is empty, will popup file selection dialog.
void setImportDir(const QString &dirname)
Sets user import directory in system settings.
QString userImportDir() const
Returns directory name which was used by the user to import files.
ProjectDocument * m_project_document
Name of directory where project directory was created.
bool isAutosaveEnabled() const
void newProject()
Processes new project request (close old project, rise dialog for project name, create project).
bool saveProjectAs()
Processes 'save project as' request.
void riseProjectLoadWarningDialog()
QStringList recentProjects()
Returns list of recent projects, validates if projects still exists on disk.
QString m_importFilter1D
Recently used import filter for 1D files.
virtual ~ProjectManager()
MessageService * m_messageService
bool restoreProjectDialog(const QString &projectFileName)
Rises dialog if the project should be restored from autosave. Returns true, if yes.
QString projectDir() const
Returns name of the current project directory.
QString workingDirectory()
Returns default project path.
QString recentlyUsedImportFilter1D() const
void writeSettings()
Saves settings of ProjectManager in global settings.
Provides save/autosave of ProjectDocument in a thread.
void setAutosaveEnabled(bool value)
void save(const QString &project_file_name)
bool isAutosaveEnabled() const
void setDocument(ProjectDocument *document)
Defines namespace Constants.
const int MAX_RECENT_PROJECTS
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
bool question(QWidget *parent, const QString &title, const QString &text, const QString &detailedText, const QString &yesText, const QString &noText)
QString lastModified(const QString &fileName)
Returns a string representing modification time of given file.
QString autosaveName(const QString &projectFileName)
Returns name of project for autoSave from given project file name.
QString projectName(const QString &projectFileName)
Returns project name deduced from project file name.
bool hasAutosavedData(const QString &projectFileName)
Returns true if project with given projectFileName contains autosaved data.
Defines class NewProjectDialog.
Defines class ProjectDocument.