55 lines
1.0 KiB
C
Raw Normal View History

2014-01-31 22:51:45 +01:00
#pragma once
2013-12-30 23:39:10 +01:00
#include <QObject>
#include <QTimer>
#include <QList>
#include <QStandardItem>
#include <QDebug>
2014-01-31 22:51:45 +01:00
#include "GroupView.h"
2013-12-30 23:39:10 +01:00
class Progresser : public QObject
{
Q_OBJECT
public:
explicit Progresser(QObject *parent = 0) : QObject(parent)
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
timer->start(50);
}
QStandardItem *addTrackedIndex(QStandardItem *item)
{
item->setData(1000, GroupViewRoles::ProgressMaximumRole);
2013-12-30 23:39:10 +01:00
m_items.append(item);
return item;
}
2014-01-31 22:51:45 +01:00
public
slots:
2013-12-30 23:39:10 +01:00
void timeout()
{
2014-02-02 10:26:38 +01:00
QList<QStandardItem *> toRemove;
2014-01-31 22:58:57 +01:00
for (auto item : m_items)
2013-12-30 23:39:10 +01:00
{
int maximum = item->data(GroupViewRoles::ProgressMaximumRole).toInt();
int value = item->data(GroupViewRoles::ProgressValueRole).toInt();
2014-02-02 10:26:38 +01:00
int newvalue = std::min(value + 3, maximum);
item->setData(newvalue, GroupViewRoles::ProgressValueRole);
2014-02-02 10:26:38 +01:00
if(newvalue >= maximum)
2013-12-30 23:39:10 +01:00
{
2014-02-02 10:26:38 +01:00
toRemove.append(item);
2013-12-30 23:39:10 +01:00
}
}
2014-02-02 10:26:38 +01:00
for(auto remove : toRemove)
{
m_items.removeAll(remove);
}
2013-12-30 23:39:10 +01:00
}
private:
QList<QStandardItem *> m_items;
};