Data Containers

C++ SDK API Documentation - Data Containers

class Spreadsheet : public AbstractDataSource

Aspect providing a spreadsheet table with column logic.

Spreadsheet is a container object for columns with no data of its own. By definition, it’s columns are all of its children inheriting from class Column. Thus, the basic API is already defined by AbstractAspect (managing the list of columns, notification of column insertion/removal) and Column (changing and monitoring state of the actual data).

Spreadsheet is a data container for related columns to be treated as a single entity.

Spreadsheet stores a pointer to its primary view of class SpreadsheetView. SpreadsheetView calls the Spreadsheet API but Spreadsheet only notifies SpreadsheetView by signals without calling its API directly. This ensures a maximum independence of UI and backend. SpreadsheetView can be easily replaced by a different class. User interaction is completely handled in SpreadsheetView and translated into Spreadsheet API calls (e.g., when a user edits a cell this will be handled by the delegate of SpreadsheetView and Spreadsheet will not know whether a script or a user changed the data.). All actions, menus etc. for the user interaction are handled SpreadsheetView, e.g., via a context menu. Selections are also handled by SpreadsheetView. The view itself is created by the first call to view();

Subclassed by LiveDataSource, MQTTTopic, StatisticsSpreadsheet

Public Functions

explicit Spreadsheet(const QString &name, bool loading = false, AspectType type = AspectType::Spreadsheet)

Constructor.

Constructs a Spreadsheet with default 2 columns each with 100 rows.

Parameters:

name – The Spreadsheet name.

~Spreadsheet() override

Destructor.

Destroys the Spreadsheet and its child columns.

virtual QIcon icon() const override

Returns an icon to be used for decorating my views.

virtual QMenu *createContextMenu() override

Returns a new context menu. The caller takes ownership of the menu.

virtual QWidget *view() const override

Constructs a primary view on me. This method may be called multiple times during the life time of an Aspect, or it might not get called at all. Aspects must not depend on the existence of a view for their operation.

StatisticsSpreadsheet *statisticsSpreadsheet() const

Returns a pointer to the StatisticsSpreadsheet for the current Spreadsheet if exists or nullptr.

See also

StatisticsSpreadsheet()

Returns:

StatisticsSpreadsheet* or nullptr

virtual QVector<AspectType> pasteTypes() const override

return the list of all aspect types that can be copy&pasted into the current aspect. returns an empty list on default, needs to be re-implemented in all derived classes that want to allow other aspects to be pasted into.

void updateHorizontalHeader()

Called when the application settings were changed. adjusts the appearence of the spreadsheet header.

void updateLocale()

Updates locale for all columns from QLocale.

int columnCount() const

Returns the number of columns in the Spreadsheet.

Returns:

The number of columns in the Spreadsheet.

int columnCount(AbstractColumn::PlotDesignation) const

Returns the number of columns in the Spreadsheet matching the plot designation.

Parameters:

pd – The plot designation the columns are matched against.

Returns:

The number of columns in the Spreadsheet matching the passed plot designation.

Column *column(int index) const

Returns the Column at the index index.

Parameters:

index – The zero-based index of the Column.

Returns:

The Column at the index index.

Column *column(const QString&) const

Returns a pointer to the Column with the name name.

Parameters:

name – The Column name.

Returns:

Pointer to the Column with the name name.

int rowCount() const

Returns the number of rows in the Spreadsheet.

Returns:

The number of rows in the Spreadsheet.

void removeRows(int first, int count, QUndoCommand *parent = nullptr)

Removes count rows starting from the first row index in the spreadsheet.

Parameters:
  • count – The number of rows to remove.

  • first – The row index to start removing rows from.

void insertRows(int before, int count, QUndoCommand *parent = nullptr)

Inserts count rows before the before row index in the spreadsheet.

Parameters:
  • count – The number of rows to insert.

  • before – The row index before which the rows are inserted.

void removeColumns(int first, int count, QUndoCommand *parent = nullptr)

Removes count columns starting from the first column index in the spreadsheet.

Parameters:
  • count – The number of columns to remove.

  • first – The column index to start removing column from.

void insertColumns(int before, int count, QUndoCommand *parent = nullptr)

Inserts count columns before the before column index in the spreadsheet.

Parameters:
  • count – The number of columns to insert.

  • before – The column index before which the columns are inserted.

QString text(int row, int col) const

Returns a text representation of the data in cell at row index and col index.

Parameters:
  • row – The cell row.

  • col – The cell column.

Returns:

Text representation of the data in cell.

virtual void save(QXmlStreamWriter*) const override

Saves as XML.

virtual bool load(XmlStreamReader*, bool preview) override

