VAPOR3 3.9.4
VaporTable.h
Go to the documentation of this file.
1#ifndef VAPORTABLE_H
2#define VAPORTABLE_H
3
4#include <QWidget>
5#include <QTableWidget>
6#include <QLineEdit>
7#include <sstream>
8
9struct Value;
10
11// class VaporTable
12//
13class VaporTable : public QWidget {
14 Q_OBJECT
15
16public:
18 ROWS = (1u << 0),
19 COLS = (1u << 1),
20 };
21
23 MUTABLE = (1u << 0),
24 IMMUTABLE = (1u << 1),
25 };
26
27 // The ValidatorTypeFlag will be used to apply validators
28 // to the cells that are regenerated on each Update call.
29 //
30 // Can this be replaced with the template info in Update?
31 //
33 INT = (1u << 0),
34 DOUBLE = (1u << 1),
35 STRING = (1u << 2),
36 };
37
38 VaporTable(QTableWidget *table, bool lastRowIsCheckboxes = false, bool lastColIsCheckboxes = false);
39
40 void Update(int rows, int columns, std::vector<int> values, std::vector<std::string> rowHeaders = std::vector<std::string>(), std::vector<std::string> colHeaders = std::vector<std::string>());
41 void Update(int rows, int columns, std::vector<double> values, std::vector<std::string> rowHeaders = std::vector<std::string>(), std::vector<std::string> colHeaders = std::vector<std::string>());
42 void Update(int rows, int columns, std::vector<std::string> values, std::vector<std::string> rowHeaders = std::vector<std::string>(),
43 std::vector<std::string> colHeaders = std::vector<std::string>());
44
46
47 Value GetValue(int row, int col);
48 std::string GetStringValue(int row, int col);
49
50 // Dump all values in the table back to the user
51 void GetValues(std::vector<std::string> &vec);
52 void GetValues(std::vector<int> &vec);
53 void GetValues(std::vector<double> &vec);
54
55 std::string GetVerticalHeaderItem(int index);
56 std::string GetHorizontalHeaderItem(int index);
57
58 void SetCheckboxesInFinalColumn(bool enabled);
59 void SetCheckboxesInFinalRow(bool enabled);
60 void EnableDisableCheckboxes(bool enabled);
61
62 // I think we may need something like this. TBD...
63 void SetCellMutability(int row, int col);
64
65 int RowCount() const { return _table->rowCount(); }
66 int ColumnCount() const { return _table->columnCount(); }
67 QWidget *CellWidget(int row, int col) { return _table->cellWidget(row, col); }
68
69 int GetActiveRow() const;
70
71 void SetActiveRow(int row);
72
73 void SetAutoResizeHeight(bool val);
74 bool GetAutoResizeHeight() const;
75
76 void StretchToColumn(int column);
77 void HideColumn(int column);
78
79 void ShowToolTips(bool showOrHide);
80 bool GetShowToolTips() const;
81
82 void SetVerticalHeaderWidth(int width);
83
84public slots:
85 void emitCellClicked(int, int);
86 void emitValueChanged(int row = 0, int col = 0);
88
89signals:
90 void valueChanged(int row, int col);
91 void cellClicked(int row, int col);
93
94private:
95 std::vector<std::string> convertToString(std::vector<int> values);
96
97 std::vector<std::string> convertToString(std::vector<double> values);
98
99 void setHorizontalHeader(std::vector<std::string> header);
100
101 void setVerticalHeader(std::vector<std::string> header);
102
103 void setValidator(QLineEdit *edit);
104
105 void setTableCells(std::vector<std::string> values);
106
107 void addCheckboxes(std::vector<std::string> values);
108
109 void addCheckbox(int row, int column, bool checked = false);
110
111 bool isValueChecked(std::vector<std::string> values, int index);
112
113 void highlightActiveRow(int row);
114
115 void resizeTableHeight();
116
117 void _correctImmutableCellText();
118
119 int _activeRow;
120 int _stretchColumn;
121 int _hideColumn;
122 bool _lastRowIsCheckboxes;
123 bool _lastColIsCheckboxes;
124 bool _checkboxesEnabled;
125 bool _autoResizeHeight;
126 bool _showToolTips;
127 QTableWidget *_table;
128
129 MutabilityFlags _mutabilityFlags;
130 ValidatorFlags _validatorFlags;
131 HighlightFlags _highlightFlags;
132};
133
134// A way to return a generic built-in type, so that the user can do:
135// int myVal = vaporTable->GetValue(0,0);
136// double myVal = vaporTable->GetValue(0,0);
137// std::string myVal = vaporTable->GetValue(0,0);
138struct Value {
139 std::string _value;
140
141 template<typename T> operator T() const // implicitly convert into T
142 {
143 std::stringstream ss(_value);
144 T convertedValue;
145 if (ss >> convertedValue)
146 return convertedValue;
147 else
148 throw std::runtime_error("conversion failed");
149 }
150};
151
152#endif
void emitCellClicked(int, int)
void Update(int rows, int columns, std::vector< int > values, std::vector< std::string > rowHeaders=std::vector< std::string >(), std::vector< std::string > colHeaders=std::vector< std::string >())
Value GetValue(int row, int col)
void EnableDisableCheckboxes(bool enabled)
void SetCellMutability(int row, int col)
int ColumnCount() const
Definition: VaporTable.h:66
void Update(int rows, int columns, std::vector< std::string > values, std::vector< std::string > rowHeaders=std::vector< std::string >(), std::vector< std::string > colHeaders=std::vector< std::string >())
void emitReturnPressed()
std::string GetHorizontalHeaderItem(int index)
bool GetAutoResizeHeight() const
int GetActiveRow() const
void StretchToColumn(int column)
QWidget * CellWidget(int row, int col)
Definition: VaporTable.h:67
void ShowToolTips(bool showOrHide)
void valueChanged(int row, int col)
void Update(int rows, int columns, std::vector< double > values, std::vector< std::string > rowHeaders=std::vector< std::string >(), std::vector< std::string > colHeaders=std::vector< std::string >())
void HideColumn(int column)
void SetActiveRow(int row)
void SetAutoResizeHeight(bool val)
void GetValues(std::vector< std::string > &vec)
void GetValues(std::vector< int > &vec)
int RowCount() const
Definition: VaporTable.h:65
std::string GetStringValue(int row, int col)
void returnPressed()
void SetVerticalHeaderWidth(int width)
bool GetShowToolTips() const
void SetCheckboxesInFinalRow(bool enabled)
void cellClicked(int row, int col)
void emitValueChanged(int row=0, int col=0)
std::string GetVerticalHeaderItem(int index)
void SetCheckboxesInFinalColumn(bool enabled)
void Reinit(ValidatorFlags vFlags, MutabilityFlags mFlags, HighlightFlags hFlags)
void GetValues(std::vector< double > &vec)
VaporTable(QTableWidget *table, bool lastRowIsCheckboxes=false, bool lastColIsCheckboxes=false)
std::string _value
Definition: VaporTable.h:139