1/*
2 Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3 a KDAB Group company, info@kdab.net,
4 author Stephen Kelly <stephen@kdab.com>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#ifndef AKONADI_ENTITYORDERPROXYMODEL_H
23#define AKONADI_ENTITYORDERPROXYMODEL_H
24
25#include <QSortFilterProxyModel>
26
27#include "akonadi_export.h"
28
29class KConfigGroup;
30
31namespace Akonadi
32{
33class EntityOrderProxyModelPrivate;
34
35/**
36 * @short A model that keeps the order of entities persistent.
37 *
38 * This proxy maintains the order of entities in a tree. The user can re-order
39 * items and the new order will be persisted restored on reset or restart.
40 *
41 * @author Stephen Kelly <stephen@kdab.com>
42 * @since 4.6
43 */
44class AKONADI_EXPORT EntityOrderProxyModel : public QSortFilterProxyModel
45{
46 Q_OBJECT
47
48public:
49 /**
50 * Creates a new entity order proxy model.
51 *
52 * @param parent The parent object.
53 */
54 EntityOrderProxyModel(QObject *parent = 0);
55
56 /**
57 * Destroys the entity order proxy model.
58 */
59 virtual ~EntityOrderProxyModel();
60
61 /**
62 * Sets the config @p group that will be used for storing the order.
63 */
64 void setOrderConfig(KConfigGroup &group);
65
66 /**
67 * Saves the order.
68 */
69 void saveOrder();
70
71 void clearOrder(const QModelIndex &index);
72 void clearTreeOrder();
73
74 /**
75 * @reimp
76 */
77 virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
78
79 /**
80 * @reimp
81 */
82 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
83
84 /**
85 * @reimp
86 */
87 virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1,
88 Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const;
89
90protected:
91 EntityOrderProxyModelPrivate *const d_ptr;
92
93 virtual QString parentConfigString(const QModelIndex &index) const;
94 virtual QString configString(const QModelIndex &index) const;
95
96private:
97 //@cond PRIVATE
98 Q_DECLARE_PRIVATE(EntityOrderProxyModel)
99 //@endcond
100};
101
102}
103
104#endif
105