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

Description

Definition at line 28 of file InstrumentLibraryEditor.h.

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

Classes

class  TreeModel
 A model extension for InstrumentsTreeModel which. More...
 

Public Member Functions

 InstrumentLibraryEditor (QWidget *parent)
 
 ~InstrumentLibraryEditor () override
 
void execAdd (const InstrumentItem &instrumentToAdd)
 Execute the dialog to add an instrument to the library. More...
 
InstrumentItemexecChoose ()
 Execute the dialog for choosing an instrument from the library. Returns nullptr if canceled. More...
 
void setDepthProbeEnabled (bool b)
 
void setGisasEnabled (bool b)
 
void setOffspecEnabled (bool b)
 
void setSpecularEnabled (bool b)
 

Private Member Functions

void createWidgetsForCurrentInstrument ()
 
QList< QAction * > getOverlayActions (const QModelIndex &index, bool asHover)
 
void onCurrentChangedForChoose ()
 
void onInstrumentChangedByEditor ()
 
void onInstrumentDescriptionEdited (const QString &t)
 
void onInstrumentNameEdited (const QString &newName)
 
void onItemDoubleClickedForChoose (const QModelIndex &index)
 

Private Attributes

InstrumentItemm_chosenItem
 
TreeModelm_treeModel
 
Ui::InstrumentLibraryEditor * m_ui
 

Constructor & Destructor Documentation

◆ InstrumentLibraryEditor()

InstrumentLibraryEditor::InstrumentLibraryEditor ( QWidget *  parent)

Definition at line 36 of file InstrumentLibraryEditor.cpp.

37  : QDialog(parent)
38  , m_ui(new Ui::InstrumentLibraryEditor)
39  , m_treeModel(new TreeModel(this, gSessionData->instrumentLibrary.collectedItems()))
40  , m_chosenItem(nullptr)
41 {
42  m_ui->setupUi(this);
43 
44  setAttribute(Qt::WA_StyledBackground, true);
45  setProperty("stylable", true); // for stylesheet addressing
46  setWindowIcon(QIcon(":/images/library.svg"));
47  setWindowFlag(Qt::WindowContextHelpButtonHint, false);
48 
50 
51  m_ui->treeView->setItemsExpandable(false);
52  m_ui->treeView->setRootIsDecorated(false);
53  m_ui->treeView->setHeaderHidden(true);
54  m_ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
55  m_ui->treeView->setModel(m_treeModel);
56  m_ui->treeView->expandAll();
57  m_ui->treeView->setVerticalScrollMode(QTreeView::ScrollPerPixel);
58  m_ui->treeView->setIndentation(0);
59  m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this));
60  m_ui->treeView->setIconSize(QSize(128, 128));
61 
62  connect(m_treeModel, &QAbstractItemModel::modelReset,
63  [this]() { m_ui->treeView->expandAll(); });
64 
65  // ensure a current item when widget is shown
66  // setCurrentItem(m_treeModel->topMostItem());
69 }
ApplicationSettings * appSettings
global pointer to the instance
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
void loadWindowSizeAndPos(QWidget *w)
Ui::InstrumentLibraryEditor * m_ui
QList< InstrumentItem * > collectedItems() const
For representing HTML text in an item *‍/.
void setResizable(QDialog *dialog)
Make modal dialog resizable.
Definition: StyleUtils.cpp:100
InstrumentLibrary instrumentLibrary
Definition: SessionData.h:26

References appSettings, InstrumentsTreeModel::enableEmptyHeadlines(), ApplicationSettings::loadWindowSizeAndPos(), m_treeModel, m_ui, and GUI::Util::Style::setResizable().

Here is the call graph for this function:

◆ ~InstrumentLibraryEditor()

InstrumentLibraryEditor::~InstrumentLibraryEditor ( )
override

Definition at line 71 of file InstrumentLibraryEditor.cpp.

72 {
74 }
void saveWindowSizeAndPos(const QWidget *w)

References appSettings, and ApplicationSettings::saveWindowSizeAndPos().

Here is the call graph for this function:

Member Function Documentation

◆ createWidgetsForCurrentInstrument()

void InstrumentLibraryEditor::createWidgetsForCurrentInstrument ( )
private

Definition at line 182 of file InstrumentLibraryEditor.cpp.

