BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectSettingsView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Toplevel/ProjectSettingsView.cpp
6 //! @brief Implements class ProjectSettingsView
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include "GUI/Util/Path.h"
19 #include "ui_ProjectSettingsView.h"
20 #include <QDir>
21 #include <QMessageBox>
22 
24  : QWidget(parentWidget)
25  , m_ui(new Ui::ProjectSettingsView)
26  , m_document(document)
27 {
28  m_ui->setupUi(this);
29  m_ui->label_6->hide(); // #baTODO show again
30  m_ui->textEdit->hide();
31 
32  setAttribute(Qt::WA_StyledBackground, true);
33  setProperty("stylable", true); // for stylesheet addressing
34 
39 
40  connect(m_ui->singleInstrumentModeRadio, &QRadioButton::toggled, this,
42 
43  connect(m_ui->singleSampleModeRadio, &QRadioButton::toggled, this,
45 
46  connect(m_ui->gisasCheck, &QCheckBox::toggled, this,
48  connect(m_ui->offspecCheck, &QCheckBox::toggled, this,
50  connect(m_ui->reflectometryCheck, &QCheckBox::toggled, this,
52  connect(m_ui->depthCheck, &QCheckBox::toggled, this,
54 
55  connect(m_ui->storeAsDefaultsButton, &QPushButton::clicked, this,
57 
58  // #baTODO should be "informationModified" or so?
60 }
61 
63 {
65 }
66 
68 {
69  QSignalBlocker b1(m_ui->singleInstrumentModeRadio);
70 
71  m_document->singleInstrumentMode() ? m_ui->singleInstrumentModeRadio->setChecked(true)
72  : m_ui->multipleInstrumentModeRadio->setChecked(true);
73 
74  m_document->singleSampleMode() ? m_ui->singleSampleModeRadio->setChecked(true)
75  : m_ui->multipleSampleModeRadio->setChecked(true);
76 
79 }
80 
82 {
83  const auto f = m_document->functionalities();
84 
85  QSignalBlocker b1(m_ui->gisasCheck);
86  QSignalBlocker b2(m_ui->offspecCheck);
87  QSignalBlocker b3(m_ui->reflectometryCheck);
88  QSignalBlocker b4(m_ui->depthCheck);
89 
90  m_ui->gisasCheck->setChecked(f.testFlag(ProjectDocument::Gisas));
91  m_ui->offspecCheck->setChecked(f.testFlag(ProjectDocument::Offspec));
92  m_ui->reflectometryCheck->setChecked(f.testFlag(ProjectDocument::Specular));
93  m_ui->depthCheck->setChecked(f.testFlag(ProjectDocument::DepthProbe));
94 }
95 
97 {
98  QString location = "[not saved yet]";
99 
100  QString name = m_document->projectName();
103  QDir::toNativeSeparators(m_document->projectFileName()));
104 
105  m_ui->currentProjectName->setText(name);
106  m_ui->currentProjectLocation->setText(location);
107 }
108 
110 {
112  appSettings->setDefaultIsSingleInstrumentMode(m_ui->singleInstrumentModeRadio->isChecked());
113  appSettings->setDefaultIsSingleSampleMode(m_ui->singleSampleModeRadio->isChecked());
114 }
115 
117 {
118  if (newState) {
119  if (m_document->collectedItems()->collectedItems().size() > 1) {
120  QMessageBox::warning(this, "Select single instrument mode",
121  "This project already contains more than one instrument. Changing "
122  "this setting is not possible.");
123 
124  QSignalBlocker b1(m_ui->singleInstrumentModeRadio);
125  m_ui->multipleInstrumentModeRadio->setChecked(true);
126  return;
127  }
128 
130  } else
132 }
133 
134 
136 {
137  if (newState) {
138  if (m_document->sampleItems()->sampleItems().size() > 1) {
139  QMessageBox::warning(this, "Select single sample mode",
140  "This project already contains more than one sample. Changing "
141  "this setting is not possible.");
142 
143  QSignalBlocker b1(m_ui->singleSampleModeRadio);
144  m_ui->multipleSampleModeRadio->setChecked(true);
145  return;
146  }
147 
149  } else
151 }
152 
154 {
155  const auto f = functionalities();
156 
157  if (f == ProjectDocument::None) {
158  QMessageBox::warning(this, "Select functionality",
159  "You have to select at least one functionality. Changing "
160  "this setting is not possible.");
161 
163  return;
164  }
165 
167 }
168 
169 ProjectDocument::Functionalities ProjectSettingsView::functionalities() const
170 {
171  ProjectDocument::Functionalities f;
172  f.setFlag(ProjectDocument::Gisas, m_ui->gisasCheck->isChecked());
173  f.setFlag(ProjectDocument::Offspec, m_ui->offspecCheck->isChecked());
174  f.setFlag(ProjectDocument::Specular, m_ui->reflectometryCheck->isChecked());
175  f.setFlag(ProjectDocument::DepthProbe, m_ui->depthCheck->isChecked());
176  return f;
177 }
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class GroupBoxCollapser.
Defines class Helpers functions.
QVariant toVariant(const ProjectDocument::Functionalities &f)
Defines class ProjectSettingsView.
void setDefaultIsSingleInstrumentMode(bool b)
void setDefaultFunctionalities(const QVariant &functionalities)
void setDefaultIsSingleSampleMode(bool b)
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
QVector< InstrumentItem * > collectedItems() const
QVector< MultiLayerItem * > sampleItems() const
Project document class handles all data related to the opened project (sample, job,...
void setSingleInstrumentMode(bool b)
QString projectFileName() const
void setSingleSampleMode(bool b)
QString projectName() const
InstrumentCollection * collectedItems() const
void setFunctionalities(const Functionalities &f)
Functionalities functionalities() const
MultiLayerItems * sampleItems()
bool singleInstrumentMode() const
void modified()
Emitted for any modifications in the document.
bool singleSampleMode() const
Widget to define project settings.
void showEvent(QShowEvent *) override
Ui::ProjectSettingsView * m_ui
ProjectDocument::Functionalities functionalities() const
void writeOptionsToUI()
Write entries in OptionsItem to UI.
ProjectDocument * m_document
void onSingleSampleRadioToggled(bool newState)
void onSingleInstrumentRadioToggled(bool newState)
ProjectSettingsView(QWidget *parentWidget, ProjectDocument *document)
QString const & name(EShape k)
Definition: particles.cpp:20
QString withTildeHomePath(const QString &path)
Definition: Path.cpp:45
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:37