Ref T105, use timer in base class CContinuousWorker

* remove unused cleanup
* object name set in base class
This commit is contained in:
Klaus Basan
2017-07-11 03:54:52 +02:00
committed by Mathew Sutcliffe
parent 4a7ad09e46
commit 0bfd9a55a2
7 changed files with 11 additions and 73 deletions

View File

@@ -37,38 +37,7 @@ namespace BlackCore
CContinuousWorker(owner, "Background data updater")
{
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
m_updateTimer.setObjectName(getName());
}
void CBackgroundDataUpdater::initialize()
{
m_updateTimer.start(60 * 1000);
}
void CBackgroundDataUpdater::cleanup()
{
m_updateTimer.stop();
}
void CBackgroundDataUpdater::startUpdating(int updateTimeSecs)
{
if (!CThreadUtils::isCurrentThreadObjectThread(this))
{
// shift in correct thread
QTimer::singleShot(0, this, [this, updateTimeSecs] { this->startUpdating(updateTimeSecs); });
return;
}
if (updateTimeSecs < 0)
{
setEnabled(false);
QTimer::singleShot(0, &m_updateTimer, &QTimer::stop);
}
else
{
setEnabled(true);
m_updateTimer.start(1000 * updateTimeSecs);
}
m_updateTimer.setInterval(60 * 1000);
}
void CBackgroundDataUpdater::doWork()

View File

@@ -35,20 +35,9 @@ namespace BlackCore
//! Constructor
CBackgroundDataUpdater(QObject *owner);
//! Enable updates
void startUpdating(int updateTimeSecs);
protected:
//! \copydoc BlackMisc::CContinuousWorker::initialize
virtual void initialize() override;
//! \copydoc BlackMisc::CContinuousWorker::cleanup
virtual void cleanup() override;
private:
int m_cycle = 0; //!< cycle
bool m_inWork = false; //!< indicates a running update
QTimer m_updateTimer { this };
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< caches
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; //!< caches

View File

@@ -28,7 +28,6 @@
#include <QObject>
#include <QReadWriteLock>
#include <QString>
#include <QTimer>
#include <QtGlobal>
#include <QNetworkReply>