diff --git a/src/libs/cplusplus/DependencyTable.cpp b/src/libs/cplusplus/DependencyTable.cpp index 20871e5b52e32deaa25e527edf24a6689ae3e6f8..ebf4776c3189118fca763c5de9e3a3d0bb43640f 100644 --- a/src/libs/cplusplus/DependencyTable.cpp +++ b/src/libs/cplusplus/DependencyTable.cpp @@ -74,9 +74,7 @@ QHash<QString, QStringList> DependencyTable::dependencyTable() const bool DependencyTable::isValidFor(const Snapshot &snapshot) const { const int documentCount = snapshot.size(); - if (documentCount != files.size() - || documentCount != includesPerFile.size() - || documentCount != includeMap.size()) + if (documentCount != files.size()) return false; for (Snapshot::const_iterator it = snapshot.begin(); it != snapshot.end(); ++it) { @@ -93,6 +91,12 @@ bool DependencyTable::isValidFor(const Snapshot &snapshot) const void DependencyTable::build(const Snapshot &snapshot) { + includesPerFile.clear(); + files.clear(); + fileIndex.clear(); + includes.clear(); + includeMap.clear(); + const int documentCount = snapshot.size(); files.resize(documentCount); includeMap.resize(documentCount); diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 3a034b0a85b1c2b0c910274bb9cb73d4bf0f781e..97052e6a5ee9096c3834f62da62ba33728efc576 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -54,6 +54,7 @@ #include <cplusplus/Overview.h> #include <QtCore/QTime> +#include <QtCore/QTimer> #include <QtCore/QtConcurrentRun> #include <QtCore/QtConcurrentMap> #include <QtCore/QDir> @@ -154,6 +155,14 @@ CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelMa m_watcher.setPendingResultsLimit(1); connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int))); connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished())); + + m_updateDependencyTableTimer = new QTimer(this); + m_updateDependencyTableTimer->setSingleShot(true); + m_updateDependencyTableTimer->setInterval(2000); + connect(m_updateDependencyTableTimer, SIGNAL(timeout()), + this, SLOT(updateDependencyTable())); + connect(modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), + m_updateDependencyTableTimer, SLOT(start())); } CppFindReferences::~CppFindReferences() @@ -216,13 +225,20 @@ static void find_helper(QFutureInterface<Usage> &future, future.setProgressValue(files.size()); } -void CppFindReferences::updateDependencyTable(const Snapshot &snapshot) +static CPlusPlus::DependencyTable dependencyTable(DependencyTable previous, CPlusPlus::Snapshot snapshot) { - if (!m_deps.isValidFor(snapshot)) { - DependencyTable newDeps; - newDeps.build(snapshot); - m_deps = newDeps; - } + if (previous.isValidFor(snapshot)) + return previous; + + DependencyTable table; + table.build(snapshot); + return table; +} + +void CppFindReferences::updateDependencyTable() +{ + m_depsFuture.cancel(); + m_depsFuture = QtConcurrent::run(&dependencyTable, m_deps, _modelManager->snapshot()); } void CppFindReferences::findUsages(Document::Ptr symbolDocument, Symbol *symbol) @@ -265,7 +281,8 @@ void CppFindReferences::findAll_helper(Document::Ptr symbolDocument, Symbol *sym Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); - updateDependencyTable(snapshot); + updateDependencyTable(); // ensure the dependency table is updated + m_deps = m_depsFuture; QFuture<Usage> result; @@ -424,7 +441,8 @@ void CppFindReferences::findMacroUses(const Macro ¯o) source.mid(macro.offset(), macro.length()), 0, macro.length()); } - updateDependencyTable(snapshot); + updateDependencyTable(); // ensure the dependency table is updated + m_deps = m_depsFuture; QFuture<Usage> result; result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, m_deps, macro); diff --git a/src/plugins/cpptools/cppfindreferences.h b/src/plugins/cpptools/cppfindreferences.h index eae46c289a95ff79245e4ea0f01ef7517c48db10..f37d2b6643d0fac5338c930b979533d743089667 100644 --- a/src/plugins/cpptools/cppfindreferences.h +++ b/src/plugins/cpptools/cppfindreferences.h @@ -39,6 +39,8 @@ #include <cplusplus/DependencyTable.h> #include <cplusplus/FindUsages.h> +QT_FORWARD_DECLARE_CLASS(QTimer) + namespace Find { class SearchResultWindow; struct SearchResultItem; @@ -75,16 +77,18 @@ private Q_SLOTS: void searchFinished(); void openEditor(const Find::SearchResultItem &item); void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items); + void updateDependencyTable(); private: void findAll_helper(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol); - void updateDependencyTable(const CPlusPlus::Snapshot &snapshot); private: QPointer<CppModelManagerInterface> _modelManager; Find::SearchResultWindow *_resultWindow; QFutureWatcher<CPlusPlus::Usage> m_watcher; CPlusPlus::DependencyTable m_deps; + QFuture<CPlusPlus::DependencyTable> m_depsFuture; + QTimer *m_updateDependencyTableTimer; }; } // end of namespace Internal diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index d77ba3c0a7a6118b7539d8582b72be99c1ba3198..d8eee0da277a5ab466892fe3263936761f26e4aa 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -131,7 +131,6 @@ public: Q_SIGNALS: void projectPathChanged(const QString &projectPath); - void documentUpdated(CPlusPlus::Document::Ptr doc); void aboutToRemoveFiles(const QStringList &files); public Q_SLOTS: diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index 771340dc8edab226b0b530aefb95b6f05dff2095..eb3b151432c902ac2eef8633917fe8700abb2608 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -127,6 +127,9 @@ public: virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0; +Q_SIGNALS: + void documentUpdated(CPlusPlus::Document::Ptr doc); + public Q_SLOTS: void updateModifiedSourceFiles(); virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles) = 0;