diff options
author | Eike Ziller <eike.ziller@nokia.com> | 2011-12-15 08:01:58 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@nokia.com> | 2011-12-20 12:03:59 +0100 |
commit | 4de9fd8dac02cf8bbfa696bb8ab77d4df192cbba (patch) | |
tree | e36fcb00035239183a3889f76736b026224f8d8b /src/plugins/cpptools/symbolsfindfilter.cpp | |
parent | 26d8b8753c365899415e8c3acc42ead5deeef260 (diff) | |
download | qt-creator-4de9fd8dac02cf8bbfa696bb8ab77d4df192cbba.tar.gz |
Implement "Search Again" for symbol search.
Task-number: QTCREATORBUG-621
Change-Id: I4bd39c88afc1df93712b1d9a76f875516c657f3d
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
Diffstat (limited to 'src/plugins/cpptools/symbolsfindfilter.cpp')
-rw-r--r-- | src/plugins/cpptools/symbolsfindfilter.cpp | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/src/plugins/cpptools/symbolsfindfilter.cpp b/src/plugins/cpptools/symbolsfindfilter.cpp index 8b4b94b98e..e29528ad81 100644 --- a/src/plugins/cpptools/symbolsfindfilter.cpp +++ b/src/plugins/cpptools/symbolsfindfilter.cpp @@ -59,22 +59,24 @@ namespace { const char * const SETTINGS_SEARCHSCOPE = "SearchScope"; void runSearch(QFutureInterface<Find::SearchResultItem> &future, - QString txt, Find::FindFlags findFlags, CPlusPlus::Snapshot snapshot, - SearchSymbols::SymbolTypes types, QSet<QString> fileNames) + SymbolsFindParameters parameters, CPlusPlus::Snapshot snapshot, + QSet<QString> fileNames) { future.setProgressRange(0, snapshot.size()); future.setProgressValue(0); int progress = 0; SearchSymbols search; - search.setSymbolsToSearchFor(types); + search.setSymbolsToSearchFor(parameters.types); search.setSeparateScope(true); CPlusPlus::Snapshot::const_iterator it = snapshot.begin(); - QString findString = (findFlags & Find::FindRegularExpression ? txt : QRegExp::escape(txt)); - if (findFlags & Find::FindWholeWords) + QString findString = (parameters.flags & Find::FindRegularExpression + ? parameters.text : QRegExp::escape(parameters.text)); + if (parameters.flags & Find::FindWholeWords) findString = QString::fromLatin1("\\b%1\\b").arg(findString); - QRegExp matcher(findString, (findFlags & Find::FindCaseSensitively ? Qt::CaseSensitive : Qt::CaseInsensitive)); + QRegExp matcher(findString, (parameters.flags & Find::FindCaseSensitively + ? Qt::CaseSensitive : Qt::CaseInsensitive)); while (it != snapshot.end() && !future.isCanceled()) { if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) { QVector<Find::SearchResultItem> resultItems; @@ -82,7 +84,8 @@ namespace { foreach (const ModelItemInfo &info, modelInfos) { int index = matcher.indexIn(info.symbolName); if (index != -1) { - QStringList path = info.fullyQualifiedName.mid(0, info.fullyQualifiedName.size() - 1); + QStringList path = info.fullyQualifiedName.mid(0, + info.fullyQualifiedName.size() - 1); Find::SearchResultItem item; item.path = path; item.text = info.symbolName; @@ -150,12 +153,28 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) { Find::SearchResultWindow *window = Find::SearchResultWindow::instance(); Find::SearchResult *search = window->startNewSearch(label(), toolTip(findFlags), txt); - connect(search, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); + search->setSearchAgainSupported(true); + connect(search, SIGNAL(activated(Find::SearchResultItem)), + this, SLOT(openEditor(Find::SearchResultItem))); connect(search, SIGNAL(cancelled()), this, SLOT(cancel())); + connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain())); + connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool))); window->popup(true); + SymbolsFindParameters parameters; + parameters.text = txt; + parameters.flags = findFlags; + parameters.types = m_symbolsToSearch; + parameters.scope = m_scope; + search->setUserData(qVariantFromValue(parameters)); + startSearch(search); +} + +void SymbolsFindFilter::startSearch(Find::SearchResult *search) +{ + SymbolsFindParameters parameters = search->userData().value<SymbolsFindParameters>(); QSet<QString> projectFileNames; - if (m_scope == SymbolsFindFilter::SearchProjectsOnly) { + if (parameters.scope == SymbolsFindFilter::SearchProjectsOnly) { foreach (ProjectExplorer::Project *project, ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects()) { projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet(); @@ -168,10 +187,9 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) this, SLOT(finish())); connect(watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(addResults(int, int))); - watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, QString, - Find::FindFlags, CPlusPlus::Snapshot, - SearchSymbols::SymbolTypes, QSet<QString> >(runSearch, txt, findFlags, m_manager->snapshot(), - m_symbolsToSearch, projectFileNames)); + watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, SymbolsFindParameters, + CPlusPlus::Snapshot, QSet<QString> >(runSearch, parameters, + m_manager->snapshot(), projectFileNames)); Core::ICore::instance()->progressManager()->addTask(watcher->future(), tr("Searching"), Find::Constants::TASK_SEARCH); @@ -254,6 +272,14 @@ void SymbolsFindFilter::onAllTasksFinished(const QString &type) } } +void SymbolsFindFilter::searchAgain() +{ + Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender()); + QTC_ASSERT(search, return); + search->reset(); + startSearch(search); +} + QString SymbolsFindFilter::label() const { return tr("C++ Symbols:"); |