32
33
= Filter proxy model containing all items (alarms/templates) of specified mime
33
34
= types in enabled collections.
34
35
=============================================================================*/
35
ItemListModel::ItemListModel(KAlarm::CalEvent::Types allowed, QObject* parent)
36
ItemListModel::ItemListModel(CalEvent::Types allowed, QObject* parent)
36
37
: EntityMimeTypeFilterModel(parent),
37
38
mAllowedTypes(allowed),
46
47
setHeaderGroup(EntityTreeModel::ItemListHeaders);
49
QStringList mimeTypes = KAlarm::CalEvent::mimeTypes(allowed);
50
QStringList mimeTypes = CalEvent::mimeTypes(allowed);
50
51
foreach (const QString& mime, mimeTypes)
51
52
addMimeTypeInclusionFilter(mime);
53
54
setHeaderGroup(EntityTreeModel::ItemListHeaders);
54
55
setSortRole(AkonadiModel::SortRole);
55
56
setDynamicSortFilter(true);
56
connect(this, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(slotRowsInserted()));
57
connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(slotRowsRemoved()));
57
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotRowsInserted()));
58
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(slotRowsRemoved()));
59
connect(AkonadiModel::instance(), SIGNAL(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)),
60
SLOT(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)));
60
63
int ItemListModel::columnCount(const QModelIndex& /*parent*/) const
92
/******************************************************************************
93
* Called when a collection parameter or status has changed.
94
* If the collection's enabled status has changed, re-filter the list to add or
97
void ItemListModel::collectionStatusChanged(const Collection& collection, AkonadiModel::Change change, const QVariant&, bool inserted)
100
if (!collection.isValid())
102
if (change == AkonadiModel::Enabled)
106
bool ItemListModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
108
if (!EntityMimeTypeFilterModel::filterAcceptsRow(sourceRow, sourceParent))
110
// Get the alarm type of the item
111
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
112
CalEvent::Type type = static_cast<CalEvent::Type>(sourceModel()->data(sourceIndex, AkonadiModel::StatusRole).toInt());
113
Collection parent = sourceIndex.data(AkonadiModel::ParentCollectionRole).value<Collection>();
114
return CollectionControlModel::isEnabled(parent, type);
90
118
QModelIndex ItemListModel::index(int row, int column, const QModelIndex& parent) const
153
181
/*=============================================================================
154
182
= Class: AlarmListModel
155
= Filter proxy model containing all alarms of specified mime types in enabled
183
= Filter proxy model containing all alarms (not templates) of specified mime
184
= types in enabled collections.
157
185
Equivalent to AlarmListFilterModel
158
186
=============================================================================*/
159
187
AlarmListModel* AlarmListModel::mAllInstance = 0;
161
189
AlarmListModel::AlarmListModel(QObject* parent)
162
: ItemListModel(KAlarm::CalEvent::ACTIVE | KAlarm::CalEvent::ARCHIVED, parent),
163
mFilterTypes(KAlarm::CalEvent::ACTIVE | KAlarm::CalEvent::ARCHIVED)
190
: ItemListModel(CalEvent::ACTIVE | CalEvent::ARCHIVED, parent),
191
mFilterTypes(CalEvent::ACTIVE | CalEvent::ARCHIVED)
180
208
return mAllInstance;
183
void AlarmListModel::setEventTypeFilter(KAlarm::CalEvent::Types types)
211
void AlarmListModel::setEventTypeFilter(CalEvent::Types types)
185
213
// Ensure that the filter isn't applied to the 'all' instance, and that
186
214
// 'types' doesn't include any disallowed alarm types
199
227
if (!ItemListModel::filterAcceptsRow(sourceRow, sourceParent))
201
if (mFilterTypes == KAlarm::CalEvent::EMPTY)
229
if (mFilterTypes == CalEvent::EMPTY)
203
231
int type = sourceModel()->data(sourceModel()->index(sourceRow, 0, sourceParent), AkonadiModel::StatusRole).toInt();
204
return static_cast<KAlarm::CalEvent::Type>(type) & mFilterTypes;
232
return static_cast<CalEvent::Type>(type) & mFilterTypes;
207
235
bool AlarmListModel::filterAcceptsColumn(int sourceCol, const QModelIndex&) const
229
257
TemplateListModel* TemplateListModel::mAllInstance = 0;
231
259
TemplateListModel::TemplateListModel(QObject* parent)
232
: ItemListModel(KAlarm::CalEvent::TEMPLATE, parent),
260
: ItemListModel(CalEvent::TEMPLATE, parent),
233
261
mActionsEnabled(KAEvent::ACT_ALL),
234
262
mActionsFilter(KAEvent::ACT_ALL)