~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/input/xcursor/sortproxymodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2006-2007 Fredrik Höglund <fredrik@kde.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public
 
6
 * License version 2 or at your option version 3 as published 
 
7
 * by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; see the file COPYING.  If not, write to
 
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#ifndef SORTPROXYMODEL_H
 
21
#define SORTPROXYMODEL_H
 
22
 
 
23
#include <QSortFilterProxyModel>
 
24
#include <thememodel.h>
 
25
 
 
26
/**
 
27
 * SortProxyModel is a sorting proxy model intended to be used in combination
 
28
 * with the ItemDelegate class.
 
29
 *
 
30
 * First it compares the Qt::DisplayRoles, and if they match it compares
 
31
 * the CursorTheme::DisplayDetailRoles.
 
32
 *
 
33
 * The model assumes both display roles are QStrings.
 
34
 */
 
35
class SortProxyModel : public QSortFilterProxyModel
 
36
{
 
37
    public:
 
38
        SortProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {}
 
39
        ~SortProxyModel() {}
 
40
        inline const CursorTheme *theme(const QModelIndex &index) const;
 
41
        inline QModelIndex findIndex(const QString &name) const;
 
42
        inline QModelIndex defaultIndex() const;
 
43
        inline void removeTheme(const QModelIndex &index);
 
44
 
 
45
    private:
 
46
        int compare(const QModelIndex &left, const QModelIndex &right, int role) const;
 
47
 
 
48
    protected:
 
49
        bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
 
50
};
 
51
 
 
52
 
 
53
const CursorTheme *SortProxyModel::theme(const QModelIndex &index) const
 
54
{
 
55
    CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
 
56
    return model->theme(mapToSource(index));
 
57
}
 
58
 
 
59
QModelIndex SortProxyModel::findIndex(const QString &name) const
 
60
{
 
61
    CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
 
62
    return mapFromSource(model->findIndex(name));
 
63
}
 
64
 
 
65
QModelIndex SortProxyModel::defaultIndex() const
 
66
{
 
67
    CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
 
68
    return mapFromSource(model->defaultIndex());
 
69
}
 
70
 
 
71
void SortProxyModel::removeTheme(const QModelIndex &index)
 
72
{
 
73
    CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
 
74
    model->removeTheme(mapToSource(index));
 
75
}
 
76
 
 
77
#endif // SORTPROXYMODEL_H