-
Notifications
You must be signed in to change notification settings - Fork 75
/
qfapplistenergroup.cpp
78 lines (61 loc) · 1.67 KB
/
qfapplistenergroup.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
#include <QFAppDispatcher>
#include "qfapplistenergroup.h"
#include "qfapplistener.h"
#include "priv/qflistener.h"
QFAppListenerGroup::QFAppListenerGroup(QQuickItem* parent) : QQuickItem(parent)
{
m_listenerId = 0;
m_listener = 0;
}
QList<int> QFAppListenerGroup::listenerIds() const
{
return m_listenerIds;
}
void QFAppListenerGroup::setListenerIds(const QList<int> &listenerIds)
{
m_listenerIds = listenerIds;
emit listenerIdsChanged();
}
void QFAppListenerGroup::componentComplete()
{
QQuickItem::componentComplete();
QQmlEngine *engine = qmlEngine(this);
Q_ASSERT(engine);
QFAppDispatcher* dispatcher = QFAppDispatcher::instance(engine);
m_listener = new QFListener(this);
m_listenerId = dispatcher->addListener(m_listener);
setListenerWaitFor();
QList<int> ids = search(this);
setListenerIds(ids);
}
QList<int> QFAppListenerGroup::search(QQuickItem *item)
{
QList<int> res;
QFAppListener* listener = qobject_cast<QFAppListener*>(item);
if (listener) {
res.append(listener->listenerId());
listener->setWaitFor(QList<int>() << m_listenerId);
}
QList<QQuickItem *> childs = item->childItems();
for (int i = 0 ; i < childs.size() ; i++) {
QList<int> subRes = search(childs.at(i));
if (subRes.size() > 0) {
res.append(subRes);
}
}
return res;
}
void QFAppListenerGroup::setListenerWaitFor()
{
m_listener->setWaitFor(m_waitFor);
}
QList<int> QFAppListenerGroup::waitFor() const
{
return m_waitFor;
}
void QFAppListenerGroup::setWaitFor(const QList<int> &waitFor)
{
m_waitFor = waitFor;
setListenerWaitFor();
emit waitForChanged();
}