BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
AbstractDataLoaderResultModel.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Support/IO/AbstractDataLoaderResultModel.h
6 //! @brief Defines class AbstractDataLoaderResultModel
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_SUPPORT_IO_ABSTRACTDATALOADERRESULTMODEL_H
16 #define BORNAGAIN_GUI_SUPPORT_IO_ABSTRACTDATALOADERRESULTMODEL_H
17 
18 #include <QAbstractItemModel>
19 #include <QIcon>
20 
21 //! Base class for result tables of data loaders. Derive from this class and return an instance in
22 //! YourDataLoader::createResultModel().
23 //! The result table is the one on the right side when importing CSV files.
24 class AbstractDataLoaderResultModel : public QAbstractTableModel {
25 public:
27 
29 
30  // overrides of QAbstractTableModel
31 public:
32  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
33  int rowCount(const QModelIndex& parent) const override;
34  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
35  QVariant headerData(int section, Qt::Orientation orientation,
36  int role = Qt::DisplayRole) const override;
37 
38 public:
39  //! The table header sections which belong to the given column type. Empty if this column type
40  //! is not present at all.
41  QVector<int> sectionsOfColumnType(ColumnType type) const;
42 
43 protected:
44  //! Returns whether the row given in the index is a skipped row. Only override this for
45  //! performance reasons.
46  virtual bool rowIsSkipped(const QModelIndex& index) const;
47 
48  //! Returns whether the row given in the index contains errors. Only override this for
49  //! performance reasons.
50  virtual bool rowHasError(const QModelIndex& index) const;
51 
52  //! Returns whether the row given in the index is a skipped row. Row counting starts with 0.
53  virtual bool rowIsSkipped(int row) const = 0;
54 
55  //! Returns whether the row given in the index contains errors. Row counting starts with 0.
56  virtual bool rowHasError(int row) const = 0;
57 
58  //! Return the table header text for the given column. For convenience, column starts at 0 for
59  //! first _calculated_ column, therefore it is not the same as the "real" section in the table
60  //! header.
61  virtual QString headerTextOfCalculatedColumn(int column) const = 0;
62 
63  //! The row count of the result table.
64  virtual int rowCount() const = 0;
65 
66  //! The number of existing columns related to the given column type. 0 if the type is not
67  //! present at all.
68  virtual int columnCount(ColumnType type) const = 0;
69 
70  //! The text of the given cell. For convenience, column starts at 0 for the given column type,
71  //! therefore it is not the same as the "real" section in the table header. This method will not
72  //! be called for every row/column present in the table. Instead, optimizations will be done
73  //! before calling it. E.g. the calculated values for lines which contain errors will never be
74  //! called. Also raw or calculated contents will not be queried if a line is skipped.
75  virtual QString cellText(ColumnType type, int row, int column) const = 0;
76 
77 private:
78  //! Calculates the column type of the given index.
79  ColumnType columnType(const QModelIndex& index) const;
80 
81  //! Calculates the column type of the real header view section.
82  ColumnType columnType(int section) const;
83 
84  //! Calculates the first real header view section of the given column type.
85  //! Returns -1 if the column type does not exist.
86  int firstSectionOfColumnType(ColumnType type) const;
87 
88  //! Calculates the last real header view section of the given column type.
89  //! Returns -1 if the column type does not exist.
90  int lastSectionOfColumnType(ColumnType type) const;
91 
92 private:
94 };
95 
96 #endif // BORNAGAIN_GUI_SUPPORT_IO_ABSTRACTDATALOADERRESULTMODEL_H
Base class for result tables of data loaders. Derive from this class and return an instance in YourDa...
virtual QString headerTextOfCalculatedColumn(int column) const =0
Return the table header text for the given column. For convenience, column starts at 0 for first calc...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int firstSectionOfColumnType(ColumnType type) const
Calculates the first real header view section of the given column type. Returns -1 if the column type...
QVector< int > sectionsOfColumnType(ColumnType type) const
The table header sections which belong to the given column type. Empty if this column type is not pre...
virtual bool rowIsSkipped(const QModelIndex &index) const
Returns whether the row given in the index is a skipped row. Only override this for performance reaso...
int columnCount(const QModelIndex &parent=QModelIndex()) const override
virtual bool rowIsSkipped(int row) const =0
Returns whether the row given in the index is a skipped row. Row counting starts with 0.
virtual QString cellText(ColumnType type, int row, int column) const =0
The text of the given cell. For convenience, column starts at 0 for the given column type,...
virtual bool rowHasError(const QModelIndex &index) const
Returns whether the row given in the index contains errors. Only override this for performance reason...
ColumnType columnType(const QModelIndex &index) const
Calculates the column type of the given index.
virtual int rowCount() const =0
The row count of the result table.
int lastSectionOfColumnType(ColumnType type) const
Calculates the last real header view section of the given column type. Returns -1 if the column type ...
virtual int columnCount(ColumnType type) const =0
The number of existing columns related to the given column type. 0 if the type is not present at all.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
virtual bool rowHasError(int row) const =0
Returns whether the row given in the index contains errors. Row counting starts with 0.