-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathve_qitem_init_monitor.cpp
86 lines (78 loc) · 1.98 KB
/
ve_qitem_init_monitor.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <QsLog.h>
#include <veutil/qt/ve_qitem.hpp>
#include "ve_qitem_init_monitor.h"
VeQItemInitMonitor::VeQItemInitMonitor(QObject *parent):
QObject(parent)
{
}
void VeQItemInitMonitor::addItem(VeQItem *item)
{
if (item->isLeaf()) {
mItems.append(item);
} else {
for (int i=0;;++i) {
VeQItem *child = item->itemChild(i);
if (child == 0)
break;
addItem(child);
}
}
}
void VeQItemInitMonitor::start()
{
updateState();
foreach (VeQItem *item, mItems) {
switch (item->getState()) {
case VeQItem::Idle:
item->getValue();
// Fall through
case VeQItem::Requested:
connect(item, SIGNAL(stateChanged(VeQItem::State)), this, SLOT(onStateChanged()));
break;
default:
// Do nothing
break;
}
}
}
bool VeQItemInitMonitor::checkState()
{
if (mItems.isEmpty())
return true;
foreach (VeQItem *item, mItems) {
VeQItem::State state = item->getState();
if (state == VeQItem::Idle || state == VeQItem::Requested)
return false;
}
return true;
}
void VeQItemInitMonitor::monitor(VeQItem *item, QObject *dest, const char *slot,
Qt::ConnectionType connectionType)
{
VeQItemInitMonitor *monitor = new VeQItemInitMonitor(dest);
connect(monitor, SIGNAL(initialized()), dest, slot, connectionType);
connect(monitor, SIGNAL(initialized()), monitor, SLOT(deleteLater()), connectionType);
monitor->addItem(item);
monitor->start();
}
void VeQItemInitMonitor::monitor(const QList<VeQItem *> &items, QObject *dest, const char *slot,
Qt::ConnectionType connectionType)
{
VeQItemInitMonitor *monitor = new VeQItemInitMonitor(dest);
connect(monitor, SIGNAL(initialized()), dest, slot, connectionType);
connect(monitor, SIGNAL(initialized()), monitor, SLOT(deleteLater()), connectionType);
foreach(VeQItem *item, items)
monitor->addItem(item);
monitor->start();
}
void VeQItemInitMonitor::onStateChanged()
{
updateState();
}
void VeQItemInitMonitor::updateState()
{
if (mItems.isEmpty() || !checkState())
return;
mItems.clear();
emit initialized();
}