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

Provide save/discard/cancel and similar dialogs on user request. More...

Collaboration diagram for gui2::UserInteractor:
[legend]

Public Member Functions

 UserInteractor (RecentProjectSettings *settings, QWidget *parent)
 
std::string onCreateDirRequest ()
 Returns new directory on disk created by the user via QFileDialog. More...
 
ModelView::SaveChangesAnswer onSaveChangesRequest ()
 Returns save/cancel/discard changes choice provided by the user. More...
 
std::string onSelectDirRequest ()
 Returns directory on disk selected by the user via QFileDialog. More...
 

Private Member Functions

std::string selectDir () const
 Summon dialog to select directory on disk. More...
 

Private Attributes

QWidget * m_parent {nullptr}
 
RecentProjectSettingsm_settings {nullptr}
 

Detailed Description

Provide save/discard/cancel and similar dialogs on user request.

Intended to work in pair with ProjectManagerDecorator.

Definition at line 34 of file userinteractor.h.

Constructor & Destructor Documentation

◆ UserInteractor()

gui2::UserInteractor::UserInteractor ( RecentProjectSettings settings,
QWidget *  parent 
)

Definition at line 40 of file userinteractor.cpp.

41  : m_settings(settings), m_parent(parent)
42 {
43 }
RecentProjectSettings * m_settings

Member Function Documentation

◆ onCreateDirRequest()

std::string gui2::UserInteractor::onCreateDirRequest ( )

Returns new directory on disk created by the user via QFileDialog.

Definition at line 68 of file userinteractor.cpp.

70 {
71  auto dirname = selectDir();
72 
73  if (dirname.empty()) // no valid selection
74  return {};
75 
76  if (!ModelView::Utils::is_empty(dirname)) {
77  QMessageBox msgBox;
78  msgBox.setText("The selected directory is not empty, choose another one.");
79  msgBox.exec();
80  return {};
81  }
82 
83  return dirname;
84 }
std::string selectDir() const
Summon dialog to select directory on disk.
MVVM_MODEL_EXPORT bool is_empty(const std::string &path)
Returns true if the file indicated by 'path' refers to empty file or directory.
Definition: fileutils.cpp:121

References ModelView::Utils::is_empty(), and selectDir().

Here is the call graph for this function:

◆ onSaveChangesRequest()

SaveChangesAnswer gui2::UserInteractor::onSaveChangesRequest ( )

Returns save/cancel/discard changes choice provided by the user.

Definition at line 88 of file userinteractor.cpp.

89 {
90  static auto translate = answer_map();
91 
92  QMessageBox msgBox;
93  msgBox.setText("The project has been modified.");
94  msgBox.setInformativeText("Do you want to save your changes?");
95  msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
96  msgBox.setDefaultButton(QMessageBox::Save);
97  auto ret = static_cast<QMessageBox::StandardButton>(msgBox.exec());
98  return translate[ret];
99 }

◆ onSelectDirRequest()

std::string gui2::UserInteractor::onSelectDirRequest ( )

Returns directory on disk selected by the user via QFileDialog.

Checks if selected directory can be the project directory.

Definition at line 48 of file userinteractor.cpp.

49 {
50  auto dirname = selectDir();
51 
52  if (dirname.empty()) // no valid selection
53  return {};
54 
56  QMessageBox msgBox;
57  msgBox.setText(
58  "Selected directory doesn't look like a project directory, choose another one");
59  msgBox.exec();
60  return {};
61  }
62 
63  return dirname;
64 }
MVVM_MODEL_EXPORT bool IsPossibleProjectDir(const std::string &project_dir)
Returns 'true' if given directory might be a project directory.

References ModelView::ProjectUtils::IsPossibleProjectDir(), and selectDir().

Here is the call graph for this function:

◆ selectDir()

std::string gui2::UserInteractor::selectDir ( ) const
private

Summon dialog to select directory on disk.

If selection is not empty, save parent directory for later re-use.

Definition at line 104 of file userinteractor.cpp.

105 {
106  QString dirname = QFileDialog::getExistingDirectory(
107  m_parent, "Select directory", m_settings->currentWorkdir(),
108  QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly);
109 
110  if (!dirname.isEmpty())
112 
113  return dirname.toStdString();
114 }
void updateWorkdirFromSelection(const QString &dirname)
Updates current workdir value from user selection.
QString currentWorkdir() const
Returns current workdir.

References gui2::RecentProjectSettings::currentWorkdir(), m_parent, m_settings, and gui2::RecentProjectSettings::updateWorkdirFromSelection().

Referenced by onCreateDirRequest(), and onSelectDirRequest().

Here is the call graph for this function:

Member Data Documentation

◆ m_parent

QWidget* gui2::UserInteractor::m_parent {nullptr}
private

Definition at line 48 of file userinteractor.h.

Referenced by selectDir().

◆ m_settings

RecentProjectSettings* gui2::UserInteractor::m_settings {nullptr}
private

Definition at line 47 of file userinteractor.h.

Referenced by selectDir().


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