not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / input / xcursor / sortproxymodel.h
blob95c9646c7c1f4c2b5a7e4a5535ce993128b1654b
1 /*
2 * Copyright © 2006-2007 Fredrik Höglund <fredrik@kde.org>
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.
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.
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.
20 #ifndef SORTPROXYMODEL_H
21 #define SORTPROXYMODEL_H
23 #include <QSortFilterProxyModel>
24 #include <thememodel.h>
26 /**
27 * SortProxyModel is a sorting proxy model intended to be used in combination
28 * with the ItemDelegate class.
30 * First it compares the Qt::DisplayRoles, and if they match it compares
31 * the CursorTheme::DisplayDetailRoles.
33 * The model assumes both display roles are QStrings.
35 class SortProxyModel : public QSortFilterProxyModel
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);
45 private:
46 int compare(const QModelIndex &left, const QModelIndex &right, int role) const;
48 protected:
49 bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
53 const CursorTheme *SortProxyModel::theme(const QModelIndex &index) const
55 CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
56 return model->theme(mapToSource(index));
59 QModelIndex SortProxyModel::findIndex(const QString &name) const
61 CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
62 return mapFromSource(model->findIndex(name));
65 QModelIndex SortProxyModel::defaultIndex() const
67 CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
68 return mapFromSource(model->defaultIndex());
71 void SortProxyModel::removeTheme(const QModelIndex &index)
73 CursorThemeModel *model = static_cast<CursorThemeModel*>(sourceModel());
74 model->removeTheme(mapToSource(index));
77 #endif // SORTPROXYMODEL_H