Skip to content

Commit 0f6c6cc

Browse files
committed
[WASimUI][MultisortTableView] Add convenience methods for mapping proxy and source indexes.
1 parent 4e5454f commit 0f6c6cc

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/WASimUI/widgets/MultisortTableView.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ class MultisortTableView : public QTableView
4646
bool isSortingEnabled() const { return m_isSortingEnabled; }
4747
/// Returns the custom proxy model used for sorting and filtering.
4848
MultiColumnProxyModel *proxyModel() const { return m_proxyModel; }
49+
/// Returns the original source model.
50+
QAbstractItemModel *sourceModel() const { return m_proxyModel->sourceModel(); }
51+
52+
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const { return m_proxyModel->mapToSource(proxyIndex); }
53+
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const { return m_proxyModel->mapFromSource(sourceIndex); }
54+
virtual QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const { return m_proxyModel->mapSelectionToSource(proxySelection); }
55+
virtual QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const { return m_proxyModel->mapSelectionFromSource(sourceSelection); }
56+
57+
bool hasSelection() const { return selectionModel()->hasSelection(); }
58+
QItemSelection selection() const { mapSelectionToSource(selectionModel()->selection()); }
59+
60+
QModelIndexList selectedRows(int column = 0) const
61+
{
62+
QModelIndexList sel = selectionModel()->selectedRows(column);
63+
for (QModelIndex &i : sel)
64+
i = mapToSource(i);
65+
return sel;
66+
}
4967

5068
public Q_SLOTS:
5169
/// Set key modifier to handle multicolumn sorting.

0 commit comments

Comments
 (0)