183 {
184  auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex());
185  if (!currentInstrument) {
186  m_ui->scrollArea->setWidget(new QWidget(m_ui->scrollArea)); // blank widget
187  return;
188  }
189 
190  QWidget* w = new QWidget(m_ui->scrollArea);
191  auto* layout = new QVBoxLayout(w);
192 
193  w->setAttribute(Qt::WA_StyledBackground, true);
194  w->setProperty("stylable", true); // for stylesheet addressing
195 
196  auto* g = new QGroupBox(m_ui->scrollArea);
197  g->setTitle(QString("Information (%1 instrument)").arg(currentInstrument->instrumentType()));
198 
199  auto* formLayout = new QFormLayout(g);
200  formLayout->setMargin(17);
201  formLayout->setSpacing(8);
202  layout->addWidget(g);
203 
204  auto* nameEdit = new QLineEdit(g);
205  formLayout->addRow("Name:", nameEdit);
206  nameEdit->setText(currentInstrument->instrumentName());
207  connect(nameEdit, &QLineEdit::textEdited, this,
209 
210  auto* descriptionEdit = new QTextEdit(g);
211  descriptionEdit->setMinimumWidth(300);
212  descriptionEdit->setMaximumHeight(100);
213  descriptionEdit->setAcceptRichText(false);
214  descriptionEdit->setTabChangesFocus(true);
215  descriptionEdit->setPlainText(currentInstrument->description());
216  formLayout->addRow("Description:", descriptionEdit);
217  connect(descriptionEdit, &QTextEdit::textChanged,
218  [=]() { onInstrumentDescriptionEdited(descriptionEdit->toPlainText()); });
219 
221 
222  if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) {
223  auto* editor = new SpecularInstrumentEditor(
224  m_ui->scrollArea, sp, gSessionData->instrumentLibrary.editController());
225  connect(editor, &SpecularInstrumentEditor::dataChanged, this,
227  layout->addWidget(editor);
228  } else if (auto* os = dynamic_cast<OffspecInstrumentItem*>(currentInstrument)) {
229  auto* editor = new OffspecInstrumentEditor(m_ui->scrollArea, os);
230  connect(editor, &OffspecInstrumentEditor::dataChanged, this,
232  layout->addWidget(editor);
233  } else if (auto* gisas = dynamic_cast<GISASInstrumentItem*>(currentInstrument)) {
234  auto* editor = new GISASInstrumentEditor(m_ui->scrollArea, gisas);
235  connect(editor, &GISASInstrumentEditor::dataChanged, this,
237  layout->addWidget(editor);
238  } else if (auto* dp = dynamic_cast<DepthProbeInstrumentItem*>(currentInstrument)) {
239  auto* editor = new DepthProbeInstrumentEditor(m_ui->scrollArea, dp);
240  connect(editor, &DepthProbeInstrumentEditor::dataChanged, this,
242  layout->addWidget(editor);
243  } else
244  ASSERT(false);
245 
246  m_ui->scrollArea->setWidget(w);
247 }
Editor for GISAS instruments.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
void onInstrumentDescriptionEdited(const QString &t)
void onInstrumentNameEdited(const QString &newName)
InstrumentsEditController * editController()
InstrumentItem * itemForIndex(const QModelIndex &index) const

References DepthProbeInstrumentEditor::dataChanged(), GISASInstrumentEditor::dataChanged(), OffspecInstrumentEditor::dataChanged(), SpecularInstrumentEditor::dataChanged(), InstrumentLibrary::editController(), gSessionData, GroupBoxCollapser::installIntoGroupBox(), SessionData::instrumentLibrary, InstrumentsTreeModel::itemForIndex(), m_treeModel, m_ui, onInstrumentChangedByEditor(), onInstrumentDescriptionEdited(), and onInstrumentNameEdited().

Referenced by execAdd(), and onCurrentChangedForChoose().

Here is the call graph for this function:

◆ execAdd()

void InstrumentLibraryEditor::execAdd ( const InstrumentItem instrumentToAdd)

Execute the dialog to add an instrument to the library.

Definition at line 116 of file InstrumentLibraryEditor.cpp.

117 {
118  const QString& newName =
120  auto* addedInstrument = gSessionData->instrumentLibrary.add(newName, instrumentToAdd);
121 
122  setWindowTitle("Instrument Library - Add instrument");
123 
124  m_treeModel->setNewInstrument(addedInstrument);
125  m_treeModel->setTypeEnabled(TreeModel::instrumentType(addedInstrument), true);
126 
128  m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); });
129  m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this));
130  connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
132 
133  m_ui->buttonBox->addButton(QDialogButtonBox::Close);
134  m_ui->buttonBox->button(QDialogButtonBox::Ok)->hide();
135  m_ui->buttonBox->button(QDialogButtonBox::Cancel)->hide();
136 
137  QModelIndex index = m_treeModel->indexForItem(addedInstrument);
138  m_ui->treeView->expandAll();
139  m_ui->treeView->setCurrentIndex(index);
140  m_ui->treeView->scrollTo(index, QAbstractItemView::PositionAtTop);
142  exec();
143 }
QString instrumentName() const
void setNewInstrument(InstrumentItem *addedInstrument)
Set the instrument which shall have a "NEW" sign in its icon.
InstrumentItem * add(const QString &name, const InstrumentItem &itemToCopy)
Returns the new element.
QString suggestName(const QString &name) const
static InstrumentType instrumentType(InstrumentItem *item)
QModelIndex indexForItem(InstrumentItem *item) const
void setTypeEnabled(InstrumentType type, bool b)
static void install(QAbstractItemView *view, FnGetActions fnGetActions)

References InstrumentLibrary::add(), createWidgetsForCurrentInstrument(), gSessionData, InstrumentsTreeModel::indexForItem(), ItemViewOverlayButtons::install(), SessionData::instrumentLibrary, InstrumentItem::instrumentName(), InstrumentsTreeModel::instrumentType(), m_treeModel, m_ui, InstrumentLibraryEditor::TreeModel::setNewInstrument(), InstrumentsTreeModel::setTypeEnabled(), and InstrumentLibrary::suggestName().

Referenced by InstrumentListView::onStoreInLibrary().

Here is the call graph for this function:

◆ execChoose()

InstrumentItem * InstrumentLibraryEditor::execChoose ( )

Execute the dialog for choosing an instrument from the library. Returns nullptr if canceled.

Definition at line 96 of file InstrumentLibraryEditor.cpp.

97 {
98  setWindowTitle("Instrument Library - Choose instrument");
99 
101  m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); });
102  m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this));
103 
104  connect(m_ui->treeView, &QTreeView::doubleClicked, this,
106  connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
109 
110  if (exec() == QDialog::Accepted)
111  return m_chosenItem;
112 
113  return nullptr;
114 }
void onItemDoubleClickedForChoose(const QModelIndex &index)

References ItemViewOverlayButtons::install(), m_chosenItem, m_ui, onCurrentChangedForChoose(), and onItemDoubleClickedForChoose().

Referenced by InstrumentListView::onLoadFromLibrary().

Here is the call graph for this function:

◆ getOverlayActions()

QList< QAction * > InstrumentLibraryEditor::getOverlayActions ( const QModelIndex &  index,
bool  asHover 
)
private

Definition at line 159 of file InstrumentLibraryEditor.cpp.

160 {
161  if (m_treeModel->isHeadline(index))
162  return {};
163 
164  // -- index belongs to item
165  if (!asHover)
166  return {};
167 
168  auto* item = m_treeModel->itemForIndex(index);
169  if (item == nullptr)
170  return {};
171 
172  auto* removeAction = new QAction(this);
173  removeAction->setText("Remove");
174  removeAction->setIcon(QIcon(":/images/delete.svg"));
175  removeAction->setIconText("Remove");
176  removeAction->setToolTip("Remove this instrument");
177  connect(removeAction, &QAction::triggered, [=]() { m_treeModel->removeItem(item); });
178 
179  return {removeAction};
180 }
bool isHeadline(const QModelIndex &index) const
void removeItem(InstrumentItem *item)

References InstrumentsTreeModel::isHeadline(), InstrumentsTreeModel::itemForIndex(), m_treeModel, and InstrumentsTreeModel::removeItem().

Here is the call graph for this function:

◆ onCurrentChangedForChoose()

void InstrumentLibraryEditor::onCurrentChangedForChoose ( )
private

Definition at line 152 of file InstrumentLibraryEditor.cpp.

153 {
154  m_chosenItem = m_treeModel->itemForIndex(m_ui->treeView->currentIndex());
155  m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_chosenItem != nullptr);
157 }

References createWidgetsForCurrentInstrument(), InstrumentsTreeModel::itemForIndex(), m_chosenItem, m_treeModel, and m_ui.

Referenced by execChoose().

Here is the call graph for this function:

◆ onInstrumentChangedByEditor()

void InstrumentLibraryEditor::onInstrumentChangedByEditor ( )
private

Definition at line 261 of file InstrumentLibraryEditor.cpp.

262 {
263  auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex());
265 }
void notifyInstrumentChanged(InstrumentItem *instrument)
Simply emits the instrumentChanged signal. Call this whenever you change an instrument's data without...

References InstrumentLibrary::editController(), gSessionData, SessionData::instrumentLibrary, InstrumentsTreeModel::itemForIndex(), m_treeModel, m_ui, and InstrumentsEditController::notifyInstrumentChanged().

Referenced by createWidgetsForCurrentInstrument().

Here is the call graph for this function:

◆ onInstrumentDescriptionEdited()

void InstrumentLibraryEditor::onInstrumentDescriptionEdited ( const QString &  t)
private

Definition at line 255 of file InstrumentLibraryEditor.cpp.

256 {
257  QModelIndex index = m_ui->treeView->currentIndex();
258  m_treeModel->setData(index, t, Qt::ToolTipRole);
259 }
bool setData(const QModelIndex &index, const QVariant &value, int role) override

References m_treeModel, m_ui, and InstrumentsTreeModel::setData().

Referenced by createWidgetsForCurrentInstrument().

Here is the call graph for this function:

◆ onInstrumentNameEdited()

void InstrumentLibraryEditor::onInstrumentNameEdited ( const QString &  newName)
private

Definition at line 249 of file InstrumentLibraryEditor.cpp.

250 {
251  QModelIndex index = m_ui->treeView->currentIndex();
252  m_treeModel->setData(index, newName, Qt::EditRole);
253 }

References m_treeModel, m_ui, and InstrumentsTreeModel::setData().

Referenced by createWidgetsForCurrentInstrument().

Here is the call graph for this function:

◆ onItemDoubleClickedForChoose()

void InstrumentLibraryEditor::onItemDoubleClickedForChoose ( const QModelIndex &  index)
private

Definition at line 145 of file InstrumentLibraryEditor.cpp.

146 {
148  if (m_chosenItem != nullptr)
149  accept();
150 }

References InstrumentsTreeModel::itemForIndex(), m_chosenItem, and m_treeModel.

Referenced by execChoose().

Here is the call graph for this function:

◆ setDepthProbeEnabled()

void InstrumentLibraryEditor::setDepthProbeEnabled ( bool  b)

Definition at line 91 of file InstrumentLibraryEditor.cpp.

References InstrumentsTreeModel::DepthProbe, m_treeModel, and InstrumentsTreeModel::setTypeEnabled().

Referenced by InstrumentListView::onLoadFromLibrary(), and InstrumentListView::onStoreInLibrary().

Here is the call graph for this function:

◆ setGisasEnabled()

void InstrumentLibraryEditor::setGisasEnabled ( bool  b)

Definition at line 76 of file InstrumentLibraryEditor.cpp.

References InstrumentsTreeModel::Gisas, m_treeModel, and InstrumentsTreeModel::setTypeEnabled().

Referenced by InstrumentListView::onLoadFromLibrary(), and InstrumentListView::onStoreInLibrary().

Here is the call graph for this function:

◆ setOffspecEnabled()

void InstrumentLibraryEditor::setOffspecEnabled ( bool  b)

Definition at line 81 of file InstrumentLibraryEditor.cpp.

References m_treeModel, InstrumentsTreeModel::Offspec, and InstrumentsTreeModel::setTypeEnabled().

Referenced by InstrumentListView::onLoadFromLibrary(), and InstrumentListView::onStoreInLibrary().

Here is the call graph for this function:

◆ setSpecularEnabled()

void InstrumentLibraryEditor::setSpecularEnabled ( bool  b)

Definition at line 86 of file InstrumentLibraryEditor.cpp.

References m_treeModel, InstrumentsTreeModel::setTypeEnabled(), and InstrumentsTreeModel::Specular.

Referenced by InstrumentListView::onLoadFromLibrary(), and InstrumentListView::onStoreInLibrary().

Here is the call graph for this function:

Member Data Documentation

◆ m_chosenItem

InstrumentItem* InstrumentLibraryEditor::m_chosenItem
private

◆ m_treeModel

◆ m_ui


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