28 #ifndef QAGGREGATION_H
29 #define QAGGREGATION_H
33 #include <QtCore/QObject>
34 #include <QtCore/QList>
35 #include <QtCore/QHash>
36 #include <QtCore/QReadWriteLock>
37 #include <QtCore/QReadLocker>
39 namespace Aggregation {
49 void add(QObject *component);
50 void remove(QObject *component);
54 foreach (QObject *component, m_components) {
55 if (T *result = qobject_cast<T *>(component))
64 foreach (QObject *component, m_components) {
65 if (T *result = qobject_cast<T *>(component)) {
72 static Aggregate *parentAggregate(QObject *obj);
73 static QReadWriteLock &lock();
76 void deleteSelf(QObject *obj);
79 static QHash<QObject *, Aggregate *> &aggregateMap();
89 return obj->template component<T>();
92 template <
typename T> T *
query(QObject *obj)
96 T *result = qobject_cast<T *>(obj);
100 result = (parentAggregation ? query<T>(parentAggregation) : 0);
110 return obj->template components<T>();
117 QReadLocker(&lock());
120 if (parentAggregation)
121 results = query_all<T>(parentAggregation);
122 else if (T *result = qobject_cast<T *>(obj))
123 results.append(result);
129 #endif // QAGGREGATION_H
static Aggregate * parentAggregate(QObject *obj)
Defines a collection of related components that can be viewed as a unit.
T * query(Aggregate *obj)
end function found on Matlab s file exchange The two functions return identical results
QList< T * > query_all(Aggregate *obj)
QList< T * > components()