BornAgain  1.19.0
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/coregui/DataLoaders/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 
37  return false;
38 }
39 
41 {
42  switch (column) {
43  case 0:
44  return "Q [1/nm]";
45  case 1:
46  return "R";
47  case 2:
48  return "sigma_R";
49  }
50  return QString();
51 }
52 
54 {
55  switch (type) {
56  case ColumnType::line:
57  return 1;
59  return 1;
60  case ColumnType::raw:
62  case ColumnType::processed: {
63  const bool showErrorColumn =
65 
66  return showErrorColumn ? 3 : 2;
67  }
68  case ColumnType::error:
69  return m_importResult->calculationErrors.isEmpty() ? 0 : 1;
70  default:
71  return 0;
72  }
73 }
74 
75 QString QREDataLoaderResultModel::cellText(ColumnType type, int row, int col) const
76 {
77  if (col < 0 || row < 0 || row >= m_importResult->lines.size())
78  return QString();
79 
80  if (type == ColumnType::fileContent)
81  return (col == 0) ? m_importResult->lines[row].second : QString();
82 
83  const bool isSkippedLine = m_importResult->lines[row].first;
84  if (isSkippedLine)
85  return QString();
86 
87  switch (type) {
88  case ColumnType::raw: {
89  if (row >= m_importResult->rawValues.size())
90  return QString();
91  const auto& d = m_importResult->rawValues[row];
92  return (col < d.size()) ? QString::number(d[col]) : QString();
93  }
94 
96  if (col == 0)
97  return (row < m_importResult->qValues.size())
98  ? QString::number(m_importResult->qValues[row])
99  : QString();
100  if (col == 1)
101  return (row < m_importResult->rValues.size())
102  ? QString::number(m_importResult->rValues[row])
103  : QString();
104  if (col == 2)
105  return (row < m_importResult->eValues.size())
106  ? QString::number(m_importResult->eValues[row])
107  : QString();
108  return QString();
109 
110  case ColumnType::error:
111  return (col == 0) ? m_importResult->errorText(row) : QString();
112 
113  default:
114  return QString();
115  }
116 }
Defines class QREDataLoaderResultModel.
QREDataLoaderResultModel(QREDataLoader::ImportResult *importResult)
virtual int rowCount() const override
The row count of the result table.
virtual bool rowHasError(int row) const override
Returns whether the row given in the index contains errors. Row counting starts with 0.
virtual QString headerTextOfCalculatedColumn(int column) const override
Return the table header text for the given column.
virtual QString cellText(ColumnType type, int row, int col) const override
The text of the given cell.
virtual bool rowIsSkipped(int row) const override
Returns whether the row given in the index is a skipped row. Row counting starts with 0.
QREDataLoader::ImportResult * m_importResult
virtual int columnCount(ColumnType type) const override
The number of existing columns related to the given column type.
Result of the file import.
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:71