BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
CsvImportTable Class Reference
Inheritance diagram for CsvImportTable:
[legend]
Collaboration diagram for CsvImportTable:
[legend]

Signals

void dataSanityChanged ()
 

Public Member Functions

 CsvImportTable (QWidget *parent=nullptr)
 
QList< QString > availableCoordinateUnits () const
 
int coordinateColumn () const
 
double coordinateMultiplier () const
 
bool dataLooksGood () const
 
void discardRows (std::set< int > rows)
 
int intensityColumn () const
 
double intensityMultiplier () const
 
void resetSelection ()
 
std::set< int > rowsToDiscard () const
 
int selectedColumn () const
 
int selectedRow () const
 
std::set< int > selectedRows () const
 
void setColumnAs (int col, csv::ColumnType type)
 
void setData (csv::DataArray data)
 
void setFirstRow (size_t row)
 
void setLastRow (size_t row)
 

Private Member Functions

bool checkData ()
 
void greyoutDiscardedRows ()
 
void markCell (int i, int j, Qt::GlobalColor color)
 
void resetColumn (int col)
 
int rowOffset () const
 
void setHeaders ()
 
void setMultiplierFields ()
 
void updateSelectedCols ()
 
void updateSelection ()
 

Private Attributes

bool m_data_is_suitable
 
CsvImportDatam_import_data
 

Detailed Description

Definition at line 73 of file CsvImportTable.h.

Constructor & Destructor Documentation

◆ CsvImportTable()

CsvImportTable::CsvImportTable ( QWidget *  parent = nullptr)

Definition at line 254 of file CsvImportTable.cpp.

255  : QTableWidget(parent), m_import_data(new CsvImportData(this)), m_data_is_suitable(true)
256 {
257 }
CsvImportData * m_import_data

Member Function Documentation

◆ availableCoordinateUnits()

QList< QString > CsvImportTable::availableCoordinateUnits ( ) const

Definition at line 372 of file CsvImportTable.cpp.

373 {
375 }
QList< QString > availableCoordinateUnits() const

References CsvImportData::availableCoordinateUnits(), and m_import_data.

Referenced by DataSelector::populateUnitsComboBox().

Here is the call graph for this function:

◆ checkData()

bool CsvImportTable::checkData ( )
private

Definition at line 465 of file CsvImportTable.cpp.

466 {
467  auto to_highlight = m_import_data->checkData();
468  for (auto index : to_highlight)
469  markCell(index.first + rowOffset(), index.second, Qt::red);
470  return to_highlight.empty();
471 }
std::set< std::pair< int, int > > checkData()
void markCell(int i, int j, Qt::GlobalColor color)
int rowOffset() const

References CsvImportData::checkData(), m_import_data, markCell(), and rowOffset().

Referenced by updateSelection().

Here is the call graph for this function:

◆ coordinateColumn()

int CsvImportTable::coordinateColumn ( ) const
inline

Definition at line 91 of file CsvImportTable.h.

int column(DATA_TYPE type) const

References CsvImportData::column(), CsvImportData::Coordinate, and m_import_data.

Referenced by DataSelector::coordinateColumn(), and DataSelector::updateSelection().

Here is the call graph for this function:

◆ coordinateMultiplier()

double CsvImportTable::coordinateMultiplier ( ) const

Definition at line 367 of file CsvImportTable.cpp.

368 {
370 }
double multiplier(DATA_TYPE type) const

References CsvImportData::Coordinate, m_import_data, and CsvImportData::multiplier().

Referenced by DataSelector::coordinateMultiplier().

Here is the call graph for this function:

◆ dataLooksGood()

bool CsvImportTable::dataLooksGood ( ) const
inline

Definition at line 96 of file CsvImportTable.h.

96 { return m_data_is_suitable; }

References m_data_is_suitable.

Referenced by DataSelector::updateSelection().

◆ dataSanityChanged

void CsvImportTable::dataSanityChanged ( )
signal

◆ discardRows()

void CsvImportTable::discardRows ( std::set< int >  rows)

Definition at line 350 of file CsvImportTable.cpp.

351 {
352  m_import_data->toggleDiscardRows(std::move(rows));
353  updateSelection();
354 }
void toggleDiscardRows(std::set< int > rows)

