VTK  9.3.20240422
Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
QVTKTableModelAdapter Class Reference

An adapter to create a vtkTable from an QAbstractItemModel. More...

#include <QVTKTableModelAdapter.h>

Inherits QObject.

Collaboration diagram for QVTKTableModelAdapter:
[legend]

Signals

void tableChanged ()
 Signal emitted when the internal vtkTable has changed.
 

Public Member Functions

 QVTKTableModelAdapter (QObject *parent=nullptr)
 
 QVTKTableModelAdapter (QAbstractItemModel *model, QObject *parent=nullptr)
 
vtkTableGetTable () const
 Access to the vtkTable.
 
virtual void SetItemModel (QAbstractItemModel *model)
 Get/set the Qt table model.
 
QAbstractItemModel * GetItemModel () const
 Get/set the Qt table model.
 

Protected Slots

virtual void onModified ()
 
virtual void onModelReset ()
 
virtual void onDataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
 
virtual void onHeaderDataChanged (Qt::Orientation orientation, int first, int last)
 
virtual void onLayoutChanged (const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
 
virtual void onRowsInserted (const QModelIndex &parent, int first, int last)
 
virtual void onRowsRemoved (const QModelIndex &parent, int first, int last)
 
virtual void onRowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 
virtual void onColumnsInserted (const QModelIndex &parent, int first, int last)
 
virtual void onColumnsRemoved (const QModelIndex &parent, int first, int last)
 
virtual void onColumnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 

Protected Member Functions

virtual QVariant modelData (int row, int col)
 The default method for retrieving data for a table entry from the item model.
 
virtual vtkAbstractArrayNewArray (const QVariant &type)
 Return a suitable vtk array for the QVariant type.
 
virtual bool HasCorrectColumnArrays ()
 Check that the correct array types are set for the columns.
 
virtual void SetCellValue (int row, int column, const QVariant &data)
 Sets the value of the cell given by row, column using the adequate QVariant type conversion.
 
virtual void UpdateTable (int row0, int column0, int row1, int column1)
 Update the internal table from row0 to inclusive row1, and from column0 to inclusive column1 so it reflects the data in the model.
 

Protected Attributes

QPointer< QAbstractItemModel > ItemModel
 
vtkNew< vtkTableTable
 

Detailed Description

An adapter to create a vtkTable from an QAbstractItemModel.

An internal table is used to buffer the QAbstractItemModel. Any changes in the model are applied to the internal table, so that it is always up-to-date with the model.

Due to the structure of vtkTable it is not possible to have columns with different variable types. The variable type of a column is determined from the first row in the model.

The data is queried using QAbstractItemModel::data() using Qt::DisplayRole.

All columns of the table must have unique names. They are queried using QAbstractItemModel::headerData() using Qt::Horizontal as orientation and Qt::DisplayRole.

Definition at line 33 of file QVTKTableModelAdapter.h.

Constructor & Destructor Documentation

◆ QVTKTableModelAdapter() [1/2]

QVTKTableModelAdapter::QVTKTableModelAdapter ( QObject *  parent = nullptr)

◆ QVTKTableModelAdapter() [2/2]

QVTKTableModelAdapter::QVTKTableModelAdapter ( QAbstractItemModel *  model,
QObject *  parent = nullptr 
)

Member Function Documentation

◆ SetItemModel()

virtual void QVTKTableModelAdapter::SetItemModel ( QAbstractItemModel *  model)
virtual

Get/set the Qt table model.

It is expected that the QAbstractItemModel passed in is a QAbstractTableModel subclass; however allowing this class to work with a QAbstractItemModel is advantageous since it enables usage of proxy models, for example for sorting and filtering.

◆ GetItemModel()

QAbstractItemModel * QVTKTableModelAdapter::GetItemModel ( ) const

Get/set the Qt table model.

It is expected that the QAbstractItemModel passed in is a QAbstractTableModel subclass; however allowing this class to work with a QAbstractItemModel is advantageous since it enables usage of proxy models, for example for sorting and filtering.

◆ GetTable()

vtkTable * QVTKTableModelAdapter::GetTable ( ) const

Access to the vtkTable.

Treat this as a const object, i.e. you should not modify it outside of this class.

◆ tableChanged

void QVTKTableModelAdapter::tableChanged ( )
signal

Signal emitted when the internal vtkTable has changed.

This signal can be used to connect to a slot which handles rendering of an attached chart.

◆ modelData()

virtual QVariant QVTKTableModelAdapter::modelData ( int  row,
int  col 
)
protectedvirtual

The default method for retrieving data for a table entry from the item model.

◆ NewArray()

virtual vtkAbstractArray * QVTKTableModelAdapter::NewArray ( const QVariant &  type)
protectedvirtual

Return a suitable vtk array for the QVariant type.

Note to call Delete() on the returned array where necessary, see vtkObjectBase::Delete() for details.

◆ HasCorrectColumnArrays()

virtual bool QVTKTableModelAdapter::HasCorrectColumnArrays ( )
protectedvirtual

Check that the correct array types are set for the columns.

◆ SetCellValue()

virtual void QVTKTableModelAdapter::SetCellValue ( int  row,
int  column,
const QVariant &  data 
)
protectedvirtual

Sets the value of the cell given by row, column using the adequate QVariant type conversion.

◆ UpdateTable()

virtual void QVTKTableModelAdapter::UpdateTable ( int  row0,
int  column0,
int  row1,
int  column1 
)
protectedvirtual

Update the internal table from row0 to inclusive row1, and from column0 to inclusive column1 so it reflects the data in the model.

◆ onModified

virtual void QVTKTableModelAdapter::onModified ( )
protectedvirtualslot

◆ onModelReset

virtual void QVTKTableModelAdapter::onModelReset ( )
protectedvirtualslot

◆ onDataChanged

virtual void QVTKTableModelAdapter::onDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight,
const QVector< int > &  roles 
)
protectedvirtualslot

◆ onHeaderDataChanged

virtual void QVTKTableModelAdapter::onHeaderDataChanged ( Qt::Orientation  orientation,
int  first,
int  last 
)
protectedvirtualslot

◆ onLayoutChanged

virtual void QVTKTableModelAdapter::onLayoutChanged ( const QList< QPersistentModelIndex > &  parents,
QAbstractItemModel::LayoutChangeHint  hint 
)
protectedvirtualslot

◆ onRowsInserted

virtual void QVTKTableModelAdapter::onRowsInserted ( const QModelIndex &  parent,
int  first,
int  last 
)
protectedvirtualslot

◆ onRowsRemoved

virtual void QVTKTableModelAdapter::onRowsRemoved ( const QModelIndex &  parent,
int  first,
int  last 
)
protectedvirtualslot

◆ onRowsMoved

virtual void QVTKTableModelAdapter::onRowsMoved ( const QModelIndex &  parent,
int  start,
int  end,
const QModelIndex &  destination,
int  row 
)
protectedvirtualslot

◆ onColumnsInserted

virtual void QVTKTableModelAdapter::onColumnsInserted ( const QModelIndex &  parent,
int  first,
int  last 
)
protectedvirtualslot

◆ onColumnsRemoved

virtual void QVTKTableModelAdapter::onColumnsRemoved ( const QModelIndex &  parent,
int  first,
int  last 
)
protectedvirtualslot

◆ onColumnsMoved

virtual void QVTKTableModelAdapter::onColumnsMoved ( const QModelIndex &  parent,
int  start,
int  end,
const QModelIndex &  destination,
int  column 
)
protectedvirtualslot

Member Data Documentation

◆ ItemModel

QPointer<QAbstractItemModel> QVTKTableModelAdapter::ItemModel
protected

Definition at line 92 of file QVTKTableModelAdapter.h.

◆ Table

vtkNew<vtkTable> QVTKTableModelAdapter::Table
protected

Definition at line 93 of file QVTKTableModelAdapter.h.


The documentation for this class was generated from the following file: