BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
QREDataLoaderResultModel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Loaders/QREDataLoaderResultModel.cpp
6 //! @brief Implements class QREDataLoaderResultModel
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 
16 
18  : m_importResult(importResult)
19 {
20 }
21 
23 {
24  return m_importResult->calculationErrors.contains(row);
25 }
26 
28 {
29  return m_importResult->lines.size();
30 }
31 
33 {
34  if (row >= 0 && row < m_importResult->lines.size())
35  return m_importResult->lines[row].first;
36  return false;
37 }
38 
40 {
41  switch (column) {
42  case 0:
43  return "Q [1/nm]";
44  case 1:
45  return "R";
46  case 2:
47  return "sigma_R";
48  default:
49  return "";
50  }
51 }
52 
54 {
55  switch (type) {
56  case ColumnType::line:
58  return 1;
59  case ColumnType::raw:
61  case ColumnType::processed: {
62  const bool showErrorColumn =
64  return showErrorColumn ? 3 : 2;
65  }
66  case ColumnType::error:
67  return m_importResult->calculationErrors.isEmpty() ? 0 : 1;
68  default:
69  return 0;
70  }
71 }
72 
73 QString QREDataLoaderResultModel::cellText(ColumnType type, int row, int col) const
74 {
75  if (col < 0 || row < 0 || row >= m_importResult->lines.size())
76  return "";
77 
78  if (type == ColumnType::fileContent)
79  return (col == 0) ? m_importResult->lines[row].second : QString();
80 
81  const bool isSkippedLine = m_importResult->lines[row].first;
82  if (isSkippedLine)
83  return "";
84 
85  switch (type) {
86  case ColumnType::raw: {
87  if (row >= m_importResult->rawValues.size())
88  return "";
89  const auto& d = m_importResult->rawValues[row];
90  return (col < d.size()) ? QString::number(d[col]) : QString();
91  }
92 
94  if (col == 0)
95  return (row < m_importResult->qValues.size())
96  ? QString::number(m_importResult->qValues[row])
97  : QString();
98  if (col == 1)
99  return (row < m_importResult->rValues.size())
100  ? QString::number(m_importResult->rValues[row])
101  : QString();
102  if (col == 2)
103  return (row < m_importResult->eValues.size())
104  ? QString::number(m_importResult->eValues[row])
105  : QString();
106  return "";
107 
108  case ColumnType::error:
109  return (col == 0) ? m_importResult->errorText(row) : QString();
110 
111  default:
112  return "";
113  }
114 }
Defines class QREDataLoaderResultModel.
QREDataLoaderResultModel(QREDataLoader::ImportResult *importResult)
int rowCount() const override
The row count of the result table.
QString headerTextOfCalculatedColumn(int column) const override
Return the table header text for the given column. For convenience, column starts at 0 for first calc...
QString cellText(ColumnType type, int row, int col) const override
The text of the given cell. For convenience, column starts at 0 for the given column type,...
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 rowHasError(const QModelIndex &index) const
Returns whether the row given in the index contains errors. Only override this for performance reason...
QREDataLoader::ImportResult * m_importResult
Result of the file import. Some of the contained data is only relevant for showing the results in the...
QVector< double > rValues
index is 0-based line number
int maxColumnCount
max found columns in raw data
QVector< QVector< double > > rawValues
index is 0-based line number
QMap< int, ErrorDefinition > calculationErrors
calculation error per line; line is 0-based
QVector< double > eValues
index is 0-based line number
QString errorText(int line) const
ImportSettings importSettings
Settings used for the import.
QVector< double > qValues
index is 0-based line number
QVector< QPair< bool, QString > > lines
bool describes whether line is skipped index is 0-based line number
QMap< DataType, ColumnDefinition > columnDefinitions
Definition: QREDataLoader.h:75