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

Description

List model for instruments.

Used e.g. to present the instrument list in the instrument view.

Definition at line 28 of file InstrumentListModel.h.

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

Public Member Functions

 InstrumentListModel (QObject *parent, InstrumentsEditController *ec)
 
QModelIndex addNewDepthProbeInstrument ()
 
QModelIndex addNewGISASInstrument ()
 
QModelIndex addNewOffspecInstrument ()
 
QModelIndex addNewSpecularInstrument ()
 
QModelIndex copyInstrument (const InstrumentItem *source)
 
QModelIndex copyInstrument (const QModelIndex &source)
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
InstrumentIteminstrumentForIndex (const QModelIndex &index) const
 
void removeInstrument (const QModelIndex &index)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 

Private Member Functions

template<class Instrument >
QModelIndex addNewInstrument ()
 
void onInstrumentNameChanged (const InstrumentItem *instrument)
 

Private Attributes

QIcon m_depthProbeIcon
 
InstrumentsEditControllerm_ec
 
QIcon m_gisasIcon
 
QIcon m_offspecIcon
 
QIcon m_specularIcon
 

Constructor & Destructor Documentation

◆ InstrumentListModel()

InstrumentListModel::InstrumentListModel ( QObject *  parent,
InstrumentsEditController ec 
)

Definition at line 55 of file InstrumentListModel.cpp.

56  : QAbstractListModel(parent)
57  , m_ec(ec)
58 {
59  m_gisasIcon.addPixmap(QPixmap(":/images/gisas_instrument.svg"), QIcon::Selected);
60  m_gisasIcon.addPixmap(QPixmap(":/images/gisas_instrument_shaded.svg"), QIcon::Normal);
61  m_offspecIcon.addPixmap(QPixmap(":/images/offspec_instrument.svg"), QIcon::Selected);
62  m_offspecIcon.addPixmap(QPixmap(":/images/offspec_instrument_shaded.svg"), QIcon::Normal);
63  m_specularIcon.addPixmap(QPixmap(":/images/specular_instrument.svg"), QIcon::Selected);
64  m_specularIcon.addPixmap(QPixmap(":/images/specular_instrument_shaded.svg"), QIcon::Normal);
65  m_depthProbeIcon.addPixmap(QPixmap(":/images/depth_instrument.svg"), QIcon::Selected);
66  m_depthProbeIcon.addPixmap(QPixmap(":/images/depth_instrument_shaded.svg"), QIcon::Normal);
67 
70 }
InstrumentsEditController * m_ec
void onInstrumentNameChanged(const InstrumentItem *instrument)
void instrumentNameChanged(const InstrumentItem *instrument)
Signals name change of the given instrument.

References InstrumentsEditController::instrumentNameChanged(), m_depthProbeIcon, m_gisasIcon, m_offspecIcon, m_specularIcon, and onInstrumentNameChanged().

Here is the call graph for this function:

Member Function Documentation

◆ addNewDepthProbeInstrument()

QModelIndex InstrumentListModel::addNewDepthProbeInstrument ( )

Definition at line 128 of file InstrumentListModel.cpp.

129 {
130  return addNewInstrument<DepthProbeInstrumentItem>();
131 }

Referenced by InstrumentListView::onNewDepthProbe().

◆ addNewGISASInstrument()

QModelIndex InstrumentListModel::addNewGISASInstrument ( )

Definition at line 113 of file InstrumentListModel.cpp.

114 {
115  return addNewInstrument<GISASInstrumentItem>();
116 }

Referenced by InstrumentListView::onNewGisas().

◆ addNewInstrument()

template<class Instrument >
QModelIndex InstrumentListModel::addNewInstrument
private

Definition at line 163 of file InstrumentListModel.cpp.

