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

Description

Instrument selector on the left side of InstrumentView.

Definition at line 29 of file InstrumentListView.h.

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

Signals

void instrumentSelected (InstrumentItem *instrument)
 

Public Member Functions

 InstrumentListView (ProjectDocument *document, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 
InstrumentItemcurrentInstrument () const
 
QSize minimumSizeHint () const override
 
QSize sizeHint () const override
 
QList< QAction * > toolbarActions () const
 

Private Slots

void onCopy ()
 Makes a copy of the currently selected instrument. More...
 
void onItemSelectionChanged ()
 
void onLoadFromLibrary ()
 
void onNewDepthProbe ()
 
void onNewGisas ()
 
void onNewOffspec ()
 
void onNewSpecular ()
 
void onRemove ()
 Removes currently selected instrument. More...
 
void onStoreInLibrary ()
 

Private Member Functions

void ensureItemSelected ()
 
void updateActions ()
 
void updateFunctionalityNarrowing ()
 Show/hide UI elements according to settings in current project. More...
 

Private Attributes

QAction * m_copyAction
 
ProjectDocumentm_document
 
QListView * m_listView
 
QAction * m_loadFromLibraryAction
 
InstrumentListModelm_model
 
QAction * m_newDepthProbeAction
 
QAction * m_newGisasAction
 
QAction * m_newOffspecAction
 
QAction * m_newSpecularAction
 
QAction * m_removeAction
 
QAction * m_separatorAction1
 
QAction * m_separatorAction2
 
QAction * m_storeInLibraryAction
 

Constructor & Destructor Documentation

◆ InstrumentListView()

InstrumentListView::InstrumentListView ( ProjectDocument document,
QWidget *  parent = nullptr,
Qt::WindowFlags  f = Qt::WindowFlags() 
)

Definition at line 27 of file InstrumentListView.cpp.

29  : QWidget(parent, f)
30  , m_document(document)
31 {
32  setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
33 
34  auto* layout = new QVBoxLayout(this);
35  layout->setMargin(10);
36 
37  m_listView = new QListView(this);
38  m_listView->setViewMode(QListView::IconMode);
39  m_listView->setIconSize(QSize(96, 84));
40  m_listView->setMovement(QListView::Static);
41  m_listView->setMaximumWidth(200);
42  m_listView->setSpacing(12);
43  m_listView->setSelectionMode(QAbstractItemView::SingleSelection);
44 
45  m_listView->setObjectName("listView");
46  m_listView->setStyleSheet(
47  QString::fromUtf8("QListView#listView\n"
48  "{\n"
49  " selection-background-color : rgb(98,100,105); \n"
50  " selection-color: rgb(255,255,255);\n"
51  " border: 1px solid rgb(98,100,105);\n"
52  "}\n"));
53  layout->addWidget(m_listView);
54 
56  m_listView->setModel(m_model);
57 
58  m_newGisasAction = new QAction("New GISAS", this);
59  m_newGisasAction->setIcon(QIcon(":/images/shape-square-plus.svg"));
60  m_newGisasAction->setToolTip("Add new GISAS instrument with default settings");
61  connect(m_newGisasAction, &QAction::triggered, this, &InstrumentListView::onNewGisas);
62  addAction(m_newGisasAction);
63 
64  m_newOffspecAction = new QAction("New off-specular", this);
65  m_newOffspecAction->setIcon(QIcon(":/images/shape-square-plus.svg"));
66  m_newOffspecAction->setToolTip("Add new off-specular instrument with default settings");
67  connect(m_newOffspecAction, &QAction::triggered, this, &InstrumentListView::onNewOffspec);
68  addAction(m_newOffspecAction);
69 
70  m_newSpecularAction = new QAction("New specular", this);
71  m_newSpecularAction->setIcon(QIcon(":/images/shape-square-plus.svg"));
72  m_newSpecularAction->setToolTip("Add new specular instrument with default settings");
73  connect(m_newSpecularAction, &QAction::triggered, this, &InstrumentListView::onNewSpecular);
74  addAction(m_newSpecularAction);
75 
76  m_newDepthProbeAction = new QAction("New depth probe", this);
77  m_newDepthProbeAction->setIcon(QIcon(":/images/shape-square-plus.svg"));
78  m_newDepthProbeAction->setToolTip("Add new depth probe instrument with default settings");
79  connect(m_newDepthProbeAction, &QAction::triggered, this, &InstrumentListView::onNewDepthProbe);
80  addAction(m_newDepthProbeAction);
81 
82  m_separatorAction1 = new QAction(this);
83  m_separatorAction1->setSeparator(true);
84  addAction(m_separatorAction1);
85 
86  m_removeAction = new QAction("Remove", this);
87  m_removeAction->setIcon(QIcon(":/images/delete.svg"));
88  m_removeAction->setToolTip("Remove selected instrument");
89  connect(m_removeAction, &QAction::triggered, this, &InstrumentListView::onRemove);
90  addAction(m_removeAction);
91 
92  m_copyAction = new QAction("Copy", this);
93  m_copyAction->setIcon(QIcon(":/images/content-copy.svg"));
94  m_copyAction->setToolTip("Make a copy of the selected instrument");
95  connect(m_copyAction, &QAction::triggered, this, &InstrumentListView::onCopy);
96  addAction(m_copyAction);
97 
98  m_separatorAction2 = new QAction(this);
99  m_separatorAction2->setSeparator(true);
100  addAction(m_separatorAction2);
101 
102  m_storeInLibraryAction = new QAction("Store in library", this);
103  m_storeInLibraryAction->setIcon(QIcon(":/images/library.svg"));
104  m_storeInLibraryAction->setToolTip("Store instrument in library");
105  connect(m_storeInLibraryAction, &QAction::triggered, this,
107  addAction(m_storeInLibraryAction);
108 
109  m_loadFromLibraryAction = new QAction("Choose from library", this);
110  m_loadFromLibraryAction->setIcon(QIcon(":/images/library.svg"));
111  m_loadFromLibraryAction->setToolTip("Load an instrument from the instrument library");
112  connect(m_loadFromLibraryAction, &QAction::triggered, this,
114  addAction(m_loadFromLibraryAction);
115 
116  setContextMenuPolicy(Qt::ActionsContextMenu);
117 
118  connect(m_listView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
120 
121  connect(m_document, &ProjectDocument::modified, this,
123 
125 
126  updateActions();
128 }
List model for instruments.
ProjectDocument * m_document
InstrumentListModel * m_model
void onCopy()
Makes a copy of the currently selected instrument.
QAction * m_newDepthProbeAction
void updateFunctionalityNarrowing()
Show/hide UI elements according to settings in current project.
void onRemove()
Removes currently selected instrument.
QAction * m_loadFromLibraryAction
QAction * m_storeInLibraryAction
void modified()
Emitted for any modifications in the document.
InstrumentsEditController * instrumentsEditController()
The edit controller for the instruments in this project document.

References ensureItemSelected(), ProjectDocument::instrumentsEditController(), m_copyAction, m_document, m_listView, m_loadFromLibraryAction, m_model, m_newDepthProbeAction, m_newGisasAction, m_newOffspecAction, m_newSpecularAction, m_removeAction, m_separatorAction1, m_separatorAction2, m_storeInLibraryAction, ProjectDocument::modified(), onCopy(), onItemSelectionChanged(), onLoadFromLibrary(), onNewDepthProbe(), onNewGisas(), onNewOffspec(), onNewSpecular(), onRemove(), onStoreInLibrary(), updateActions(), and updateFunctionalityNarrowing().

Here is the call graph for this function:

Member Function Documentation

◆ currentInstrument()

InstrumentItem * InstrumentListView::currentInstrument ( ) const

Definition at line 148 of file InstrumentListView.cpp.

149 {
150  const QModelIndexList indexes = m_listView->selectionModel()->selectedIndexes();
151  if (!indexes.empty())
152  return m_model->instrumentForIndex(indexes.front());
153  return nullptr;
154 }
InstrumentItem * instrumentForIndex(const QModelIndex &index) const

References InstrumentListModel::instrumentForIndex(), m_listView, and m_model.

Referenced by InstrumentView::createWidgetsForCurrentInstrument(), InstrumentView::onInstrumentChangedByEditor(), InstrumentView::onInstrumentChangedFromExternal(), InstrumentView::onInstrumentdescriptionEdited(), and InstrumentView::onInstrumentNameEdited().

Here is the call graph for this function:

◆ ensureItemSelected()

void InstrumentListView::ensureItemSelected ( )
private

Definition at line 269 of file InstrumentListView.cpp.

270 {
271  if (!m_listView->selectionModel()->hasSelection() && m_model->rowCount()) {
272  QModelIndex last = m_model->index(m_model->rowCount() - 1, 0, QModelIndex());
273  m_listView->selectionModel()->select(last, QItemSelectionModel::ClearAndSelect);
274  }
275 }
int rowCount(const QModelIndex &parent=QModelIndex()) const override

References m_listView, m_model, and InstrumentListModel::rowCount().

Referenced by InstrumentListView(), and onRemove().

Here is the call graph for this function:

◆ instrumentSelected

void InstrumentListView::instrumentSelected ( InstrumentItem instrument)
signal

◆ minimumSizeHint()

QSize InstrumentListView::minimumSizeHint ( ) const
override

Definition at line 135 of file InstrumentListView.cpp.

136 {
137  return QSize(96, 200);
138 }

◆ onCopy

void InstrumentListView::onCopy ( )
privateslot

Makes a copy of the currently selected instrument.

Definition at line 203 of file InstrumentListView.cpp.

204 {
205  QModelIndexList indexes = m_listView->selectionModel()->selectedIndexes();
206  if (!indexes.empty()) {
207  QModelIndex idx = m_model->copyInstrument(indexes.front());
208  m_listView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
209  }
210 }
QModelIndex copyInstrument(const QModelIndex &source)

References InstrumentListModel::copyInstrument(), m_listView, and m_model.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onItemSelectionChanged

void InstrumentListView::onItemSelectionChanged ( )
privateslot

Definition at line 156 of file InstrumentListView.cpp.

157 {
158  updateActions();
159 
160  QModelIndexList indexes = m_listView->selectionModel()->selectedIndexes();
161  if (!indexes.empty())
162  emit instrumentSelected(m_model->instrumentForIndex(indexes.front()));
163  else
164  emit instrumentSelected(nullptr);
165 }
void instrumentSelected(InstrumentItem *instrument)

References InstrumentListModel::instrumentForIndex(), instrumentSelected(), m_listView, m_model, and updateActions().

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onLoadFromLibrary

void InstrumentListView::onLoadFromLibrary ( )
privateslot

Definition at line 228 of file InstrumentListView.cpp.

229 {
231  QMessageBox::information(GUI::Global::mainWindow, "Select from library",
232  "The library does not contain instruments so far.");
233  return;
234  }
235 
237  dlg.setGisasEnabled(m_document->functionalities().testFlag(ProjectDocument::Gisas));
238  dlg.setOffspecEnabled(m_document->functionalities().testFlag(ProjectDocument::Offspec));
239  dlg.setSpecularEnabled(m_document->functionalities().testFlag(ProjectDocument::Specular));
240  dlg.setDepthProbeEnabled(m_document->functionalities().testFlag(ProjectDocument::DepthProbe));
241 
242  auto* instrumentToCopy = dlg.execChoose();
243  if (instrumentToCopy == nullptr)
244  return;
245 
246  QModelIndex idx = m_model->copyInstrument(instrumentToCopy);
247  m_listView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
248 }
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
Functionalities functionalities() const
static QMainWindow * mainWindow
Definition: Globals.h:22
void information(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:22
InstrumentLibrary instrumentLibrary
Definition: SessionData.h:26

References InstrumentListModel::copyInstrument(), ProjectDocument::DepthProbe, InstrumentLibraryEditor::execChoose(), ProjectDocument::functionalities(), ProjectDocument::Gisas, gSessionData, GUI::View::Helpers::information(), SessionData::instrumentLibrary, InstrumentLibrary::isEmpty(), m_document, m_listView, m_model, GUI::Global::mainWindow, ProjectDocument::Offspec, InstrumentLibraryEditor::setDepthProbeEnabled(), InstrumentLibraryEditor::setGisasEnabled(), InstrumentLibraryEditor::setOffspecEnabled(), InstrumentLibraryEditor::setSpecularEnabled(), and ProjectDocument::Specular.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onNewDepthProbe

void InstrumentListView::onNewDepthProbe ( )
privateslot

Definition at line 185 of file InstrumentListView.cpp.

186 {
187  QModelIndex idx = m_model->addNewDepthProbeInstrument();
188  m_listView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
189 }
QModelIndex addNewDepthProbeInstrument()

References InstrumentListModel::addNewDepthProbeInstrument(), m_listView, and m_model.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onNewGisas

void InstrumentListView::onNewGisas ( )
privateslot

Definition at line 167 of file InstrumentListView.cpp.

168 {
169  QModelIndex idx = m_model->addNewGISASInstrument();
170  m_listView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
171 }
QModelIndex addNewGISASInstrument()

References InstrumentListModel::addNewGISASInstrument(), m_listView, and m_model.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onNewOffspec

void InstrumentListView::onNewOffspec ( )
privateslot

Definition at line 173 of file InstrumentListView.cpp.

174 {
175  QModelIndex idx = m_model->addNewOffspecInstrument();
176  m_listView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
177 }
QModelIndex addNewOffspecInstrument()

References InstrumentListModel::addNewOffspecInstrument(), m_listView, and m_model.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onNewSpecular

void InstrumentListView::onNewSpecular ( )
privateslot

Definition at line 179 of file InstrumentListView.cpp.

180 {
181  QModelIndex idx = m_model->addNewSpecularInstrument();
182  m_listView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
183 }
QModelIndex addNewSpecularInstrument()

References InstrumentListModel::addNewSpecularInstrument(), m_listView, and m_model.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onRemove

void InstrumentListView::onRemove ( )
privateslot

Removes currently selected instrument.

Definition at line 192 of file InstrumentListView.cpp.

193 {
194  QModelIndexList indexes = m_listView->selectionModel()->selectedIndexes();
195  if (!indexes.empty()) {
196  m_model->removeInstrument(indexes.front());
197 
199  }
200 }
void removeInstrument(const QModelIndex &index)

References ensureItemSelected(), m_listView, m_model, and InstrumentListModel::removeInstrument().

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ onStoreInLibrary

void InstrumentListView::onStoreInLibrary ( )
privateslot

Definition at line 212 of file InstrumentListView.cpp.

213 {
214  if (!m_listView->selectionModel()->hasSelection())
215  return;
216 
217  QModelIndex idx = m_listView->selectionModel()->selectedIndexes().front();
218  InstrumentItem* instrument = m_model->instrumentForIndex(idx);
219 
221  dlg.setGisasEnabled(m_document->functionalities().testFlag(ProjectDocument::Gisas));
222  dlg.setOffspecEnabled(m_document->functionalities().testFlag(ProjectDocument::Offspec));
223  dlg.setSpecularEnabled(m_document->functionalities().testFlag(ProjectDocument::Specular));
224  dlg.setDepthProbeEnabled(m_document->functionalities().testFlag(ProjectDocument::DepthProbe));
225  dlg.execAdd(*instrument);
226 }
Abstract base class for instrument-specific item classes.

References ProjectDocument::DepthProbe, InstrumentLibraryEditor::execAdd(), ProjectDocument::functionalities(), ProjectDocument::Gisas, InstrumentListModel::instrumentForIndex(), m_document, m_listView, m_model, GUI::Global::mainWindow, ProjectDocument::Offspec, InstrumentLibraryEditor::setDepthProbeEnabled(), InstrumentLibraryEditor::setGisasEnabled(), InstrumentLibraryEditor::setOffspecEnabled(), InstrumentLibraryEditor::setSpecularEnabled(), and ProjectDocument::Specular.

Referenced by InstrumentListView().

Here is the call graph for this function:

◆ sizeHint()

QSize InstrumentListView::sizeHint ( ) const
override

Definition at line 130 of file InstrumentListView.cpp.

131 {
132  return QSize(170, 400);
133 }

◆ toolbarActions()

◆ updateActions()

void InstrumentListView::updateActions ( )
private

Definition at line 261 of file InstrumentListView.cpp.

262 {
263  bool enabled = m_listView->selectionModel()->hasSelection();
264  m_removeAction->setEnabled(enabled);
265  m_copyAction->setEnabled(enabled);
266  m_storeInLibraryAction->setEnabled(enabled);
267 }

References m_copyAction, m_listView, m_removeAction, and m_storeInLibraryAction.

Referenced by InstrumentListView(), and onItemSelectionChanged().

◆ updateFunctionalityNarrowing()

void InstrumentListView::updateFunctionalityNarrowing ( )
private

Show/hide UI elements according to settings in current project.

Definition at line 250 of file InstrumentListView.cpp.

251 {
252  const auto f = m_document->functionalities();
253 
254  m_newGisasAction->setVisible(f.testFlag(ProjectDocument::Gisas));
255  m_newOffspecAction->setVisible(f.testFlag(ProjectDocument::Offspec));
256  m_newSpecularAction->setVisible(f.testFlag(ProjectDocument::Specular));
257  m_newDepthProbeAction->setVisible(f.testFlag(ProjectDocument::DepthProbe));
259 }
bool singleInstrumentMode() const

References ProjectDocument::DepthProbe, ProjectDocument::functionalities(), ProjectDocument::Gisas, m_copyAction, m_document, m_newDepthProbeAction, m_newGisasAction, m_newOffspecAction, m_newSpecularAction, ProjectDocument::Offspec, ProjectDocument::singleInstrumentMode(), and ProjectDocument::Specular.

Referenced by InstrumentListView().

Here is the call graph for this function:

Member Data Documentation

◆ m_copyAction

QAction* InstrumentListView::m_copyAction
private

◆ m_document

ProjectDocument* InstrumentListView::m_document
private

◆ m_listView

◆ m_loadFromLibraryAction

QAction* InstrumentListView::m_loadFromLibraryAction
private

Definition at line 79 of file InstrumentListView.h.

Referenced by InstrumentListView(), and toolbarActions().

◆ m_model

◆ m_newDepthProbeAction

QAction* InstrumentListView::m_newDepthProbeAction
private

◆ m_newGisasAction

QAction* InstrumentListView::m_newGisasAction
private

◆ m_newOffspecAction

QAction* InstrumentListView::m_newOffspecAction
private

◆ m_newSpecularAction

QAction* InstrumentListView::m_newSpecularAction
private

◆ m_removeAction

QAction* InstrumentListView::m_removeAction
private

Definition at line 75 of file InstrumentListView.h.

Referenced by InstrumentListView(), toolbarActions(), and updateActions().

◆ m_separatorAction1

QAction* InstrumentListView::m_separatorAction1
private

Definition at line 74 of file InstrumentListView.h.

Referenced by InstrumentListView(), and toolbarActions().

◆ m_separatorAction2

QAction* InstrumentListView::m_separatorAction2
private

Definition at line 77 of file InstrumentListView.h.

Referenced by InstrumentListView(), and toolbarActions().

◆ m_storeInLibraryAction

QAction* InstrumentListView::m_storeInLibraryAction
private

Definition at line 78 of file InstrumentListView.h.

Referenced by InstrumentListView(), toolbarActions(), and updateActions().


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