BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
AutomaticDataLoader1DResultModel Class Reference

The result model of a AutomaticDataLoader1D (for showing the import results in a table view). More...

Inheritance diagram for AutomaticDataLoader1DResultModel:
[legend]
Collaboration diagram for AutomaticDataLoader1DResultModel:
[legend]

Public Types

enum class  ColumnType {
  none , line , fileContent , raw ,
  processed , error
}
 

Public Member Functions

 AutomaticDataLoader1DResultModel (RealDataItem *item)
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
virtual int rowCount (const QModelIndex &parent) const override
 
QVector< int > sectionsOfColumnType (ColumnType type) const
 The table header sections which belong to the given column type. More...
 

Protected Member Functions

virtual QString cellText (ColumnType type, int row, int col) const override
 The text of the given cell. More...
 
virtual int columnCount (ColumnType type) const override
 The number of existing columns related to the given column type. More...
 
virtual QString headerTextOfCalculatedColumn (int column) const override
 Return the table header text for the given column. More...
 
virtual int rowCount () const override
 The row count of the result table. More...
 
virtual bool rowHasError (const QModelIndex &index) const
 Returns whether the row given in the index contains errors. More...
 
virtual bool rowHasError (int row) const override
 Returns whether the row given in the index contains errors. Row counting starts with 0. More...
 
virtual bool rowIsSkipped (const QModelIndex &index) const
 Returns whether the row given in the index is a skipped row. More...
 
virtual bool rowIsSkipped (int row) const override
 Returns whether the row given in the index is a skipped row. Row counting starts with 0. More...
 

Private Member Functions

ColumnType columnType (const QModelIndex &index) const
 Calculates the column type of the given index. More...
 
ColumnType columnType (int section) const
 Calculates the column type of the real header view section. More...
 
int firstSectionOfColumnType (ColumnType type) const
 Calculates the first real header view section of the given column type. More...
 
int lastSectionOfColumnType (ColumnType type) const
 Calculates the last real header view section of the given column type. More...
 

Private Attributes

RealDataItemm_item
 
QIcon m_warningIcon
 

Detailed Description

The result model of a AutomaticDataLoader1D (for showing the import results in a table view).

Definition at line 23 of file AutomaticDataLoader1DResultModel.h.

Member Enumeration Documentation

◆ ColumnType

Enumerator
none 
line 
fileContent 
raw 
processed 
error 

Definition at line 26 of file AbstractDataLoaderResultModel.h.

26 { none, line, fileContent, raw, processed, error };
@ none
undefined converter mode

Constructor & Destructor Documentation

◆ AutomaticDataLoader1DResultModel()

AutomaticDataLoader1DResultModel::AutomaticDataLoader1DResultModel ( RealDataItem item)

Definition at line 19 of file AutomaticDataLoader1DResultModel.cpp.

20  : m_item(item)
21 {
22 }

Member Function Documentation

◆ cellText()

QString AutomaticDataLoader1DResultModel::cellText ( ColumnType  type,
int  row,
int  column 
) const
overrideprotectedvirtual

The text of the given cell.

For convenience, column starts at 0 for the given column type, therefore it is not the same as the "real" section in the table header. This method will not be called for every row/column present in the table. Instead, optimizations will be done before calling it. E.g. the calculated values for lines which contain errors will never be called. Also raw or calculated contents will not be queried if a line is skipped.

Implements AbstractDataLoaderResultModel.

Definition at line 59 of file AutomaticDataLoader1DResultModel.cpp.

60 {
61  if (col < 0 || row < 0 || row >= rowCount() || type != ColumnType::processed)
62  return QString();
63 
65 
66  if (col == 0)
67  return QString::number(data->getAxisValue(row, 0));
68 
69  if (col == 1)
70  return QString::number(data->operator[](row));
71 
72  return QString();
73 }
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual int rowCount() const override
The row count of the result table.
OutputData< double > * getOutputData()
Definition: DataItem.h:36
SpecularDataItem * specularDataItem()

References AbstractDataLoaderResultModel::data(), DataItem::getOutputData(), m_item, AbstractDataLoaderResultModel::processed, rowCount(), and RealDataItem::specularDataItem().

Here is the call graph for this function:

◆ columnCount() [1/2]

int AutomaticDataLoader1DResultModel::columnCount ( ColumnType  type) const
overrideprotectedvirtual

The number of existing columns related to the given column type.

0 if the type is not present at all.

Implements AbstractDataLoaderResultModel.

Definition at line 54 of file AutomaticDataLoader1DResultModel.cpp.

55 {
56  return (type == ColumnType::processed) ? 2 : 0;
57 }

References AbstractDataLoaderResultModel::processed.

◆ columnCount() [2/2]

int AbstractDataLoaderResultModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
overridevirtualinherited

◆ columnType() [1/2]

AbstractDataLoaderResultModel::ColumnType AbstractDataLoaderResultModel::columnType ( const QModelIndex &  index) const
privateinherited

Calculates the column type of the given index.

Definition at line 193 of file AbstractDataLoaderResultModel.cpp.

194 {
195  return columnType(index.column());
196 }
ColumnType columnType(const QModelIndex &index) const
Calculates the column type of the given index.

Referenced by AbstractDataLoaderResultModel::data(), and AbstractDataLoaderResultModel::headerData().

◆ columnType() [2/2]

AbstractDataLoaderResultModel::ColumnType AbstractDataLoaderResultModel::columnType ( int  section) const
privateinherited

Calculates the column type of the real header view section.

Definition at line 175 of file AbstractDataLoaderResultModel.cpp.

176 {
179 
180  for (ColumnType type : colTypes) {
181  const int firstSection = firstSectionOfColumnType(type);
182  if (firstSection < 0)
183  continue;
184 
185  if (section >= firstSection && section <= lastSectionOfColumnType(type))
186  return type;
187  }
188 
189  return ColumnType::none;
190 }
int firstSectionOfColumnType(ColumnType type) const
Calculates the first real header view section of the given column type.
int lastSectionOfColumnType(ColumnType type) const
Calculates the last real header view section of the given column type.

References AbstractDataLoaderResultModel::error, AbstractDataLoaderResultModel::fileContent, AbstractDataLoaderResultModel::firstSectionOfColumnType(), AbstractDataLoaderResultModel::lastSectionOfColumnType(), AbstractDataLoaderResultModel::line, AbstractDataLoaderResultModel::none, AbstractDataLoaderResultModel::processed, and AbstractDataLoaderResultModel::raw.

Here is the call graph for this function:

◆ data()

QVariant AbstractDataLoaderResultModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
overridevirtualinherited

Definition at line 62 of file AbstractDataLoaderResultModel.cpp.

64 {
65  if (!index.isValid())
66  return QVariant();
67 
68  const auto colType = columnType(index);
69 
70  if (role == Qt::BackgroundRole) {
71  switch (colType) {
72  case ColumnType::line:
73  return Palette::backgroundColorFileContent;
75  return Palette::backgroundColorFileContent;
76  case ColumnType::raw:
77  return rowIsSkipped(index) ? QVariant() : Palette::backgroundColorRawContent;
79  return rowIsSkipped(index) || rowHasError(index)
80  ? QVariant()
81  : Palette::backgroundColorProcessedContent;
82  case ColumnType::error:
83  return rowIsSkipped(index) || !rowHasError(index) ? QVariant()
84  : Palette::backgroundColorErrors;
85  default:
86  return QVariant();
87  }
88  }
89 
90  if (role == Qt::ForegroundRole) {
91  if (colType == ColumnType::fileContent && rowIsSkipped(index))
92  return Palette::skippedLineTextColor;
93  return QVariant();
94  }
95 
96  if (role == Qt::DisplayRole) {
97  switch (colType) {
98  case ColumnType::line:
99  return QString::number(index.row() + 1);
100 
102  QString lineContent =
103  cellText(colType, index.row(), index.column() - firstSectionOfColumnType(colType));
104  lineContent.replace("\t", " --> ");
105  return lineContent;
106  }
107 
108  case ColumnType::raw:
109  case ColumnType::error: {
110  if (!rowIsSkipped(index))
111  return cellText(colType, index.row(),
112  index.column() - firstSectionOfColumnType(colType));
113  }
114 
115  case ColumnType::processed: {
116  if (!rowIsSkipped(index) && !rowHasError(index))
117  return cellText(colType, index.row(),
118  index.column() - firstSectionOfColumnType(colType));
119  }
120  }
121 
122  return QVariant();
123  }
124 
125  if (role == Qt::DecorationRole && (colType == ColumnType::line || colType == ColumnType::error)
126  && rowHasError(index))
127  return m_warningIcon;
128 
129  if (role == Qt::TextAlignmentRole && colType == ColumnType::line)
130  return QVariant(Qt::AlignRight | Qt::AlignVCenter);
131 
132  if (role == Qt::ToolTipRole && colType == ColumnType::line && rowHasError(index))
133  return cellText(ColumnType::error, index.row(), 0);
134 
135  return QVariant();
136 }
virtual bool rowIsSkipped(const QModelIndex &index) const
Returns whether the row given in the index is a skipped row.
virtual QString cellText(ColumnType type, int row, int column) const =0
The text of the given cell.
virtual bool rowHasError(const QModelIndex &index) const
Returns whether the row given in the index contains errors.
QVariant DecorationRole(const SessionItem &item)
Returns tooltip for given item.
QVariant ToolTipRole(const SessionItem &item, int ncol=0)
Returns tooltip for given item.
QVariant ForegroundRole(const SessionItem &item)
Returns text color for given item.

