From d3b58c2db3aa305dc4173c4d2cc949ac66ad5e0c Mon Sep 17 00:00:00 2001 From: Nicolas Arnaud-Cormos <nicolas@kdab.com> Date: Mon, 17 May 2010 09:58:36 +0200 Subject: [PATCH] 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> --- src/libs/aggregation/aggregate.cpp | 32 ++++++++++------- src/libs/aggregation/aggregate.h | 3 ++ src/plugins/find/currentdocumentfind.cpp | 46 ++++++++++++++++++++++-- src/plugins/find/currentdocumentfind.h | 4 ++- 4 files changed, 68 insertions(+), 17 deletions(-) diff --git a/src/libs/aggregation/aggregate.cpp b/src/libs/aggregation/aggregate.cpp index a4c00e86384..03f23e629bc 100644 --- a/src/libs/aggregation/aggregate.cpp +++ b/src/libs/aggregation/aggregate.cpp @@ -232,15 +232,18 @@ void Aggregate::add(QObject *component) { if (!component) return; - QWriteLocker locker(&lock()); - Aggregate *parentAggregation = aggregateMap().value(component); - if (parentAggregation == this) - return; - if (parentAggregation) - parentAggregation->remove(component); - m_components.append(component); - connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); - aggregateMap().insert(component, this); + { + QWriteLocker locker(&lock()); + Aggregate *parentAggregation = aggregateMap().value(component); + if (parentAggregation == this) + return; + if (parentAggregation) + parentAggregation->remove(component); + m_components.append(component); + connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); + aggregateMap().insert(component, this); + } + emit changed(); } /*! @@ -254,8 +257,11 @@ void Aggregate::remove(QObject *component) { if (!component) return; - QWriteLocker locker(&lock()); - aggregateMap().remove(component); - m_components.removeAll(component); - disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); + { + QWriteLocker locker(&lock()); + aggregateMap().remove(component); + m_components.removeAll(component); + disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); + } + emit changed(); } diff --git a/src/libs/aggregation/aggregate.h b/src/libs/aggregation/aggregate.h index 6bd36dffa50..c3240f8de0f 100644 --- a/src/libs/aggregation/aggregate.h +++ b/src/libs/aggregation/aggregate.h @@ -74,6 +74,9 @@ public: static Aggregate *parentAggregate(QObject *obj); static QReadWriteLock &lock(); +signals: + void changed(); + private slots: void deleteSelf(QObject *obj); diff --git a/src/plugins/find/currentdocumentfind.cpp b/src/plugins/find/currentdocumentfind.cpp index 728a73dec54..0ca72b834a7 100644 --- a/src/plugins/find/currentdocumentfind.cpp +++ b/src/plugins/find/currentdocumentfind.cpp @@ -154,8 +154,14 @@ void CurrentDocumentFind::updateCandidateFindFilter(QWidget *old, QWidget *now) if (!impl) candidate = candidate->parentWidget(); } + if (m_candidateWidget) + disconnect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()), + this, SLOT(candidateAggregationChanged())); m_candidateWidget = candidate; m_candidateFind = impl; + if (m_candidateWidget) + connect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()), + this, SLOT(candidateAggregationChanged())); emit candidateChanged(); } @@ -166,11 +172,18 @@ void CurrentDocumentFind::acceptCandidate() removeFindSupportConnections(); if (m_currentFind) m_currentFind->highlightAll(QString(), 0); + + if (m_currentWidget) + disconnect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()), + this, SLOT(aggregationChanged())); m_currentWidget = m_candidateWidget; + connect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()), + this, SLOT(aggregationChanged())); + m_currentFind = m_candidateFind; if (m_currentFind) { 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) m_currentWidget->installEventFilter(this); @@ -181,13 +194,13 @@ void CurrentDocumentFind::removeFindSupportConnections() { if (m_currentFind) { 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) m_currentWidget->removeEventFilter(this); } -void CurrentDocumentFind::findSupportDestroyed() +void CurrentDocumentFind::clearFindSupport() { removeFindSupportConnections(); m_currentWidget = 0; @@ -213,3 +226,30 @@ bool CurrentDocumentFind::eventFilter(QObject *obj, QEvent *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(); + } +} diff --git a/src/plugins/find/currentdocumentfind.h b/src/plugins/find/currentdocumentfind.h index 6e3def7791d..f104ef5f4b1 100644 --- a/src/plugins/find/currentdocumentfind.h +++ b/src/plugins/find/currentdocumentfind.h @@ -75,7 +75,9 @@ signals: private slots: void updateCandidateFindFilter(QWidget *old, QWidget *now); - void findSupportDestroyed(); + void clearFindSupport(); + void aggregationChanged(); + void candidateAggregationChanged(); private: void removeFindSupportConnections(); -- GitLab