Commit a61735f7 authored by jpetrell's avatar jpetrell

[nemo-calendar] Allow filtering multiple events from each notebook. Contributes to JB#48449

parent f744c44e
......@@ -138,11 +138,25 @@ void CalendarAgendaModel::doRefresh(QList<CalendarEventOccurrence *> newEvents)
QList<CalendarEventOccurrence *> events = mEvents;
QList<CalendarEventOccurrence *> skippedEvents;
QSet<QString> alreadyAddedCalendarUids;
// filter out if necessary
if (mFilterMode == FilterNonAllDay) {
if (mFilterMode != FilterNone) {
QList<CalendarEventOccurrence *>::iterator it = newEvents.begin();
while (it != newEvents.end()) {
if (!(*it)->eventObject()->allDay()) {
bool skip = false;
if (mFilterMode & FilterNonAllDay && !(*it)->eventObject()->allDay()) {
skip = true;
}
if (mFilterMode & FilterMultipleEventsPerNotebook) {
QString uid = (*it)->eventObject()->calendarUid();
if (alreadyAddedCalendarUids.contains(uid)) {
skip = true;
} else {
alreadyAddedCalendarUids.insert(uid);
}
}
if (skip) {
skippedEvents.append(*it);
it = newEvents.erase(it);
} else {
......
......@@ -44,12 +44,10 @@ class CalendarAgendaModel : public QAbstractListModel, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_ENUMS(FilterMode)
Q_ENUMS(AgendaRoles)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged)
Q_PROPERTY(int filterMode READ filterMode WRITE setFilterMode NOTIFY filterModeChanged)
Q_PROPERTY(FilterModes filterMode READ filterMode WRITE setFilterMode NOTIFY filterModeChanged)
public:
enum AgendaRoles {
......@@ -57,11 +55,16 @@ public:
OccurrenceObjectRole,
SectionBucketRole
};
Q_ENUM(AgendaRoles)
enum FilterMode {
FilterNone,
FilterNonAllDay
FilterNonAllDay = 0x1,
FilterMultipleEventsPerNotebook = 0x2
};
Q_ENUM(FilterMode)
Q_DECLARE_FLAGS(FilterModes, FilterMode)
Q_FLAG(FilterModes)
explicit CalendarAgendaModel(QObject *parent = 0);
virtual ~CalendarAgendaModel();
......@@ -109,4 +112,6 @@ private:
int mFilterMode;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(CalendarAgendaModel::FilterModes)
#endif // CALENDARAGENDAMODEL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment