pollymc/main.h

55 lines
1.1 KiB
C
Raw Normal View History

2014-02-01 03:21:45 +05:30
#pragma once
2013-12-31 04:09:10 +05:30
#include <QObject>
#include <QTimer>
#include <QList>
#include <QStandardItem>
#include <QDebug>
2014-02-01 03:21:45 +05:30
#include "GroupView.h"
2013-12-31 04:09:10 +05:30
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;
}
2014-02-01 03:21:45 +05:30
public
slots:
2013-12-31 04:09:10 +05:30
void timeout()
{
2014-02-02 14:56:38 +05:30
QList<QStandardItem *> toRemove;
2014-02-01 03:28:57 +05:30
for (auto item : m_items)
2013-12-31 04:09:10 +05:30
{
2014-02-02 14:56:38 +05:30
int maximum = item->data(CategorizedViewRoles::ProgressMaximumRole).toInt();
2013-12-31 04:09:10 +05:30
int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
2014-02-02 14:56:38 +05:30
int newvalue = std::min(value + 3, maximum);
item->setData(newvalue, CategorizedViewRoles::ProgressValueRole);
if(newvalue >= maximum)
2013-12-31 04:09:10 +05:30
{
2014-02-02 14:56:38 +05:30
toRemove.append(item);
2013-12-31 04:09:10 +05:30
}
}
2014-02-02 14:56:38 +05:30
for(auto remove : toRemove)
{
m_items.removeAll(remove);
}
2013-12-31 04:09:10 +05:30
}
private:
QList<QStandardItem *> m_items;
};