Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/notificationsortproxymodel.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
45 | { | 45 | { | ||
46 | if (m_sortMode != sortMode) { | 46 | if (m_sortMode != sortMode) { | ||
47 | m_sortMode = sortMode; | 47 | m_sortMode = sortMode; | ||
48 | invalidate(); | 48 | invalidate(); | ||
49 | emit sortModeChanged(); | 49 | emit sortModeChanged(); | ||
50 | } | 50 | } | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | Qt::SortOrder NotificationSortProxyModel::sortOrder() const | ||||
54 | { | ||||
55 | return m_sortOrder; | ||||
56 | } | ||||
57 | | ||||
58 | void NotificationSortProxyModel::setSortOrder(Qt::SortOrder sortOrder) | ||||
59 | { | ||||
60 | if (m_sortOrder != sortOrder) { | ||||
61 | m_sortOrder = sortOrder; | ||||
62 | invalidate(); | ||||
63 | emit sortOrderChanged(); | ||||
64 | } | ||||
65 | } | ||||
66 | | ||||
53 | int sortScore(const QModelIndex &idx) | 67 | int sortScore(const QModelIndex &idx) | ||
54 | { | 68 | { | ||
55 | const auto urgency = idx.data(Notifications::UrgencyRole).toInt(); | 69 | const auto urgency = idx.data(Notifications::UrgencyRole).toInt(); | ||
56 | if (urgency == Notifications::CriticalUrgency) { | 70 | if (urgency == Notifications::CriticalUrgency) { | ||
57 | return 3; | 71 | return 3; | ||
58 | } | 72 | } | ||
59 | 73 | | |||
60 | const int type = idx.data(Notifications::TypeRole).toInt(); | 74 | const int type = idx.data(Notifications::TypeRole).toInt(); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 117 | if (!timeLeft.isValid()) { | |||
104 | timeLeft = source_left.data(Notifications::CreatedRole).toDateTime(); | 118 | timeLeft = source_left.data(Notifications::CreatedRole).toDateTime(); | ||
105 | } | 119 | } | ||
106 | 120 | | |||
107 | QDateTime timeRight = source_right.data(Notifications::UpdatedRole).toDateTime(); | 121 | QDateTime timeRight = source_right.data(Notifications::UpdatedRole).toDateTime(); | ||
108 | if (!timeRight.isValid()) { | 122 | if (!timeRight.isValid()) { | ||
109 | timeRight = source_right.data(Notifications::CreatedRole).toDateTime(); | 123 | timeRight = source_right.data(Notifications::CreatedRole).toDateTime(); | ||
110 | } | 124 | } | ||
111 | 125 | | |||
112 | // sorts descending by time (newest first) | 126 | if (m_sortOrder == Qt::DescendingOrder) { | ||
113 | return timeLeft > timeRight; | 127 | return timeLeft > timeRight; | ||
128 | } else { | ||||
129 | return timeLeft < timeRight; | ||||
130 | } | ||||
114 | } | 131 | } | ||
115 | 132 | | |||
116 | return scoreLeft > scoreRight; | 133 | return scoreLeft > scoreRight; | ||
117 | } | 134 | } |