File indexing completed on 2024-11-24 03:56:27
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractItemModel> 0010 #include <QSortFilterProxyModel> 0011 #include <QStyledItemDelegate> 0012 0013 #include "keyboard_shortcuts.hpp" 0014 0015 namespace app::settings { 0016 0017 class KeyboardShortcutsModel : public QAbstractItemModel 0018 { 0019 Q_OBJECT 0020 0021 public: 0022 enum { 0023 DefaultKeyRole = Qt::UserRole 0024 }; 0025 0026 KeyboardShortcutsModel(ShortcutSettings* settings, QObject* parent = nullptr); 0027 0028 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0029 int columnCount(const QModelIndex & parent) const override; 0030 int rowCount(const QModelIndex & parent) const override; 0031 0032 Qt::ItemFlags flags(const QModelIndex & index) const override; 0033 QVariant data(const QModelIndex & index, int role) const override; 0034 bool setData(const QModelIndex & index, const QVariant & value, int role) override; 0035 0036 QModelIndex index(int row, int column, const QModelIndex & parent) const override; 0037 QModelIndex parent(const QModelIndex & child) const override; 0038 0039 ShortcutAction* action(const QModelIndex & index) const; 0040 0041 public Q_SLOTS: 0042 void begin_change_data(); 0043 void end_change_data(); 0044 0045 private: 0046 ShortcutSettings* settings; 0047 }; 0048 0049 class KeyboardShortcutsFilterModel : public QSortFilterProxyModel 0050 { 0051 public: 0052 using QSortFilterProxyModel::QSortFilterProxyModel; 0053 bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override; 0054 }; 0055 0056 class KeyboardShortcutsDelegate : public QStyledItemDelegate 0057 { 0058 public: 0059 using QStyledItemDelegate::QStyledItemDelegate; 0060 0061 QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override; 0062 void setEditorData(QWidget * editor, const QModelIndex & index) const override; 0063 void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; 0064 }; 0065 0066 } // namespace app::settings