QT creator源码分析 ----点击search后的动作
来源:互联网 发布:如何做金融投资 知乎 编辑:程序博客网 时间:2024/06/06 04:25
环境:源代码用的是qt-creator-opensource-src-3.4.1.tar.gz
此篇文章说明的的是在QT creator中,Ctrl+Shift+F,然后点击search后的动作
Ctrl+Shift+F,输入内容
点击search
在FindToolWindow的构造函数中
connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(search()));
void FindToolWindow::search(){ QString term; IFindFilter *filter = 0; acceptAndGetParameters(&term, &filter); QTC_ASSERT(filter, return); filter->findAll(term, m_plugin->findFlags());//BaseFileFind继承自IFindFilter}
void BaseFileFind::findAll(const QString &txt, FindFlags findFlags){ runNewSearch(txt, findFlags, SearchResultWindow::SearchOnly);}
void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags, SearchResultWindow::SearchMode searchMode){ d->m_currentFindSupport = 0; if (d->m_filterCombo) updateComboEntries(d->m_filterCombo, true); SearchResult *search = SearchResultWindow::instance()->startNewSearch(label(), toolTip().arg(IFindFilter::descriptionForFindFlags(findFlags)), txt, searchMode, SearchResultWindow::PreserveCaseEnabled, QString::fromLatin1("TextEditor")); //获取搜索框 search->setTextToReplace(txt); search->setSearchAgainSupported(true); FileFindParameters parameters; parameters.text = txt; parameters.flags = findFlags; parameters.nameFilters = fileNameFilters(); parameters.additionalParameters = additionalParameters(); search->setUserData(qVariantFromValue(parameters)); connect(search, SIGNAL(activated(Core::SearchResultItem)), this, SLOT(openEditor(Core::SearchResultItem)));//用编辑器打开 if (searchMode == SearchResultWindow::SearchAndReplace) { connect(search, SIGNAL(replaceButtonClicked(QString,QList<Core::SearchResultItem>,bool)), this, SLOT(doReplace(QString,QList<Core::SearchResultItem>,bool)));//文本替换 } connect(search, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool))); connect(search, SIGNAL(cancelled()), this, SLOT(cancel())); connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool))); connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));//再次搜索 connect(this, SIGNAL(enabledChanged(bool)), search, SIGNAL(requestEnabledCheck())); connect(search, SIGNAL(requestEnabledCheck()), this, SLOT(recheckEnabled())); runSearch(search);}
void BaseFileFind::runSearch(SearchResult *search){ FileFindParameters parameters = search->userData().value<FileFindParameters>(); CountingLabel *label = new CountingLabel; connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int))); CountingLabel *statusLabel = new CountingLabel; connect(search, SIGNAL(countChanged(int)), statusLabel, SLOT(updateCount(int)));//找到了新的搜索内容时更新条目信息 SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch|IOutputPane::WithFocus)); QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>(); d->m_watchers.insert(watcher, search); watcher->setPendingResultsLimit(1); connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));//显示搜索结果 connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished())); if (parameters.flags & FindRegularExpression) { watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), TextDocument::openedTextDocumentContents())); } else { watcher->setFuture(Utils::findInFiles(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), TextDocument::openedTextDocumentContents())); } FutureProgress *progress = ProgressManager::addTask(watcher->future(), tr("Searching"), Constants::TASK_SEARCH); progress->setWidget(label); progress->setStatusBarWidget(statusLabel); connect(progress, SIGNAL(clicked()), search, SLOT(popup()));}
void BaseFileFind::displayResult(int index) { QFutureWatcher<FileSearchResultList> *watcher = static_cast<QFutureWatcher<FileSearchResultList> *>(sender()); SearchResult *search = d->m_watchers.value(watcher); if (!search) { // search was removed from search history while the search is running watcher->cancel(); return; } FileSearchResultList results = watcher->resultAt(index); QList<SearchResultItem> items; foreach (const FileSearchResult &result, results) { SearchResultItem item; item.path = QStringList() << QDir::toNativeSeparators(result.fileName); item.lineNumber = result.lineNumber; item.text = result.matchingLine; item.textMarkLength = result.matchLength; item.textMarkPos = result.matchStart; item.useTextEditorFont = true; item.userData = result.regexpCapturedTexts; items << item; } search->addResults(items, SearchResult::AddOrdered);//增加搜索结果}
void SearchResult::addResults(const QList<SearchResultItem> &items, AddMode mode){ m_widget->addResults(items, mode); emit countChanged(m_widget->count());//发送信号变更统计的搜索条目}
↓↓双击打开编辑void BaseFileFind::openEditor(const SearchResultItem &item){ SearchResult *result = qobject_cast<SearchResult *>(sender()); IEditor *openedEditor = 0; if (item.path.size() > 0) { openedEditor = EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()), item.lineNumber, item.textMarkPos, Id(), EditorManager::DoNotSwitchToDesignMode); } else { openedEditor = EditorManager::openEditor(QDir::fromNativeSeparators(item.text)); } if (d->m_currentFindSupport) d->m_currentFindSupport->clearHighlights(); d->m_currentFindSupport = 0; if (!openedEditor) return; // highlight results if (IFindSupport *findSupport = Aggregation::query<IFindSupport>(openedEditor->widget())) { if (result) { FileFindParameters parameters = result->userData().value<FileFindParameters>(); d->m_currentFindSupport = findSupport; d->m_currentFindSupport->highlightAll(parameters.text, parameters.flags);//在编辑框中高亮搜索内容 } }}
void BaseTextFind::highlightAll(const QString &txt, FindFlags findFlags){ emit highlightAllRequested(txt, findFlags);}
在TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)中 connect(baseTextFind, &BaseTextFind::highlightAllRequested, this, &TextEditorWidgetPrivate::highlightSearchResultsSlot);
void TextEditorWidgetPrivate::highlightSearchResultsSlot(const QString &txt, FindFlags findFlags){ if (m_searchExpr.pattern() == txt) return; m_searchExpr.setPattern(txt); m_searchExpr.setPatternSyntax((findFlags & FindRegularExpression) ? QRegExp::RegExp : QRegExp::FixedString); m_searchExpr.setCaseSensitivity((findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); m_findFlags = findFlags; m_delayedUpdateTimer.start(50);//刷新}
0 0
- QT creator源码分析 ----点击search后的动作
- Qt Creator看不到源码
- Android 一次点击动作的分析
- qt-creator源码研究2
- Qt Creator的安装
- Qt creator 的使用
- Qt Creator的配置
- Qt Creator的使用
- QT的添加动作
- Qt creator 加入资源后无法使用
- qt-creator源码研究与调试
- Qt Creator应用程序的发布
- Qt Creator 所有的快捷键
- Qt creator的下载地址
- Qt Creator的pro文件格式
- 一、qt creator的使用
- 对Qt Creator的认识
- Qt Creator:QSqlTableModel的进阶
- Java内存模型——锁
- 找出字串的最长重复子串
- IIS下虚拟目录或应用程序不继承根web.config的解决方法
- java基础回顾加强
- Mybatis接口在service注入失败的解决办法
- QT creator源码分析 ----点击search后的动作
- C++中std::string::find_last_of用法
- not a regular file问题
- CentOS7.3安装VirtualBox
- 1.Linux基本概念及操作
- 【Unity 3D学习】NGUI中自定义Toggle
- Java Instrument动态修改字节码入门-添加方法耗时监控
- i++和++i的区别
- android 内存泄漏解决方案