• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 24764840037

22 Apr 2026 06:58AM UTC coverage: 27.36% (-0.04%) from 27.404%
24764840037

push

github

web-flow
Fix: QProgressIndicator memory leak and dark mode support (#1129)

* Apply suggested fix to src/qprogressindicator.cpp from Copilot Autofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Fix: QProgressIndicator memory leak and dark mode support

- Fix memory leak in KeygenDialog by tracking and deleting QProgressIndicator
- Use std::unique_ptr for automatic memory management
- Add dark mode support: use palette color when no explicit color set
- Update tst_ui test to match new default color behavior
- Add reset to invalid color test in tst_ui.cpp
- Remove duplicate tests from tst_util.cpp

---------

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Henk <henk@annejan.com>

1 of 10 new or added lines in 2 files covered. (10.0%)

26 existing lines in 3 files now uncovered.

1597 of 5837 relevant lines covered (27.36%)

30.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.56
/src/qprogressindicator.cpp
1
// SPDX-FileCopyrightText: 2011 Morgan Leborgne
2
// SPDX-FileCopyrightText: 2015 Anne Jan Brouwer
3
// SPDX-License-Identifier: MIT
4
#include "qprogressindicator.h"
5
#include <QPainter>
6

7
/**
8
 * @brief QProgressIndicator::QProgressIndicator constructor.
9
 * @param parent widget the indicator is placed in.
10
 */
11
QProgressIndicator::QProgressIndicator(QWidget *parent)
16✔
12
    : QWidget(parent), m_angle(0), m_timerId(-1), m_delay(40),
16✔
13
      m_displayedWhenStopped(false), m_color() {
16✔
14
  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
16✔
15
  setFocusPolicy(Qt::NoFocus);
16✔
16
}
16✔
17

18
auto QProgressIndicator::isAnimated() const -> bool { return m_timerId != -1; }
17✔
19

20
void QProgressIndicator::setDisplayedWhenStopped(bool state) {
2✔
21
  m_displayedWhenStopped = state;
2✔
22

23
  update();
2✔
24
}
2✔
25

26
auto QProgressIndicator::isDisplayedWhenStopped() const -> bool {
4✔
27
  return m_displayedWhenStopped;
4✔
28
}
29

30
void QProgressIndicator::startAnimation() {
7✔
31
  m_angle = 0;
7✔
32

33
  if (m_timerId == -1) {
7✔
34
    m_timerId = startTimer(m_delay);
6✔
35
  }
36
}
7✔
37

38
void QProgressIndicator::stopAnimation() {
7✔
39
  if (m_timerId != -1) {
7✔
40
    killTimer(m_timerId);
6✔
41
  }
42

43
  m_timerId = -1;
7✔
44

45
  update();
7✔
46
}
7✔
47

48
void QProgressIndicator::setAnimationDelay(int delay) {
1✔
49
  if (m_timerId != -1) {
1✔
UNCOV
50
    killTimer(m_timerId);
×
51
  }
52

53
  m_delay = delay;
1✔
54

55
  if (m_timerId != -1) {
1✔
UNCOV
56
    m_timerId = startTimer(m_delay);
×
57
  }
58
}
1✔
59

60
void QProgressIndicator::setColor(const QColor &color) {
2✔
61
  m_color = color;
2✔
62

63
  update();
2✔
64
}
2✔
65

66
/**
67
 * @brief QProgressIndicator::sizeHint default minimum size.
68
 * @return QSize(20, 20)
69
 */
70
auto QProgressIndicator::sizeHint() const -> QSize { return {20, 20}; }
1✔
71

72
/**
73
 * @brief QProgressIndicator::heightForWidth square ratio.
74
 * @param w requested width
75
 * @return w returned height
76
 */
77
auto QProgressIndicator::heightForWidth(int w) const -> int { return w; }
3✔
78

79
/**
80
 * @brief QProgressIndicator::timerEvent do the actual animation.
81
 */
UNCOV
82
void QProgressIndicator::timerEvent(QTimerEvent * /*event*/) {
×
UNCOV
83
  m_angle = (m_angle + 30) % 360;
×
84

UNCOV
85
  update();
×
UNCOV
86
}
×
87

88
/**
89
 * @brief QProgressIndicator::paintEvent draw the spinner.
90
 */
UNCOV
91
void QProgressIndicator::paintEvent(QPaintEvent * /*event*/) {
×
UNCOV
92
  if (!m_displayedWhenStopped && !isAnimated()) {
×
UNCOV
93
    return;
×
94
  }
95

UNCOV
96
  int width = qMin(this->width(), this->height());
×
97

UNCOV
98
  QPainter p(this);
×
UNCOV
99
  p.setRenderHint(QPainter::Antialiasing);
×
100

UNCOV
101
  auto outerRadius = int((width - 1) * 0.5);
×
UNCOV
102
  auto innerRadius = int((width - 1) * 0.5 * 0.38);
×
103

UNCOV
104
  int capsuleHeight = outerRadius - innerRadius;
×
105
  int capsuleWidth =
UNCOV
106
      (width > 32) ? int(capsuleHeight * 0.23) : int(capsuleHeight * 0.35);
×
107
  int capsuleRadius = capsuleWidth / 2;
×
108

UNCOV
109
  for (int i = 0; i < 12; ++i) {
×
NEW
110
    QColor color = m_color.isValid() ? m_color : palette().windowText().color();
×
NEW
111
    color.setAlphaF(1.0f - (i / 12.0f));
×
UNCOV
112
    p.setPen(Qt::NoPen);
×
UNCOV
113
    p.setBrush(color);
×
UNCOV
114
    p.save();
×
UNCOV
115
    p.translate(rect().center());
×
116
    p.rotate(int(m_angle - i * 30.0f));
×
117
    p.drawRoundedRect(int(-capsuleWidth * 0.5), -(innerRadius + capsuleHeight),
×
118
                      capsuleWidth, capsuleHeight, capsuleRadius,
119
                      capsuleRadius);
UNCOV
120
    p.restore();
×
121
  }
UNCOV
122
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc