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>
27 namespace KCategorizedItemsViewModels
{
29 typedef QPair
<QString
, QVariant
> Filter
;
32 * Abstract class that needs to be implemented and used with the ItemModel
34 class AbstractItem
: public QStandardItem
38 * Returns a localized string - name of the item
40 virtual QString
name() const;
43 * Returns a localized string - description of the item
45 virtual QString
description() const;
48 * Returns if the item is flagged as favorite
49 * Default implementation checks if the item passes the Filter("favorite", "1") filter
51 virtual bool isFavorite() const;
54 * Returns the item's number of running applets
55 * Default implementation just returns 0
57 virtual int running() const;
60 * Returns if the item contains string specified by pattern.
61 * Default implementation checks whether name or description contain the
62 * string (not needed to be exactly that string)
64 virtual bool matches(const QString
&pattern
) const;
67 * sets the favorite flag for the item
69 virtual void setFavorite(bool favorite
) = 0;
71 * sets the number of running applets for the item
73 virtual void setRunning(int count
) = 0;
76 * Returns if the item passes the filter specified
78 virtual bool passesFiltering(const Filter
&filter
) const = 0;
83 * The default implementation of the model containing filters
85 class DefaultFilterModel
: public QStandardItemModel
88 DefaultFilterModel(QObject
*parent
= 0);
91 * Adds a filter to the model
92 * @param caption The localized string to be displayed as a name of the filter
93 * @param filter The filter structure
95 void addFilter(const QString
&caption
, const Filter
&filter
, const KIcon
&icon
= KIcon());
98 * Adds a separator to the model
99 * @param caption The localized string to be displayed as a name of the separator
101 void addSeparator(const QString
&caption
);
105 * Default filter proxy model.
107 class DefaultItemFilterProxyModel
: public QSortFilterProxyModel
112 DefaultItemFilterProxyModel(QObject
*parent
= 0);
114 bool filterAcceptsRow(int sourceRow
, const QModelIndex
&sourceParent
) const;
115 bool lessThan(const QModelIndex
&left
, const QModelIndex
&right
) const;
117 void setSearch(const QString
&pattern
);
118 void setFilter(const Filter
&filter
);
120 void setSourceModel(QAbstractItemModel
*sourceModel
);
122 QStandardItemModel
*sourceModel() const;
124 int columnCount(const QModelIndex
&index
) const;
126 QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const;
129 void searchTermChanged(const QString
&term
);
133 class InnerProxyModel
: public QAbstractItemModel
136 InnerProxyModel(QObject
*parent
= 0);
138 Qt::ItemFlags
flags(const QModelIndex
&index
) const;
140 QVariant
data(const QModelIndex
&index
, bool favoriteColumn
,
141 int role
= Qt::DisplayRole
) const;
142 QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const;
143 bool setData(const QModelIndex
&index
, const QVariant
&value
,
144 int role
= Qt::EditRole
);
146 QVariant
headerData(int section
, Qt::Orientation orientation
,
147 int role
= Qt::DisplayRole
) const;
148 bool setHeaderData(int section
, Qt::Orientation orientation
,
149 const QVariant
&value
, int role
= Qt::EditRole
);
151 int rowCount(const QModelIndex
&parent
= QModelIndex()) const;
152 int columnCount(const QModelIndex
&index
) const;
154 QModelIndex
index(int row
, int column
,
155 const QModelIndex
&parent
= QModelIndex()) const;
156 QModelIndex
parent(const QModelIndex
&index
) const;
158 QMimeData
*mimeData(const QModelIndexList
&indexes
) const;
160 void setSourceModel(QStandardItemModel
*sourceModel
);
161 QStandardItemModel
*sourceModel() const;
164 QStandardItemModel
*m_sourceModel
;
168 QString m_searchPattern
;
169 InnerProxyModel m_innerModel
;
174 * The default implementation of the model containing items. It /is/ QStandardItemModel
176 class DefaultItemModel
: public QStandardItemModel
179 DefaultItemModel(QObject
*parent
= 0);
184 Q_DECLARE_METATYPE(KCategorizedItemsViewModels::Filter
)
186 #endif /*KCATEGORIZEDITEMSVIEWMODELS_H_*/