mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 03:23:56 -07:00
shortcut search now displays all rows in section (#5307)
This commit is contained in:
parent
205e1c7a59
commit
ec17a477be
2 changed files with 32 additions and 4 deletions
|
|
@ -4,7 +4,22 @@
|
||||||
#include "shortcuts_settings.h"
|
#include "shortcuts_settings.h"
|
||||||
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
|
ShortcutFilterProxyModel::ShortcutFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if this row or its parent matches the search string
|
||||||
|
*/
|
||||||
|
bool ShortcutFilterProxyModel::filterAcceptsRow(const int sourceRow, const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
QModelIndex nameIndex = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent);
|
||||||
|
QModelIndex parentIndex = sourceModel()->index(sourceParent.row(), filterKeyColumn(), sourceParent.parent());
|
||||||
|
|
||||||
|
return sourceModel()->data(nameIndex).toString().contains(filterRegularExpression()) ||
|
||||||
|
sourceModel()->data(parentIndex).toString().contains(filterRegularExpression());
|
||||||
|
}
|
||||||
|
|
||||||
ShortcutTreeView::ShortcutTreeView(QWidget *parent) : QTreeView(parent)
|
ShortcutTreeView::ShortcutTreeView(QWidget *parent) : QTreeView(parent)
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +29,7 @@ ShortcutTreeView::ShortcutTreeView(QWidget *parent) : QTreeView(parent)
|
||||||
populateShortcutsModel();
|
populateShortcutsModel();
|
||||||
|
|
||||||
// filter proxy
|
// filter proxy
|
||||||
proxyModel = new QSortFilterProxyModel(this);
|
proxyModel = new ShortcutFilterProxyModel(this);
|
||||||
proxyModel->setRecursiveFilteringEnabled(true);
|
proxyModel->setRecursiveFilteringEnabled(true);
|
||||||
proxyModel->setSourceModel(shortcutsModel);
|
proxyModel->setSourceModel(shortcutsModel);
|
||||||
proxyModel->setDynamicSortFilter(true);
|
proxyModel->setDynamicSortFilter(true);
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,23 @@
|
||||||
#define SHORTCUT_TREEVIEW_H
|
#define SHORTCUT_TREEVIEW_H
|
||||||
|
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
class QSortFilterProxyModel;
|
/**
|
||||||
|
* Custom implementation of QSortFilterProxyModel that also searches in the parent's string when filtering
|
||||||
|
*/
|
||||||
|
class ShortcutFilterProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ShortcutFilterProxyModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
|
};
|
||||||
|
|
||||||
class ShortcutTreeView : public QTreeView
|
class ShortcutTreeView : public QTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -21,7 +34,7 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStandardItemModel *shortcutsModel;
|
QStandardItemModel *shortcutsModel;
|
||||||
QSortFilterProxyModel *proxyModel;
|
ShortcutFilterProxyModel *proxyModel;
|
||||||
void populateShortcutsModel();
|
void populateShortcutsModel();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue