BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectManager Class Reference

Description

Handles activity related to opening/save projects.

Definition at line 28 of file ProjectManager.h.

Inheritance diagram for ProjectManager:
[legend]
Collaboration diagram for ProjectManager:
[legend]

Public Slots

void clearRecentProjects ()
 Clears list of recent projects. More...
 
bool closeCurrentProject ()
 Processes close current project request. Call save/discard/cancel dialog, if necessary. Returns false if saving was canceled. More...
 
void newProject ()
 Processes new project request (close old project, rise dialog for project name, create project). More...
 
void openProject (QString fileName="")
 Opens existing project. If fileName is empty, will popup file selection dialog. More...
 
bool saveProject (QString projectFileName="")
 Processes save project request. More...
 
bool saveProjectAs ()
 Processes 'save project as' request. More...
 
void setAutosaveEnabled (bool value)
 

Signals

void aboutToCloseDocument ()
 
void documentModified ()
 
void documentOpenedOrClosed (bool opened)
 
void recentListModified ()
 

Public Member Functions

 ProjectManager (QObject *parent)
 
 ~ProjectManager () override
 
bool isAutosaveEnabled () const
 
QString projectDir () const
 Returns name of the current project directory. More...
 
void readSettings ()
 Reads settings of ProjectManager from global settings. More...
 
QString recentlyUsedImportFilter1D () const
 
QString recentlyUsedImportFilter2D () const
 
QStringList recentProjects ()
 Returns list of recent projects, validates if projects still exists on disk. More...
 
void setImportDir (const QString &dirname)
 Sets user import directory in system settings. More...
 
void setImportDirFromFilePath (const QString &filePath)
 Sets user import directory in system settings. More...
 
void setRecentlyUsedImportFilter1D (const QString &filter)
 
void setRecentlyUsedImportFilter2D (const QString &filter)
 
QString userImportDir () const
 Returns directory name which was used by the user to import files. More...
 
void writeSettings ()
 Saves settings of ProjectManager in global settings. More...
 

Static Public Member Functions

static ProjectManagerinstance ()
 

Private Member Functions

QString acquireProjectFileName ()
 Returns project file name from dialog. Returns empty string if dialog was canceled. More...
 
void addToRecentProjects ()
 Add name of the current project to the name of recent projects. More...
 
void createNewProject ()
 Calls dialog window to define project path and name. More...
 
void deleteCurrentProject ()
 
ProjectDocument::ReadResult loadProject (const QString &projectFileName, MessageService &messageService)
 Load project data from file name. If autosave info exists, opens dialog for project restore. More...
 
bool restoreProjectDialog (const QString &projectFileName, QString autosaveName)
 Name of directory where project directory was created. More...
 
void riseProjectLoadFailedDialog (const MessageService &messageService)
 
void riseProjectLoadProblemDialog (const MessageService &messageService)
 
QString untitledProjectName ()
 Will return 'Untitled' if the directory with such name doesn't exist in project path. Otherwise will return Untitled1, Untitled2 etc. More...
 
QString workingDirectory ()
 Returns default project path. More...
 

Private Attributes

QString m_importDirectory
 
QString m_importFilter1D
 Recently used import filter for 1D files. More...
 
QString m_importFilter2D
 Recently used import filter for 2D files. More...
 
QStringList m_recentProjects
 
SaveServicem_saveService
 
QString m_workingDirectory
 Name of directory from there user prefer to import files. More...
 

Static Private Attributes

static ProjectManagers_instance = nullptr
 

Constructor & Destructor Documentation

◆ ProjectManager()

ProjectManager::ProjectManager ( QObject *  parent)

Definition at line 49 of file ProjectManager.cpp.

50  : QObject(parent)
51  , m_saveService(new SaveService(this))
52 
53 {
54  if (s_instance != nullptr)
55  throw Error("ProjectManager::ProjectManager -> Error. Attempt to create "
56  "ProjectManager twice.");
57 
58  s_instance = this;
59 }
SaveService * m_saveService
static ProjectManager * s_instance
Provides save/autosave of ProjectDocument in a thread.
Definition: SaveService.h:26

References Error, and s_instance.

◆ ~ProjectManager()

ProjectManager::~ProjectManager ( )
override

Definition at line 61 of file ProjectManager.cpp.

62 {
63  s_instance = nullptr;
65 }
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
std::optional< ProjectDocument * > projectDocument
Definition: SessionData.h:27

