KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
listview.h
1#ifndef LISTVIEW_H
2#define LISTVIEW_H
3#include <QListView>
4
5#include <Kanoop/utility/loggingbaseclass.h>
6#include <Kanoop/gui/libkanoopgui.h>
7
8class QSortFilterProxyModel;
10
11/**
12 * @brief QListView subclass that integrates with AbstractItemModel and adds UUID-based navigation.
13 *
14 * ListView automatically wraps the source model in a QSortFilterProxyModel and
15 * provides helpers for locating and selecting items by UUID.
16 */
17class LIBKANOOPGUI_EXPORT ListView : public QListView,
18 public LoggingBaseClass
19{
20 Q_OBJECT
21public:
22 /**
23 * @brief Construct with an optional parent.
24 * @param parent Optional QWidget parent
25 */
26 explicit ListView(QWidget* parent = nullptr);
27
28 /**
29 * @brief Set the model, wrapping it in an internal sort/filter proxy.
30 * @param model Model to display (should derive from AbstractItemModel)
31 */
32 virtual void setModel(QAbstractItemModel* model) override;
33
34 /**
35 * @brief Return the first index whose item UUID matches.
36 * @param uuid UUID to search for
37 * @return First matching index, or invalid index if not found
38 */
39 virtual QModelIndex firstIndexOfEntityUuid(const QUuid& uuid) const;
40
41 /**
42 * @brief Return all indexes whose item UUID matches.
43 * @param uuid UUID to search for
44 * @return List of matching indexes
45 */
46 virtual QModelIndexList indexesOfUuid(const QUuid& uuid) const;
47
48 /**
49 * @brief Select the item with the given UUID and optionally scroll to it.
50 * @param uuid UUID of the item to select
51 * @param scrollHint How to scroll to make the item visible
52 */
53 virtual void setCurrentUuid(const QUuid& uuid, ScrollHint scrollHint = EnsureVisible);
54
55 /**
56 * @brief Return the underlying AbstractItemModel (without the proxy).
57 * @return Pointer to the source model
58 */
59 AbstractItemModel* sourceModel() const { return _sourceModel; }
60
61 /**
62 * @brief Return the internal sort/filter proxy model.
63 * @return Pointer to the proxy model
64 */
65 QSortFilterProxyModel* proxyModel() const { return _proxyModel; }
66
67private:
68 AbstractItemModel* _sourceModel = nullptr;
69 QSortFilterProxyModel* _proxyModel = nullptr;
70
71signals:
72 /** @brief Emitted when the current selection changes. */
74 /**
75 * @brief Emitted when the current index changes.
76 * @param index The newly current index
77 */
78 void currentIndexChanged(const QModelIndex& index);
79
80private slots:
81 /** @brief Internal handler forwarding selection changes to currentSelectionChanged(). */
82 void onCurrentSelectionChanged(const QModelIndex &current, const QModelIndex &previous);
83};
84
85#endif // LISTVIEW_H
Extended QAbstractItemModel providing EntityMetadata-based item lookup and header management.
QListView subclass that integrates with AbstractItemModel and adds UUID-based navigation.
Definition listview.h:19
void currentSelectionChanged()
Emitted when the current selection changes.
void currentIndexChanged(const QModelIndex &index)
Emitted when the current index changes.
virtual QModelIndex firstIndexOfEntityUuid(const QUuid &uuid) const
Return the first index whose item UUID matches.
virtual void setCurrentUuid(const QUuid &uuid, ScrollHint scrollHint=EnsureVisible)
Select the item with the given UUID and optionally scroll to it.
AbstractItemModel * sourceModel() const
Return the underlying AbstractItemModel (without the proxy).
Definition listview.h:59
QSortFilterProxyModel * proxyModel() const
Return the internal sort/filter proxy model.
Definition listview.h:65
virtual QModelIndexList indexesOfUuid(const QUuid &uuid) const
Return all indexes whose item UUID matches.
virtual void setModel(QAbstractItemModel *model) override
Set the model, wrapping it in an internal sort/filter proxy.
ListView(QWidget *parent=nullptr)
Construct with an optional parent.