11#ifndef TABLEVIEWBASE_H
12#define TABLEVIEWBASE_H
13#include <Kanoop/entitymetadata.h>
14#include <Kanoop/utility/loggingbaseclass.h>
17#include <Kanoop/gui/libkanoopgui.h>
19class QStyledItemDelegate;
20class QSortFilterProxyModel;
31 public LoggingBaseClass
49 virtual void setModel(QAbstractItemModel* model)
override;
81 QSortFilterProxyModel*
proxyModel()
const {
return _proxyModel; }
93 virtual void addRow(
const EntityMetadata& metadata) { emit entityAdded(metadata); }
156 QSortFilterProxyModel* _proxyModel;
157 QMap<int, QStyledItemDelegate*> _columnDelegates;
159 QAction* _actionColSettings =
nullptr;
160 QAction* _actionHideCol =
nullptr;
161 QAction* _actionAutoResizeCols =
nullptr;
162 QAction* _actionResetCols =
nullptr;
164 QPoint _contextMenuPoint;
190 virtual void currentChanged(
const QModelIndex& current,
const QModelIndex& previous)
override;
193 virtual void onHorizontalHeaderResized(
int ,
int ,
int );
194 virtual void onVerticalHeaderResized(
int ,
int ,
int );
196 void onHeaderContextMenuRequested(
const QPoint& pos);
197 void onColumnSettingsClicked();
198 void onHideColumnClicked();
199 void onAutoResizeColumnsClicked();
200 void onResetColumnsClicked();
Extended QAbstractItemModel providing EntityMetadata-based item lookup and header management.
QTableView subclass integrating AbstractItemModel with entity metadata helpers.
virtual ~TableViewBase()
Destructor.
void currentIndexChanged(const QModelIndex ¤t, const QModelIndex &previous)
Emitted when the current index changes.
QSortFilterProxyModel * proxyModel() const
Return the internal sort/filter proxy model.
void entityUpdated(const EntityMetadata &metadata)
Emitted when an entity row is updated.
void currentSelectionChanged()
Emitted when the current selection changes.
void horizontalHeaderChanged()
Emitted when the horizontal header is resized.
int rowCount() const
Return the number of rows currently in the view.
void entityDeleted(const EntityMetadata &metadata)
Emitted when an entity row is deleted.
virtual void deleteRow(const QModelIndex &index)
Delete the row identified by the given model index.
virtual QModelIndex firstIndexOfEntityUuid(const QUuid &uuid) const
Return the first index whose item UUID matches.
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override
Internal override forwarding current-index changes to currentIndexChanged().
QModelIndex findFirstMatch(const QVariant &needle, int role) const
Return the first model index where the given role matches a value.
void restoreHeaderStates()
Restore both horizontal and vertical header states from settings.
void restoreVerticalHeaderState()
Restore vertical header state (row heights) from settings.
bool isIndexVisible(const QModelIndex &index) const
Return whether the given model index is currently visible in the viewport.
virtual void setModel(QAbstractItemModel *model) override
Set the model, wrapping it in an internal sort/filter proxy.
void entityAdded(const EntityMetadata &metadata)
Emitted when a row is to be added with the given metadata.
int entityTypeAtPos(const QPoint &pos)
Return the entity type of the item at a view position.
AbstractItemModel * sourceModel() const
Return the underlying AbstractItemModel (without the proxy).
void restoreHorizontalHeaderState()
Restore horizontal header state (column widths/order) from settings.
virtual void addRow(const EntityMetadata &metadata)
Emit entityAdded() for the given metadata (override to customise).
EntityMetadata metadataAtPos(const QPoint &pos) const
Return the EntityMetadata of the item at a view position.
void clear()
Remove all rows from the view model.
QModelIndexList allRows() const
Return model indexes for all rows in the view.
void setCurrentUuid(const QUuid &uuid, ScrollHint scrollHint=EnsureVisible)
Select the item with the given UUID and optionally scroll to it.
TableViewBase(QWidget *parent=nullptr)
Construct with an optional parent widget.
void setColumnDelegate(int type, QStyledItemDelegate *delegate)
Assign a custom item delegate to the column of the given header type.
EntityMetadata currentMetadata() const
Return the EntityMetadata of the currently selected item.
void verticalHeaderChanged()
Emitted when the vertical header is resized.