References m_import_data, CsvImportData::toggleDiscardRows(), and updateSelection().

Referenced by DataSelector::discardRow().

Here is the call graph for this function:

◆ greyoutDiscardedRows()

void CsvImportTable::greyoutDiscardedRows ( )
private

Definition at line 453 of file CsvImportTable.cpp.

454 {
455  int nRows = this->rowCount();
456  int nCols = this->columnCount();
457 
458  for (int i = rowOffset(); i < nRows; i++) {
459  Qt::GlobalColor color = m_import_data->rowExcluded(i - rowOffset()) ? Qt::gray : Qt::white;
460  for (int j = 0; j < nCols; j++)
461  markCell(i, j, color);
462  }
463 }
bool rowExcluded(int row)

References m_import_data, markCell(), CsvImportData::rowExcluded(), and rowOffset().

Referenced by updateSelection().

Here is the call graph for this function:

◆ intensityColumn()

int CsvImportTable::intensityColumn ( ) const
inline

Definition at line 90 of file CsvImportTable.h.

References CsvImportData::column(), CsvImportData::Intensity, and m_import_data.

Referenced by DataSelector::intensityColumn(), and DataSelector::updateSelection().

Here is the call graph for this function:

◆ intensityMultiplier()

double CsvImportTable::intensityMultiplier ( ) const

Definition at line 362 of file CsvImportTable.cpp.

363 {
365 }

References CsvImportData::Intensity, m_import_data, and CsvImportData::multiplier().

Referenced by DataSelector::intensityMultiplier().

Here is the call graph for this function:

◆ markCell()

void CsvImportTable::markCell ( int  i,
int  j,
Qt::GlobalColor  color 
)
private

Definition at line 485 of file CsvImportTable.cpp.

486 {
487  item(i, j)->setBackground(color);
488 }

Referenced by checkData(), and greyoutDiscardedRows().

◆ resetColumn()

void CsvImportTable::resetColumn ( int  col)
private

Definition at line 473 of file CsvImportTable.cpp.

474 {
475  if (columnCount() >= col || col < 0)
476  return;
477 
478  const csv::DataColumn data = m_import_data->values(col);
479  for (size_t i = 0; i < data.size(); i++) {
480  QString originalText = QString::fromStdString(data[i]);
481  setItem(static_cast<int>(i) + rowOffset(), int(col), new QTableWidgetItem(originalText));
482  }
483 }
csv::DataColumn values(int col) const
std::vector< std::string > DataColumn
Definition: CsvNamespace.h:28

References m_import_data, rowOffset(), and CsvImportData::values().

Referenced by setColumnAs().

Here is the call graph for this function:

◆ resetSelection()

void CsvImportTable::resetSelection ( )

Definition at line 356 of file CsvImportTable.cpp.

357 {
359  updateSelection();
360 }

References m_import_data, CsvImportData::resetSelection(), and updateSelection().

Referenced by DataSelector::resetSelection().

Here is the call graph for this function:

◆ rowOffset()

int CsvImportTable::rowOffset ( ) const
inlineprivate

Definition at line 109 of file CsvImportTable.h.

109 { return 1; } // this comes from the multipliers in the first row

Referenced by checkData(), greyoutDiscardedRows(), resetColumn(), selectedRow(), selectedRows(), setMultiplierFields(), and updateSelectedCols().

◆ rowsToDiscard()

std::set<int> CsvImportTable::rowsToDiscard ( ) const
inline

Definition at line 95 of file CsvImportTable.h.

95 { return m_import_data->rowsToDiscard(); }
std::set< int > rowsToDiscard() const

References m_import_data, and CsvImportData::rowsToDiscard().

Referenced by DataSelector::rowsToDiscard().

Here is the call graph for this function:

◆ selectedColumn()

int CsvImportTable::selectedColumn ( ) const

Definition at line 288 of file CsvImportTable.cpp.

289 {
290  auto selectedRanges = this->selectedRanges();
291  if (selectedRanges.empty())
292  return -1;
293  auto front = selectedRanges.front();
294  auto col = front.leftColumn();
295  return col;
296 }

Referenced by DataSelector::setColumnAs().

◆ selectedRow()

int CsvImportTable::selectedRow ( ) const

