Move and cleanup search specific API to SearchResult class

Change-Id: I7e64701e8833ad38b9ac01d316bd00302602a390
Rubber-stamped-by: Daniel Teske
Reviewed-on: http://codereview.qt.nokia.com/4179
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Eike Ziller
2011-09-02 11:51:31 +02:00
parent 3fb2e7246e
commit 0594887dea
24 changed files with 216 additions and 143 deletions

View File

@@ -162,7 +162,7 @@ public:
CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager)
: QObject(modelManager),
_modelManager(modelManager),
_resultWindow(Find::SearchResultWindow::instance())
m_currentSearch(0)
{
m_watcher.setPendingResultsLimit(1);
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
@@ -227,9 +227,9 @@ static void find_helper(QFutureInterface<Usage> &future,
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context)
{
Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly);
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly);
connect(search, SIGNAL(activated(Find::SearchResultItem)),
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
findAll_helper(symbol, context);
@@ -242,14 +242,14 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus:
const QString textToReplace = replacement.isEmpty()
? QString::fromUtf8(id->chars(), id->size()) : replacement;
Find::SearchResult *search = _resultWindow->startNewSearch(
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor"));
_resultWindow->setTextToReplace(textToReplace);
m_currentSearch->setTextToReplace(textToReplace);
connect(search, SIGNAL(activated(Find::SearchResultItem)),
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
findAll_helper(symbol, context);
@@ -261,7 +261,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont
if (! (symbol && symbol->identifier()))
return;
_resultWindow->popup(true);
Find::SearchResultWindow::instance()->popup(true);
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
@@ -275,7 +275,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
CppTools::Constants::TASK_SEARCH);
connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup()));
connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
}
void CppFindReferences::onReplaceButtonClicked(const QString &text,
@@ -284,7 +284,7 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items);
if (!fileNames.isEmpty()) {
_modelManager->updateSourceFiles(fileNames);
_resultWindow->hide();
Find::SearchResultWindow::instance()->hide();
}
}
@@ -292,7 +292,7 @@ void CppFindReferences::displayResults(int first, int last)
{
for (int index = first; index != last; ++index) {
Usage result = m_watcher.future().resultAt(index);
_resultWindow->addResult(result.path,
m_currentSearch->addResult(result.path,
result.line,
result.lineText,
result.col,
@@ -302,7 +302,8 @@ void CppFindReferences::displayResults(int first, int last)
void CppFindReferences::searchFinished()
{
_resultWindow->finishSearch();
m_currentSearch->finishSearch();
m_currentSearch = 0;
emit changed();
}
@@ -413,11 +414,11 @@ static void findMacroUses_helper(QFutureInterface<Usage> &future,
void CppFindReferences::findMacroUses(const Macro &macro)
{
Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly);
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly);
_resultWindow->popup(true);
Find::SearchResultWindow::instance()->popup(true);
connect(search, SIGNAL(activated(Find::SearchResultItem)),
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
const Snapshot snapshot = _modelManager->snapshot();
@@ -427,7 +428,7 @@ void CppFindReferences::findMacroUses(const Macro &macro)
{
// ### FIXME: Encoding?
const QByteArray &source = getSource(macro.fileName(), workingCopy).toLatin1();
_resultWindow->addResult(macro.fileName(), macro.line(),
m_currentSearch->addResult(macro.fileName(), macro.line(),
source.mid(macro.offset(), macro.length()), 0, macro.length());
}
@@ -438,7 +439,7 @@ void CppFindReferences::findMacroUses(const Macro &macro)
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
CppTools::Constants::TASK_SEARCH);
connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup()));
connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
}
DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot snapshot)

View File

@@ -46,8 +46,8 @@
QT_FORWARD_DECLARE_CLASS(QTimer)
namespace Find {
class SearchResultWindow;
struct SearchResultItem;
class SearchResult;
} // namespace Find
namespace CPlusPlus {
@@ -92,7 +92,7 @@ private:
private:
QPointer<CPlusPlus::CppModelManagerInterface> _modelManager;
Find::SearchResultWindow *_resultWindow;
Find::SearchResult *m_currentSearch;
QFutureWatcher<CPlusPlus::Usage> m_watcher;
mutable QMutex m_depsLock;

View File

@@ -102,10 +102,11 @@ namespace {
SymbolsFindFilter::SymbolsFindFilter(CppModelManager *manager)
: m_manager(manager),
m_isRunning(false),
m_enabled(true),
m_symbolsToSearch(SearchSymbols::AllTypes),
m_scope(SearchProjectsOnly)
m_isRunning(false),
m_enabled(true),
m_currentSearch(0),
m_symbolsToSearch(SearchSymbols::AllTypes),
m_scope(SearchProjectsOnly)
{
// for disabling while parser is running
connect(Core::ICore::instance()->progressManager(), SIGNAL(taskStarted(QString)),
@@ -154,8 +155,8 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
m_isRunning = true;
emit changed();
Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
Find::SearchResult *result = window->startNewSearch();
connect(result, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
m_currentSearch = window->startNewSearch();
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
window->popup(true);
m_search.setSymbolsToSearchFor(m_symbolsToSearch);
@@ -179,17 +180,16 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
void SymbolsFindFilter::addResults(int begin, int end)
{
Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
QList<Find::SearchResultItem> items;
for (int i = begin; i < end; ++i)
items << m_watcher.resultAt(i);
window->addResults(items, Find::SearchResultWindow::AddSorted);
m_currentSearch->addResults(items, Find::SearchResult::AddSorted);
}
void SymbolsFindFilter::finish()
{
Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
window->finishSearch();
m_currentSearch->finishSearch();
m_currentSearch = 0;
m_isRunning = false;
emit changed();
}

View File

@@ -95,6 +95,7 @@ private:
bool m_isRunning;
bool m_enabled;
QFutureWatcher<Find::SearchResultItem> m_watcher;
Find::SearchResult *m_currentSearch;
SearchSymbols::SymbolTypes m_symbolsToSearch;
SearchSymbols m_search;
SearchScope m_scope;