File indexing completed on 2024-04-14 04:46:15
0001 /* 0002 SPDX-FileCopyrightText: 2014 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 This file is part of Kdenlive. See www.kdenlive.org. 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include <QCollator> 0011 #include <QSortFilterProxyModel> 0012 0013 class QItemSelectionModel; 0014 0015 /** 0016 * @class ProjectSortProxyModel 0017 * @brief Acts as an filtering proxy for the Bin Views, used when triggering the lineedit filter. 0018 */ 0019 class ProjectSortProxyModel : public QSortFilterProxyModel 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 enum UsageFilter { All, Used, Unused }; 0025 0026 explicit ProjectSortProxyModel(QObject *parent = nullptr); 0027 QItemSelectionModel *selectionModel(); 0028 0029 public Q_SLOTS: 0030 /** @brief Set search string that will filter the view */ 0031 void slotSetSearchString(const QString &str); 0032 /** @brief Set search tag that will filter the view */ 0033 void slotSetFilters(const QStringList &tagFilters, const QList<int> rateFilters, const QList<int> typeFilters, UsageFilter unusedFilter); 0034 /** @brief Reset search filters */ 0035 void slotClearSearchFilters(); 0036 /** @brief Relay datachanged signal from view's model */ 0037 void slotDataChanged(const QModelIndex &ix1, const QModelIndex &ix2, const QVector<int> &roles); 0038 /** @brief Select all items in model */ 0039 void selectAll(const QModelIndex &rootIndex = QModelIndex()); 0040 0041 private Q_SLOTS: 0042 /** @brief Called when a row change is detected by selection model */ 0043 void onCurrentRowChanged(const QItemSelection ¤t, const QItemSelection &previous); 0044 0045 protected: 0046 /** @brief Decide which items should be displayed depending on the search string */ 0047 // cppcheck-suppress unusedFunction 0048 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0049 /** @brief Reimplemented to show folders first */ 0050 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0051 bool filterAcceptsRowItself(int source_row, const QModelIndex &source_parent) const; 0052 bool hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const; 0053 0054 private: 0055 QItemSelectionModel *m_selection; 0056 QString m_searchString; 0057 QStringList m_searchTag; 0058 QList<int> m_searchType; 0059 QList<int> m_searchRating; 0060 UsageFilter m_usageFilter{UsageFilter::All}; 0061 QCollator m_collator; 0062 0063 Q_SIGNALS: 0064 /** @brief Emitted when the row changes, used to prepare action for selected item */ 0065 void selectModel(const QModelIndex &); 0066 /** @brief Set item rating */ 0067 void updateRating(const QModelIndex &index, uint rating); 0068 };