summaryrefslogtreecommitdiffstats
path: root/main.h
blob: f4c7a3f89a9787f8a72df34f77af6dc7a1b4edf1 (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
#ifndef MAIN_H
#define MAIN_H

#include <QObject>
#include <QTimer>
#include <QList>
#include <QStandardItem>
#include <QDebug>

#include "CategorizedView.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, CategorizedViewRoles::ProgressMaximumRole);
		m_items.append(item);
		return item;
	}

public slots:
	void timeout()
	{
		foreach (QStandardItem *item, m_items)
		{
			int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
			value += qrand() % 3;
			if (value >= item->data(CategorizedViewRoles::ProgressMaximumRole).toInt())
			{
				item->setData(item->data(CategorizedViewRoles::ProgressMaximumRole).toInt(),
							  CategorizedViewRoles::ProgressValueRole);
			}
			else
			{
				item->setData(value, CategorizedViewRoles::ProgressValueRole);
			}
		}
	}

private:
	QList<QStandardItem *> m_items;
};

#endif // MAIN_H