Definition at line 259 of file CsvImportTable.cpp.

260 {
261  auto selectedRanges = this->selectedRanges();
262  if (selectedRanges.empty())
263  return -1;
264  auto front = selectedRanges.front();
265  auto row = front.topRow();
266  return row - rowOffset();
267 }

References rowOffset().

Referenced by DataSelector::setFirstRow(), and DataSelector::setLastRow().

Here is the call graph for this function:

◆ selectedRows()

std::set< int > CsvImportTable::selectedRows ( ) const

Definition at line 269 of file CsvImportTable.cpp.

270 {
271  std::set<int> accumulator;
272 
273  auto selection = selectedRanges();
274  if (selection.empty())
275  return {};
276 
277  int size = selection.size();
278  for (int rangenumber = 0; rangenumber < size; ++rangenumber) {
279  int row0 = selectedRanges()[rangenumber].topRow() - rowOffset();
280  int rowN = selectedRanges()[rangenumber].bottomRow() - rowOffset();
281  for (int r = row0; r <= rowN; ++r) {
282  accumulator.insert(r);
283  }
284  }
285  return accumulator;
286 }

References rowOffset().

Referenced by DataSelector::discardRow().

Here is the call graph for this function:

◆ setColumnAs()

void CsvImportTable::setColumnAs ( int  col,
csv::ColumnType  type 
)

Definition at line 327 of file CsvImportTable.cpp.

328 {
329  int prev_col = m_import_data->setColumnAs(col, type);
330  resetColumn(prev_col);
331  updateSelection();
332 }
int setColumnAs(int col, csv::ColumnType type)
sets type to a column col.
void resetColumn(int col)

References m_import_data, resetColumn(), CsvImportData::setColumnAs(), and updateSelection().

Referenced by DataSelector::setColumnAs().

Here is the call graph for this function:

◆ setData()

void CsvImportTable::setData ( csv::DataArray  data)

Definition at line 298 of file CsvImportTable.cpp.

299 {
300  if (data.empty()) {
301  clearContents();
302  setRowCount(0);
303  m_import_data->setData(std::move(data));
304  return;
305  }
306 
307  size_t nRows = data.size();
308  size_t nCols = data[0].size();
309  clearContents();
310  setColumnCount(int(nCols));
311  setRowCount(0);
312 
313  insertRow(rowCount());
314 
315  for (size_t i = 0; i < nRows; i++) {
316  insertRow(rowCount());
317  size_t I = size_t(rowCount()) - 1;
318  for (size_t j = 0; j < data[i].size(); j++) {
319  setItem(int(I), int(j), new QTableWidgetItem(QString::fromStdString(data[i][j])));
320  }
321  }
322 
323  m_import_data->setData(std::move(data));
325 }
constexpr complex_t I
Definition: Complex.h:21
void setData(csv::DataArray data)
void setMultiplierFields()

References I, m_import_data, CsvImportData::setData(), and setMultiplierFields().

Referenced by DataSelector::updateData().

Here is the call graph for this function:

◆ setFirstRow()

void CsvImportTable::setFirstRow ( size_t  row)

Definition at line 334 of file CsvImportTable.cpp.

335 {
336  if (row == m_import_data->firstRow())
337  return;
339  updateSelection();
340 }
size_t firstRow()
void setFirstRow(size_t row)

References CsvImportData::firstRow(), m_import_data, CsvImportData::setFirstRow(), and updateSelection().

Referenced by DataSelector::setFirstRow(), and DataSelector::updateSelection().

Here is the call graph for this function:

◆ setHeaders()

void CsvImportTable::setHeaders ( )
private

Definition at line 391 of file CsvImportTable.cpp.

392 {
393  // Reset header labels
394  QStringList headers;
395 
396  for (int j = 0; j < this->columnCount(); j++)
397  headers.append(QString::number(j + 1));
398  setHorizontalHeaderLabels(headers);
399 
400  for (auto type : CsvImportData::availableTypes()) {
401  int col = m_import_data->column(type);
402  if (col < 0)
403  continue;
404  setHorizontalHeaderItem(col, new QTableWidgetItem(m_import_data->columnLabel(type)));
405  }
406 }
QString columnLabel(DATA_TYPE type) const
static std::vector< DATA_TYPE > availableTypes()

