summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/qa/extras/indexing/SearchResultLocatorTest.cxx30
-rw-r--r--sw/source/core/inc/SearchResultLocator.hxx2
-rw-r--r--sw/source/core/model/ModelTraverser.cxx1
-rw-r--r--sw/source/core/model/SearchResultLocator.cxx50
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx55
5 files changed, 91 insertions, 47 deletions
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
index 99ee267e4e02..c740f982b2c3 100644
--- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
+++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
@@ -27,10 +27,12 @@ private:
public:
void testSearchResultLocator();
+ void testSearchResultLocatorUsingPayload();
void testSearchResultLocatorForSdrObjects();
CPPUNIT_TEST_SUITE(SearchResultLocatorTest);
CPPUNIT_TEST(testSearchResultLocator);
+ CPPUNIT_TEST(testSearchResultLocatorUsingPayload);
CPPUNIT_TEST(testSearchResultLocatorForSdrObjects);
CPPUNIT_TEST_SUITE_END();
};
@@ -74,6 +76,34 @@ void SearchResultLocatorTest::testSearchResultLocator()
#endif
}
+void SearchResultLocatorTest::testSearchResultLocatorUsingPayload()
+{
+ if (!IsDefaultDPI())
+ return;
+
+ SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt");
+ CPPUNIT_ASSERT(pDoc);
+
+ sw::search::SearchResultLocator aLocator(pDoc);
+ OString payload = "<indexing>"
+ "<paragraph type=\"1\" index=\"14\" />"
+ "</indexing>";
+
+ sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr());
+ CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
+
+ // skip asserting exact values for macOS and Windows because of
+ // inconsistent results
+#if !defined(_WIN32) && !defined(MACOSX)
+ auto aRectangle = aResult.maRectangles[0];
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4);
+#endif
+}
+
void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
{
if (!IsDefaultDPI())
diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx
index cd1b2e4bb5e5..7dac632ae58f 100644
--- a/sw/source/core/inc/SearchResultLocator.hxx
+++ b/sw/source/core/inc/SearchResultLocator.hxx
@@ -58,6 +58,8 @@ public:
}
LocationResult find(std::vector<SearchIndexData> const& rSearchIndexDataVector);
+
+ LocationResult findForPayload(const char* pPayload);
};
} // end sw namespace
diff --git a/sw/source/core/model/ModelTraverser.cxx b/sw/source/core/model/ModelTraverser.cxx
index 0a01f5cd97c5..bb959a95dec6 100644
--- a/sw/source/core/model/ModelTraverser.cxx
+++ b/sw/source/core/model/ModelTraverser.cxx
@@ -24,6 +24,7 @@ void ModelTraverser::traverse()
auto const& pNodes = m_pDoc->GetNodes();
SwNode* pNode = nullptr;
+
for (sal_uLong n = 0; n < pNodes.Count(); ++n)
{
pNode = pNodes[n];
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
index 0b91c7a507e9..a0e405b2ed33 100644
--- a/sw/source/core/model/SearchResultLocator.cxx
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -17,6 +17,9 @@
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
+#include <tools/XmlWalker.hxx>
+#include <tools/stream.hxx>
+
#include <svx/svdpage.hxx>
#include <svx/svdobj.hxx>
@@ -82,6 +85,53 @@ LocationResult SearchResultLocator::find(std::vector<SearchIndexData> const& rSe
return aResult;
}
+LocationResult SearchResultLocator::findForPayload(const char* pPayload)
+{
+ LocationResult aResult;
+
+ const OString aPayloadString(pPayload);
+
+ SvMemoryStream aStream(const_cast<char*>(aPayloadString.getStr()), aPayloadString.getLength(),
+ StreamMode::READ);
+ tools::XmlWalker aWalker;
+
+ if (!aWalker.open(&aStream))
+ return aResult;
+
+ if (aWalker.name() == "indexing")
+ {
+ std::vector<sw::search::SearchIndexData> aDataVector;
+ aWalker.children();
+ while (aWalker.isValid())
+ {
+ if (aWalker.name() == "paragraph")
+ {
+ OString sType = aWalker.attribute("type");
+ OString sIndex = aWalker.attribute("index");
+
+ if (!sType.isEmpty() && !sIndex.isEmpty())
+ {
+ sw::search::SearchIndexData aData;
+ aData.mnNodeIndex = sIndex.toInt32();
+ aData.meType = sw::search::NodeType(sType.toInt32());
+
+ aDataVector.push_back(aData);
+ }
+ }
+ aWalker.next();
+ }
+ aWalker.parent();
+
+ if (!aDataVector.empty())
+ {
+ for (auto const& rSearchIndexData : aDataVector)
+ findOne(aResult, rSearchIndexData);
+ }
+ }
+
+ return aResult;
+}
+
} // end sw namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index e991de6df09c..e778f4fc8621 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -164,7 +164,6 @@
#include <IDocumentOutlineNodes.hxx>
#include <SearchResultLocator.hxx>
-#include <tools/XmlWalker.hxx>
#define TWIPS_PER_PIXEL 15
@@ -3395,55 +3394,17 @@ void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments)
std::vector<basegfx::B2DRange>
SwXTextDocument::getSearchResultRectangles(const char* pPayload)
{
- std::vector<basegfx::B2DRange> aRectangles;
-
- const OString aPayloadString(pPayload);
-
- SvMemoryStream aStream(const_cast<char *>(aPayloadString.getStr()), aPayloadString.getLength(), StreamMode::READ);
- tools::XmlWalker aWalker;
- if (!aWalker.open(&aStream))
- return aRectangles;
+ SwDoc* pDoc = m_pDocShell->GetDoc();
+ if (!pDoc)
+ return std::vector<basegfx::B2DRange>();
- if (aWalker.name() == "indexing")
+ sw::search::SearchResultLocator aLocator(pDoc);
+ sw::search::LocationResult aResult = aLocator.findForPayload(pPayload);
+ if (aResult.mbFound)
{
- SwDoc* pDoc = m_pDocShell->GetDoc();
-
- std::vector<sw::search::SearchIndexData> aDataVector;
- aWalker.children();
- while (aWalker.isValid())
- {
- if (aWalker.name() == "paragraph")
- {
- OString sType = aWalker.attribute("type");
- OString sIndex = aWalker.attribute("index");
-
- if (!sType.isEmpty() && !sIndex.isEmpty())
- {
- sw::search::SearchIndexData aData;
- aData.mnNodeIndex = sIndex.toInt32();
- aData.meType = sw::search::NodeType(sType.toInt32());
-
- 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 aResult.maRectangles;
}
-
- return aRectangles;
+ return std::vector<basegfx::B2DRange>();
}
int SwXTextDocument::getPart()