References gSessionData, SessionData::projectDocument, and s_instance.

Member Function Documentation

◆ aboutToCloseDocument

void ProjectManager::aboutToCloseDocument ( )
signal

◆ acquireProjectFileName()

QString ProjectManager::acquireProjectFileName ( )
private

Returns project file name from dialog. Returns empty string if dialog was canceled.

Definition at line 389 of file ProjectManager.cpp.

390 {
392 
393  if (dialog.exec() != QDialog::Accepted)
394  return "";
395 
396  m_workingDirectory = dialog.getWorkingDirectory();
397 
398  return dialog.getProjectFileName();
399 }
new project dialog window
QString untitledProjectName()
Will return 'Untitled' if the directory with such name doesn't exist in project path....
QString m_workingDirectory
Name of directory from there user prefer to import files.
QString workingDirectory()
Returns default project path.
static QMainWindow * mainWindow
Definition: Globals.h:22

References NewProjectDialog::getProjectFileName(), NewProjectDialog::getWorkingDirectory(), m_workingDirectory, GUI::Global::mainWindow, untitledProjectName(), and workingDirectory().

Referenced by saveProject(), and saveProjectAs().

Here is the call graph for this function:

◆ addToRecentProjects()

void ProjectManager::addToRecentProjects ( )
private

Add name of the current project to the name of recent projects.

Definition at line 403 of file ProjectManager.cpp.

404 {
405  QString fileName = gSessionData->projectDocument.value()->projectFileName();
406  m_recentProjects.removeAll(fileName);
407  m_recentProjects.prepend(fileName);
409  m_recentProjects.removeLast();
410 
411  emit recentListModified();
412 }
void recentListModified()
QStringList m_recentProjects
const int MAX_RECENT_PROJECTS

References gSessionData, m_recentProjects, GUI::Constants::MAX_RECENT_PROJECTS, SessionData::projectDocument, and recentListModified().

Referenced by openProject(), and saveProject().

◆ clearRecentProjects

void ProjectManager::clearRecentProjects ( )
slot

Clears list of recent projects.

Definition at line 201 of file ProjectManager.cpp.

202 {
203  m_recentProjects.clear();
204  emit recentListModified();
205 }

References m_recentProjects, and recentListModified().

Referenced by ActionManager::onAboutToShowFileMenu().

◆ closeCurrentProject

bool ProjectManager::closeCurrentProject ( )
slot

Processes close current project request. Call save/discard/cancel dialog, if necessary. Returns false if saving was canceled.

Definition at line 220 of file ProjectManager.cpp.

221 {
222  if (!gSessionData->projectDocument.has_value())
223  return true;
224 
225  if (gSessionData->projectDocument.value()->isModified()) {
226  QMessageBox msgBox;
227  msgBox.setText("The project has been modified.");
228  msgBox.setInformativeText("Do you want to save your changes?");
229  msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
230  msgBox.setDefaultButton(QMessageBox::Save);
231 
232  switch (msgBox.exec()) {
233  case QMessageBox::Save:
234  if (!saveProject())
235  return false;
236  break;
237  case QMessageBox::Discard:
238  break;
239  case QMessageBox::Cancel:
240  return false;
241  default:
242  break;
243  }
244  }
245 
247  emit documentOpenedOrClosed(false);
248  return true;
249 }
bool saveProject(QString projectFileName="")
Processes save project request.
void deleteCurrentProject()
void documentOpenedOrClosed(bool opened)

References deleteCurrentProject(), documentOpenedOrClosed(), gSessionData, SessionData::projectDocument, and saveProject().

Referenced by MainWindow::closeEvent(), ActionManager::createActions(), newProject(), and openProject().

Here is the call graph for this function:

◆ createNewProject()

void ProjectManager::createNewProject ( )
private

Calls dialog window to define project path and name.

Definition at line 329 of file ProjectManager.cpp.

