blob: 2a358329ac0bd3eb5ec4c862bfa60c668d34c7ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#pragma once
#include <QObject>
#include <QTimer>
#include <QList>
#include <QStandardItem>
#include <QDebug>
#include "GroupView.h"
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);
m_items.append(item);
return item;
}
public
slots:
void timeout()
{
QList<QStandardItem *> toRemove;
for (auto item : m_items)
{
int maximum = item->data(GroupViewRoles::ProgressMaximumRole).toInt();
int value = item->data(GroupViewRoles::ProgressValueRole).toInt();
int newvalue = std::min(value + 3, maximum);
item->setData(newvalue, GroupViewRoles::ProgressValueRole);
if(newvalue >= maximum)
{
toRemove.append(item);
}
}
for(auto remove : toRemove)
{
m_items.removeAll(remove);
}
}
private:
QList<QStandardItem *> m_items;
};
|