References CsvImportData::availableTypes(), CsvImportData::column(), CsvImportData::columnLabel(), and m_import_data.

Referenced by updateSelection().

Here is the call graph for this function:

◆ setLastRow()

void CsvImportTable::setLastRow ( size_t  row)

Definition at line 342 of file CsvImportTable.cpp.

343 {
344  if (row == m_import_data->lastRow())
345  return;
347  updateSelection();
348 }
size_t lastRow()
void setLastRow(size_t row)

References CsvImportData::lastRow(), m_import_data, CsvImportData::setLastRow(), and updateSelection().

Referenced by DataSelector::setLastRow(), and DataSelector::updateSelection().

Here is the call graph for this function:

◆ setMultiplierFields()

void CsvImportTable::setMultiplierFields ( )
private

Definition at line 422 of file CsvImportTable.cpp.

423 {
424  const int n_cols = static_cast<int>(m_import_data->nCols());
425 
426  for (int n = 0; n < n_cols; ++n)
427  setCellWidget(0, n, createMultiplierBox());
428 
429  auto types = CsvImportData::availableTypes();
430  for (auto type : types)
431  if (m_import_data->column(type) >= 0) {
432  auto spin_box =
433  static_cast<ScientificSpinBox*>(cellWidget(0, m_import_data->column(type)));
434  spin_box->setEnabled(true);
435  spin_box->setValue(m_import_data->multiplier(type));
436  connect(spin_box, &ScientificSpinBox::editingFinished, this, [this, spin_box, type]() {
437  m_import_data->setMultiplier(type, spin_box->value());
438  updateSelection();
439  });
440  }
441 
442  // FIXME: move row headers initialization elsewhere
443  int nRows = this->rowCount();
444 
445  QStringList vhlabels;
446  vhlabels << "Multiplier: ";
447  for (int i = rowOffset(); i < nRows; i++)
448  vhlabels << QString::number(i);
449 
450  this->setVerticalHeaderLabels(vhlabels);
451 }
size_t nCols() const
void setMultiplier(DATA_TYPE type, double value)
void setValue(double val)

References CsvImportData::availableTypes(), CsvImportData::column(), m_import_data, CsvImportData::multiplier(), CsvImportData::nCols(), rowOffset(), CsvImportData::setMultiplier(), ScientificSpinBox::setValue(), and updateSelection().

Referenced by setData(), and updateSelection().

Here is the call graph for this function:

◆ updateSelectedCols()

void CsvImportTable::updateSelectedCols ( )
private

Definition at line 408 of file CsvImportTable.cpp.

409 {
410  // FIXME: replace recreation of sell items with value assignment
411  for (auto type : CsvImportData::availableTypes()) {
413  if (values.empty())
414  continue;
415  int col = m_import_data->column(type);
416  for (size_t i = 0; i < values.size(); ++i)
417  setItem(static_cast<int>(i) + rowOffset(), col,
418  new QTableWidgetItem(QString::fromStdString(values[i])));
419  }
420 }
csv::DataColumn multipliedValues(DATA_TYPE type) const

References CsvImportData::availableTypes(), CsvImportData::column(), m_import_data, CsvImportData::multipliedValues(), and rowOffset().

Referenced by updateSelection().

Here is the call graph for this function:

◆ updateSelection()

void CsvImportTable::updateSelection ( )
private

Definition at line 377 of file CsvImportTable.cpp.

378 {
379  setHeaders();
380  // FIXME: replace re-creation of all spin boxes with blocking/unlocking
384  if (checkData() != m_data_is_suitable) {
386  emit dataSanityChanged();
387  }
388 }
void dataSanityChanged()
void greyoutDiscardedRows()

References checkData(), dataSanityChanged(), greyoutDiscardedRows(), m_data_is_suitable, setHeaders(), setMultiplierFields(), and updateSelectedCols().

Referenced by discardRows(), resetSelection(), setColumnAs(), setFirstRow(), setLastRow(), and setMultiplierFields().

Here is the call graph for this function:

Member Data Documentation

◆ m_data_is_suitable

bool CsvImportTable::m_data_is_suitable
private

Definition at line 114 of file CsvImportTable.h.

Referenced by dataLooksGood(), and updateSelection().

◆ m_import_data


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