13#include <Kanoop/entitymetadata.h>
17#include <Kanoop/utility/loggingbaseclass.h>
18#include <Kanoop/gui/libkanoopgui.h>
20class QSortFilterProxyModel;
21class QStyledItemDelegate;
32 public LoggingBaseClass
81 virtual void setCurrentUuid(
const QUuid& uuid, ScrollHint scrollHint = EnsureVisible);
88 virtual void setCurrentIndex(
const QModelIndex& index, ScrollHint scrollHint = EnsureVisible);
96 virtual QModelIndex
findNextMatch(
const QString& text,
const QModelIndex& fromIndex)
const;
118 virtual QModelIndex
nextIndex(
const QModelIndex& from)
const;
137 const QVariant &value,
int hits = 1,
138 Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap))
const;
165 virtual void setModel(QAbstractItemModel* model)
override;
183 QSortFilterProxyModel*
proxyModel()
const {
return _proxyModel; }
273 EntityMetadata
findFirstParent(
const QModelIndex& index,
int entityMetadataType)
const;
287 QModelIndexList
mapToSource(
const QModelIndexList& indexes)
const;
297 static void logIndex(
const char* file,
int lineNumber, Log::LogLevel level,
const QModelIndex& index,
const QString& text);
299 static bool testMatch(
const QModelIndex& index,
int role,
const QVariant &value, Qt::MatchFlags flags, QModelIndexList& foundIndexes);
303 QSortFilterProxyModel* _proxyModel =
nullptr;
304 QMap<int, QStyledItemDelegate*> _columnDelegates;
306 QAction* _actionColSettings =
nullptr;
307 QAction* _actionHideCol =
nullptr;
308 QAction* _actionAutoResizeCols =
nullptr;
309 QAction* _actionResetCols =
nullptr;
311 QPoint _contextMenuPos;
334 virtual void onHorizontalHeaderResized(
int ,
int ,
int );
336 void onHeaderContextMenuRequested();
337 void onColumnSettingsClicked();
338 void onHideColumnClicked();
339 void onAutoResizeColumnsClicked();
340 void onResetColumnsClicked();
341 void onCurrentSelectionChanged(
const QModelIndex& current,
const QModelIndex& previous);
Extended QAbstractItemModel providing EntityMetadata-based item lookup and header management.
QTreeView subclass integrating AbstractItemModel with rich navigation helpers.
void headerChanged()
Emitted when the header is resized or reordered.
virtual void addHeaderContextMenuItems(QMenu *menu, const QPoint &globalPos)
Override to add application-specific items to the header context menu.
void setColumnDelegate(int type, QStyledItemDelegate *delegate)
Assign a custom item delegate to the column of the given header type.
EntityMetadata findCurrentParent(int entityMetadataType) const
Walk ancestors of the current index to find one with the given entity type.
QSortFilterProxyModel * proxyModel() const
Return the internal sort/filter proxy model.
void entityAdded(const EntityMetadata &metadata)
Emitted when an entity is added.
virtual void setCurrentIndex(const QModelIndex &index, ScrollHint scrollHint=EnsureVisible)
Set the current index and optionally scroll to it.
QModelIndex currentSourceIndex() const
Return the current source model index (mapped through the proxy).
static void logIndex(const char *file, int lineNumber, Log::LogLevel level, const QModelIndex &index, const QString &text)
Log a model index at the given log level.
void currentIndexChanged(const QModelIndex &index)
Emitted when the current index changes.
void setColumnsVisible(const QList< int > &columns, bool visible, bool exclusive=false)
Show or hide columns by column index.
virtual QModelIndex previousIndex(const QModelIndex &from) const
Return the previous index in display order before from.
EntityMetadata findFirstParent(const QModelIndex &index, int entityMetadataType) const
Walk ancestors of index to find one with the given entity type.
void restoreState(const QByteArray &state)
Restore header and expansion state from a byte array.
virtual QModelIndex findPreviousMatch(const QString &text, const QModelIndex &fromIndex) const
Find the previous index whose display text matches, searching backward.
bool isIndexVisible(const QModelIndex &index) const
Return whether the given index is visible in the current viewport.
int columnForHeaderType(int headerType) const
Return the column index for a given header type.
void currentSelectionChanged()
Emitted when the current selection changes.
QModelIndexList mapToSource(const QModelIndexList &indexes) const
Map a list of view indexes to their source model equivalents.
QByteArray saveState() const
Save the header and expansion state to a byte array.
void restoreHeaderStates()
Restore horizontal header state (column widths/order) from settings.
static bool testMatch(const QModelIndex &index, int role, const QVariant &value, Qt::MatchFlags flags, QModelIndexList &foundIndexes)
Test whether index matches value under role using flags, appending to foundIndexes.
QModelIndexList findParents(const QModelIndex &index) const
Return all ancestor indexes of index.
void entityUpdated(const EntityMetadata &metadata)
Emitted when an entity is updated.
virtual QModelIndex nextIndex(const QModelIndex &from) const
Return the next index in display order after from.
virtual QModelIndexList indexesOfUuid(const QUuid &uuid) const
Return all indexes whose item UUID matches.
bool isLeafExpanded(const QModelIndex &index, bool recursive=true) const
Return whether the deepest expanded leaf under index is expanded.
TreeViewBase(QWidget *parent=nullptr)
Construct with an optional parent widget.
virtual EntityMetadata metadataAtPos(const QPoint &pos) const
Return the EntityMetadata of the item at a view position.
virtual EntityMetadata currentMetadata() const
Return the EntityMetadata of the currently selected item.
virtual QModelIndex firstIndexOfEntityUuid(const QUuid &uuid) const
Return the first index whose item UUID matches.
void itemProgramaticallySelected(const QModelIndex &index)
Emitted when an item is selected programmatically.
AbstractItemModel * sourceModel() const
Return the underlying AbstractItemModel (without the proxy).
virtual void clear()
Remove all items from the view model.
virtual void setSelectionModel(QItemSelectionModel *selectionModel) override
Set the selection model.
virtual QModelIndex findNextMatch(const QString &text, const QModelIndex &fromIndex) const
Find the next index whose display text matches, searching forward.
virtual QModelIndex finalChildIndex(const QModelIndex &from) const
Return the deepest last child of the given index.
virtual QModelIndexList matchBackwards(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Search backward from start for indexes matching a role value.
virtual void setModel(QAbstractItemModel *model) override
Set the model, wrapping it in an internal sort/filter proxy.
void setColumnTypesVisible(const QList< int > &headerTypes, bool visible, bool exclusive=false)
Show or hide columns identified by header types.
void collapseRecursively(const QModelIndex &index, int depth=-1)
Recursively collapse index and all its descendants up to a depth limit.
virtual void refreshVisibleIndexes(const QModelIndexList &indexes)
Refresh the display of a set of source model indexes.
virtual void refreshIndex(const QModelIndex &sourceIndex)
Refresh a single source model index.
void entityDeleted(const EntityMetadata &metadata)
Emitted when an entity is deleted.
int entityTypeAtPos(const QPoint &pos)
Return the entity type of the item at a view position.
virtual void setCurrentUuid(const QUuid &uuid, ScrollHint scrollHint=EnsureVisible)
Select the item with the given UUID and optionally scroll to it.
virtual void refreshVisibleColumns(const QList< int > &columns)
Refresh the display of a set of columns.