Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
MileageManager.cpp
Go to the documentation of this file.
1
17
18#include "MileageManager.hpp"
19#include <QDebug>
20#include "MileageCalculator.hpp"
22
33MileageManager::MileageManager(const QString &filePath,
34 IMileageCalculator *calculator,
35 IMileageFileHandler *fileHandler,
36 QObject *parent)
37 : QObject(parent)
38 , m_calculator(calculator ? calculator : new MileageCalculator())
39 , m_fileHandler(fileHandler ? fileHandler : new MileageFileHandler(filePath))
40 , m_ownCalculator(calculator == nullptr)
41 , m_ownFileHandler(fileHandler == nullptr)
42 , m_totalMileage(0.0)
43{}
44
53{
54 shutdown();
55
56 // Only delete instances if they were created internally
57 if (m_ownCalculator) {
58 delete m_calculator;
59 }
60 if (m_ownFileHandler) {
61 delete m_fileHandler;
62 }
63}
64
72{
73 m_totalMileage = m_fileHandler->readMileage();
74
75 connect(&m_updateTimer, &QTimer::timeout, this, &MileageManager::updateMileage);
76 m_updateTimer.start(1000);
77
78 connect(&m_persistenceTimer, &QTimer::timeout, this, &MileageManager::saveMileage);
79 m_persistenceTimer.start(10000);
80}
81
89{
91 m_updateTimer.stop();
92 m_persistenceTimer.stop();
93}
94
102{
103 double distance = m_calculator->calculateDistance();
104 m_totalMileage += distance;
106}
107
114{
115 m_fileHandler->writeMileage(m_totalMileage);
116}
117
126{
127 m_calculator->addSpeed(speed);
128}
Definition of the MileageCalculator class.
Definition of the MileageFileHandler class.
Definition of the MileageManager class.
Interface for calculating the mileage of a vehicle.
Interface for reading and writing the mileage of a vehicle to a file.
Class that calculates the total distance traveled based on speed measurements.
Class that manages the mileage file.
MileageManager(const QString &filePath, IMileageCalculator *calculator=nullptr, IMileageFileHandler *fileHandler=nullptr, QObject *parent=nullptr)
Constructs a MileageManager object with the specified file path, calculator, and file handler.
IMileageCalculator * m_calculator
void updateMileage()
Updates the mileage.
void mileageUpdated(double mileage)
void shutdown()
Shuts down the MileageManager object.
void initialize()
Initializes the MileageManager object.
void saveMileage()
Saves the mileage to the file.
~MileageManager()
Destructs the MileageManager object.
IMileageFileHandler * m_fileHandler
void onSpeedUpdated(float speed)
Handles the speed updated signal.