2
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library/Lesser General Public License
6
* version 2, or (at your option) any later version, as published by the
7
* 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
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library/Lesser General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#ifndef PLASMA_KCATEGORIZEDITEMSVIEWMODELS_P_H
21
#define PLASMA_KCATEGORIZEDITEMSVIEWMODELS_P_H
23
#include <QtGui/QtGui>
24
#include <QtCore/QtCore>
28
namespace KCategorizedItemsViewModels {
30
typedef QPair<QString, QVariant> Filter;
33
* Abstract class that needs to be implemented and used with the ItemModel
35
class AbstractItem : public QStandardItem
39
* Returns a localized string - name of the item
41
virtual QString name() const;
44
* Returns a unique id related to this item
46
virtual QString id() const;
49
* Returns a localized string - description of the item
51
virtual QString description() const;
54
* Returns if the item is flagged as favorite
55
* Default implementation checks if the item passes the Filter("favorite", "1") filter
57
virtual bool isFavorite() const;
60
* Returns the item's number of running applets
61
* Default implementation just returns 0
63
virtual int running() const;
66
* Returns if the item contains string specified by pattern.
67
* Default implementation checks whether name or description contain the
68
* string (not needed to be exactly that string)
70
virtual bool matches(const QString &pattern) const;
73
* sets the favorite flag for the item
75
virtual void setFavorite(bool favorite) = 0;
77
* sets the number of running applets for the item
79
virtual void setRunning(int count) = 0;
82
* Returns if the item passes the filter specified
84
virtual bool passesFiltering(const Filter &filter) const = 0;
89
* The default implementation of the model containing filters
91
class DefaultFilterModel : public QStandardItemModel
94
DefaultFilterModel(QObject *parent = 0);
97
* Adds a filter to the model
98
* @param caption The localized string to be displayed as a name of the filter
99
* @param filter The filter structure
101
void addFilter(const QString &caption, const Filter &filter, const KIcon &icon = KIcon());
104
* Adds a separator to the model
105
* @param caption The localized string to be displayed as a name of the separator
107
void addSeparator(const QString &caption);
111
* Default filter proxy model.
113
class DefaultItemFilterProxyModel : public QSortFilterProxyModel
118
DefaultItemFilterProxyModel(QObject *parent = 0);
120
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
121
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
123
void setSearch(const QString &pattern);
124
void setFilter(const Filter &filter);
126
void setSourceModel(QAbstractItemModel *sourceModel);
128
QStandardItemModel *sourceModel() const;
130
int columnCount(const QModelIndex &index) const;
132
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
135
void searchTermChanged(const QString &term);
136
void filterChanged();
140
class InnerProxyModel : public QAbstractItemModel
143
InnerProxyModel(QObject *parent = 0);
145
Qt::ItemFlags flags(const QModelIndex &index) const;
147
QVariant data(const QModelIndex &index, bool favoriteColumn,
148
int role = Qt::DisplayRole) const;
149
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
150
bool setData(const QModelIndex &index, const QVariant &value,
151
int role = Qt::EditRole);
153
QVariant headerData(int section, Qt::Orientation orientation,
154
int role = Qt::DisplayRole) const;
155
bool setHeaderData(int section, Qt::Orientation orientation,
156
const QVariant &value, int role = Qt::EditRole);
158
int rowCount(const QModelIndex &parent = QModelIndex()) const;
159
int columnCount(const QModelIndex &index) const;
161
QModelIndex index(int row, int column,
162
const QModelIndex &parent = QModelIndex()) const;
163
QModelIndex parent(const QModelIndex &index) const;
165
QMimeData *mimeData(const QModelIndexList &indexes) const;
167
void setSourceModel(QStandardItemModel *sourceModel);
168
QStandardItemModel *sourceModel() const;
171
QStandardItemModel *m_sourceModel;
175
QString m_searchPattern;
176
InnerProxyModel m_innerModel;
182
Q_DECLARE_METATYPE(KCategorizedItemsViewModels::Filter)
184
#endif /*KCATEGORIZEDITEMSVIEWMODELS_H_*/