presentation/CalendarSearch.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "CalendarSearch.h" | ||
| 2 | |||
| 3 | #include "data/CalendarStore.h" | ||
| 4 | #include "data/RecurrenceExpansion.h" | ||
| 5 | |||
| 6 | #include <QHash> | ||
| 7 | #include <algorithm> | ||
| 8 | |||
| 9 | namespace CalendarSearch { | ||
| 10 | |||
| 11 | 1132 | QStringList words(const QString &query) { | |
| 12 | 1132 | QStringList result; | |
| 13 | 1132 | QString current; | |
| 14 | 1132 | bool quoted = false; | |
| 15 |
2/2✓ Branch 21 → 4 taken 170 times.
✓ Branch 21 → 22 taken 1132 times.
|
1302 | for (const QChar c : query) { |
| 16 |
2/2✓ Branch 7 → 8 taken 4 times.
✓ Branch 7 → 9 taken 166 times.
|
170 | if (c == QLatin1Char('"')) quoted = !quoted; |
| 17 |
6/6✓ Branch 10 → 11 taken 7 times.
✓ Branch 10 → 13 taken 159 times.
✓ Branch 11 → 12 taken 5 times.
✓ Branch 11 → 13 taken 2 times.
✓ Branch 14 → 15 taken 5 times.
✓ Branch 14 → 19 taken 161 times.
|
166 | else if (c.isSpace() && !quoted) { |
| 18 |
3/3✓ Branch 16 → 17 taken 3 times.
✓ Branch 16 → 18 taken 2 times.
✓ Branch 17 → 18 taken 3 times.
|
5 | if (!current.isEmpty()) result.append(current); |
| 19 | 5 | current.clear(); | |
| 20 |
1/1✓ Branch 19 → 20 taken 161 times.
|
161 | } else current.append(c); |
| 21 | } | ||
| 22 |
3/3✓ Branch 23 → 24 taken 20 times.
✓ Branch 23 → 25 taken 1112 times.
✓ Branch 24 → 25 taken 20 times.
|
1132 | if (!current.isEmpty()) result.append(current); |
| 23 | 1132 | return result; | |
| 24 | 1132 | } | |
| 25 | |||
| 26 | 20 | QList<CalendarOccurrence> matches(const CalendarStore &store, const QStringList &words, | |
| 27 | const QStringList &hiddenCalendars, const QDate &today, | ||
| 28 | const QSet<QString> &unlimitedSeries) { | ||
| 29 |
2/2✓ Branch 2 → 3 taken 20 times.
✓ Branch 3 → 4 taken 20 times.
|
20 | const QDate from = today.addDays(-365), to = today.addDays(730); |
| 30 | 20 | QHash<QString, CalendarInfoLookup> calendars; | |
| 31 |
5/5✓ Branch 4 → 5 taken 20 times.
✓ Branch 5 → 6 taken 20 times.
✓ Branch 6 → 7 taken 20 times.
✓ Branch 16 → 8 taken 22 times.
✓ Branch 16 → 17 taken 20 times.
|
42 | for (const CalendarInfo &calendar : store.allCalendars()) |
| 32 |
1/1✓ Branch 11 → 12 taken 22 times.
|
22 | calendars.insert(calendarSelectionKey(calendar.accountId, calendar.path), |
| 33 | 20 | {calendar.displayName, calendar.readOnly}); | |
| 34 | 20 | QList<CalendarEvent> rows; | |
| 35 |
5/5✓ Branch 18 → 19 taken 20 times.
✓ Branch 19 → 20 taken 20 times.
✓ Branch 20 → 21 taken 20 times.
✓ Branch 36 → 22 taken 13 times.
✓ Branch 36 → 37 taken 20 times.
|
33 | for (const CalendarEvent &event : store.searchEvents(words)) |
| 36 |
6/12✓ Branch 23 → 24 taken 13 times.
✓ Branch 24 → 25 taken 13 times.
✗ Branch 24 → 29 not taken.
✓ Branch 25 → 26 taken 13 times.
✓ Branch 27 → 28 taken 13 times.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 13 times.
✗ Branch 30 → 32 not taken.
✓ Branch 32 → 33 taken 13 times.
✗ Branch 32 → 34 not taken.
✗ Branch 90 → 91 not taken.
✗ Branch 90 → 92 not taken.
|
13 | if (event.isSchedulable() && !hiddenCalendars.contains(calendarSelectionKey(event.accountId, event.calendarPath))) |
| 37 |
1/1✓ Branch 33 → 34 taken 13 times.
|
33 | rows.append(event); |
| 38 | 20 | QHash<QString, CalendarOccurrence> seriesPick; | |
| 39 | 20 | QList<CalendarOccurrence> picked; | |
| 40 | // S106-288: the per-series budget counts from `from`; a series denser | ||
| 41 | // than about three a day spends it before today. A second expansion that | ||
| 42 | // starts today finds its next occurrence; "Show all" lifts the budget. | ||
| 43 | 20 | const DisplayLimit limit{kDisplayOccurrencesPerSeries, unlimitedSeries}; | |
| 44 | 2219 | const auto consider = [&seriesPick, &today](const CalendarOccurrence &occurrence) { | |
| 45 |
2/2✓ Branch 2 → 3 taken 2219 times.
✓ Branch 3 → 4 taken 2219 times.
|
2219 | const QString key = calendarSelectionKey(occurrence.accountId, occurrence.calendarPath) + occurrence.uid; |
| 46 |
1/1✓ Branch 5 → 6 taken 2219 times.
|
2219 | auto it = seriesPick.find(key); |
| 47 |
3/3✓ Branch 8 → 9 taken 3 times.
✓ Branch 8 → 11 taken 2216 times.
✓ Branch 9 → 10 taken 3 times.
|
2219 | if (it == seriesPick.end()) { seriesPick.insert(key, occurrence); return; } |
| 48 | 2216 | const bool upcoming = occurrence.lastDay >= today; | |
| 49 | 2216 | const bool keptUpcoming = it->lastDay >= today; | |
| 50 |
8/9✓ Branch 16 → 17 taken 1215 times.
✓ Branch 16 → 22 taken 1001 times.
✓ Branch 17 → 18 taken 1213 times.
✓ Branch 17 → 28 taken 2 times.
✓ Branch 19 → 20 taken 1213 times.
✓ Branch 21 → 22 taken 1213 times.
✗ Branch 21 → 28 not taken.
✓ Branch 30 → 31 taken 1003 times.
✓ Branch 30 → 33 taken 1213 times.
|
4430 | if ((upcoming && (!keptUpcoming || occurrence.start < it->start)) || |
| 51 |
5/7✓ Branch 22 → 23 taken 1001 times.
✓ Branch 22 → 29 taken 1213 times.
✓ Branch 23 → 24 taken 1001 times.
✗ Branch 23 → 29 not taken.
✓ Branch 25 → 26 taken 1001 times.
✓ Branch 27 → 28 taken 1001 times.
✗ Branch 27 → 29 not taken.
|
2214 | (!upcoming && !keptUpcoming && occurrence.start > it->start)) |
| 52 | 1003 | *it = occurrence; | |
| 53 |
2/2✓ Branch 35 → 36 taken 2216 times.
✓ Branch 35 → 38 taken 3 times.
|
2219 | }; |
| 54 |
5/5✓ Branch 39 → 40 taken 20 times.
✓ Branch 40 → 41 taken 20 times.
✓ Branch 41 → 42 taken 20 times.
✓ Branch 51 → 43 taken 1121 times.
✓ Branch 51 → 52 taken 20 times.
|
1141 | for (const CalendarEvent &event : expandEventsForDisplay(rows, from, to, false, limit)) { |
| 55 |
1/1✓ Branch 44 → 45 taken 1121 times.
|
1121 | const CalendarOccurrence occurrence = CalendarLayout::fromEvent(event, calendars); |
| 56 |
3/3✓ Branch 45 → 46 taken 1111 times.
✓ Branch 45 → 47 taken 10 times.
✓ Branch 46 → 48 taken 1111 times.
|
1121 | if (occurrence.recurring) consider(occurrence); |
| 57 |
1/1✓ Branch 47 → 48 taken 10 times.
|
10 | else picked.append(occurrence); |
| 58 | 1141 | } | |
| 59 |
5/5✓ Branch 53 → 54 taken 20 times.
✓ Branch 54 → 55 taken 20 times.
✓ Branch 55 → 56 taken 20 times.
✓ Branch 64 → 57 taken 1118 times.
✓ Branch 64 → 65 taken 20 times.
|
1138 | for (const CalendarEvent &event : expandEventsForDisplay(rows, today, to, false, limit)) { |
| 60 |
1/1✓ Branch 58 → 59 taken 1118 times.
|
1118 | const CalendarOccurrence occurrence = CalendarLayout::fromEvent(event, calendars); |
| 61 |
3/3✓ Branch 59 → 60 taken 1108 times.
✓ Branch 59 → 61 taken 10 times.
✓ Branch 60 → 61 taken 1108 times.
|
1118 | if (occurrence.recurring) consider(occurrence); |
| 62 | 1138 | } | |
| 63 |
2/2✓ Branch 66 → 67 taken 20 times.
✓ Branch 67 → 68 taken 20 times.
|
20 | picked.append(seriesPick.values()); |
| 64 |
3/3✓ Branch 69 → 70 taken 20 times.
✓ Branch 70 → 71 taken 20 times.
✓ Branch 71 → 72 taken 20 times.
|
20 | std::sort(picked.begin(), picked.end(), |
| 65 | 6 | [](const CalendarOccurrence &a, const CalendarOccurrence &b) { return a.start < b.start; }); | |
| 66 | 20 | return picked; | |
| 67 | 42 | } | |
| 68 | |||
| 69 | } // namespace CalendarSearch | ||
| 70 |