File indexing completed on 2025-01-19 04:46:52
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "foldersettingfilterproxymodel.h" 0008 #include <Akonadi/EntityTreeModel> 0009 0010 FolderSettingFilterProxyModel::FolderSettingFilterProxyModel(QObject *parent) 0011 : QSortFilterProxyModel(parent) 0012 { 0013 } 0014 0015 FolderSettingFilterProxyModel::~FolderSettingFilterProxyModel() = default; 0016 0017 QVariant FolderSettingFilterProxyModel::data(const QModelIndex &index, int role) const 0018 { 0019 if (role == Qt::CheckStateRole) { 0020 // Make top-level collections uncheckable 0021 const auto col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); 0022 if (col.parentCollection() == Akonadi::Collection::root()) { 0023 return {}; 0024 } 0025 } 0026 0027 return QSortFilterProxyModel::data(index, role); 0028 } 0029 0030 Qt::ItemFlags FolderSettingFilterProxyModel::flags(const QModelIndex &index) const 0031 { 0032 // Make top-level collections uncheckable 0033 const auto col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); 0034 if (col.parentCollection() == Akonadi::Collection::root()) { 0035 return QSortFilterProxyModel::flags(index) & ~Qt::ItemIsUserCheckable; 0036 } else { 0037 return QSortFilterProxyModel::flags(index); 0038 } 0039 } 0040 0041 Akonadi::Collection::List FolderSettingFilterProxyModel::listCollections() const 0042 { 0043 return mListCollections; 0044 } 0045 0046 bool FolderSettingFilterProxyModel::setData(const QModelIndex &index, const QVariant &value, int role) 0047 { 0048 if (role == Qt::CheckStateRole) { 0049 if (index.isValid()) { 0050 const auto collection = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); 0051 if (value == Qt::Checked) { 0052 mListCollections.append(collection); 0053 } else { 0054 mListCollections.removeAll(collection); 0055 } 0056 Q_EMIT dataChanged(index, index); 0057 } 0058 } 0059 0060 return QSortFilterProxyModel::setData(index, value, role); 0061 } 0062 0063 #include "moc_foldersettingfilterproxymodel.cpp"