BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentsTreeModel.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Instrument/InstrumentsTreeModel.h
6 //! @brief Defines class InstrumentsTreeModel
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 
15 #ifndef BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTSTREEMODEL_H
16 #define BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTSTREEMODEL_H
17 
18 #include <QAbstractItemModel>
19 #include <QSet>
20 
22 class InstrumentItem;
23 
24 //! Tree model for instrument item selection. Used e.g. for the instrument library.
25 class InstrumentsTreeModel : public QAbstractItemModel {
26 public:
28 
30  None = 0x0,
31  Gisas = 0x1,
32  Offspec = 0x2,
33  Specular = 0x4,
34  DepthProbe = 0x8,
36  };
37  Q_DECLARE_FLAGS(VisibleInstrumentTypes, InstrumentType)
38 
39  void enableEmptyHeadlines(bool b);
40  void setTypeEnabled(InstrumentType type, bool b);
41 
42  QModelIndex index(int row, int column,
43  const QModelIndex& parent = QModelIndex()) const override;
44 
45  QModelIndex parent(const QModelIndex& index) const override;
46  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
47  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
48  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
49  Qt::ItemFlags flags(const QModelIndex& index) const override;
50  bool setData(const QModelIndex& index, const QVariant& value, int role) override;
51  InstrumentItem* itemForIndex(const QModelIndex& index) const;
52  QModelIndex indexForItem(InstrumentItem* item) const;
53 
54  void removeItem(InstrumentItem* item);
56 
57  //! The topmost visible item. Can be null of course.
58  InstrumentItem* topMostItem() const;
59 
60  QModelIndex indexOfHeadline(InstrumentType type) const;
61  bool isHeadline(const QModelIndex& index) const;
62 
64 
65 private:
66  void clear();
67  QList<InstrumentType> visibleTypes() const;
68  QVector<InstrumentItem*> instruments(InstrumentType type) const;
69 
70 private:
72  VisibleInstrumentTypes m_visibleTypes;
75 };
76 
77 #endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTSTREEMODEL_H
Abstract base class for instrument-specific item classes.
Tree model for instrument item selection. Used e.g. for the instrument library.
Qt::ItemFlags flags(const QModelIndex &index) const override
VisibleInstrumentTypes m_visibleTypes
bool setData(const QModelIndex &index, const QVariant &value, int role) override
static InstrumentType instrumentType(InstrumentItem *item)
QModelIndex parent(const QModelIndex &index) const override
QModelIndex indexForItem(InstrumentItem *item) const
InstrumentItem * topMostItem() const
The topmost visible item. Can be null of course.
InstrumentCollection * m_model
QList< InstrumentType > visibleTypes() const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex indexOfHeadline(InstrumentType type) const
InstrumentItem * itemForIndex(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
InstrumentsTreeModel(QObject *parent, InstrumentCollection *model)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool isHeadline(const QModelIndex &index) const
QVector< InstrumentItem * > instruments(InstrumentType type) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setTypeEnabled(InstrumentType type, bool b)
void removeItem(InstrumentItem *item)