Commit 9d7efda4 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Core: Export and de-templatize ProgressTimer

* Enable usage with QFutureInterface of non-void types
* Remove watcher. Instead, start the timer immediately
* Replace inheritance with aggregation of QTimer

Change-Id: I4a7d8e2b8c885fd7a84a0134be3e41220952c185
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 9a248913
......@@ -780,21 +780,20 @@ void ProgressManager::cancelTasks(Id type)
ProgressTimer::ProgressTimer(QObject *parent,
const QFutureInterface<void> &futureInterface,
const QFutureInterfaceBase &futureInterface,
int expectedSeconds)
: QTimer(parent),
: QObject(parent),
m_futureInterface(futureInterface),
m_expectedTime(expectedSeconds),
m_currentTime(0)
{
m_futureWatcher.setFuture(m_futureInterface.future());
m_futureInterface.setProgressRange(0, 100);
m_futureInterface.setProgressValue(0);
setInterval(1000); // 1 second
connect(this, &QTimer::timeout, this, &ProgressTimer::handleTimeout);
connect(&m_futureWatcher, &QFutureWatcherBase::started, this, [this]() { start(); });
m_timer = new QTimer(this);
m_timer->setInterval(1000); // 1 second
connect(m_timer, &QTimer::timeout, this, &ProgressTimer::handleTimeout);
m_timer->start();
}
void ProgressTimer::handleTimeout()
......
......@@ -29,8 +29,11 @@
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QObject>
#include <QFuture>
#include <QFutureInterfaceBase>
#include <QObject>
QT_FORWARD_DECLARE_CLASS(QTimer)
namespace Core {
class FutureProgress;
......@@ -69,6 +72,20 @@ private:
friend class Core::Internal::ProgressManagerPrivate;
};
class CORE_EXPORT ProgressTimer : public QObject
{
public:
ProgressTimer(QObject *parent, const QFutureInterfaceBase &futureInterface, int expectedSeconds);
private:
void handleTimeout();
QFutureInterfaceBase m_futureInterface;
int m_expectedTime;
int m_currentTime;
QTimer *m_timer;
};
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::ProgressManager::ProgressFlags)
......
......@@ -34,7 +34,6 @@
#include <QHBoxLayout>
#include <QPointer>
#include <QPropertyAnimation>
#include <QTimer>
#include <QToolButton>
namespace Core {
......@@ -121,23 +120,6 @@ public:
void paintEvent(QPaintEvent *event);
};
class ProgressTimer : public QTimer
{
Q_OBJECT
public:
ProgressTimer(QObject *parent, const QFutureInterface<void> &futureInterface, int expectedSeconds);
private:
void handleTimeout();
QFutureInterface<void> m_futureInterface;
QFutureWatcher<void> m_futureWatcher;
int m_expectedTime;
int m_currentTime;
};
} // namespace Internal
} // namespace Core
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment