BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::RecentProjectSettings Class Reference

Collection of settings for RecentProjectWidget. More...

Public Member Functions

 RecentProjectSettings ()
 
 ~RecentProjectSettings ()
 
void addToRecentProjects (const QString &dirname)
 Adds directory to the list of recent projects. More...
 
void clearRecentProjectsList ()
 
QString currentWorkdir () const
 Returns current workdir. More...
 
QStringList recentProjects ()
 Returns list of recent projects, validates if projects still exists on disk. More...
 
void updateWorkdirFromSelection (const QString &dirname)
 Updates current workdir value from user selection. More...
 

Private Member Functions

void readSettings ()
 Reads all settings from file. More...
 
void writeSettings ()
 Write all settings to file. More...
 

Private Attributes

QString m_currentWorkdir
 
QStringList m_recentProjects
 

Detailed Description

Collection of settings for RecentProjectWidget.

Used to save last directory selected by the user, and list of recent projects. Relies on QSettings machinery.

Definition at line 26 of file recentprojectsettings.h.

Constructor & Destructor Documentation

◆ RecentProjectSettings()

gui2::RecentProjectSettings::RecentProjectSettings ( )

Definition at line 41 of file recentprojectsettings.cpp.

42 {
43  readSettings();
44 }
void readSettings()
Reads all settings from file.

References readSettings().

Here is the call graph for this function:

◆ ~RecentProjectSettings()

gui2::RecentProjectSettings::~RecentProjectSettings ( )

Definition at line 46 of file recentprojectsettings.cpp.

47 {
48  writeSettings();
49 }
void writeSettings()
Write all settings to file.

References writeSettings().

Here is the call graph for this function:

Member Function Documentation

◆ addToRecentProjects()

void gui2::RecentProjectSettings::addToRecentProjects ( const QString &  dirname)

Adds directory to the list of recent projects.

Definition at line 80 of file recentprojectsettings.cpp.

81 {
82  m_recentProjects.removeAll(dirname);
83  m_recentProjects.prepend(dirname);
84  while (m_recentProjects.size() > max_recent_projects)
85  m_recentProjects.removeLast();
86 }

References m_recentProjects.

◆ clearRecentProjectsList()

void gui2::RecentProjectSettings::clearRecentProjectsList ( )

Definition at line 88 of file recentprojectsettings.cpp.

89 {
90  m_recentProjects.clear();
91 }

References m_recentProjects.

◆ currentWorkdir()

QString gui2::RecentProjectSettings::currentWorkdir ( ) const

Returns current workdir.

Definition at line 52 of file recentprojectsettings.cpp.

53 {
54  return m_currentWorkdir;
55 }

References m_currentWorkdir.

Referenced by gui2::UserInteractor::selectDir().

◆ readSettings()

void gui2::RecentProjectSettings::readSettings ( )
private

Reads all settings from file.

Definition at line 102 of file recentprojectsettings.cpp.

103 {
104  QSettings settings;
105  m_currentWorkdir = QDir::homePath();
106 
107  if (settings.contains(workdir_setting_name()))
108  m_currentWorkdir = settings.value(workdir_setting_name()).toString();
109 
110  if (settings.contains(recent_projects_setting_name()))
111  m_recentProjects = settings.value(recent_projects_setting_name()).toStringList();
112 }

References m_currentWorkdir, and m_recentProjects.

Referenced by RecentProjectSettings().

◆ recentProjects()

QStringList gui2::RecentProjectSettings::recentProjects ( )

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

Definition at line 68 of file recentprojectsettings.cpp.

69 {
70  QStringList updatedList;
71  for (const auto& fileName : m_recentProjects) {
72  if (ModelView::Utils::exists(fileName.toStdString()))
73  updatedList.append(fileName);
74  }
75  m_recentProjects = updatedList;
76  return m_recentProjects;
77 }
MVVM_MODEL_EXPORT bool exists(const std::string &fileName)
Returns true if file exists.
Definition: fileutils.cpp:27

References ModelView::Utils::exists(), and m_recentProjects.

Here is the call graph for this function:

◆ updateWorkdirFromSelection()

void gui2::RecentProjectSettings::updateWorkdirFromSelection ( const QString &  dirname)

Updates current workdir value from user selection.

Workdir will be set as parent director of selected dirname.

Definition at line 59 of file recentprojectsettings.cpp.

60 {
61  if (!dirname.isEmpty()) {
62  auto parent_path = ModelView::Utils::parent_path(dirname.toStdString());
63  m_currentWorkdir = QString::fromStdString(parent_path);
64  }
65 }
MVVM_MODEL_EXPORT std::string parent_path(const std::string &path)
Returns the path to the parent directory.
Definition: fileutils.cpp:111

References m_currentWorkdir, and ModelView::Utils::parent_path().

Referenced by gui2::UserInteractor::selectDir().

Here is the call graph for this function:

◆ writeSettings()

void gui2::RecentProjectSettings::writeSettings ( )
private

Write all settings to file.

Definition at line 94 of file recentprojectsettings.cpp.

95 {
96  QSettings settings;
97  settings.setValue(workdir_setting_name(), m_currentWorkdir);
98  settings.setValue(recent_projects_setting_name(), m_recentProjects);
99 }

References m_currentWorkdir, and m_recentProjects.

Referenced by ~RecentProjectSettings().

Member Data Documentation

◆ m_currentWorkdir

QString gui2::RecentProjectSettings::m_currentWorkdir
private

◆ m_recentProjects

QStringList gui2::RecentProjectSettings::m_recentProjects
private

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