[Libreoffice-commits] core.git: sw/qa sw/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Fri Aug 13 04:22:17 UTC 2021
sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 15 ++++-------
sw/source/core/inc/SearchResultLocator.hxx | 19 +++++++++++--
sw/source/core/model/SearchResultLocator.cxx | 30 +++++++++++++---------
sw/source/uibase/uno/unotxdoc.cxx | 28 ++++++++++++--------
4 files changed, 56 insertions(+), 36 deletions(-)
New commits:
commit adf65471e889676a600a9c6d0454c75cbd549ad3
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Aug 12 22:48:31 2021 +0900
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Aug 13 06:21:45 2021 +0200
indexing: allow for multiple entries in search indexing data
Change-Id: Idb9bbbaa940b7cd48423c6cc65b9c7d0b94f57dc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120396
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
index 99f33422a065..99ee267e4e02 100644
--- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
+++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
@@ -56,11 +56,10 @@ void SearchResultLocatorTest::testSearchResultLocator()
CPPUNIT_ASSERT(pDoc);
sw::search::SearchResultLocator aLocator(pDoc);
- sw::search::SearchIndexData aData;
- aData.eType = sw::search::NodeType::WriterNode;
- aData.nNodeIndex = 14;
+ std::vector<sw::search::SearchIndexData> aDataVector;
+ aDataVector.emplace_back(sw::search::NodeType::WriterNode, 14);
- sw::search::LocationResult aResult = aLocator.find(aData);
+ sw::search::LocationResult aResult = aLocator.find(aDataVector);
CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
// skip asserting exact values for macOS and Windows because of
@@ -84,12 +83,10 @@ void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
CPPUNIT_ASSERT(pDoc);
sw::search::SearchResultLocator aLocator(pDoc);
- sw::search::SearchIndexData aData;
- aData.eType = sw::search::NodeType::SdrObject;
- aData.aObjectName = u"Circle";
- aData.nNodeIndex = 1;
+ std::vector<sw::search::SearchIndexData> aDataVector;
+ aDataVector.emplace_back(sw::search::NodeType::SdrObject, 1, u"Circle");
- sw::search::LocationResult aResult = aLocator.find(aData);
+ sw::search::LocationResult aResult = aLocator.find(aDataVector);
CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
// skip asserting exact values for macOS and Windows because of
diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx
index 5621a397b85c..cd1b2e4bb5e5 100644
--- a/sw/source/core/inc/SearchResultLocator.hxx
+++ b/sw/source/core/inc/SearchResultLocator.hxx
@@ -25,9 +25,18 @@ enum class NodeType
struct SearchIndexData
{
- NodeType eType = NodeType::Undefined;
- OUString aObjectName;
- sal_uInt32 nNodeIndex = 0;
+ NodeType meType = NodeType::Undefined;
+ sal_uInt32 mnNodeIndex = 0;
+ OUString maObjectName;
+
+ SearchIndexData() {}
+
+ SearchIndexData(NodeType eType, sal_uInt32 nNodeIndex, OUString const& aObjectName = OUString())
+ : meType(eType)
+ , mnNodeIndex(nNodeIndex)
+ , maObjectName(aObjectName)
+ {
+ }
};
struct LocationResult
@@ -40,13 +49,15 @@ class SW_DLLPUBLIC SearchResultLocator
{
SwDoc* mpDocument;
+ void findOne(LocationResult& rResult, SearchIndexData const& rSearchIndexData);
+
public:
SearchResultLocator(SwDoc* pDoc)
: mpDocument(pDoc)
{
}
- LocationResult find(SearchIndexData const& rSearchIndexData);
+ LocationResult find(std::vector<SearchIndexData> const& rSearchIndexDataVector);
};
} // end sw namespace
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
index 9b22c61fa441..0b91c7a507e9 100644
--- a/sw/source/core/model/SearchResultLocator.cxx
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -22,15 +22,14 @@
namespace sw::search
{
-LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData)
+void SearchResultLocator::findOne(LocationResult& rResult, SearchIndexData const& rSearchIndexData)
{
- LocationResult aResult;
- if (rSearchIndexData.eType == NodeType::WriterNode)
+ if (rSearchIndexData.meType == NodeType::WriterNode)
{
SwNodes const& rNodes = mpDocument->GetNodes();
- if (rSearchIndexData.nNodeIndex >= rNodes.Count())
- return aResult;
- SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex];
+ if (rSearchIndexData.mnNodeIndex >= rNodes.Count())
+ return;
+ SwNode* pNode = rNodes[rSearchIndexData.mnNodeIndex];
auto* pContentNode = pNode->GetContentNode();
auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell();
@@ -41,13 +40,13 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData
= pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr);
SwRect const& rArea = pFrame->getFrameArea();
- aResult.mbFound = true;
- aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(),
+ rResult.mbFound = true;
+ rResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(),
rArea.Left() + rArea.Width(),
rArea.Top() + rArea.Height());
}
}
- else if (rSearchIndexData.eType == NodeType::SdrObject)
+ else if (rSearchIndexData.meType == NodeType::SdrObject)
{
IDocumentDrawModelAccess& rDrawModelAccess = mpDocument->getIDocumentDrawModelAccess();
auto* pModel = rDrawModelAccess.GetDrawModel();
@@ -59,12 +58,12 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData
SdrObject* pObject = pPage->GetObj(nObject);
if (pObject)
{
- if (pObject->GetName() == rSearchIndexData.aObjectName)
+ if (pObject->GetName() == rSearchIndexData.maObjectName)
{
auto aRect = o3tl::convert(pObject->GetLogicRect(), o3tl::Length::mm100,
o3tl::Length::twip);
- aResult.mbFound = true;
- aResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(),
+ rResult.mbFound = true;
+ rResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(),
aRect.Left() + aRect.GetWidth(),
aRect.Top() + aRect.GetHeight());
}
@@ -72,6 +71,13 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData
}
}
}
+}
+
+LocationResult SearchResultLocator::find(std::vector<SearchIndexData> const& rSearchIndexDataVector)
+{
+ LocationResult aResult;
+ for (auto const& rSearchIndexData : rSearchIndexDataVector)
+ findOne(aResult, rSearchIndexData);
return aResult;
}
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 2037d316a0f2..911a4b201982 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3407,8 +3407,7 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload)
{
SwDoc* pDoc = m_pDocShell->GetDoc();
- sw::search::SearchIndexData aData;
-
+ std::vector<sw::search::SearchIndexData> aDataVector;
aWalker.children();
while (aWalker.isValid())
{
@@ -3419,21 +3418,28 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload)
if (!sType.isEmpty() && !sIndex.isEmpty())
{
- aData.nNodeIndex = sIndex.toInt32();
- aData.eType = sw::search::NodeType(sType.toInt32());
+ sw::search::SearchIndexData aData;
+ aData.mnNodeIndex = sIndex.toInt32();
+ aData.meType = sw::search::NodeType(sType.toInt32());
- sw::search::SearchResultLocator aLocator(pDoc);
- sw::search::LocationResult aResult = aLocator.find(aData);
- if (aResult.mbFound)
- {
- for (auto const & rRect : aResult.maRectangles)
- aRectangles.push_back(rRect);
- }
+ aDataVector.push_back(aData);
}
}
aWalker.next();
}
aWalker.parent();
+
+
+ if (!aDataVector.empty())
+ {
+ sw::search::SearchResultLocator aLocator(pDoc);
+ sw::search::LocationResult aResult = aLocator.find(aDataVector);
+ if (aResult.mbFound)
+ {
+ for (auto const & rRect : aResult.maRectangles)
+ aRectangles.push_back(rRect);
+ }
+ }
}
return aRectangles;
More information about the Libreoffice-commits
mailing list