References AbstractDataLoaderResultModel::cellText(), AbstractDataLoaderResultModel::columnType(), SessionItemUtils::DecorationRole(), AbstractDataLoaderResultModel::error, AbstractDataLoaderResultModel::fileContent, AbstractDataLoaderResultModel::firstSectionOfColumnType(), SessionItemUtils::ForegroundRole(), AbstractDataLoaderResultModel::line, AbstractDataLoaderResultModel::m_warningIcon, AbstractDataLoaderResultModel::processed, AbstractDataLoaderResultModel::raw, AbstractDataLoaderResultModel::rowHasError(), AbstractDataLoaderResultModel::rowIsSkipped(), and SessionItemUtils::ToolTipRole().

Referenced by cellText(), and rowCount().

Here is the call graph for this function:

◆ firstSectionOfColumnType()

int AbstractDataLoaderResultModel::firstSectionOfColumnType ( ColumnType  type) const
privateinherited

Calculates the first real header view section of the given column type.

Returns -1 if the column type does not exist.

Definition at line 198 of file AbstractDataLoaderResultModel.cpp.

199 {
200  const int lineColumnCount = columnCount(ColumnType::line);
201  const int fileContentColumnCount = columnCount(ColumnType::fileContent);
202 
203  if (type == ColumnType::line)
204  return lineColumnCount > 0 ? 0 : -1;
205 
206  if (type == ColumnType::fileContent)
207  return columnCount(ColumnType::fileContent) > 0 ? lineColumnCount : -1;
208 
209  if (type == ColumnType::raw) {
210  const bool hasRawContent = columnCount(ColumnType::raw) > 0;
211  return hasRawContent ? lineColumnCount + fileContentColumnCount : -1;
212  }
213 
214  if (type == ColumnType::processed) {
215  const bool hasProcessedContent = columnCount(ColumnType::processed) > 0;
216  return hasProcessedContent
217  ? (lineColumnCount + fileContentColumnCount + columnCount(ColumnType::raw))
218  : -1;
219  }
220 
221  if (type == ColumnType::error) {
222  const bool hasParsingErrors = columnCount(ColumnType::error) > 0;
223  return hasParsingErrors
224  ? (lineColumnCount + fileContentColumnCount + columnCount(ColumnType::raw)
226  : -1;
227  }
228 
229  return -1;
230 }

References AbstractDataLoaderResultModel::columnCount(), AbstractDataLoaderResultModel::error, AbstractDataLoaderResultModel::fileContent, AbstractDataLoaderResultModel::line, AbstractDataLoaderResultModel::processed, and AbstractDataLoaderResultModel::raw.

Referenced by AbstractDataLoaderResultModel::columnType(), AbstractDataLoaderResultModel::data(), AbstractDataLoaderResultModel::headerData(), AbstractDataLoaderResultModel::lastSectionOfColumnType(), and AbstractDataLoaderResultModel::sectionsOfColumnType().

Here is the call graph for this function:

◆ headerData()

QVariant AbstractDataLoaderResultModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
overridevirtualinherited

Definition at line 138 of file AbstractDataLoaderResultModel.cpp.

140 {
141  if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
142  switch (columnType(section)) {
143  case ColumnType::line:
144  return "Line";
146  return "File content (text)";
147  case ColumnType::raw:
148  return QString("Column %1 raw")
149  .arg(section - firstSectionOfColumnType(ColumnType::raw) + 1);
151  return headerTextOfCalculatedColumn(section
153  case ColumnType::error:
154  return "Parser warnings";
155  default:
156  return QVariant();
157  }
158  }
159 
160  return QAbstractTableModel::headerData(section, orientation, role);
161 }
virtual QString headerTextOfCalculatedColumn(int column) const =0
Return the table header text for the given column.

References AbstractDataLoaderResultModel::columnType(), AbstractDataLoaderResultModel::error, AbstractDataLoaderResultModel::fileContent, AbstractDataLoaderResultModel::firstSectionOfColumnType(), AbstractDataLoaderResultModel::headerTextOfCalculatedColumn(), AbstractDataLoaderResultModel::line, AbstractDataLoaderResultModel::processed, and AbstractDataLoaderResultModel::raw.

Here is the call graph for this function:

◆ headerTextOfCalculatedColumn()

QString AutomaticDataLoader1DResultModel::headerTextOfCalculatedColumn ( int  column) const
overrideprotectedvirtual

Return the table header text for the given column.

For convenience, column starts at 0 for first calculated column, therefore it is not the same as the "real" section in the table header.

Implements AbstractDataLoaderResultModel.

Definition at line 43 of file AutomaticDataLoader1DResultModel.cpp.

44 {
45  switch (column) {
46  case 0:
47  return "Q [1/nm]";
48  case 1:
49  return "R";
50  }
51  return QString();
52 }

◆ lastSectionOfColumnType()

int AbstractDataLoaderResultModel::lastSectionOfColumnType ( ColumnType  type) const
privateinherited

Calculates the last real header view section of the given column type.

Returns -1 if the column type does not exist.

Definition at line 232 of file AbstractDataLoaderResultModel.cpp.

233 {
234  const int firstSection = firstSectionOfColumnType(type);
235  if (firstSection == -1)
236  return -1;
237 
238  return firstSection + columnCount(type) - 1;
239 }

References AbstractDataLoaderResultModel::columnCount(), and AbstractDataLoaderResultModel::firstSectionOfColumnType().

Referenced by AbstractDataLoaderResultModel::columnType(), and AbstractDataLoaderResultModel::sectionsOfColumnType().

Here is the call graph for this function:

◆ rowCount() [1/2]

int AutomaticDataLoader1DResultModel::rowCount ( ) const
overrideprotectedvirtual

The row count of the result table.

Implements AbstractDataLoaderResultModel.

Definition at line 29 of file AutomaticDataLoader1DResultModel.cpp.

30 {
32  if (!data)
33  return 0;
34 
35  return int(data->getAllocatedSize());
36 }

References AbstractDataLoaderResultModel::data(), DataItem::getOutputData(), m_item, and RealDataItem::specularDataItem().

Referenced by cellText().

Here is the call graph for this function:

◆ rowCount() [2/2]

int AbstractDataLoaderResultModel::rowCount ( const QModelIndex &  parent) const
overridevirtualinherited

Definition at line 57 of file AbstractDataLoaderResultModel.cpp.

58 {
59  return parent.isValid() ? 0 : rowCount();
60 }
virtual int rowCount() const =0
The row count of the result table.

References AbstractDataLoaderResultModel::rowCount().

Here is the call graph for this function:

◆ rowHasError() [1/2]

bool AbstractDataLoaderResultModel::rowHasError ( const QModelIndex &  index) const
protectedvirtualinherited

Returns whether the row given in the index contains errors.

Only override this for performance reasons.

Definition at line 246 of file AbstractDataLoaderResultModel.cpp.

247 {
248  return rowHasError(index.row());
249 }

Referenced by AbstractDataLoaderResultModel::data().

◆ rowHasError() [2/2]

bool AutomaticDataLoader1DResultModel::rowHasError ( int  row) const
overrideprotectedvirtual

Returns whether the row given in the index contains errors. Row counting starts with 0.

Implements AbstractDataLoaderResultModel.

Definition at line 24 of file AutomaticDataLoader1DResultModel.cpp.

25 {
26  return false;
27 }

◆ rowIsSkipped() [1/2]

bool AbstractDataLoaderResultModel::rowIsSkipped ( const QModelIndex &  index) const
protectedvirtualinherited

Returns whether the row given in the index is a skipped row.

Only override this for performance reasons.

Definition at line 241 of file AbstractDataLoaderResultModel.cpp.

242 {
243  return rowIsSkipped(index.row());
244 }

Referenced by AbstractDataLoaderResultModel::data().

◆ rowIsSkipped() [2/2]

bool AutomaticDataLoader1DResultModel::rowIsSkipped ( int  row) const
overrideprotectedvirtual

Returns whether the row given in the index is a skipped row. Row counting starts with 0.

Implements AbstractDataLoaderResultModel.

Definition at line 38 of file AutomaticDataLoader1DResultModel.cpp.

39 {
40  return false;
41 }

◆ sectionsOfColumnType()

QVector< int > AbstractDataLoaderResultModel::sectionsOfColumnType ( ColumnType  type) const
inherited

The table header sections which belong to the given column type.

Empty if this column type is not present at all.

Definition at line 163 of file AbstractDataLoaderResultModel.cpp.

164 {
165  QVector<int> sections;
166  for (int section = firstSectionOfColumnType(type); section <= lastSectionOfColumnType(type);
167  section++)
168  if (section >= 0)
169  sections << section;
170 
171  return sections;
172 }

References AbstractDataLoaderResultModel::firstSectionOfColumnType(), and AbstractDataLoaderResultModel::lastSectionOfColumnType().

Referenced by SpecularDataImportWidget::updatePreview().

Here is the call graph for this function:

Member Data Documentation

◆ m_item

RealDataItem* AutomaticDataLoader1DResultModel::m_item
private

Definition at line 36 of file AutomaticDataLoader1DResultModel.h.

Referenced by cellText(), and rowCount().

◆ m_warningIcon

QIcon AbstractDataLoaderResultModel::m_warningIcon
privateinherited

The documentation for this class was generated from the following files: