summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-07-09 19:36:58 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-09-02 11:20:18 +0200
commitec5992bc89cc0eba0ab9f0ea4b07e31df9ed9a6a (patch)
tree0d72835a51d2ee83add7b0aebfb1d07d166ed9ab /sw
parente06d98c0d8683f9823b388f648f91b5d3de5c717 (diff)
indexing: add support for SdrObjects in SearchResultLocator
Also add (node) "type" parameter because we need to differentiate between Writer nodes and SdrObject nodes. Change-Id: I590695ae71781f64c22bdd7e1df01d69e3376e67 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118671 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit ea1818b8ba34378b777b8706069d28fade2cc924) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121111 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/indexing/SearchResultLocatorTest.cxx37
-rw-r--r--sw/source/core/inc/SearchResultLocator.hxx13
-rw-r--r--sw/source/core/model/SearchResultLocator.cxx64
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx9
4 files changed, 102 insertions, 21 deletions
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
index 07ccc8da1c58..0b452a6d564e 100644
--- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
+++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
@@ -27,9 +27,11 @@ private:
public:
void testSearchResultLocator();
+ void testSearchResultLocatorForSdrObjects();
CPPUNIT_TEST_SUITE(SearchResultLocatorTest);
CPPUNIT_TEST(testSearchResultLocator);
+ CPPUNIT_TEST(testSearchResultLocatorForSdrObjects);
CPPUNIT_TEST_SUITE_END();
};
@@ -50,13 +52,16 @@ void SearchResultLocatorTest::testSearchResultLocator()
SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt");
CPPUNIT_ASSERT(pDoc);
- sw::SearchResultLocator aLocator(pDoc);
- sw::SearchIndexData aData;
+ sw::search::SearchResultLocator aLocator(pDoc);
+ sw::search::SearchIndexData aData;
+ aData.eType = sw::search::NodeType::WriterNode;
aData.nNodeIndex = 14;
- sw::LocationResult aResult = aLocator.find(aData);
+ sw::search::LocationResult aResult = aLocator.find(aData);
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);
@@ -67,6 +72,32 @@ void SearchResultLocatorTest::testSearchResultLocator()
#endif
}
+void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
+{
+ SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt");
+ 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;
+
+ sw::search::LocationResult aResult = aLocator.find(aData);
+ 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(1478.0, aRectangle.getMinX(), 1e-4);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(3223.0, aRectangle.getMinY(), 1e-4);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getWidth(), 1e-4);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getHeight(), 1e-4);
+#endif
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx
index f9e3aab6929b..5621a397b85c 100644
--- a/sw/source/core/inc/SearchResultLocator.hxx
+++ b/sw/source/core/inc/SearchResultLocator.hxx
@@ -14,11 +14,20 @@
#include <doc.hxx>
#include <basegfx/range/b2drange.hxx>
-namespace sw
+namespace sw::search
{
+enum class NodeType
+{
+ Undefined,
+ WriterNode,
+ SdrObject
+};
+
struct SearchIndexData
{
- sal_uInt32 nNodeIndex;
+ NodeType eType = NodeType::Undefined;
+ OUString aObjectName;
+ sal_uInt32 nNodeIndex = 0;
};
struct LocationResult
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
index 09aa12ffeb85..d86d518f082a 100644
--- a/sw/source/core/model/SearchResultLocator.cxx
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -14,29 +14,67 @@
#include <frame.hxx>
#include <cntfrm.hxx>
#include <viewsh.hxx>
+#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
-namespace sw
+#include <tools/UnitConversion.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/svdobj.hxx>
+
+namespace sw::search
{
LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData)
{
LocationResult aResult;
- SwNodes const& rNodes = mpDocument->GetNodes();
- if (rSearchIndexData.nNodeIndex >= rNodes.Count())
- return aResult;
- SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex];
+ if (rSearchIndexData.eType == NodeType::WriterNode)
+ {
+ SwNodes const& rNodes = mpDocument->GetNodes();
+ if (rSearchIndexData.nNodeIndex >= rNodes.Count())
+ return aResult;
+ SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex];
- auto* pContentNode = pNode->GetContentNode();
- auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell();
+ auto* pContentNode = pNode->GetContentNode();
+ auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell();
- if (pContentNode && pShell)
+ if (pContentNode && pShell)
+ {
+ const SwFrame* pFrame
+ = pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr);
+ SwRect const& rArea = pFrame->getFrameArea();
+
+ aResult.mbFound = true;
+ aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(),
+ rArea.Left() + rArea.Width(),
+ rArea.Top() + rArea.Height());
+ }
+ }
+ else if (rSearchIndexData.eType == NodeType::SdrObject)
{
- const SwFrame* pFrame = pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr);
- SwRect const& rArea = pFrame->getFrameArea();
+ IDocumentDrawModelAccess& rDrawModelAccess = mpDocument->getIDocumentDrawModelAccess();
+ auto* pModel = rDrawModelAccess.GetDrawModel();
+ for (sal_uInt16 nPage = 0; nPage < pModel->GetPageCount(); ++nPage)
+ {
+ SdrPage* pPage = pModel->GetPage(nPage);
+ for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject)
+ {
+ SdrObject* pObject = pPage->GetObj(nObject);
+ if (pObject)
+ {
+ if (pObject->GetName() == rSearchIndexData.aObjectName)
+ {
+ auto aLogicRect = pObject->GetLogicRect();
+ auto nLeft = convertMm100ToTwip(aLogicRect.Left());
+ auto nTop = convertMm100ToTwip(aLogicRect.Top());
+ auto nWidth = convertMm100ToTwip(aLogicRect.GetWidth());
+ auto nHeight = convertMm100ToTwip(aLogicRect.GetHeight());
- aResult.mbFound = true;
- aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(), rArea.Left() + rArea.Width(),
- rArea.Top() + rArea.Height());
+ aResult.mbFound = true;
+ aResult.maRectangles.emplace_back(nLeft, nTop, nLeft + nWidth,
+ nTop + nHeight);
+ }
+ }
+ }
+ }
}
return aResult;
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 8bff5487fc7d..6f4a24402ca5 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3417,14 +3417,17 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload)
std::stringstream aStream(pPayload);
boost::property_tree::read_json(aStream, aTree);
- sw::SearchIndexData aData;
+ sw::search::SearchIndexData aData;
+
+ int nType = aTree.get<int>("type");
aData.nNodeIndex = sal_uInt32(aTree.get<int>("node_index"));
+ aData.eType = sw::search::NodeType(nType);
SwDoc* pDoc = m_pDocShell->GetDoc();
- sw::SearchResultLocator aLocator(pDoc);
- sw::LocationResult aResult = aLocator.find(aData);
+ sw::search::SearchResultLocator aLocator(pDoc);
+ sw::search::LocationResult aResult = aLocator.find(aData);
if (aResult.mbFound)
aRectangles = aResult.maRectangles;