Skip to content
Snippets Groups Projects
Commit d3b58c2d authored by Nicolas Arnaud-Cormos's avatar Nicolas Arnaud-Cormos Committed by con
Browse files

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: default avatarcon <qtc-committer@nokia.com>
parent e2297e4c
No related branches found
No related tags found
No related merge requests found
...@@ -232,15 +232,18 @@ void Aggregate::add(QObject *component) ...@@ -232,15 +232,18 @@ void Aggregate::add(QObject *component)
{ {
if (!component) if (!component)
return; return;
QWriteLocker locker(&lock()); {
Aggregate *parentAggregation = aggregateMap().value(component); QWriteLocker locker(&lock());
if (parentAggregation == this) Aggregate *parentAggregation = aggregateMap().value(component);
return; if (parentAggregation == this)
if (parentAggregation) return;
parentAggregation->remove(component); if (parentAggregation)
m_components.append(component); parentAggregation->remove(component);
connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); m_components.append(component);
aggregateMap().insert(component, this); connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*)));
aggregateMap().insert(component, this);
}
emit changed();
} }
/*! /*!
...@@ -254,8 +257,11 @@ void Aggregate::remove(QObject *component) ...@@ -254,8 +257,11 @@ void Aggregate::remove(QObject *component)
{ {
if (!component) if (!component)
return; return;
QWriteLocker locker(&lock()); {
aggregateMap().remove(component); QWriteLocker locker(&lock());
m_components.removeAll(component); aggregateMap().remove(component);
disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*))); m_components.removeAll(component);
disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(deleteSelf(QObject*)));
}
emit changed();
} }
...@@ -74,6 +74,9 @@ public: ...@@ -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);
......
...@@ -154,8 +154,14 @@ void CurrentDocumentFind::updateCandidateFindFilter(QWidget *old, QWidget *now) ...@@ -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() ...@@ -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() ...@@ -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) ...@@ -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();
}
}
...@@ -75,7 +75,9 @@ signals: ...@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment