Add a changed signal in Aggregation

Use it to change the find and candidate find object in CurrentDocumentFind:
this will allow to replace the IFindSupport object used.

Merge-request: 115
Reviewed-by: con <qtc-committer@nokia.com>
This commit is contained in:
Nicolas Arnaud-Cormos
2010-05-17 09:58:36 +02:00
committed by con
parent e2297e4cbd
commit d3b58c2db3
4 changed files with 68 additions and 17 deletions

View File

@@ -232,6 +232,7 @@ void Aggregate::add(QObject *component)
{ {
if (!component) if (!component)
return; return;
{
QWriteLocker locker(&lock()); QWriteLocker locker(&lock());
Aggregate *parentAggregation = aggregateMap().value(component); Aggregate *parentAggregation = aggregateMap().value(component);
if (parentAggregation == this) if (parentAggregation == this)
@@ -241,6 +242,8 @@ void Aggregate::add(QObject *component)
m_components.append(component); m_components.append(component);
connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*)));
aggregateMap().insert(component, this); aggregateMap().insert(component, this);
}
emit changed();
} }
/*! /*!
@@ -254,8 +257,11 @@ void Aggregate::remove(QObject *component)
{ {
if (!component) if (!component)
return; return;
{
QWriteLocker locker(&lock()); QWriteLocker locker(&lock());
aggregateMap().remove(component); aggregateMap().remove(component);
m_components.removeAll(component); m_components.removeAll(component);
disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*)));
}
emit changed();
} }

View File

@@ -74,6 +74,9 @@ public:
static Aggregate *parentAggregate(QObject *obj); static Aggregate *parentAggregate(QObject *obj);
static QReadWriteLock &lock(); static QReadWriteLock &lock();
signals:
void changed();
private slots: private slots:
void deleteSelf(QObject *obj); void deleteSelf(QObject *obj);

View File

@@ -154,8 +154,14 @@ void CurrentDocumentFind::updateCandidateFindFilter(QWidget *old, QWidget *now)
if (!impl) if (!impl)
candidate = candidate->parentWidget(); candidate = candidate->parentWidget();
} }
if (m_candidateWidget)
disconnect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()),
this, SLOT(candidateAggregationChanged()));
m_candidateWidget = candidate; m_candidateWidget = candidate;
m_candidateFind = impl; m_candidateFind = impl;
if (m_candidateWidget)
connect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()),
this, SLOT(candidateAggregationChanged()));
emit candidateChanged(); emit candidateChanged();
} }
@@ -166,11 +172,18 @@ void CurrentDocumentFind::acceptCandidate()
removeFindSupportConnections(); removeFindSupportConnections();
if (m_currentFind) if (m_currentFind)
m_currentFind->highlightAll(QString(), 0); m_currentFind->highlightAll(QString(), 0);
if (m_currentWidget)
disconnect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()),
this, SLOT(aggregationChanged()));
m_currentWidget = m_candidateWidget; m_currentWidget = m_candidateWidget;
connect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()),
this, SLOT(aggregationChanged()));
m_currentFind = m_candidateFind; m_currentFind = m_candidateFind;
if (m_currentFind) { if (m_currentFind) {
connect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed())); connect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed()));
connect(m_currentFind, SIGNAL(destroyed(QObject*)), SLOT(findSupportDestroyed())); connect(m_currentFind, SIGNAL(destroyed(QObject*)), SLOT(clearFindSupport()));
} }
if (m_currentWidget) if (m_currentWidget)
m_currentWidget->installEventFilter(this); m_currentWidget->installEventFilter(this);
@@ -181,13 +194,13 @@ void CurrentDocumentFind::removeFindSupportConnections()
{ {
if (m_currentFind) { if (m_currentFind) {
disconnect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed())); disconnect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed()));
disconnect(m_currentFind, SIGNAL(destroyed(QObject*)), this, SLOT(findSupportDestroyed())); disconnect(m_currentFind, SIGNAL(destroyed(QObject*)), this, SLOT(clearFindSupport()));
} }
if (m_currentWidget) if (m_currentWidget)
m_currentWidget->removeEventFilter(this); m_currentWidget->removeEventFilter(this);
} }
void CurrentDocumentFind::findSupportDestroyed() void CurrentDocumentFind::clearFindSupport()
{ {
removeFindSupportConnections(); removeFindSupportConnections();
m_currentWidget = 0; m_currentWidget = 0;
@@ -213,3 +226,30 @@ bool CurrentDocumentFind::eventFilter(QObject *obj, QEvent *event)
} }
return QObject::eventFilter(obj, event); return QObject::eventFilter(obj, event);
} }
void CurrentDocumentFind::aggregationChanged()
{
if (m_currentWidget) {
QPointer<IFindSupport> currentFind = Aggregation::query<IFindSupport>(m_currentWidget);
if (currentFind != m_currentFind) {
// There's a change in the find support
if (currentFind) {
m_candidateWidget = m_currentWidget;
m_candidateFind = currentFind;
acceptCandidate();
}
else {
clearFindSupport();
m_currentFind = 0;
}
}
}
}
void CurrentDocumentFind::candidateAggregationChanged()
{
if (m_candidateWidget && m_candidateWidget!=m_currentWidget) {
m_candidateFind = Aggregation::query<IFindSupport>(m_candidateWidget);
emit candidateChanged();
}
}

View File

@@ -75,7 +75,9 @@ signals:
private slots: private slots:
void updateCandidateFindFilter(QWidget *old, QWidget *now); void updateCandidateFindFilter(QWidget *old, QWidget *now);
void findSupportDestroyed(); void clearFindSupport();
void aggregationChanged();
void candidateAggregationChanged();
private: private:
void removeFindSupportConnections(); void removeFindSupportConnections();