OpenMS  2.8.0
Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
TableView Class Reference

A better QTable for TOPPView, which supports exporting to TSV and conveniently adding data to cells and headers. More...

#include <OpenMS/VISUAL/TableView.h>

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

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...
 

Detailed Description

A better QTable for TOPPView, which supports exporting to TSV and conveniently adding data to cells and headers.

Constructor & Destructor Documentation

◆ TableView()

TableView ( QWidget parent = nullptr)

Constructor.

◆ ~TableView()

~TableView ( )
overridedefault

Destructor.

Member Function Documentation

◆ appendRow()

void appendRow ( )

adds a new row to the bottom

◆ exportEntries()

virtual void exportEntries ( )
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()

◆ getHeaderExportName()

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.

Parameters
header_columnIndex of column
Exceptions
Exception::ElementNotFoundif header at index header_column is not valid

◆ getHeaderName()

QString getHeaderName ( const int  header_column)

get the displayed name of the header in column with index header_column

Exceptions
Exception::ElementNotFoundif header at index header_column is not valid

◆ getHeaderNames()

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().

Parameters
whichWith or without invisible columns?
use_export_nameIf column has a hidden export name, use that instead of the displayed name
Returns
List of header names

◆ headerContextMenu_

void headerContextMenu_ ( const QPoint &  )
protectedslot

Display header context menu; allows to show/hide columns.

◆ hideColumns()

void hideColumns ( const QStringList &  header_names)

hides columns with the given names

Exceptions
Exception::InvalidParameterif a name is not matching the current column names

◆ resized

void resized ( )
signal

emitted when the widget is resized

◆ resizeEvent()

void resizeEvent ( QResizeEvent *  event)
overrideprotected

emits the resized signal

◆ setAtBottomRow() [1/6]

QTableWidgetItem* setAtBottomRow ( const bool  selected,
size_t  column_index,
const QColor &  background,
const QColor &  foreground = QColor("SomeInvalidColor") 
)

create a checkbox item (with no text)

◆ setAtBottomRow() [2/6]

QTableWidgetItem* setAtBottomRow ( const char *  text,
size_t  column_index,
const QColor &  background,
const QColor &  foreground = QColor("SomeInvalidColor") 
)

◆ setAtBottomRow() [3/6]

QTableWidgetItem* setAtBottomRow ( const double  d,
size_t  column_index,
const QColor &  background,
const QColor &  foreground = QColor("SomeInvalidColor") 
)

◆ setAtBottomRow() [4/6]

QTableWidgetItem* setAtBottomRow ( const int  i,
size_t  column_index,
const QColor &  background,
const QColor &  foreground = QColor("SomeInvalidColor") 
)

◆ setAtBottomRow() [5/6]

QTableWidgetItem* setAtBottomRow ( const QString &  text,
size_t  column_index,
const QColor &  background,
const QColor &  foreground = QColor("SomeInvalidColor") 
)

◆ setAtBottomRow() [6/6]

QTableWidgetItem* setAtBottomRow ( QTableWidgetItem *  item,
size_t  column_index,
const QColor &  background,
const QColor &  foreground 
)

create a custom item (if above methods are not sufficient)

◆ setHeaderExportName()

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.

Parameters
header_columnIndex of column
export_nameNew export name to set
Exceptions
Exception::ElementNotFoundif header at index header_column is not valid

◆ setHeaders()

void setHeaders ( const QStringList &  headers)

sets the visible headers (and the number of columns)

◆ setMandatoryExportColumns()

void setMandatoryExportColumns ( QStringList &  cols)

Set the mandatory export columns cols which get exported even if the user decided to hide them.

◆ updateCheckBoxItem()

static void updateCheckBoxItem ( QTableWidgetItem *  item)
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

Member Data Documentation

◆ mandatory_export_columns_

QStringList mandatory_export_columns_
protected

columns that are exported to tsv files even if they are hidden in the GUI