Loads from XML.

void setColumnSelectedInView(int index, bool selected)

Emits the signal to select or to deselect the column number index in the project explorer, if selected=true or selected=false, respectively. The signal is handled in AspectTreeModel and forwarded to the tree view in ProjectExplorer. This function is called in SpreadsheetView upon selection changes.

int resize(AbstractFileFilter::ImportMode, const QStringList &colNameList, int cols)

resize data source to cols columns returns column offset depending on import mode

Public Slots

void appendRows(int)

Inserts count rows before the last row index in the spreadsheet.

Parameters:

count – The number of rows to insert.

void appendRow()

Inserts a row before the last row index in the spreadsheet.

void removeEmptyRows()

Removes all rows in the spreadsheet in which the value of one or more of its columns is missing/empty.

void maskEmptyRows()

Masks all rows in the spreadsheet in which the value of one or more of its columns is missing/empty.

void appendColumns(int)

Inserts count columns before the last column index in the spreadsheet.

Parameters:

count – The number of columns to insert.

void appendColumn()

Inserts a column before the last column index in the spreadsheet.

void prependColumns(int)

Inserts count columns before the first column index in the spreadsheet.

Parameters:

count – The number of columns to insert.

void setColumnCount(int, QUndoCommand *parent = nullptr)

Grows/shrinks the number of columns in the spreadsheet to new_size.

Parameters:

new_size – The new number of columns in the spreadsheet.

void setRowCount(int, QUndoCommand *parent = nullptr)

Grows/shrinks the number of rows in the spreadsheet to new_size.

Parameters:

new_size – The new number of rows in the spreadsheet.

void clear()

Clears all values in the spreadsheet.

void clear(const QVector<Column*>&)

Clears all values in the specified columns.

Parameters:

columns – The columns in the spreadsheet to clear.

void clearMasks()

Clears all masks in the spreadsheet.

void moveColumn(int from, int to)

Move column at from index to to index.

Parameters:
  • from – The current index of the column.

  • to – The future index of the column.

void sortColumns(Column *leading, const QVector<Column*>&, bool ascending)

Clears all values in the specified columns.

Parameters:

cols – The columns in the spreadsheet to clear.

void toggleStatisticsSpreadsheet(bool)

Toggles the StatisticsSpreadsheet for the current spreadsheet.

Parameters:

on – Enable/disable the StatisticsSpreadsheet if true/false.

struct Linking
class Matrix : public AbstractDataSource

Public Functions

virtual QIcon icon() const override

Returns an icon to be used for decorating my views.

virtual QMenu *createContextMenu() override

Returns a new context menu. The caller takes ownership of the menu.

virtual QWidget *view() const override

Construct a primary view on me.

The caller receives ownership of the view.

This method may be called multiple times during the life time of a Part, or it might not get called at all. Parts must not depend on the existence of a view for their operation.

void setRowHeight(int row, int height)

This method should only be called by the view.

This method does not change the view, it only changes the values that are saved when the matrix is saved. The view has to take care of reading and applying these values

void setColumnWidth(int col, int width)

This method should only be called by the view.

This method does not change the view, it only changes the values that are saved when the matrix is saved. The view has to take care of reading and applying these values

template<typename T>
T cell(int row, int col) const

Return the value in the given cell (needs explicit instantiation)

template<typename T>
QString text(int row, int col)

Return the text displayed in the given cell (needs explicit instantiation)

template<typename T>
void setCell(int row, int col, T value)

Set the value of the cell (needs explicit instantiation)

template<typename T>
QVector<T> columnCells(int col, int first_row, int last_row)

Return the values in the given cells as vector.

template<typename T>
void setColumnCells(int col, int first_row, int last_row, const QVector<T> &values)

Set the values in the given cells from a type T vector.

template<typename T>
QVector<T> rowCells(int row, int first_column, int last_column)

Return the values in the given cells as vector (needs explicit instantiation)

template<typename T>
void setRowCells(int row, int first_column, int last_column, const QVector<T> &values)

Set the values in the given cells from a type T vector.

virtual void save(QXmlStreamWriter*) const override

Save as XML.

virtual bool load(XmlStreamReader*, bool preview) override

Load from XML.

XmlStreamReader supports errors as well as warnings. If only warnings (non-critical errors) occur, this function must return the reader at the end element corresponding to the current element at the time the function was called.

This function is normally intended to be called directly after the ctor. If you want to call load on an aspect that has been altered, you must make sure beforehand that it is in the same state as after creation, e.g., remove all its child aspects.

Returns:

false on error

Public Slots

void clear()

Clear the whole matrix (i.e. reset all cells)