Skip to content

Commit

Permalink
Refactor progress bar counter logic to use a dedicated timer event ha…
Browse files Browse the repository at this point in the history
…ndler.
  • Loading branch information
przemek83 committed Dec 26, 2024
1 parent ea35aed commit 575f029
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 15 additions & 14 deletions examples/Examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,9 @@ QGroupBox* Examples::createProgressBarInfinite()
QGroupBox* Examples::createProgressBarCounter()
{
progressCounterTimer_.setInterval(TIME_INTERVAL);
QObject::connect(
&progressCounterTimer_, &QTimer::timeout, &progressBarCounter_,
[&progress = progress_, &bar = progressBarCounter_,
&startStop = startStopButtonCounter_, &timer = progressCounterTimer_]()
{
bar.updateProgress(progress);
++progress;
if (progress > MAX_PROGRESS_BAR_VALUE)
{
timer.stop();
progress = 0;
startStop.click();
}
});
QObject::connect(&progressCounterTimer_, &QTimer::timeout, this,
&Examples::counterTimerEvent);

QObject::connect(&startStopButtonCounter_, &QPushButton::clicked, this,
&Examples::counterButtonClicked);

Expand Down Expand Up @@ -215,3 +204,15 @@ void Examples::counterButtonClicked()
startStopButtonCounter_.setText(QStringLiteral("stop"));
}
}

void Examples::counterTimerEvent()
{
progressBarCounter_.updateProgress(progress_);
++progress_;
if (progress_ > MAX_PROGRESS_BAR_VALUE)
{
progress_ = 0;
progressCounterTimer_.stop();
startStopButtonCounter_.click();
}
}
2 changes: 2 additions & 0 deletions examples/Examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ private slots:
void infiniteButtonClicked();

void counterButtonClicked();

void counterTimerEvent();
};

0 comments on commit 575f029

Please sign in to comment.