164 {
165  const QString name =
166  m_ec->collectedItems()->suggestInstrumentName(defaultInstrumentName<Instrument>());
167  const int row = m_ec->collectedItems()->collectedItems().size();
168 
169  beginInsertRows(QModelIndex(), row, row);
170  auto* instrument = m_ec->addInstrument<Instrument>();
171  m_ec->setInstrumentName(instrument, name);
172  endInsertRows();
173 
174  return createIndex(row, 0);
175 }
QVector< InstrumentItem * > collectedItems() const
QString suggestInstrumentName(const QString &baseName) const
Assembles beam, detector and their relative positions with respect to the sample.
Definition: Instrument.h:26
void setInstrumentName(InstrumentItem *instrument, const QString &name)
Set an instrument's name and emit the respective signal.
InstrumentCollection * collectedItems()
The list of existing instruments.
T * addInstrument()
Add an instrument and emit the respective signal.
QString const & name(EShape k)
Definition: particles.cpp:20

References InstrumentsEditController::addInstrument(), InstrumentsEditController::collectedItems(), InstrumentCollection::collectedItems(), m_ec, GUI::RealSpace::Particles::name(), InstrumentsEditController::setInstrumentName(), and InstrumentCollection::suggestInstrumentName().

Here is the call graph for this function:

◆ addNewOffspecInstrument()

QModelIndex InstrumentListModel::addNewOffspecInstrument ( )

Definition at line 118 of file InstrumentListModel.cpp.

119 {
120  return addNewInstrument<OffspecInstrumentItem>();
121 }

Referenced by InstrumentListView::onNewOffspec().

◆ addNewSpecularInstrument()

QModelIndex InstrumentListModel::addNewSpecularInstrument ( )

Definition at line 123 of file InstrumentListModel.cpp.

124 {
125  return addNewInstrument<SpecularInstrumentItem>();
126 }

Referenced by InstrumentListView::onNewSpecular().

◆ copyInstrument() [1/2]

QModelIndex InstrumentListModel::copyInstrument ( const InstrumentItem source)

Definition at line 149 of file InstrumentListModel.cpp.

150 {
151  const QString copyName =
153  const int row = m_ec->collectedItems()->collectedItems().size();
154 
155  beginInsertRows(QModelIndex(), row, row);
156  m_ec->addCopy(source, copyName);
157  endInsertRows();
158 
159  return createIndex(row, 0);
160 }
QString instrumentName() const
InstrumentItem * addCopy(const InstrumentItem *instrument, const QString &name)
Copy an instrument, set its name and emit the respective signal.

References InstrumentsEditController::addCopy(), InstrumentsEditController::collectedItems(), InstrumentCollection::collectedItems(), InstrumentItem::instrumentName(), m_ec, and InstrumentCollection::suggestInstrumentName().

Here is the call graph for this function:

◆ copyInstrument() [2/2]

QModelIndex InstrumentListModel::copyInstrument ( const QModelIndex &  source)

Definition at line 141 of file InstrumentListModel.cpp.

142 {
143  const InstrumentItem* srcInstr = instrumentForIndex(source);
144  ASSERT(srcInstr);
145 
146  return copyInstrument(srcInstr);
147 }
Abstract base class for instrument-specific item classes.
QModelIndex copyInstrument(const QModelIndex &source)
InstrumentItem * instrumentForIndex(const QModelIndex &index) const

References instrumentForIndex().

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

Here is the call graph for this function:

◆ data()

QVariant InstrumentListModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 77 of file InstrumentListModel.cpp.

78 {
79  QVector<InstrumentItem*> instruments = m_ec->collectedItems()->collectedItems();
80  if (!index.isValid() || index.row() >= instruments.size() || index.row() < 0)
81  return {};
82 
83  const InstrumentItem* item = instruments[index.row()];
84  if (role == Qt::DecorationRole) {
85  if (dynamic_cast<const GISASInstrumentItem*>(item))
86  return m_gisasIcon;
87  if (dynamic_cast<const OffspecInstrumentItem*>(item))
88  return m_offspecIcon;
89  if (dynamic_cast<const SpecularInstrumentItem*>(item))
90  return m_specularIcon;
91  if (dynamic_cast<const DepthProbeInstrumentItem*>(item))
92  return m_depthProbeIcon;
93  return {};
94  }
95 
96  if (role == Qt::DisplayRole)
97  return item->instrumentName();
98 
99  return {};
100 }

