File indexing completed on 2024-09-22 04:41:01
0001 /* 0002 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, 0003 a KDAB Group company, info@kdab.net 0004 SPDX-FileContributor: Stephen Kelly <stephen@kdab.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "akonadicore_export.h" 0012 #include "collection.h" 0013 0014 #include <QSortFilterProxyModel> 0015 0016 #include <memory> 0017 0018 class KConfigGroup; 0019 0020 namespace Akonadi 0021 { 0022 class EntityOrderProxyModelPrivate; 0023 0024 /** 0025 * @short A model that keeps the order of entities persistent. 0026 * 0027 * This proxy maintains the order of entities in a tree. The user can re-order 0028 * items and the new order will be persisted restored on reset or restart. 0029 * 0030 * @author Stephen Kelly <stephen@kdab.com> 0031 * @since 4.6 0032 */ 0033 class AKONADICORE_EXPORT EntityOrderProxyModel : public QSortFilterProxyModel 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 /** 0039 * Creates a new entity order proxy model. 0040 * 0041 * @param parent The parent object. 0042 */ 0043 explicit EntityOrderProxyModel(QObject *parent = nullptr); 0044 0045 /** 0046 * Destroys the entity order proxy model. 0047 */ 0048 ~EntityOrderProxyModel() override; 0049 0050 /** 0051 * Sets the config @p group that will be used for storing the order. 0052 */ 0053 void setOrderConfig(const KConfigGroup &group); 0054 0055 /** 0056 * Saves the order. 0057 */ 0058 void saveOrder(); 0059 0060 void clearOrder(const QModelIndex &index); 0061 void clearTreeOrder(); 0062 0063 /** 0064 * @reimp 0065 */ 0066 [[nodiscard]] bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0067 0068 /** 0069 * @reimp 0070 */ 0071 [[nodiscard]] bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0072 0073 /** 0074 * @reimp 0075 */ 0076 [[nodiscard]] QModelIndexList match(const QModelIndex &start, 0077 int role, 0078 const QVariant &value, 0079 int hits = 1, 0080 Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override; 0081 0082 protected: 0083 std::unique_ptr<EntityOrderProxyModelPrivate> const d_ptr; 0084 0085 virtual QString parentConfigString(const QModelIndex &index) const; 0086 virtual QString configString(const QModelIndex &index) const; 0087 virtual Akonadi::Collection parentCollection(const QModelIndex &index) const; 0088 0089 private: 0090 QStringList configStringsForDroppedUrls(const QList<QUrl> &urls, const Akonadi::Collection &parentCol, bool *containsMove) const; 0091 0092 /// @cond PRIVATE 0093 Q_DECLARE_PRIVATE(EntityOrderProxyModel) 0094 /// @endcond 0095 }; 0096 0097 }