BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
CsvImportTable.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportTable.h
6 //! @brief Defines class CsvImportTable
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_CSVIMPORTASSISTANT_CSVIMPORTTABLE_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_CSVIMPORTASSISTANT_CSVIMPORTTABLE_H
17 
19 #include <QTableWidget>
20 #include <set>
21 
22 class CsvImportData : public QObject {
23 public:
24  // FIXME: move DATA_TYPE enumeration to csv namespace
26 
27  CsvImportData(QObject* parent = nullptr);
28 
30  //! sets _type_ to a column _col_. Returns the
31  //! column number previously set to the type
32  int setColumnAs(int col, csv::ColumnType type);
33  void setMultiplier(DATA_TYPE type, double value);
34  void setFirstRow(size_t row);
35  void setLastRow(size_t row);
36  void toggleDiscardRows(std::set<int> rows);
37 
38  // static methods
39  // FIXME: move to csv namespace or utilities
40  static std::vector<DATA_TYPE> availableTypes();
41  // accessors
42  const csv::DataArray& data() const;
43  int column(DATA_TYPE type) const;
44  csv::DataColumn values(int col) const;
46  double multiplier(DATA_TYPE type) const;
47  QString columnLabel(DATA_TYPE type) const;
48  QList<QString> availableCoordinateUnits() const;
49  std::set<int> rowsToDiscard() const { return m_discarded_rows; }
50  size_t nCols() const;
51  size_t nRows() const;
52  bool rowExcluded(int row);
53  size_t firstRow() { return m_n_header; }
54  size_t lastRow() { return m_n_footer + 1 >= nRows() ? 0 : nRows() - m_n_footer - 1; }
55 
56  std::set<std::pair<int, int>> checkData();
57  void resetSelection();
58 
59 private:
60  //! Checks if selected data is suitable for import.
61  //! All values must be convertible to doubles, positive and
62  //! sorted in ascending order if _check_ordering_ is set to true.
63  //! Returns a set of rows where the check failed.
64  std::set<int> checkFormat(const csv::DataColumn& values, bool check_ordering);
65 
66  std::unique_ptr<const csv::DataArray> m_data;
67  std::map<DATA_TYPE, CsvCoordinateColumn> m_selected_cols;
68  size_t m_n_header; //!< number of header rows
69  size_t m_n_footer; //!< number of footer rows
70  std::set<int> m_discarded_rows;
71 };
72 
73 class CsvImportTable : public QTableWidget {
74  Q_OBJECT
75 public:
76  CsvImportTable(QWidget* parent = nullptr);
77 
78  int selectedRow() const;
79  std::set<int> selectedRows() const;
80  int selectedColumn() const;
81 
82  void setData(csv::DataArray data);
83  void setColumnAs(int col, csv::ColumnType type);
84  void setFirstRow(size_t row);
85  void setLastRow(size_t row);
86  void discardRows(std::set<int> rows);
87  void resetSelection();
88 
89  // accessors
92  double intensityMultiplier() const;
93  double coordinateMultiplier() const;
94  QList<QString> availableCoordinateUnits() const;
95  std::set<int> rowsToDiscard() const { return m_import_data->rowsToDiscard(); }
96  bool dataLooksGood() const { return m_data_is_suitable; }
97 
98 signals:
100 
101 private:
102  void updateSelection();
103  void setHeaders();
104  void updateSelectedCols(); // replacement for applyMultipliers
105  void setMultiplierFields();
106  void greyoutDiscardedRows();
107  bool checkData();
108  void resetColumn(int col);
109  int rowOffset() const { return 1; } // this comes from the multipliers in the first row
110 
111  void markCell(int i, int j, Qt::GlobalColor color);
112 
115 };
116 
117 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_CSVIMPORTASSISTANT_CSVIMPORTTABLE_H
Defines classes CsvIntensityColumn and CsvCoordinateColumn.
size_t lastRow()
std::set< int > rowsToDiscard() const
size_t firstRow()
void setLastRow(size_t row)
CsvImportData(QObject *parent=nullptr)
size_t nRows() const
bool rowExcluded(int row)
std::set< int > m_discarded_rows
const csv::DataArray & data() const
std::set< std::pair< int, int > > checkData()
size_t m_n_footer
number of footer rows
void toggleDiscardRows(std::set< int > rows)
double multiplier(DATA_TYPE type) const
size_t nCols() const
int column(DATA_TYPE type) const
int setColumnAs(int col, csv::ColumnType type)
sets type to a column col.
size_t m_n_header
number of header rows
std::set< int > checkFormat(const csv::DataColumn &values, bool check_ordering)
Checks if selected data is suitable for import.
void setMultiplier(DATA_TYPE type, double value)
void setData(csv::DataArray data)
std::map< DATA_TYPE, CsvCoordinateColumn > m_selected_cols
QString columnLabel(DATA_TYPE type) const
csv::DataColumn multipliedValues(DATA_TYPE type) const
std::unique_ptr< const csv::DataArray > m_data
QList< QString > availableCoordinateUnits() const
csv::DataColumn values(int col) const
void setFirstRow(size_t row)
static std::vector< DATA_TYPE > availableTypes()
CsvImportTable(QWidget *parent=nullptr)
void setMultiplierFields()
void markCell(int i, int j, Qt::GlobalColor color)
void resetColumn(int col)
CsvImportData * m_import_data
void dataSanityChanged()
int intensityColumn() const
int rowOffset() const
int coordinateColumn() const
std::set< int > selectedRows() const
double coordinateMultiplier() const
void setLastRow(size_t row)
void greyoutDiscardedRows()
bool dataLooksGood() const
void discardRows(std::set< int > rows)
int selectedRow() const
void setData(csv::DataArray data)
int selectedColumn() const
std::set< int > rowsToDiscard() const
double intensityMultiplier() const
void setColumnAs(int col, csv::ColumnType type)
QList< QString > availableCoordinateUnits() const
void setFirstRow(size_t row)
ColumnType
Definition: CsvNamespace.h:23
std::vector< std::string > DataColumn
Definition: CsvNamespace.h:28
std::vector< std::vector< std::string > > DataArray
Definition: CsvNamespace.h:26