2 * itemlistmodel.h - Akonadi item models
4 * Copyright © 2010,2011 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef ITEMLISTMODEL_H
22 #define ITEMLISTMODEL_H
24 #include "akonadimodel.h"
26 #include <kalarmcal/kacalendar.h>
27 #include <kalarmcal/kaevent.h>
29 #include <AkonadiCore/entitymimetypefiltermodel.h>
31 using namespace KAlarmCal
;
33 /*=============================================================================
34 = Class: ItemListModel
35 = Filter proxy model containing all items (alarms/templates) of specified mime
36 = types in enabled collections.
37 =============================================================================*/
38 class ItemListModel
: public Akonadi::EntityMimeTypeFilterModel
43 * @param allowed the alarm types (active/archived/template) included in this model
45 explicit ItemListModel(CalEvent::Types allowed
, QObject
* parent
= Q_NULLPTR
);
47 CalEvent::Types
includedTypes() const { return mAllowedTypes
; }
48 KAEvent
event(int row
) const;
49 KAEvent
event(const QModelIndex
&) const;
50 using QObject::event
; // prevent warning about hidden virtual method
51 QModelIndex
eventIndex(Akonadi::Item::Id
) const;
53 /** Determine whether the model contains any items. */
54 bool haveEvents() const;
56 int columnCount(const QModelIndex
& parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
57 Qt::ItemFlags
flags(const QModelIndex
&) const Q_DECL_OVERRIDE
;
59 static int iconWidth() { return AkonadiModel::iconSize().width(); }
62 /** Signal emitted when either the first item is added to the model,
63 * or when the last item is deleted from the model.
65 void haveEventsStatus(bool have
);
68 bool filterAcceptsRow(int sourceRow
, const QModelIndex
& sourceParent
) const Q_DECL_OVERRIDE
;
71 void slotRowsInserted();
72 void slotRowsRemoved();
73 void collectionStatusChanged(const Akonadi::Collection
& collection
, AkonadiModel::Change change
, const QVariant
&, bool inserted
);
76 CalEvent::Types mAllowedTypes
; // types of events allowed in this model
77 bool mHaveEvents
; // there are events in this model
81 /*=============================================================================
82 = Class: AlarmListModel
83 = Filter proxy model containing all alarms of specified mime types in enabled
85 Equivalent to AlarmListFilterModel
86 =============================================================================*/
87 class AlarmListModel
: public ItemListModel
91 enum { // data columns
92 TimeColumn
= 0, TimeToColumn
, RepeatColumn
, ColourColumn
, TypeColumn
, TextColumn
,
96 explicit AlarmListModel(QObject
* parent
= Q_NULLPTR
);
99 /** Return the model containing all active and archived alarms. */
100 static AlarmListModel
* all();
102 /** Set a filter to restrict the event types to a subset of those
103 * specified in the constructor.
104 * @param types the event types to be included in the model
106 void setEventTypeFilter(CalEvent::Types types
);
108 /** Return the filter set by setEventTypeFilter().
109 * @return all event types included in the model
111 CalEvent::Types
eventTypeFilter() const { return mFilterTypes
; }
113 int columnCount(const QModelIndex
& = QModelIndex()) const Q_DECL_OVERRIDE
{ return ColumnCount
; }
114 QVariant
headerData(int section
, Qt::Orientation
, int role
= Qt::DisplayRole
) const Q_DECL_OVERRIDE
;
117 bool filterAcceptsRow(int sourceRow
, const QModelIndex
& sourceParent
) const Q_DECL_OVERRIDE
;
118 bool filterAcceptsColumn(int sourceCol
, const QModelIndex
& sourceParent
) const Q_DECL_OVERRIDE
;
121 static AlarmListModel
* mAllInstance
;
123 CalEvent::Types mFilterTypes
; // types of events contained in this model
127 /*=============================================================================
128 = Class: TemplateListModel
129 = Filter proxy model containing all alarm templates for specified alarm types
130 = in enabled collections.
131 Equivalent to TemplateListFilterModel
132 =============================================================================*/
133 class TemplateListModel
: public ItemListModel
137 enum { // data columns
138 TypeColumn
, TemplateNameColumn
,
142 explicit TemplateListModel(QObject
* parent
= Q_NULLPTR
);
143 ~TemplateListModel();
145 /** Return the model containing all alarm templates. */
146 static TemplateListModel
* all();
148 /** Set which alarm action types should be included in the model. */
149 void setAlarmActionFilter(KAEvent::Actions
);
151 /** Return which alarm action types are included in the model. */
152 KAEvent::Actions
alarmActionFilter() const { return mActionsFilter
; }
154 /** Set which alarm types should be shown as disabled in the model. */
155 void setAlarmActionsEnabled(KAEvent::Actions
);
157 /** Set which alarm types should be shown as disabled in the model. */
158 KAEvent::Actions
setAlarmActionsEnabled() const { return mActionsEnabled
; }
160 int columnCount(const QModelIndex
& = QModelIndex()) const Q_DECL_OVERRIDE
{ return ColumnCount
; }
161 QVariant
headerData(int section
, Qt::Orientation
, int role
= Qt::DisplayRole
) const Q_DECL_OVERRIDE
;
162 Qt::ItemFlags
flags(const QModelIndex
&) const Q_DECL_OVERRIDE
;
165 bool filterAcceptsRow(int sourceRow
, const QModelIndex
& sourceParent
) const Q_DECL_OVERRIDE
;
166 bool filterAcceptsColumn(int sourceCol
, const QModelIndex
& sourceParent
) const Q_DECL_OVERRIDE
;
169 static TemplateListModel
* mAllInstance
;
171 KAEvent::Actions mActionsEnabled
; // disable types not in this mask
172 KAEvent::Actions mActionsFilter
; // hide types not in this mask
175 #endif // ITEMLISTMODEL_H