File indexing completed on 2023-11-26 08:16:44
0001 /* 0002 * Copyright (C) 2012 David Edmundson <kde@davidedmundson.co.uk> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 #include "groups-tree-proxy-model.h" 0020 0021 #include "types.h" 0022 0023 #include <KLocalizedString> 0024 0025 class KTp::GroupsTreeProxyModel::Private 0026 { 0027 public: 0028 //nothing here yet, added anyway in case we need private members without breaking the ABI 0029 }; 0030 0031 0032 KTp::GroupsTreeProxyModel::GroupsTreeProxyModel(QAbstractItemModel *sourceModel) : 0033 AbstractGroupingProxyModel(sourceModel), 0034 d(new KTp::GroupsTreeProxyModel::Private()) 0035 { 0036 } 0037 0038 KTp::GroupsTreeProxyModel::~GroupsTreeProxyModel() 0039 { 0040 delete d; 0041 } 0042 0043 QSet<QString> KTp::GroupsTreeProxyModel::groupsForIndex(const QModelIndex &sourceIndex) const 0044 { 0045 QStringList groups = sourceIndex.data(KTp::ContactGroupsRole).value<QStringList>(); 0046 if (groups.isEmpty()) { 0047 groups.append(QLatin1String("_unsorted")); 0048 } 0049 0050 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) 0051 return groups.toSet(); 0052 #else 0053 return QSet<QString>(groups.begin(), groups.end()); 0054 #endif 0055 } 0056 0057 0058 QVariant KTp::GroupsTreeProxyModel::dataForGroup(const QString &group, int role) const 0059 { 0060 switch (role) { 0061 case KTp::RowTypeRole: 0062 return KTp::GroupRowType; 0063 case Qt::DisplayRole: 0064 if (group == QLatin1String("_unsorted")) { 0065 return i18n("Unsorted"); 0066 } else { 0067 return group; 0068 } 0069 case KTp::IdRole: 0070 return group; 0071 } 0072 return QVariant(); 0073 }