| 47 | } |
| 48 | |
| 49 | QVariant NotificationModel::data(const QModelIndex &index, int role) const |
| 50 | { |
| 51 | if (!index.isValid() || index.row() > (rowCount(QModelIndex()) - 1)) { |
| 52 | return QVariant(); |
| 53 | } |
| 54 | |
| 55 | EntityPtr entity = d->getEntityByRow(index.row()); |
| 56 | if (entity) { |
| 57 | switch (role) { |
| 58 | case Qt::DecorationRole: { |
| 59 | auto type = entity->type(); |
| 60 | switch (type) { |
| 61 | case NotificationEntity::Information: |
| 62 | return QIcon::fromTheme("notification_info"); |
| 63 | case NotificationEntity::Warning: |
| 64 | return QIcon::fromTheme("notification_warning"); |
| 65 | case NotificationEntity::Error: |
| 66 | return QIcon::fromTheme("notification_error"); |
| 67 | } |
| 68 | } |
| 69 | case Qt::DisplayRole: |
| 70 | return entity->message(); |
| 71 | case kActionsRole: |
| 72 | return entity->actions(); |
| 73 | case kSourceRole: { |
| 74 | QString source = entity->name(); |
| 75 | if (!source.isEmpty()) |
| 76 | return tr("Source: %1").arg(source); |
| 77 | } |
| 78 | case kEntityRole: |
| 79 | return qVariantFromValue(entity); |
| 80 | default: |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return QVariant(); |
| 86 | } |
| 87 | |
| 88 | void NotificationModel::setNotifications(const QList<EntityPtr> &datas) |
| 89 | { |
no test coverage detected