presentation/StatusMessageState.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "StatusMessageState.h" | ||
| 2 | #include <utility> | ||
| 3 | |||
| 4 |
3/3✓ Branch 8 → 9 taken 800 times.
✓ Branch 9 → 10 taken 800 times.
✓ Branch 10 → 11 taken 800 times.
|
800 | StatusMessageState::StatusMessageState(QObject *parent) : QObject(parent) { |
| 5 |
1/1✓ Branch 11 → 12 taken 800 times.
|
800 | m_errorHold.setSingleShot(true); |
| 6 |
1/1✓ Branch 12 → 13 taken 800 times.
|
800 | m_errorHold.setInterval(10000); |
| 7 |
1/1✓ Branch 13 → 14 taken 800 times.
|
800 | connect(&m_errorHold, &QTimer::timeout, this, [this] { |
| 8 |
1/4✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 2 times.
✗ Branch 4 → 5 not taken.
✗ Branch 5 → 6 not taken.
|
2 | if (!m_pendingErrors.isEmpty()) { error(m_pendingErrors.takeFirst()); return; } |
| 9 |
3/3✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 16 taken 1 time.
✓ Branch 12 → 13 taken 1 time.
|
2 | if (!m_pendingFeedback.isEmpty()) { feedback(std::exchange(m_pendingFeedback, {})); return; } |
| 10 |
1/2✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
|
1 | if (showPendingAction()) return; |
| 11 |
1/2✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 22 not taken.
|
1 | if (!m_pendingProgress.isEmpty()) m_progressTimer.start(); |
| 12 | }); | ||
| 13 |
1/1✓ Branch 15 → 16 taken 800 times.
|
800 | m_progressTimer.setSingleShot(true); |
| 14 |
1/1✓ Branch 16 → 17 taken 800 times.
|
800 | m_progressTimer.setInterval(500); |
| 15 |
1/1✓ Branch 17 → 18 taken 800 times.
|
800 | m_feedbackHold.setSingleShot(true); |
| 16 |
1/1✓ Branch 18 → 19 taken 800 times.
|
800 | m_feedbackHold.setInterval(5000); |
| 17 |
1/1✓ Branch 19 → 20 taken 800 times.
|
800 | connect(&m_progressTimer, &QTimer::timeout, this, [this] { |
| 18 |
4/8✓ Branch 3 → 4 taken 38 times.
✗ Branch 3 → 9 not taken.
✓ Branch 5 → 6 taken 38 times.
✗ Branch 5 → 9 not taken.
✓ Branch 7 → 8 taken 38 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 38 times.
✗ Branch 10 → 17 not taken.
|
38 | if (!m_errorHold.isActive() && !m_feedbackHold.isActive() && !m_pendingProgress.isEmpty()) { |
| 19 | 38 | const auto text = std::exchange(m_pendingProgress, {}); | |
| 20 |
1/1✓ Branch 14 → 15 taken 38 times.
|
38 | publish(text); |
| 21 | 38 | } | |
| 22 | 38 | }); | |
| 23 |
1/1✓ Branch 21 → 22 taken 800 times.
|
800 | connect(&m_feedbackHold, &QTimer::timeout, this, [this] { |
| 24 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 30 times.
|
32 | if (showPendingAction()) return; |
| 25 |
2/2✓ Branch 6 → 7 taken 19 times.
✓ Branch 6 → 8 taken 11 times.
|
30 | if (!m_pendingProgress.isEmpty()) m_progressTimer.start(); |
| 26 | }); | ||
| 27 | 800 | } | |
| 28 | 2032 | void StatusMessageState::publish(const QString &text, qint64 action) { | |
| 29 | 2032 | m_visibleAction = action; | |
| 30 |
2/2✓ Branch 3 → 4 taken 709 times.
✓ Branch 3 → 5 taken 1323 times.
|
2032 | if (m_text == text) return; |
| 31 | 1323 | m_text = text; | |
| 32 | 1323 | emit changed(); | |
| 33 | } | ||
| 34 | 1221 | void StatusMessageState::feedback(const QString &text) { | |
| 35 | // S106-356: during an error's hold the newest feedback waits and shows | ||
| 36 | // when the hold ends (it used to be dropped). | ||
| 37 |
2/2✓ Branch 3 → 4 taken 20 times.
✓ Branch 3 → 6 taken 1201 times.
|
1221 | if (m_errorHold.isActive()) { m_pendingFeedback = text; return; } |
| 38 | 1201 | m_progressTimer.stop(); | |
| 39 | 1201 | m_feedbackHold.start(); | |
| 40 | 1201 | publish(text); | |
| 41 | } | ||
| 42 | 25 | void StatusMessageState::error(const QString &text) { | |
| 43 | 25 | m_progressTimer.stop(); | |
| 44 | 25 | m_feedbackHold.stop(); | |
| 45 | // A duplicate error must not keep extending its own lifetime. | ||
| 46 |
2/2✓ Branch 5 → 6 taken 11 times.
✓ Branch 5 → 17 taken 14 times.
|
25 | if (m_errorHold.isActive()) { |
| 47 |
7/8✓ Branch 7 → 8 taken 8 times.
✓ Branch 7 → 13 taken 3 times.
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 13 taken 2 times.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 6 times.
✓ Branch 14 → 16 taken 5 times.
|
11 | if (m_text != text && !m_pendingErrors.contains(text) && m_pendingErrors.size() < 20) |
| 48 | 6 | m_pendingErrors.append(text); | |
| 49 | 11 | return; | |
| 50 | } | ||
| 51 | 14 | m_errorHold.start(); | |
| 52 | 14 | publish(text); | |
| 53 | } | ||
| 54 | 796 | void StatusMessageState::progress(const QString &text) { | |
| 55 | 796 | m_pendingProgress = text; | |
| 56 | // Do not restart this timer for every update: continuous streams must still | ||
| 57 | // publish their newest progress at a bounded rate rather than starve it. | ||
| 58 |
2/2✓ Branch 6 → 7 taken 191 times.
✓ Branch 6 → 12 taken 501 times.
|
1488 | if (!m_errorHold.isActive() && !m_feedbackHold.isActive() && |
| 59 |
7/8✓ Branch 4 → 5 taken 692 times.
✓ Branch 4 → 12 taken 104 times.
✓ Branch 8 → 9 taken 191 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 90 times.
✓ Branch 10 → 12 taken 101 times.
✓ Branch 13 → 14 taken 90 times.
✓ Branch 13 → 15 taken 706 times.
|
1488 | m_pendingActions.isEmpty() && !m_progressTimer.isActive()) |
| 60 | 90 | m_progressTimer.start(); | |
| 61 | 796 | } | |
| 62 | 813 | bool StatusMessageState::showPendingAction() { | |
| 63 |
8/8✓ Branch 3 → 4 taken 14 times.
✓ Branch 3 → 8 taken 799 times.
✓ Branch 5 → 6 taken 13 times.
✓ Branch 5 → 8 taken 1 time.
✓ Branch 7 → 8 taken 3 times.
✓ Branch 7 → 9 taken 10 times.
✓ Branch 10 → 11 taken 803 times.
✓ Branch 10 → 12 taken 10 times.
|
813 | if (m_pendingActions.isEmpty() || m_errorHold.isActive() || m_feedbackHold.isActive()) |
| 64 | 803 | return false; | |
| 65 | 10 | m_progressTimer.stop(); | |
| 66 | 10 | publish(m_pendingActions.first(), m_pendingActions.firstKey()); | |
| 67 | 10 | return true; | |
| 68 | } | ||
| 69 | 24 | void StatusMessageState::pendingAction(qint64 token, const QString &text) { | |
| 70 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 24 times.
|
24 | if (token <= 0) return; |
| 71 |
2/2✓ Branch 5 → 6 taken 11 times.
✓ Branch 5 → 9 taken 13 times.
|
24 | if (!text.isEmpty()) { |
| 72 | 11 | m_pendingActions.insert(token, text); | |
| 73 | 11 | showPendingAction(); | |
| 74 | 11 | return; | |
| 75 | } | ||
| 76 | 13 | m_pendingActions.remove(token); | |
| 77 |
2/2✓ Branch 10 → 11 taken 10 times.
✓ Branch 10 → 12 taken 3 times.
|
13 | if (m_visibleAction != token) return; |
| 78 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 20 taken 1 time.
|
3 | if (!showPendingAction()) { |
| 79 |
1/1✓ Branch 15 → 16 taken 2 times.
|
2 | publish({}); |
| 80 |
1/2✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 2 times.
|
2 | if (!m_pendingProgress.isEmpty()) m_progressTimer.start(); |
| 81 | } | ||
| 82 | } | ||
| 83 | 771 | void StatusMessageState::clearPendingActions() { | |
| 84 | 771 | m_pendingActions.clear(); | |
| 85 |
3/3✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 8 taken 770 times.
✓ Branch 5 → 6 taken 1 time.
|
771 | if (m_visibleAction != 0) publish({}); |
| 86 | 771 | } | |
| 87 | 770 | void StatusMessageState::reset() { | |
| 88 |
2/2✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 7 taken 766 times.
|
770 | if (m_errorHold.isActive()) { m_pendingProgress.clear(); m_pendingFeedback.clear(); return; } |
| 89 | 766 | m_progressTimer.stop(); | |
| 90 | 766 | m_feedbackHold.stop(); | |
| 91 | 766 | m_pendingProgress.clear(); | |
| 92 |
1/2✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 766 times.
|
766 | if (showPendingAction()) return; |
| 93 |
1/1✓ Branch 14 → 15 taken 766 times.
|
766 | publish({}); |
| 94 | } | ||
| 95 |