File indexing completed on 2023-12-03 08:28:34
0001 /* 0002 * Turns a list model into a tree allowing nodes to be in multiple groups 0003 * 0004 * Copyright (C) 2012 David Edmundson <kde@davidedmundson.co.uk> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 0022 #ifndef KTP_ABSTRACT_GROUPING_PROXY_MODEL_H 0023 #define KTP_ABSTRACT_GROUPING_PROXY_MODEL_H 0024 0025 #include <QStandardItemModel> 0026 0027 #include <KTp/Models/ktpmodels_export.h> 0028 0029 class ProxyNode; 0030 class GroupNode; 0031 0032 namespace KTp 0033 { 0034 0035 class KTPMODELS_EXPORT AbstractGroupingProxyModel : public QStandardItemModel 0036 { 0037 Q_OBJECT 0038 public: 0039 explicit AbstractGroupingProxyModel(QAbstractItemModel *source); 0040 ~AbstractGroupingProxyModel() override; 0041 0042 void forceGroup(const QString &group); 0043 void unforceGroup(const QString &group); 0044 0045 void groupChanged(const QString &group); 0046 0047 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; 0048 0049 //protected: 0050 /** Return a list of all groups this items belongs to. Subclasses must override this*/ 0051 virtual QSet<QString> groupsForIndex(const QModelIndex &sourceIndex) const = 0; 0052 /** Equivalent of QAbstractItemModel::data() called for a specific group header*/ 0053 virtual QVariant dataForGroup(const QString &group, int role) const = 0; 0054 0055 private Q_SLOTS: 0056 void onRowsInserted(const QModelIndex &sourceParent, int start, int end); 0057 void onRowsRemoved(const QModelIndex &sourceParent, int start, int end); 0058 void onDataChanged(const QModelIndex &sourceTopLeft, const QModelIndex &sourceBottomRight); 0059 void onModelReset(); 0060 void onLoad(); 0061 0062 private: 0063 Q_DISABLE_COPY(AbstractGroupingProxyModel) 0064 class Private; 0065 Private *d; 0066 0067 0068 /** Create a new proxyNode appended to the given parent in this model*/ 0069 void addProxyNode(const QModelIndex &sourceIndex, QStandardItem *parent); 0070 0071 void removeProxyNodes(const QModelIndex &sourceIndex, const QList<ProxyNode *> &removedItems); 0072 0073 0074 /** Returns the standard Item belonging to a particular group name. Creating one if needed*/ 0075 GroupNode *itemForGroup(const QString &group); 0076 }; 0077 0078 } 0079 0080 #endif