File indexing completed on 2024-05-19 04:59:20
0001 /* ============================================================ 0002 * VerticalTabs plugin for Falkon 0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "tabfiltermodel.h" 0019 0020 #include "tabmodel.h" 0021 0022 TabFilterModel::TabFilterModel(QObject *parent) 0023 : QSortFilterProxyModel(parent) 0024 { 0025 } 0026 0027 void TabFilterModel::resetFilter() 0028 { 0029 m_mode = NoFilter; 0030 invalidateFilter(); 0031 } 0032 0033 void TabFilterModel::setFilterPinnedTabs(bool filter) 0034 { 0035 m_mode = FilterPinnedTabs; 0036 m_filterPinnedTabs = filter; 0037 invalidateFilter(); 0038 } 0039 0040 void TabFilterModel::setRejectDropOnLastIndex(bool reject) 0041 { 0042 m_rejectDropOnLastIndex = reject; 0043 } 0044 0045 bool TabFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const 0046 { 0047 if (m_mode == NoFilter) { 0048 return true; 0049 } 0050 0051 const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); 0052 return index.data(TabModel::PinnedRole).toBool() != m_filterPinnedTabs; 0053 } 0054 0055 bool TabFilterModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const 0056 { 0057 if (m_rejectDropOnLastIndex && row == rowCount()) { 0058 return false; 0059 } 0060 return QSortFilterProxyModel::canDropMimeData(data, action, row, column, parent); 0061 }