KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
TableViewBase Class Reference

QTableView subclass integrating AbstractItemModel with entity metadata helpers. More...

#include <tableviewbase.h>

+ Inheritance diagram for TableViewBase:
+ Collaboration diagram for TableViewBase:

Public Slots

void clear ()
 Remove all rows from the view model.
 

Signals

void horizontalHeaderChanged ()
 Emitted when the horizontal header is resized.
 
void verticalHeaderChanged ()
 Emitted when the vertical header is resized.
 
void currentSelectionChanged ()
 Emitted when the current selection changes.
 
void currentIndexChanged (const QModelIndex &current, const QModelIndex &previous)
 Emitted when the current index changes.
 
void entityAdded (const EntityMetadata &metadata)
 Emitted when a row is to be added with the given metadata.
 
void entityDeleted (const EntityMetadata &metadata)
 Emitted when an entity row is deleted.
 
void entityUpdated (const EntityMetadata &metadata)
 Emitted when an entity row is updated.
 

Public Member Functions

 TableViewBase (QWidget *parent=nullptr)
 Construct with an optional parent widget.
 
virtual ~TableViewBase ()
 Destructor.
 
virtual void setModel (QAbstractItemModel *model) override
 Set the model, wrapping it in an internal sort/filter proxy.
 
int entityTypeAtPos (const QPoint &pos)
 Return the entity type of the item at a view position.
 
EntityMetadata currentMetadata () const
 Return the EntityMetadata of the currently selected item.
 
EntityMetadata metadataAtPos (const QPoint &pos) const
 Return the EntityMetadata of the item at a view position.
 
AbstractItemModelsourceModel () const
 Return the underlying AbstractItemModel (without the proxy).
 
QSortFilterProxyModel * proxyModel () const
 Return the internal sort/filter proxy model.
 
virtual void deleteRow (const QModelIndex &index)
 Delete the row identified by the given model index.
 
virtual void addRow (const EntityMetadata &metadata)
 Emit entityAdded() for the given metadata (override to customise).
 
int rowCount () const
 Return the number of rows currently in the view.
 
QModelIndexList allRows () const
 Return model indexes for all rows in the view.
 
QModelIndex findFirstMatch (const QVariant &needle, int role) const
 Return the first model index where the given role matches a value.
 
virtual QModelIndex firstIndexOfEntityUuid (const QUuid &uuid) const
 Return the first index whose item UUID matches.
 
void setCurrentUuid (const QUuid &uuid, ScrollHint scrollHint=EnsureVisible)
 Select the item with the given UUID and optionally scroll to it.
 
bool isIndexVisible (const QModelIndex &index) const
 Return whether the given model index is currently visible in the viewport.
 
void restoreHeaderStates ()
 Restore both horizontal and vertical header states from settings.
 
void restoreHorizontalHeaderState ()
 Restore horizontal header state (column widths/order) from settings.
 
void restoreVerticalHeaderState ()
 Restore vertical header state (row heights) from settings.
 
void setColumnDelegate (int type, QStyledItemDelegate *delegate)
 Assign a custom item delegate to the column of the given header type.
 

Protected Slots

virtual void currentChanged (const QModelIndex &current, const QModelIndex &previous) override
 Internal override forwarding current-index changes to currentIndexChanged().
 

Detailed Description

QTableView subclass integrating AbstractItemModel with entity metadata helpers.

TableViewBase wraps the source model in a QSortFilterProxyModel and provides helpers for accessing EntityMetadata at positions, navigating by UUID, managing row delegates, and restoring column/row header states.

Definition at line 30 of file tableviewbase.h.

Constructor & Destructor Documentation

◆ TableViewBase()

TableViewBase::TableViewBase ( QWidget *  parent = nullptr)
explicit

Construct with an optional parent widget.

Parameters
parentOptional QWidget parent

Member Function Documentation

◆ addRow()

virtual void TableViewBase::addRow ( const EntityMetadata &  metadata)
inlinevirtual

Emit entityAdded() for the given metadata (override to customise).

Parameters
metadataMetadata describing the entity to add

Definition at line 93 of file tableviewbase.h.

◆ allRows()

QModelIndexList TableViewBase::allRows ( ) const

Return model indexes for all rows in the view.

Returns
List of all row indexes (first column of each row)

◆ currentIndexChanged

void TableViewBase::currentIndexChanged ( const QModelIndex &  current,
const QModelIndex &  previous 
)
signal

Emitted when the current index changes.

Parameters
currentThe newly current index
previousThe previously current index

◆ currentMetadata()

EntityMetadata TableViewBase::currentMetadata ( ) const

Return the EntityMetadata of the currently selected item.

Returns
EntityMetadata for the current selection

◆ deleteRow()

virtual void TableViewBase::deleteRow ( const QModelIndex &  index)
virtual

Delete the row identified by the given model index.

Parameters
indexModel index of the row to delete

◆ entityTypeAtPos()

int TableViewBase::entityTypeAtPos ( const QPoint &  pos)

Return the entity type of the item at a view position.

Parameters
posView-local position
Returns
Entity type integer, or -1 if no item at that position

◆ findFirstMatch()

QModelIndex TableViewBase::findFirstMatch ( const QVariant &  needle,
int  role 
) const

Return the first model index where the given role matches a value.

Parameters
needleValue to search for
roleModel role to compare
Returns
First matching index, or invalid index if not found

◆ firstIndexOfEntityUuid()

virtual QModelIndex TableViewBase::firstIndexOfEntityUuid ( const QUuid &  uuid) const
virtual

Return the first index whose item UUID matches.

Parameters
uuidUUID to search for
Returns
First matching index, or invalid index if not found

◆ isIndexVisible()

bool TableViewBase::isIndexVisible ( const QModelIndex &  index) const

Return whether the given model index is currently visible in the viewport.

Parameters
indexModel index to check
Returns
true if the index is within the visible area

◆ metadataAtPos()

EntityMetadata TableViewBase::metadataAtPos ( const QPoint &  pos) const

Return the EntityMetadata of the item at a view position.

Parameters
posView-local position
Returns
EntityMetadata at that position

◆ proxyModel()

QSortFilterProxyModel * TableViewBase::proxyModel ( ) const
inline

Return the internal sort/filter proxy model.

Returns
Pointer to the proxy model

Definition at line 81 of file tableviewbase.h.

◆ rowCount()

int TableViewBase::rowCount ( ) const

Return the number of rows currently in the view.

Returns
Row count

◆ setColumnDelegate()

void TableViewBase::setColumnDelegate ( int  type,
QStyledItemDelegate *  delegate 
)

Assign a custom item delegate to the column of the given header type.

Parameters
typeColumn header type identifier
delegateDelegate to install

◆ setCurrentUuid()

void TableViewBase::setCurrentUuid ( const QUuid &  uuid,
ScrollHint  scrollHint = EnsureVisible 
)

Select the item with the given UUID and optionally scroll to it.

Parameters
uuidUUID of the item to select
scrollHintHow to scroll to make the item visible

◆ setModel()

virtual void TableViewBase::setModel ( QAbstractItemModel *  model)
overridevirtual

Set the model, wrapping it in an internal sort/filter proxy.

Parameters
modelModel to display (should derive from AbstractItemModel)

◆ sourceModel()

AbstractItemModel * TableViewBase::sourceModel ( ) const
inline

Return the underlying AbstractItemModel (without the proxy).

Returns
Pointer to the source model

Definition at line 75 of file tableviewbase.h.


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