From abdf3b1eaba8151f1b8e862750c38cb7a5411d2a Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 13 Aug 2012 21:31:52 +0200 Subject: make watchsimulator work again --- libsowatch/notificationsmodel.cpp | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 libsowatch/notificationsmodel.cpp (limited to 'libsowatch/notificationsmodel.cpp') diff --git a/libsowatch/notificationsmodel.cpp b/libsowatch/notificationsmodel.cpp new file mode 100644 index 0000000..2eba9a0 --- /dev/null +++ b/libsowatch/notificationsmodel.cpp @@ -0,0 +1,70 @@ +#include "notificationsmodel.h" + +using namespace sowatch; + +#define FOREACH_TYPE_FROM_TO(x, from, to) \ + for(Notification::Type x = from; x < to; x = static_cast(x + 1)) + +#define FOREACH_TYPE_UNTIL(x, to) FOREACH_TYPE_FROM_TO(x, Notification::OtherNotification, to) + +#define FOREACH_TYPE(x) FOREACH_TYPE_FROM_TO(x, Notification::OtherNotification, Notification::TypeCount) + +NotificationsModel::NotificationsModel(QObject *parent) : + QAbstractListModel(parent) +{ +} + +int NotificationsModel::rowCount(const QModelIndex &parent) const +{ + int count = 0; + Q_UNUSED(parent); + FOREACH_TYPE(type) { + count += _list[type].count(); + } + return count; +} + +QVariant NotificationsModel::data(const QModelIndex &index, int role) const +{ +} + +void NotificationsModel::add(Notification *n) +{ +} + +void NotificationsModel::remove(Notification *n) +{ + +} + +int NotificationsModel::fullCount() const +{ + int count = 0; + FOREACH_TYPE(type) { + count += fullCountByType(type); + } + return count; +} + +int NotificationsModel::fullCountByType(Notification::Type type) const +{ + int count = 0; + Q_FOREACH(const Notification *n, _list[type]) { + count += n->count(); + } + return count; +} + +bool NotificationsModel::removeDeletedNotification(Notification *n) +{ + // Can't call any methods of 'n' +} + +int NotificationsModel::getOffsetForType(Notification::Type type) +{ + int count = 0; + FOREACH_TYPE_UNTIL(t, type) { + count += _list[type].count(); + } + return count; +} -- cgit v1.2.3