BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RealDataTreeModel.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/ImportDataWidgets/RealDataTreeModel.h
6 //! @brief Defines class RealDataTreeModel
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_COREGUI_VIEWS_IMPORTDATAWIDGETS_REALDATATREEMODEL_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_REALDATATREEMODEL_H
17 
18 #include <QAbstractItemModel>
19 
20 class RealDataModel;
21 class RealDataItem;
22 
23 //! Tree model for real data item selection. Used for the tree in the import view.
24 class RealDataTreeModel : public QAbstractItemModel {
25 public:
26  void setRealDataModel(RealDataModel* model);
27 
28  virtual QModelIndex index(int row, int column,
29  const QModelIndex& parent = QModelIndex()) const override;
30 
31  virtual QModelIndex parent(const QModelIndex& index) const override;
32  virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
33  virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
34  virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
35  virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
36  virtual bool setData(const QModelIndex& index, const QVariant& value, int role) override;
37  RealDataItem* itemForIndex(const QModelIndex& index) const;
38  QModelIndex indexForItem(RealDataItem* item) const;
39 
41 
42  void removeItem(RealDataItem* item);
45 
46  //! The topmost visible item. Can be null of course.
47  RealDataItem* topMostItem() const;
48 
49 private:
50  bool isHeadline(const QModelIndex& index) const;
51  QModelIndex create1DHeadlineIndex() const;
52  QModelIndex create2DHeadlineIndex() const;
53  void updateSubsriptions();
55  void clear();
56 
57 private:
58  RealDataModel* m_model = nullptr;
59  QVector<RealDataItem*> m_items1D; //< Items borrowed from realDataModel. Never delete the ptrs!
60  QVector<RealDataItem*> m_items2D; //< Items borrowed from realDataModel. Never delete the ptrs!
61  bool m_intermediate1DHeadline = false; //< intermediate state while inserting/removing items
62  bool m_intermediate2DHeadline = false; //< intermediate state while inserting/removing items
63 };
64 
65 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_REALDATATREEMODEL_H
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
The RealDataModel class is a model to store all imported RealDataItem's.
Definition: RealDataModel.h:26
Tree model for real data item selection. Used for the tree in the import view.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVector< RealDataItem * > m_items2D
virtual QModelIndex parent(const QModelIndex &index) const override
QModelIndex indexForItem(RealDataItem *item) const
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
void setRealDataModel(RealDataModel *model)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
QModelIndex create2DHeadlineIndex() const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
RealDataItem * insertIntensityDataItem()
bool isHeadline(const QModelIndex &index) const
RealDataModel * m_model
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
RealDataItem * topMostItem() const
The topmost visible item. Can be null of course.
RealDataItem * insertSpecularDataItem()
QVector< RealDataItem * > m_items1D
RealDataItem * itemForIndex(const QModelIndex &index) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void onContentsProcessed(RealDataItem *item)
void removeItem(RealDataItem *item)
QModelIndex create1DHeadlineIndex() const