Commit 40bae63c authored by Roberto Raggi's avatar Roberto Raggi

Don't wait for the dependencyTable computation in the GUI thread.

Done-with: Erik Verbruggen
parent 64bba7ed
......@@ -157,6 +157,8 @@ CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelMa
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
connect(&m_watchDependencyTable, SIGNAL(finished()), this, SLOT(dependencyTableUpdated()));
m_updateDependencyTableTimer = new QTimer(this);
m_updateDependencyTableTimer->setSingleShot(true);
m_updateDependencyTableTimer->setInterval(2000);
......@@ -188,11 +190,10 @@ static void find_helper(QFutureInterface<Usage> &future,
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy,
Snapshot snapshot,
Document::Ptr symbolDocument,
DependencyTable dependencyTable,
QFuture<DependencyTable> dependencyTableFuture,
Symbol *symbol)
{
QTime tm;
tm.start();
const DependencyTable dependencyTable = dependencyTableFuture;
const Identifier *symbolId = symbol->identifier();
Q_ASSERT(symbolId != 0);
......@@ -226,7 +227,7 @@ static void find_helper(QFutureInterface<Usage> &future,
future.setProgressValue(files.size());
}
static CPlusPlus::DependencyTable dependencyTable(DependencyTable previous, CPlusPlus::Snapshot snapshot)
static CPlusPlus::DependencyTable dependencyTable_helper(DependencyTable previous, CPlusPlus::Snapshot snapshot)
{
if (previous.isValidFor(snapshot))
return previous;
......@@ -238,8 +239,14 @@ static CPlusPlus::DependencyTable dependencyTable(DependencyTable previous, CPlu
void CppFindReferences::updateDependencyTable()
{
m_depsFuture.cancel();
m_depsFuture = QtConcurrent::run(&dependencyTable, m_deps, _modelManager->snapshot());
m_dependencyTableFuture.cancel();
m_dependencyTableFuture = QtConcurrent::run(&dependencyTable_helper, m_deps, _modelManager->snapshot());
m_watchDependencyTable.setFuture(m_dependencyTableFuture);
}
void CppFindReferences::dependencyTableUpdated()
{
m_deps = m_dependencyTableFuture;
}
void CppFindReferences::findUsages(Document::Ptr symbolDocument, Symbol *symbol)
......@@ -283,11 +290,10 @@ void CppFindReferences::findAll_helper(Document::Ptr symbolDocument, Symbol *sym
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
updateDependencyTable(); // ensure the dependency table is updated
m_deps = m_depsFuture;
QFuture<Usage> result;
result = QtConcurrent::run(&find_helper, workingCopy, snapshot, symbolDocument, m_deps, symbol);
result = QtConcurrent::run(&find_helper, workingCopy, snapshot, symbolDocument, m_dependencyTableFuture, symbol);
m_watcher.setFuture(result);
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
......@@ -405,9 +411,10 @@ public:
static void findMacroUses_helper(QFutureInterface<Usage> &future,
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy,
const Snapshot snapshot,
DependencyTable dependencyTable,
QFuture<DependencyTable> dependencyTableFuture,
const Macro macro)
{
const DependencyTable dependencyTable = dependencyTableFuture;
const QString& sourceFile = macro.fileName();
QStringList files(sourceFile);
files += dependencyTable.filesDependingOn(sourceFile);
......@@ -443,10 +450,9 @@ void CppFindReferences::findMacroUses(const Macro &macro)
}
updateDependencyTable(); // ensure the dependency table is updated
m_deps = m_depsFuture;
QFuture<Usage> result;
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, m_deps, macro);
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, m_dependencyTableFuture, macro);
m_watcher.setFuture(result);
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
......
......@@ -78,6 +78,7 @@ private Q_SLOTS:
void openEditor(const Find::SearchResultItem &item);
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
void updateDependencyTable();
void dependencyTableUpdated();
private:
void findAll_helper(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol);
......@@ -86,8 +87,9 @@ private:
QPointer<CppModelManagerInterface> _modelManager;
Find::SearchResultWindow *_resultWindow;
QFutureWatcher<CPlusPlus::Usage> m_watcher;
QFutureWatcher<CPlusPlus::DependencyTable> m_watchDependencyTable;
CPlusPlus::DependencyTable m_deps;
QFuture<CPlusPlus::DependencyTable> m_depsFuture;
QFuture<CPlusPlus::DependencyTable> m_dependencyTableFuture;
QTimer *m_updateDependencyTableTimer;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment