27 #include "ui_InstrumentLibraryEditor.h"
29 #include <QFormLayout>
31 #include <QInputDialog>
32 #include <QMessageBox>
33 #include <QPushButton>
40 , m_chosenItem(nullptr)
44 setAttribute(Qt::WA_StyledBackground,
true);
45 setProperty(
"stylable",
true);
46 setWindowIcon(QIcon(
":/images/library.svg"));
47 setWindowFlag(Qt::WindowContextHelpButtonHint,
false);
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);
56 m_ui->treeView->expandAll();
57 m_ui->treeView->setVerticalScrollMode(QTreeView::ScrollPerPixel);
58 m_ui->treeView->setIndentation(0);
60 m_ui->treeView->setIconSize(QSize(128, 128));
62 connect(
m_treeModel, &QAbstractItemModel::modelReset,
63 [
this]() {
m_ui->treeView->expandAll(); });
98 setWindowTitle(
"Instrument Library - Choose instrument");
101 m_ui->treeView, [=](
const QModelIndex& i,
bool h) { return getOverlayActions(i, h); });
104 connect(
m_ui->treeView, &QTreeView::doubleClicked,
this,
106 connect(
m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
110 if (exec() == QDialog::Accepted)
118 const QString& newName =
122 setWindowTitle(
"Instrument Library - Add instrument");
128 m_ui->treeView, [=](
const QModelIndex& i,
bool h) { return getOverlayActions(i, h); });
130 connect(
m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
133 m_ui->buttonBox->addButton(QDialogButtonBox::Close);
134 m_ui->buttonBox->button(QDialogButtonBox::Ok)->hide();
135 m_ui->buttonBox->button(QDialogButtonBox::Cancel)->hide();
138 m_ui->treeView->expandAll();
139 m_ui->treeView->setCurrentIndex(index);
140 m_ui->treeView->scrollTo(index, QAbstractItemView::PositionAtTop);
155 m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
m_chosenItem !=
nullptr);
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");
179 return {removeAction};
185 if (!currentInstrument) {
186 m_ui->scrollArea->setWidget(
new QWidget(
m_ui->scrollArea));
190 QWidget* w =
new QWidget(
m_ui->scrollArea);
191 auto* layout =
new QVBoxLayout(w);
193 w->setAttribute(Qt::WA_StyledBackground,
true);
194 w->setProperty(
"stylable",
true);
196 auto* g =
new QGroupBox(
m_ui->scrollArea);
197 g->setTitle(QString(
"Information (%1 instrument)").arg(currentInstrument->instrumentType()));
199 auto* formLayout =
new QFormLayout(g);
200 formLayout->setMargin(17);
201 formLayout->setSpacing(8);
202 layout->addWidget(g);
204 auto* nameEdit =
new QLineEdit(g);
205 formLayout->addRow(
"Name:", nameEdit);
206 nameEdit->setText(currentInstrument->instrumentName());
207 connect(nameEdit, &QLineEdit::textEdited,
this,
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,
227 layout->addWidget(editor);
232 layout->addWidget(editor);
237 layout->addWidget(editor);
242 layout->addWidget(editor);
246 m_ui->scrollArea->setWidget(w);
251 QModelIndex index =
m_ui->treeView->currentIndex();
257 QModelIndex index =
m_ui->treeView->currentIndex();
271 , m_newInstrument(nullptr)
277 m_newInstrument = addedInstrument;
282 if (isHeadline(index))
285 auto*
const item = itemForIndex(index);
287 if (role == Qt::DisplayRole) {
288 auto descr = item->description();
289 if (!descr.isEmpty()) {
290 descr.prepend(
"<br><br>");
292 while (descr.count(
"\n") > 3) {
293 descr.truncate(descr.lastIndexOf(
"\n"));
296 descr.replace(
"\n",
"<br>");
298 return "<b>" + item->instrumentName() +
"</b>" + descr;
301 if (role == Qt::DecorationRole && (item == m_newInstrument)) {
302 if (role == Qt::DecorationRole)
303 switch (instrumentType(item)) {
305 return QIcon(
":/images/gisas_instrument_new.svg");
307 return QIcon(
":/images/offspec_instrument_new.svg");
309 return QIcon(
":/images/specular_instrument_new.svg");
311 return QIcon(
":/images/depth_instrument_new.svg");
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class DepthProbeInstrumentEditor.
Defines class GISASInstrumentEditor.
Defines class GroupBoxCollapser.
Defines class InstrumentItem and all its children.
Defines class InstrumentLibraryEditor.
Defines class ItemDelegateForHTML.
Defines class OffspecInstrumentEditor.
SessionData * gSessionData
global pointer to the single instance
Defines struct SessionData.
Defines class SpecularInstrumentEditor.
Defines GUI::StyleUtils namespace.
void loadWindowSizeAndPos(QWidget *w)
void saveWindowSizeAndPos(const QWidget *w)
Editor for GISAS instruments.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Abstract base class for instrument-specific item classes.
QString instrumentName() const
A model extension for InstrumentsTreeModel which.
void setNewInstrument(InstrumentItem *addedInstrument)
Set the instrument which shall have a "NEW" sign in its icon.
TreeModel(QObject *parent, InstrumentCollection *model)
QVariant data(const QModelIndex &index, int role) const override
Ui::InstrumentLibraryEditor * m_ui
InstrumentLibraryEditor(QWidget *parent)
void onInstrumentChangedByEditor()
void createWidgetsForCurrentInstrument()
void onInstrumentDescriptionEdited(const QString &t)
void onCurrentChangedForChoose()
~InstrumentLibraryEditor() override
void setOffspecEnabled(bool b)
InstrumentItem * execChoose()
Execute the dialog for choosing an instrument from the library. Returns nullptr if canceled.
void onItemDoubleClickedForChoose(const QModelIndex &index)
QList< QAction * > getOverlayActions(const QModelIndex &index, bool asHover)
void execAdd(const InstrumentItem &instrumentToAdd)
Execute the dialog to add an instrument to the library.
void setGisasEnabled(bool b)
void setSpecularEnabled(bool b)
void onInstrumentNameEdited(const QString &newName)
InstrumentItem * m_chosenItem
void setDepthProbeEnabled(bool b)
InstrumentsEditController * editController()
InstrumentItem * add(const QString &name, const InstrumentItem &itemToCopy)
Returns the new element.
QString suggestName(const QString &name) const
void notifyInstrumentChanged(InstrumentItem *instrument)
Simply emits the instrumentChanged signal. Call this whenever you change an instrument's data without...
Tree model for instrument item selection. Used e.g. for the instrument library.
void enableEmptyHeadlines(bool b)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
static InstrumentType instrumentType(InstrumentItem *item)
QModelIndex indexForItem(InstrumentItem *item) const
InstrumentItem * itemForIndex(const QModelIndex &index) const
bool isHeadline(const QModelIndex &index) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setTypeEnabled(InstrumentType type, bool b)
void removeItem(InstrumentItem *item)
For representing HTML text in an item */.
void setResizable(QDialog *dialog)
Make modal dialog resizable.
InstrumentLibrary instrumentLibrary