330 {
331  if (gSessionData->projectDocument.has_value())
332  throw Error("ProjectManager::createNewProject() -> Project already exists");
333 
335 
336  const QVariant defFunctionalities =
338  gSessionData->projectDocument.value()->setFunctionalities(
339  toFunctionalities(defFunctionalities));
340  gSessionData->projectDocument.value()->setSingleInstrumentMode(
342  gSessionData->projectDocument.value()->setSingleSampleMode(
344 
345  gSessionData->projectDocument.value()->setProjectName("Untitled");
346  gSessionData->projectDocument.value()->clearModified();
347 
349 
350  connect(gSessionData->projectDocument.value(), &ProjectDocument::modified, this,
352 }
ApplicationSettings * appSettings
global pointer to the instance
ProjectDocument::Functionalities toFunctionalities(const QVariant &v)
QVariant toVariant(const ProjectDocument::Functionalities &f)
bool defaultIsSingleSampleMode() const
bool defaultIsSingleInstrumentMode() const
QVariant defaultFunctionalities(const QVariant &absenceValue) const
Project document class handles all data related to the opened project (sample, job,...
void modified()
Emitted for any modifications in the document.
void documentModified()
void setDocument(ProjectDocument *document)
Definition: SaveService.cpp:52

References ProjectDocument::All, appSettings, ApplicationSettings::defaultFunctionalities(), ApplicationSettings::defaultIsSingleInstrumentMode(), ApplicationSettings::defaultIsSingleSampleMode(), documentModified(), Error, gSessionData, m_saveService, ProjectDocument::modified(), SessionData::projectDocument, SaveService::setDocument(), toFunctionalities(), and toVariant().

Referenced by newProject(), and openProject().

Here is the call graph for this function:

◆ deleteCurrentProject()

void ProjectManager::deleteCurrentProject ( )
private

Definition at line 354 of file ProjectManager.cpp.

355 {
356  emit aboutToCloseDocument();
358 
359  gSessionData->projectDocument.reset();
360 }
void aboutToCloseDocument()
void stopService()

References aboutToCloseDocument(), gSessionData, m_saveService, SessionData::projectDocument, and SaveService::stopService().

Referenced by closeCurrentProject(), and openProject().

Here is the call graph for this function:

◆ documentModified

void ProjectManager::documentModified ( )
signal

◆ documentOpenedOrClosed

void ProjectManager::documentOpenedOrClosed ( bool  opened)
signal

◆ instance()

ProjectManager * ProjectManager::instance ( )
static

Definition at line 67 of file ProjectManager.cpp.

68 {
69  if (!s_instance)
70  throw Error("ProjectManager::instance() -> Error. Attempt to access "
71  "non existing ProjectManager.");
72 
73  return s_instance;
74 }

References Error, and s_instance.

Referenced by ActionManager::ActionManager(), SimulationView::exportPythonScript(), RealDataSelectorWidget::importData1D(), RealDataSelectorWidget::importData2D(), and WelcomeView::projectManager().

◆ isAutosaveEnabled()

bool ProjectManager::isAutosaveEnabled ( ) const

Definition at line 187 of file ProjectManager.cpp.

188 {
190 }
bool isAutosaveEnabled() const
Definition: SaveService.cpp:84

References SaveService::isAutosaveEnabled(), and m_saveService.

Referenced by ActionManager::onAboutToShowSettingsMenu().

Here is the call graph for this function:

◆ loadProject()

ProjectDocument::ReadResult ProjectManager::loadProject ( const QString &  projectFileName,
MessageService messageService 
)
private

Load project data from file name. If autosave info exists, opens dialog for project restore.

Definition at line 364 of file ProjectManager.cpp.

366 {
367  auto readResult = ProjectDocument::ReadResult::ok;
368 
369  const bool useAutosave =
371  const QString autosaveName = GUI::Project::Utils::autosaveName(projectFileName);
372  if (useAutosave && restoreProjectDialog(projectFileName, autosaveName)) {
373  QApplication::setOverrideCursor(Qt::WaitCursor);
374  readResult =
375  gSessionData->projectDocument.value()->loadProjectFile(autosaveName, messageService);
376  gSessionData->projectDocument.value()->setProjectFileName(projectFileName);
377  gSessionData->projectDocument.value()->setModified();
378  } else {
379  QApplication::setOverrideCursor(Qt::WaitCursor);
380  readResult =
381  gSessionData->projectDocument.value()->loadProjectFile(projectFileName, messageService);
382  }
383  QApplication::restoreOverrideCursor();
384  return readResult;
385 }
bool restoreProjectDialog(const QString &projectFileName, QString autosaveName)
Name of directory where project directory was created.
bool hasAutosavedData(const QString &projectFileName)
Returns true if project with given projectFileName contains autosaved data.
QString autosaveName(const QString &projectFileName)
Returns name of project for autoSave from given project file name. E.g. from '/projects/Untitled2/Unt...

References GUI::Project::Utils::autosaveName(), gSessionData, GUI::Project::Utils::hasAutosavedData(), m_saveService, ProjectDocument::ok, SessionData::projectDocument, and restoreProjectDialog().

Referenced by openProject().

Here is the call graph for this function:

◆ newProject

void ProjectManager::newProject ( )
slot

Processes new project request (close old project, rise dialog for project name, create project).

Definition at line 209 of file ProjectManager.cpp.

210 {
211  if (!closeCurrentProject())
212  return;
214  emit documentOpenedOrClosed(true);
215 }
void createNewProject()
Calls dialog window to define project path and name.
bool closeCurrentProject()
Processes close current project request. Call save/discard/cancel dialog, if necessary....

References closeCurrentProject(), createNewProject(), and documentOpenedOrClosed().

Referenced by MainWindow::MainWindow(), WelcomeView::WelcomeView(), and ActionManager::createActions().

Here is the call graph for this function:

◆ openProject

void ProjectManager::openProject ( QString  fileName = "")
slot

Opens existing project. If fileName is empty, will popup file selection dialog.

Definition at line 295 of file ProjectManager.cpp.

296 {
297  if (!closeCurrentProject())
298  return;
299 
300  if (fileName.isEmpty()) {
301  fileName = QFileDialog::getOpenFileName(
302  GUI::Global::mainWindow, "Open project file", workingDirectory(),
303  "BornAgain project Files (*.pro)", nullptr,
304  appSettings->useNativeFileDialog() ? QFileDialog::Options()
305  : QFileDialog::DontUseNativeDialog);
306  if (fileName.isEmpty())
307  return;
308  }
309 
311  MessageService messageService;
312  const auto readResult = loadProject(fileName, messageService);
313 
314  if (readResult == ProjectDocument::ReadResult::ok)
316  else if (readResult == ProjectDocument::ReadResult::error) {
317  riseProjectLoadFailedDialog(messageService);
319  } else if (readResult == ProjectDocument::ReadResult::warning) {
320  riseProjectLoadProblemDialog(messageService);
322  }
323  if (gSessionData->projectDocument.has_value())
324  emit documentOpenedOrClosed(true);
325 }
bool useNativeFileDialog() const
The service to collect messages from different senders.
ProjectDocument::ReadResult loadProject(const QString &projectFileName, MessageService &messageService)
Load project data from file name. If autosave info exists, opens dialog for project restore.
void riseProjectLoadProblemDialog(const MessageService &messageService)
void addToRecentProjects()
Add name of the current project to the name of recent projects.
void riseProjectLoadFailedDialog(const MessageService &messageService)

References addToRecentProjects(), appSettings, closeCurrentProject(), createNewProject(), deleteCurrentProject(), documentOpenedOrClosed(), ProjectDocument::error, gSessionData, loadProject(), GUI::Global::mainWindow, ProjectDocument::ok, SessionData::projectDocument, riseProjectLoadFailedDialog(), riseProjectLoadProblemDialog(), ApplicationSettings::useNativeFileDialog(), ProjectDocument::warning, and workingDirectory().

Referenced by ActionManager::createActions(), MainWindow::openRecentProject(), and WelcomeView::updateRecentProjectPanel().

Here is the call graph for this function:

◆ projectDir()

QString ProjectManager::projectDir ( ) const

Returns name of the current project directory.

Definition at line 134 of file ProjectManager.cpp.

135 {
136  if (gSessionData->projectDocument.has_value())
137  return gSessionData->projectDocument.value()->validProjectDir();
138  return "";
139 }

References gSessionData, and SessionData::projectDocument.

Referenced by untitledProjectName().

◆ readSettings()

void ProjectManager::readSettings ( )

Reads settings of ProjectManager from global settings.

Definition at line 78 of file ProjectManager.cpp.

79 {
80  QSettings settings;
81  m_workingDirectory = QDir::homePath();
82  if (settings.childGroups().contains(S_PROJECTMANAGER)) {
83  settings.beginGroup(S_PROJECTMANAGER);
84 
85  if (!settings.contains(S_AUTOSAVE))
86  settings.setValue(S_AUTOSAVE, true);
87 
88  m_workingDirectory = settings.value(S_DEFAULTPROJECTPATH).toString();
89  m_recentProjects = settings.value(S_RECENTPROJECTS).toStringList();
90 
91  if (settings.contains(S_LASTUSEDIMPORTDIR))
92  m_importDirectory = settings.value(S_LASTUSEDIMPORTDIR, QString()).toString();
93 
94  m_importFilter1D = settings.value(S_LASTUSEDIMPORFILTER1D, m_importFilter1D).toString();
95  m_importFilter2D = settings.value(S_LASTUSEDIMPORFILTER2D, m_importFilter2D).toString();
96 
97  setAutosaveEnabled(settings.value(S_AUTOSAVE).toBool());
98 
99  settings.endGroup();
100  }
101 }
QString m_importFilter2D
Recently used import filter for 2D files.
void setAutosaveEnabled(bool value)
QString m_importDirectory
QString m_importFilter1D
Recently used import filter for 1D files.

References m_importDirectory, m_importFilter1D, m_importFilter2D, m_recentProjects, m_workingDirectory, and setAutosaveEnabled().

Referenced by MainWindow::readSettings().

Here is the call graph for this function:

◆ recentListModified

void ProjectManager::recentListModified ( )
signal

◆ recentlyUsedImportFilter1D()

QString ProjectManager::recentlyUsedImportFilter1D ( ) const

Definition at line 153 of file ProjectManager.cpp.

154 {
155  return m_importFilter1D;
156 }

References m_importFilter1D.

Referenced by RealDataSelectorWidget::importData1D().

◆ recentlyUsedImportFilter2D()

QString ProjectManager::recentlyUsedImportFilter2D ( ) const

Definition at line 158 of file ProjectManager.cpp.

159 {
160  return m_importFilter2D;
161 }

References m_importFilter2D.

Referenced by RealDataSelectorWidget::importData2D().

◆ recentProjects()

QStringList ProjectManager::recentProjects ( )

Returns list of recent projects, validates if projects still exists on disk.

Definition at line 122 of file ProjectManager.cpp.

123 {
124  QStringList updatedList;
125  for (const QString& fileName : m_recentProjects)
126  if (QFile fin(fileName); fin.exists())
127  updatedList.append(fileName);
128  m_recentProjects = updatedList;
129  return m_recentProjects;
130 }

References m_recentProjects.

Referenced by ActionManager::onAboutToShowFileMenu().

◆ restoreProjectDialog()

bool ProjectManager::restoreProjectDialog ( const QString &  projectFileName,
QString  autosaveName 
)
private

Name of directory where project directory was created.

Rises dialog if the project should be restored from autosave. Returns true, if yes.

Definition at line 467 of file ProjectManager.cpp.

469 {
470  const QString title("Recover project");
471  const QString lmProject =
472  QFileInfo(projectFileName).lastModified().toString("hh:mm:ss, MMMM d, yyyy");
473  const QString lmAutoSave =
474  QFileInfo(autosaveName).lastModified().toString("hh:mm:ss, MMMM d, yyyy");
475 
476  QString message = QString("Project '%1' contains autosaved data.\n\n"
477  "Project saved at %2\nAutosave from %3")
478  .arg(GUI::Project::Utils::projectName(projectFileName))
479  .arg(lmProject)
480  .arg(lmAutoSave);
481 
483  "\nDo you want to restore from autosave?\n",
484  "Yes, please restore.", "No, keep loading original");
485 }
QString projectName(const QString &projectFileName)
Returns project name deduced from project file name.
bool question(QWidget *parent, const QString &title, const QString &text, const QString &detailedText, const QString &yesText, const QString &noText)
Definition: MessageBox.cpp:52

References GUI::Project::Utils::autosaveName(), GUI::Global::mainWindow, GUI::Project::Utils::projectName(), and GUI::View::Helpers::question().

Referenced by loadProject().

Here is the call graph for this function:

◆ riseProjectLoadFailedDialog()

void ProjectManager::riseProjectLoadFailedDialog ( const MessageService messageService)
private

Definition at line 443 of file ProjectManager.cpp.

444 {
445  QString message = QString("Failed to load the project '%1' \n\n")
446  .arg(gSessionData->projectDocument.value()->projectFileName());
447 
448  for (const auto& details : messageService.errors())
449  message.append(details + "\n");
450 
451  QMessageBox::warning(GUI::Global::mainWindow, "Error while opening project file", message);
452 }
QStringList errors(bool includeSenders=false) const
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:37

References MessageService::errors(), gSessionData, GUI::Global::mainWindow, SessionData::projectDocument, and GUI::View::Helpers::warning().

Referenced by openProject().

Here is the call graph for this function:

◆ riseProjectLoadProblemDialog()

void ProjectManager::riseProjectLoadProblemDialog ( const MessageService messageService)
private

Definition at line 454 of file ProjectManager.cpp.

455 {
456  ASSERT(gSessionData->projectDocument.has_value());
457  auto* problemDialog =
459  gSessionData->projectDocument.value()->documentVersion());
460 
461  problemDialog->show();
462  problemDialog->raise();
463 }
QStringList warnings(bool includeSenders=false) const
The dialog to inform user about encountered problems during the loading of old project.

References gSessionData, GUI::Global::mainWindow, SessionData::projectDocument, and MessageService::warnings().

Referenced by openProject().

Here is the call graph for this function:

◆ saveProject

bool ProjectManager::saveProject ( QString  projectFileName = "")
slot

Processes save project request.

Definition at line 253 of file ProjectManager.cpp.

254 {
255  if (projectFileName.isEmpty()) {
256  if (gSessionData->projectDocument.value()->hasValidNameAndPath())
257  projectFileName = gSessionData->projectDocument.value()->projectFileName();
258  else
259  projectFileName = acquireProjectFileName();
260  }
261 
262  if (projectFileName.isEmpty())
263  return false;
264 
265  try {
266  m_saveService->save(projectFileName);
267  } catch (const std::exception& ex) {
268  QString message = QString("Failed to save project under '%1'. \n\n").arg(projectFileName);
269  message.append("Exception was thrown.\n\n");
270  message.append(ex.what());
271 
272  QMessageBox::warning(GUI::Global::mainWindow, "Error while saving project", message);
273  return false;
274  }
275 
277 
278  return true;
279 }
QString acquireProjectFileName()
Returns project file name from dialog. Returns empty string if dialog was canceled.
void save(const QString &project_file_name)
Definition: SaveService.cpp:62

References acquireProjectFileName(), addToRecentProjects(), gSessionData, m_saveService, GUI::Global::mainWindow, SessionData::projectDocument, SaveService::save(), and GUI::View::Helpers::warning().

Referenced by closeCurrentProject(), ActionManager::createActions(), and saveProjectAs().

Here is the call graph for this function:

◆ saveProjectAs

bool ProjectManager::saveProjectAs ( )
slot

Processes 'save project as' request.

Definition at line 283 of file ProjectManager.cpp.

284 {
285  QString projectFileName = acquireProjectFileName();
286 
287  if (projectFileName.isEmpty())
288  return false;
289 
290  return saveProject(projectFileName);
291 }

References acquireProjectFileName(), and saveProject().

Referenced by ActionManager::createActions().

Here is the call graph for this function:

◆ setAutosaveEnabled

void ProjectManager::setAutosaveEnabled ( bool  value)
slot

Definition at line 192 of file ProjectManager.cpp.

193 {
195  QSettings settings;
196  settings.setValue(S_PROJECTMANAGER + "/" + S_AUTOSAVE, value);
197 }
void setAutosaveEnabled(bool value)
Definition: SaveService.cpp:70

References m_saveService, and SaveService::setAutosaveEnabled().

Referenced by ActionManager::onAboutToShowSettingsMenu(), and readSettings().

Here is the call graph for this function:

◆ setImportDir()

void ProjectManager::setImportDir ( const QString &  dirname)

Sets user import directory in system settings.

Definition at line 165 of file ProjectManager.cpp.

166 {
167  m_importDirectory = dirname;
168 }

References m_importDirectory.

◆ setImportDirFromFilePath()

void ProjectManager::setImportDirFromFilePath ( const QString &  filePath)

Sets user import directory in system settings.

Definition at line 172 of file ProjectManager.cpp.

173 {
174  m_importDirectory = QFileInfo(filePath).absolutePath();
175 }

References m_importDirectory.

Referenced by RealDataSelectorWidget::importData1D(), and RealDataSelectorWidget::importData2D().

◆ setRecentlyUsedImportFilter1D()

void ProjectManager::setRecentlyUsedImportFilter1D ( const QString &  filter)

Definition at line 177 of file ProjectManager.cpp.

178 {
179  m_importFilter1D = filter;
180 }

References m_importFilter1D.

Referenced by RealDataSelectorWidget::importData1D().

◆ setRecentlyUsedImportFilter2D()

void ProjectManager::setRecentlyUsedImportFilter2D ( const QString &  filter)

Definition at line 182 of file ProjectManager.cpp.

183 {
184  m_importFilter2D = filter;
185 }

References m_importFilter2D.

Referenced by RealDataSelectorWidget::importData2D().

◆ untitledProjectName()

QString ProjectManager::untitledProjectName ( )
private

Will return 'Untitled' if the directory with such name doesn't exist in project path. Otherwise will return Untitled1, Untitled2 etc.

Definition at line 424 of file ProjectManager.cpp.

425 {
426  QString result = "Untitled";
427  QDir projectDir = workingDirectory() + "/" + result;
428  if (projectDir.exists()) {
429  for (size_t i = 1; i < 99; ++i) {
430  result = QString("Untitled") + QString::number(i);
431 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
432  projectDir.setPath(workingDirectory() + "/" + result);
433 #else
434  projectDir = workingDirectory() + "/" + result;
435 #endif
436  if (!projectDir.exists())
437  break;
438  }
439  }
440  return result;
441 }
QString projectDir() const
Returns name of the current project directory.

References projectDir(), and workingDirectory().

Referenced by acquireProjectFileName().

Here is the call graph for this function:

◆ userImportDir()

QString ProjectManager::userImportDir ( ) const

Returns directory name which was used by the user to import files.

Definition at line 143 of file ProjectManager.cpp.

144 {
145  if (m_importDirectory.isEmpty()) {
146  if (gSessionData->projectDocument.has_value())
147  return gSessionData->projectDocument.value()->userExportDir();
148  return "";
149  }
150  return m_importDirectory;
151 }

References gSessionData, m_importDirectory, and SessionData::projectDocument.

Referenced by RealDataSelectorWidget::importData1D(), and RealDataSelectorWidget::importData2D().

◆ workingDirectory()

QString ProjectManager::workingDirectory ( )
private

Returns default project path.

Definition at line 416 of file ProjectManager.cpp.

417 {
418  return m_workingDirectory;
419 }

References m_workingDirectory.

Referenced by acquireProjectFileName(), openProject(), and untitledProjectName().

◆ writeSettings()

void ProjectManager::writeSettings ( )

Saves settings of ProjectManager in global settings.

Definition at line 105 of file ProjectManager.cpp.

106 {
107  QSettings settings;
108  settings.beginGroup(S_PROJECTMANAGER);
109  settings.setValue(S_DEFAULTPROJECTPATH, m_workingDirectory);
110  settings.setValue(S_RECENTPROJECTS, m_recentProjects);
111 
112  if (!m_importDirectory.isEmpty())
113  settings.setValue(S_LASTUSEDIMPORTDIR, m_importDirectory);
114  settings.setValue(S_LASTUSEDIMPORFILTER1D, m_importFilter1D);
115  settings.setValue(S_LASTUSEDIMPORFILTER2D, m_importFilter2D);
116 
117  settings.endGroup();
118 }

References m_importDirectory, m_importFilter1D, m_importFilter2D, m_recentProjects, and m_workingDirectory.

Referenced by MainWindow::writeSettings().

Member Data Documentation

◆ m_importDirectory

QString ProjectManager::m_importDirectory
private

◆ m_importFilter1D

QString ProjectManager::m_importFilter1D
private

Recently used import filter for 1D files.

Definition at line 88 of file ProjectManager.h.

Referenced by readSettings(), recentlyUsedImportFilter1D(), setRecentlyUsedImportFilter1D(), and writeSettings().

◆ m_importFilter2D

QString ProjectManager::m_importFilter2D
private

Recently used import filter for 2D files.

Definition at line 91 of file ProjectManager.h.

Referenced by readSettings(), recentlyUsedImportFilter2D(), setRecentlyUsedImportFilter2D(), and writeSettings().

◆ m_recentProjects

QStringList ProjectManager::m_recentProjects
private

◆ m_saveService

SaveService* ProjectManager::m_saveService
private

◆ m_workingDirectory

QString ProjectManager::m_workingDirectory
private

Name of directory from there user prefer to import files.

Definition at line 82 of file ProjectManager.h.

Referenced by acquireProjectFileName(), readSettings(), workingDirectory(), and writeSettings().

◆ s_instance

ProjectManager * ProjectManager::s_instance = nullptr
staticprivate

Definition at line 96 of file ProjectManager.h.

Referenced by ProjectManager(), ~ProjectManager(), and instance().


The documentation for this class was generated from the following files: