From 8de8b0dda8097fa6a49f18baea3eff3066dfafca Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 30 Oct 2021 08:14:51 +0800 Subject: [PATCH] support search tag in SearchPanel --- src/search/searchdata.h | 1 + src/search/searcher.cpp | 33 +++++++++++++++++++++++---------- src/search/searcher.h | 3 +++ src/widgets/searchpanel.cpp | 15 +++++---------- src/widgets/searchpanel.h | 2 -- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/search/searchdata.h b/src/search/searchdata.h index d81cff42..debe3037 100644 --- a/src/search/searchdata.h +++ b/src/search/searchdata.h @@ -57,6 +57,7 @@ namespace vnotex ObjectNone = 0, SearchName = 0x1UL, SearchContent = 0x2UL, + // SearchOutline is not supported yet. SearchOutline = 0x4UL, SearchTag = 0x8UL, SearchPath = 0x10UL diff --git a/src/search/searcher.cpp b/src/search/searcher.cpp index 1b6becb7..72231feb 100644 --- a/src/search/searcher.cpp +++ b/src/search/searcher.cpp @@ -218,12 +218,10 @@ bool Searcher::firstPhaseSearch(const File *p_file) } } - if (testObject(SearchObject::SearchOutline)) { - emit logRequested(tr("Searching outline is not supported yet")); - } - if (testObject(SearchObject::SearchTag)) { - emit logRequested(tr("Searching tag is not supported yet")); + if (searchTag(p_file->getNode())) { + emit resultItemAdded(SearchResultItem::createBufferItem(filePath, relativePath)); + } } // Make SearchContent always the last one to check. @@ -427,12 +425,10 @@ bool Searcher::firstPhaseSearch(Node *p_node, QVector &p_ } } - if (testObject(SearchObject::SearchOutline)) { - emit logRequested(tr("Searching outline is not supported yet")); - } - if (testObject(SearchObject::SearchTag)) { - emit logRequested(tr("Searching tag is not supported yet")); + if (searchTag(p_node)) { + emit resultItemAdded(SearchResultItem::createBufferItem(filePath, relativePath)); + } } if (testObject(SearchObject::SearchContent)) { @@ -518,3 +514,20 @@ const SearchToken &Searcher::getToken() const { return m_token; } + +bool Searcher::searchTag(const Node *p_node) const +{ + if (!p_node) { + return false; + } + + Q_ASSERT(p_node->isLoaded()); + + for (const auto &tag : p_node->getTags()) { + if (isTokenMatched(tag)) { + return true; + } + } + + return false; +} diff --git a/src/search/searcher.h b/src/search/searcher.h index 9f8d6b98..6e1d4b0f 100644 --- a/src/search/searcher.h +++ b/src/search/searcher.h @@ -78,6 +78,9 @@ namespace vnotex bool searchContent(const File *p_file); + // Return true if matched. + bool searchTag(const Node *p_node) const; + void createSearchEngine(); QSharedPointer m_option; diff --git a/src/widgets/searchpanel.cpp b/src/widgets/searchpanel.cpp index 4e195f84..ee4d0e12 100644 --- a/src/widgets/searchpanel.cpp +++ b/src/widgets/searchpanel.cpp @@ -169,14 +169,11 @@ void SearchPanel::setupSearchObject(QFormLayout *p_layout, QWidget *p_parent) m_searchObjectContentCheckBox = WidgetsFactory::createCheckBox(tr("Content"), p_parent); gridLayout->addWidget(m_searchObjectContentCheckBox, 0, 1); - m_searchObjectOutlineCheckBox = WidgetsFactory::createCheckBox(tr("Outline"), p_parent); - gridLayout->addWidget(m_searchObjectOutlineCheckBox, 1, 0); - m_searchObjectTagCheckBox = WidgetsFactory::createCheckBox(tr("Tag"), p_parent); - gridLayout->addWidget(m_searchObjectTagCheckBox, 1, 1); + gridLayout->addWidget(m_searchObjectTagCheckBox, 1, 0); m_searchObjectPathCheckBox = WidgetsFactory::createCheckBox(tr("Path"), p_parent); - gridLayout->addWidget(m_searchObjectPathCheckBox, 2, 0); + gridLayout->addWidget(m_searchObjectPathCheckBox, 1, 1); } void SearchPanel::setupSearchTarget(QFormLayout *p_layout, QWidget *p_parent) @@ -256,7 +253,6 @@ void SearchPanel::restoreFields(const SearchOption &p_option) { m_searchObjectNameCheckBox->setChecked(p_option.m_objects & SearchObject::SearchName); m_searchObjectContentCheckBox->setChecked(p_option.m_objects & SearchObject::SearchContent); - m_searchObjectOutlineCheckBox->setChecked(p_option.m_objects & SearchObject::SearchOutline); m_searchObjectTagCheckBox->setChecked(p_option.m_objects & SearchObject::SearchTag); m_searchObjectPathCheckBox->setChecked(p_option.m_objects & SearchObject::SearchPath); } @@ -379,9 +375,6 @@ void SearchPanel::saveFields(SearchOption &p_option) if (m_searchObjectContentCheckBox->isChecked()) { p_option.m_objects |= SearchObject::SearchContent; } - if (m_searchObjectOutlineCheckBox->isChecked()) { - p_option.m_objects |= SearchObject::SearchOutline; - } if (m_searchObjectTagCheckBox->isChecked()) { p_option.m_objects |= SearchObject::SearchTag; } @@ -566,7 +559,9 @@ void SearchPanel::handleLocationActivated(const Location &p_location) Q_ASSERT(m_searcher); if (!m_searchTokenOfSession) { - m_searchTokenOfSession = QSharedPointer::create(m_searcher->getToken()); + if (m_option->m_objects & SearchObject::SearchContent) { + m_searchTokenOfSession = QSharedPointer::create(m_searcher->getToken()); + } } // TODO: decode the path of location and handle different types of destination. diff --git a/src/widgets/searchpanel.h b/src/widgets/searchpanel.h index 71a88864..56c6028d 100644 --- a/src/widgets/searchpanel.h +++ b/src/widgets/searchpanel.h @@ -111,8 +111,6 @@ namespace vnotex QCheckBox *m_searchObjectContentCheckBox = nullptr; - QCheckBox *m_searchObjectOutlineCheckBox = nullptr; - QCheckBox *m_searchObjectTagCheckBox = nullptr; QCheckBox *m_searchObjectPathCheckBox = nullptr;