OpenMS
|
A better QTable for TOPPView, which supports exporting to TSV and conveniently adding data to cells and headers. More...
#include <OpenMS/VISUAL/TableView.h>
Signals | |
void | resized () |
emitted when the widget is resized More... | |
Public Member Functions | |
TableView (QWidget *parent=nullptr) | |
Constructor. More... | |
~TableView () override=default | |
Destructor. More... | |
virtual void | exportEntries () |
Export table entries as currently shown in the table in TSV format (only for visible data) More... | |
void | appendRow () |
adds a new row to the bottom More... | |
QTableWidgetItem * | setAtBottomRow (const QString &text, size_t column_index, const QColor &background, const QColor &foreground=QColor("SomeInvalidColor")) |
QTableWidgetItem * | setAtBottomRow (const char *text, size_t column_index, const QColor &background, const QColor &foreground=QColor("SomeInvalidColor")) |
QTableWidgetItem * | setAtBottomRow (const int i, size_t column_index, const QColor &background, const QColor &foreground=QColor("SomeInvalidColor")) |
QTableWidgetItem * | setAtBottomRow (const double d, size_t column_index, const QColor &background, const QColor &foreground=QColor("SomeInvalidColor")) |
QTableWidgetItem * | setAtBottomRow (const bool selected, size_t column_index, const QColor &background, const QColor &foreground=QColor("SomeInvalidColor")) |
create a checkbox item (with no text) More... | |
QTableWidgetItem * | setAtBottomRow (QTableWidgetItem *item, size_t column_index, const QColor &background, const QColor &foreground) |
create a custom item (if above methods are not sufficient) More... | |
void | setHeaders (const QStringList &headers) |
sets the visible headers (and the number of columns) More... | |
void | hideColumns (const QStringList &header_names) |
QStringList | getHeaderNames (const WidgetHeader which, bool use_export_name=false) |
Obtain header names, either from all, or only the visible columns. More... | |
void | setHeaderExportName (const int header_column, const QString &export_name) |
Set the export-name of a column, which will be returned in getHeaderNames() when use_export_name it true. More... | |
QString | getHeaderExportName (const int header_column) |
Gets the export-name of a column. More... | |
QString | getHeaderName (const int header_column) |
void | setMandatoryExportColumns (QStringList &cols) |
Set the mandatory export columns cols which get exported even if the user decided to hide them. More... | |
Static Public Member Functions | |
static void | updateCheckBoxItem (QTableWidgetItem *item) |
Protected Slots | |
void | headerContextMenu_ (const QPoint &) |
Display header context menu; allows to show/hide columns. More... | |
Protected Member Functions | |
void | resizeEvent (QResizeEvent *event) override |
emits the resized signal More... | |
Protected Attributes | |
QStringList | mandatory_export_columns_ |
columns that are exported to tsv files even if they are hidden in the GUI More... | |
A better QTable for TOPPView, which supports exporting to TSV and conveniently adding data to cells and headers.
|
overridedefault |
Destructor.
void appendRow | ( | ) |
adds a new row to the bottom
|
virtual |
Export table entries as currently shown in the table in TSV format (only for visible data)
A filename will be queried using a dialog, before exporting.
Headers will be exported using their export name (if available, see setHeaderExportName()
).
All cells will be queried for their Qt::UserRole, then for Qt::DisplayRole and last for Qt::CheckStateRole. The first item to return data will be used! Thus, to export data which differs from the visible (==DisplayRole), use QTableWidgetItem::setData(Qt::UserRole, ...).
Note: to force export of hidden columns use setMandatoryExportColumns()
QString getHeaderExportName | ( | const int | header_column | ) |
Gets the export-name of a column.
Export names are useful when exporting the table to CSV (see exportEntries()
), and the column header should be a bit more verbose.
Internally, this queries the Qt::UserRole's data to get the value. If the export name was not set (using setHeaderExportName()
), it returns the display name.
header_column | Index of column |
Exception::ElementNotFound | if header at index header_column is not valid |
QString getHeaderName | ( | const int | header_column | ) |
get the displayed name of the header in column with index header_column
Exception::ElementNotFound | if header at index header_column is not valid |
QStringList getHeaderNames | ( | const WidgetHeader | which, |
bool | use_export_name = false |
||
) |
Obtain header names, either from all, or only the visible columns.
Headers can be obtained as shown (use_export_name
= false) or for exporting to CSV where the alternative export name is preferred (if exists). See setHeaderExportName().
which | With or without invisible columns? |
use_export_name | If column has a hidden export name, use that instead of the displayed name |
|
protectedslot |
Display header context menu; allows to show/hide columns.
void hideColumns | ( | const QStringList & | header_names | ) |
hides columns with the given names
Exception::InvalidParameter | if a name is not matching the current column names |
|
signal |
emitted when the widget is resized
|
overrideprotected |
emits the resized signal
QTableWidgetItem* setAtBottomRow | ( | const bool | selected, |
size_t | column_index, | ||
const QColor & | background, | ||
const QColor & | foreground = QColor("SomeInvalidColor") |
||
) |
create a checkbox item (with no text)
QTableWidgetItem* setAtBottomRow | ( | const char * | text, |
size_t | column_index, | ||
const QColor & | background, | ||
const QColor & | foreground = QColor("SomeInvalidColor") |
||
) |
QTableWidgetItem* setAtBottomRow | ( | const double | d, |
size_t | column_index, | ||
const QColor & | background, | ||
const QColor & | foreground = QColor("SomeInvalidColor") |
||
) |
QTableWidgetItem* setAtBottomRow | ( | const int | i, |
size_t | column_index, | ||
const QColor & | background, | ||
const QColor & | foreground = QColor("SomeInvalidColor") |
||
) |
QTableWidgetItem* setAtBottomRow | ( | const QString & | text, |
size_t | column_index, | ||
const QColor & | background, | ||
const QColor & | foreground = QColor("SomeInvalidColor") |
||
) |
QTableWidgetItem* setAtBottomRow | ( | QTableWidgetItem * | item, |
size_t | column_index, | ||
const QColor & | background, | ||
const QColor & | foreground | ||
) |
create a custom item (if above methods are not sufficient)
void setHeaderExportName | ( | const int | header_column, |
const QString & | export_name | ||
) |
Set the export-name of a column, which will be returned in getHeaderNames() when use_export_name
it true.
Export names are useful when exporting the table to CSV (see exportEntries()
), and the column header should be a bit more verbose.
Internally, this uses the Qt::UserRole's data to store the value.
header_column | Index of column |
export_name | New export name to set |
Exception::ElementNotFound | if header at index header_column is not valid |
void setHeaders | ( | const QStringList & | headers | ) |
sets the visible headers (and the number of columns)
void setMandatoryExportColumns | ( | QStringList & | cols | ) |
Set the mandatory export columns cols
which get exported even if the user decided to hide them.
|
static |
if the item is purely a checkbox (e.g. added with setAtBottomRow(const bool selected, ...)), we set its DisplayRole to either '' or ' ', depending on checked state, to allow for row sorting This function should be called whenever the check-state of the item changes
|
protected |
columns that are exported to tsv files even if they are hidden in the GUI