/** * @RDE_HEADER@ * Base class for ScreenToLocation and LocationToElevation * $Id$ * $HeadURL$ * $Author$ */ // Own #include "screen_location_elevation_helper_base.h" #include "Map/situation_map_utils.h" // ESRI #include //---------------------------------------------------------------------------- namespace SituationMap { //---------------------------------------------------------------------------- class ScreenLocationElevationHelperBase::Private { public: Private() = default; ~Private() = default; QMap m_taskWatcherCont; QTimer *m_mainTimer = nullptr; QTimer *m_killTimer = nullptr; }; //---------------------------------------------------------------------------- ScreenLocationElevationHelperBase::ScreenLocationElevationHelperBase(QObject *parent) : BaseClass(parent) , m_logger(getLogger("ScreenLocationElevationHelperBase")) , d(new Private) { TRACE_LOG(m_logger) << LOGFUNCTION << " START"; const int mainTimerMsec = 250; // mainTimer d->m_mainTimer = new QTimer(this); d->m_mainTimer->setInterval(mainTimerMsec); connect(d->m_mainTimer, &QTimer::timeout, this, &ScreenLocationElevationHelperBase::onMainTimoutInternal); // killTimer d->m_killTimer = new QTimer(this); d->m_killTimer->setSingleShot(true); d->m_killTimer->setInterval(mainTimerMsec + 50); connect(d->m_killTimer, &QTimer::timeout, this, &ScreenLocationElevationHelperBase::onKillTimout); TRACE_LOG(m_logger) << LOGFUNCTION << " END"; } ScreenLocationElevationHelperBase::~ScreenLocationElevationHelperBase() { TRACE_LOG(m_logger) << LOGFUNCTION << " START"; this->stop(); delete d; TRACE_LOG(m_logger) << LOGFUNCTION << " END"; } int ScreenLocationElevationHelperBase::pendingOperationsCount() const { return d->m_taskWatcherCont.size(); } void ScreenLocationElevationHelperBase::cancel() { if (d->m_taskWatcherCont.isEmpty()) return; QMutableMapIterator it(d->m_taskWatcherCont); while (it.hasNext()) { it.next(); if (it.value().cancel()) { DEBUG_LOG(m_logger) << LOGFUNCTION << " TaskWatcher canceled"; it.remove(); } else ERROR_LOG(m_logger) << LOGFUNCTION << " TaskWatcher.cancel() failed"; } // while } void ScreenLocationElevationHelperBase::stop() { this->cancel(); d->m_mainTimer->stop(); d->m_killTimer->stop(); } void ScreenLocationElevationHelperBase::newComputationRequested() { // long absence? if (!d->m_mainTimer->isActive()) d->m_mainTimer->start(); // restarting killTimer d->m_killTimer->start(); } void ScreenLocationElevationHelperBase::onMainTimoutInternal() { this->mainComputation(); } void ScreenLocationElevationHelperBase::onKillTimout() { TRACE_LOG(m_logger) << LOGFUNCTION << " killTimer stop mainTimer..." << " (size of m_taskIdSet=" << d->m_taskWatcherCont.size() << ")"; d->m_mainTimer->stop(); } bool ScreenLocationElevationHelperBase::insertTask(const Esri::ArcGISRuntime::TaskWatcher &tw) { if (!tw.isValid()) { ERROR_LOG(m_logger) << LOGFUNCTION << " task not valid"; return false; } d->m_taskWatcherCont.insert(tw.taskId(), tw); return true; } bool ScreenLocationElevationHelperBase::removeTask(const QUuid &taskId) { return (d->m_taskWatcherCont.remove(taskId) > 0); } } // namespace SituationMap