30 #include <QtCore/QWriteLocker>
152 using namespace Aggregation;
161 QReadLocker locker(&
lock());
162 return aggregateMap().value(obj);
165 QHash<QObject *, Aggregate *> &Aggregate::aggregateMap()
167 static QHash<QObject *, Aggregate *> map;
177 static QReadWriteLock
lock;
191 QWriteLocker locker(&
lock());
192 aggregateMap().insert(
this,
this);
202 QWriteLocker locker(&
lock());
203 foreach (QObject *
component, m_components) {
204 disconnect(component, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteSelf(QObject*)));
205 aggregateMap().remove(component);
207 qDeleteAll(m_components);
208 m_components.clear();
209 aggregateMap().remove(
this);
212 void Aggregate::deleteSelf(QObject *obj)
215 QWriteLocker locker(&
lock());
216 aggregateMap().remove(obj);
217 m_components.removeAll(obj);
233 QWriteLocker locker(&
lock());
234 Aggregate *parentAggregation = aggregateMap().value(component);
235 if (parentAggregation ==
this)
237 if (parentAggregation)
238 parentAggregation->
remove(component);
239 m_components.append(component);
240 connect(component, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteSelf(QObject*)));
241 aggregateMap().insert(component,
this);
255 QWriteLocker locker(&
lock());
256 aggregateMap().remove(component);
257 m_components.removeAll(component);
258 disconnect(component, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteSelf(QObject*)));
Aggregate(QObject *parent=0)
static Aggregate * parentAggregate(QObject *obj)
Defines a collection of related components that can be viewed as a unit.
void remove(QObject *component)
void add(QObject *component)
static QReadWriteLock & lock()