-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickVtkDispatcher.cpp
More file actions
130 lines (107 loc) · 3.11 KB
/
quickVtkDispatcher.cpp
File metadata and controls
130 lines (107 loc) · 3.11 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <quickVtkDispatcher.h>
#include <QtCore/QCoreApplication>
#include <algorithm>
namespace quick { namespace vtk {
void Dispatcher::aboutToBeDeleted()
{
for(auto p : qAsConst(m_aboutToBeDeleted))
p->aboutToBeDeleted();
}
/*-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-= */
QSet<SharedData*> SharedData::s_instances;
SharedData::SharedData()
{
s_instances.insert(this);
}
SharedData::~SharedData()
{
s_instances.remove(this);
}
bool SharedData::findDispatchers(std::function<bool(Dispatcher*)> f)
{
if (!m_quickVtkParents.size())
{
auto dispatcher = dynamic_cast<Dispatcher*>(this); if (dispatcher)
{
return f(dispatcher);
}
else
{
QString s; QDebug(&s) << this;
qFatal("YIKES!! I'm not a Dispatcher but I should be: %s", s.toStdString().c_str());
}
}
else
{
bool found = false; for(auto const& p : qAsConst(m_quickVtkParents))
{
if (p)
{
auto sharedData = dynamic_cast<SharedData*>(p.data()); if (sharedData)
{
if (sharedData->findDispatchers(f))
return true;
}
else
{
QString s; QDebug(&s) << p.data();
qFatal("YIKES!! found a non-SharedData parent: %s", s.toStdString().c_str());
}
found = true;
}
}
if (!found) {
QString s; QDebug(&s) << this;
qFatal("YIKES!! all my parents have been deleted: %s", s.toStdString().c_str());
}
}
return false;
}
void SharedData::refreshCaches()
{
m_dispatcher = nullptr;
findDispatchers([this](Dispatcher* d) {
m_dispatcher = d;
return true;
});
m_dispatchers.clear();
findDispatchers([this](Dispatcher *d) {
auto qobj = dynamic_cast<QObject*>(d); if (qobj) {
if (!m_dispatchers.contains(qobj))
m_dispatchers.append(qobj);
} else {
QString s; QDebug(&s) << d;
qFatal("YIKES!! this dispatcher is not a QObject but it should be: %s", s.toStdString().c_str());
}
return false;
});
m_dirtyCache = false;
}
Dispatcher* SharedData::dispatcher()
{
if (m_dirtyCache)
refreshCaches();
return m_dispatcher;
}
QVector<QPointer<QObject>> SharedData::dispatchers()
{
if (m_dirtyCache)
refreshCaches();
return m_dispatchers;
}
void SharedData::addVtkParent(QObject * qobj)
{
m_quickVtkParents.push_back(qobj);
for(auto pThis : qAsConst(s_instances))
pThis->m_dirtyCache = true;
}
void SharedData::delVtkParent(QObject * qobj)
{
if (auto i = std::find(m_quickVtkParents.begin(), m_quickVtkParents.end(), qobj); i != m_quickVtkParents.end())
m_quickVtkParents.erase(i);
else
qWarning() << "YIKES!! m_quickVtkParents.remove(qobj) FAILED: " << qobj;
for(auto pThis :qAsConst(s_instances))
pThis->m_dirtyCache = true;
}
} }