Skip to content

Commit

Permalink
Refactor: Use TimerBase instead of QTimer in PlanRunner
Browse files Browse the repository at this point in the history
* Add functions to set all timer

Ticket: #5
  • Loading branch information
Sebastian Hahn committed Jan 20, 2022
1 parent fdd2074 commit 3aeab97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
22 changes: 11 additions & 11 deletions src/Intervaltimer/intervaltimer/PlanRunner.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#include "PlanRunner.h"

PlanRunner::PlanRunner(QObject* object)
: QObject(object) {
: QObject(object) {}

timerThread->start(QThread::LowPriority);
}

PlanRunner::~PlanRunner() {
timerThread->exit();
// needed to avoid an exception
while (!timerThread->isFinished()) {
}
}

int PlanRunner::getPlanDurationCompleteTime() const { return plan->getDuration().count(); }

Expand Down Expand Up @@ -92,4 +83,13 @@ void PlanRunner::changedIntervalRunningTime() { emit changedIntervalDurationRunn

void PlanRunner::changedPlanRunningTime() { emit changedPlanDurationRunningTime(); }

void PlanRunner::setIntervalTimer(std::shared_ptr<QTimer> newTimer) { intervalTimer = std::move(newTimer); }
void PlanRunner::setIntervalTimer(std::shared_ptr<TimerBase> newTimer) { intervalTimer = std::move(newTimer); }

void PlanRunner::setIntervalRefeshingTimer(std::shared_ptr<TimerBase> newTimer) {
intervalRefreshingTimer = std::move(newTimer);
}

void PlanRunner::setPlanTimer(std::shared_ptr<TimerBase> newTimer) { planTimer = std::move(newTimer); }
void PlanRunner::setPlanRefeshingTimer(std::shared_ptr<TimerBase> newTimer) {
planRefreshingTimer = std::move(newTimer);
}
19 changes: 11 additions & 8 deletions src/Intervaltimer/intervaltimer/PlanRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <QtQml/qqmlregistration.h>
#include <memory>

#include <QTimer>
#include "Timer.h"
#include "TimerBase.h"

class PlanRunner : public QObject {
Q_OBJECT
Expand All @@ -24,7 +25,6 @@ class PlanRunner : public QObject {

public:
PlanRunner(QObject* = nullptr);
~PlanRunner();

int getPlanDurationCompleteTime() const;
int getPlanDurationRunningTime() const;
Expand All @@ -47,17 +47,20 @@ class PlanRunner : public QObject {
Q_INVOKABLE void stop();
// Q_INVOKABLE void pause();

void setIntervalTimer(std::shared_ptr<QTimer> newTimer);
void setIntervalTimer(std::shared_ptr<TimerBase> newTimer);
void setIntervalRefeshingTimer(std::shared_ptr<TimerBase> newTimer);

void setPlanTimer(std::shared_ptr<TimerBase> newTimer);
void setPlanRefeshingTimer(std::shared_ptr<TimerBase> newTimer);

protected:
bool isRunning{false};
std::shared_ptr<Plan> plan{nullptr};
PlanIterator iterator{};
std::shared_ptr<QTimer> intervalTimer{new QTimer{}};
std::shared_ptr<QTimer> planRefreshingTimer{new QTimer{}};
std::shared_ptr<QTimer> planTimer{new QTimer{}};
std::shared_ptr<QTimer> intervalRefreshingTimer{new QTimer{}};
std::unique_ptr<QThread> timerThread{new QThread{}};
std::shared_ptr<TimerBase> intervalTimer{new Timer{}};
std::shared_ptr<TimerBase> planRefreshingTimer{new Timer{}};
std::shared_ptr<TimerBase> planTimer{new Timer{}};
std::shared_ptr<TimerBase> intervalRefreshingTimer{new Timer{}};
std::chrono::milliseconds refreshingTimeForRunningInterval{500};
std::chrono::milliseconds refreshingTimeForRunningPlan{500};
std::chrono::milliseconds totalDurationOfAllPlans{};
Expand Down

0 comments on commit 3aeab97

Please sign in to comment.