References InstrumentsEditController::collectedItems(), InstrumentCollection::collectedItems(), InstrumentItem::instrumentName(), m_depthProbeIcon, m_ec, m_gisasIcon, m_offspecIcon, and m_specularIcon.

Here is the call graph for this function:

◆ instrumentForIndex()

InstrumentItem * InstrumentListModel::instrumentForIndex ( const QModelIndex &  index) const

Definition at line 102 of file InstrumentListModel.cpp.

103 {
104  if (!index.isValid())
105  return nullptr;
106 
107  QVector<InstrumentItem*> instruments = m_ec->collectedItems()->collectedItems();
108  if (index.row() >= 0 && index.row() < instruments.size())
109  return instruments[index.row()];
110  return nullptr;
111 }

References InstrumentsEditController::collectedItems(), InstrumentCollection::collectedItems(), and m_ec.

Referenced by copyInstrument(), InstrumentListView::currentInstrument(), InstrumentListView::onItemSelectionChanged(), InstrumentListView::onStoreInLibrary(), and removeInstrument().

Here is the call graph for this function:

◆ onInstrumentNameChanged()

void InstrumentListModel::onInstrumentNameChanged ( const InstrumentItem instrument)
private

Definition at line 177 of file InstrumentListModel.cpp.

178 {
179  const auto instruments = m_ec->collectedItems()->collectedItems();
180  if (const auto row = instruments.indexOf(const_cast<InstrumentItem*>(instrument)); row != -1)
181  emit dataChanged(index(row, 0), index(row, 0));
182 }

References InstrumentsEditController::collectedItems(), InstrumentCollection::collectedItems(), and m_ec.

Referenced by InstrumentListModel().

Here is the call graph for this function:

◆ removeInstrument()

void InstrumentListModel::removeInstrument ( const QModelIndex &  index)

Definition at line 133 of file InstrumentListModel.cpp.

134 {
135  beginRemoveRows(QModelIndex(), index.row(), index.row());
136  InstrumentItem* instrument = instrumentForIndex(index);
137  m_ec->removeInstrument(instrument);
138  endRemoveRows();
139 }
void removeInstrument(InstrumentItem *instrument)
Add an instrument and emit the respective signal.

References instrumentForIndex(), m_ec, and InstrumentsEditController::removeInstrument().

Referenced by InstrumentListView::onRemove().

Here is the call graph for this function:

◆ rowCount()

int InstrumentListModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 72 of file InstrumentListModel.cpp.

73 {
74  return m_ec->collectedItems()->collectedItems().size();
75 }

References InstrumentsEditController::collectedItems(), InstrumentCollection::collectedItems(), and m_ec.

Referenced by InstrumentListView::ensureItemSelected().

Here is the call graph for this function:

Member Data Documentation

◆ m_depthProbeIcon

QIcon InstrumentListModel::m_depthProbeIcon
private

Definition at line 60 of file InstrumentListModel.h.

Referenced by InstrumentListModel(), and data().

◆ m_ec

◆ m_gisasIcon

QIcon InstrumentListModel::m_gisasIcon
private

Definition at line 57 of file InstrumentListModel.h.

Referenced by InstrumentListModel(), and data().

◆ m_offspecIcon

QIcon InstrumentListModel::m_offspecIcon
private

Definition at line 58 of file InstrumentListModel.h.

Referenced by InstrumentListModel(), and data().

◆ m_specularIcon

QIcon InstrumentListModel::m_specularIcon
private

Definition at line 59 of file InstrumentListModel.h.

Referenced by InstrumentListModel(), and data().


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