File indexing completed on 2024-11-24 04:53:13
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef IMAP_MODEL_SUBTREEMODEL_H 0024 #define IMAP_MODEL_SUBTREEMODEL_H 0025 0026 #include <QAbstractProxyModel> 0027 0028 /** @short Namespace for IMAP interaction */ 0029 namespace Imap 0030 { 0031 0032 /** @short Classes for handling of mailboxes and connections */ 0033 namespace Mailbox 0034 { 0035 0036 /** @short Helper for SubtreeModel for type-safe casting of the source model due to QAIM's createIndex being protected */ 0037 class SubtreeClassAdaptor; 0038 0039 /** @short Proxy model showing a subtree of the source model 0040 0041 This proxy model presents a subtree of the source model. The index passed to setSourceModel's rootIndex option 0042 will act as the root item of the exported portion of the original tree. 0043 0044 Certain operations like wide dataChanged() on "weird" regions are not supported and will end in an QASSERT(false). 0045 */ 0046 class SubtreeModel: public QAbstractProxyModel 0047 { 0048 Q_OBJECT 0049 Q_DISABLE_COPY(SubtreeModel) 0050 0051 Q_PROPERTY(bool itemsValid READ itemsValid NOTIFY validityChanged) 0052 0053 public: 0054 SubtreeModel(QObject *parent, SubtreeClassAdaptor *classSpecificAdaptor); 0055 virtual ~SubtreeModel(); 0056 0057 virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 0058 virtual QModelIndex parent(const QModelIndex &child) const; 0059 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; 0060 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; 0061 virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const; 0062 virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; 0063 virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; 0064 void setSourceModel(QAbstractItemModel *sourceModel); 0065 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); 0066 Q_INVOKABLE void setRootItem(QModelIndex rootIndex); 0067 Q_INVOKABLE void setRootItemByOffset(const int row); 0068 Q_INVOKABLE void setRootOneLevelUp(); 0069 Q_INVOKABLE void setOriginalRoot(); 0070 Q_INVOKABLE QModelIndex parentOfRoot() const; 0071 Q_INVOKABLE bool itemsValid() const; 0072 QModelIndex rootIndex() const; 0073 virtual QHash<int, QByteArray> roleNames() const; 0074 0075 private slots: 0076 void handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 0077 void handleModelAboutToBeReset(); 0078 void handleModelReset(); 0079 void handleRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last); 0080 void handleRowsRemoved(const QModelIndex &parent, int first, int last); 0081 void handleRowsAboutToBeInserted(const QModelIndex &parent, int first, int last); 0082 void handleRowsInserted(const QModelIndex &parent, int first, int last); 0083 0084 signals: 0085 void validityChanged(); 0086 0087 private: 0088 bool isVisibleIndex(QModelIndex sourceIndex) const; 0089 QPersistentModelIndex m_rootIndex; 0090 SubtreeClassAdaptor *m_classAdaptor; 0091 bool m_usingInvalidRoot; 0092 }; 0093 0094 /** @short Subtree model implementation for Model */ 0095 class SubtreeModelOfModel: public SubtreeModel 0096 { 0097 Q_OBJECT 0098 Q_DISABLE_COPY(SubtreeModelOfModel) 0099 0100 public: 0101 explicit SubtreeModelOfModel(QObject *parent = 0); 0102 }; 0103 0104 /** @short Subtree model implementation for MailboxModel */ 0105 class SubtreeModelOfMailboxModel: public SubtreeModel 0106 { 0107 Q_OBJECT 0108 Q_DISABLE_COPY(SubtreeModelOfMailboxModel) 0109 0110 public: 0111 explicit SubtreeModelOfMailboxModel(QObject *parent = 0); 0112 }; 0113 0114 } 0115 0116 } 0117 0118 #endif /* IMAP_MODEL_SUBTREEMODEL_H */