[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - desktop/qa sw/qa sw/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 2 09:20:53 UTC 2021


 desktop/qa/desktop_lib/test_desktop_lib.cxx       |    2 
 sw/qa/extras/indexing/SearchResultLocatorTest.cxx |   37 +++++++++++-
 sw/source/core/inc/SearchResultLocator.hxx        |   13 +++-
 sw/source/core/model/SearchResultLocator.cxx      |   64 +++++++++++++++++-----
 sw/source/uibase/uno/unotxdoc.cxx                 |    9 ++-
 5 files changed, 103 insertions(+), 22 deletions(-)

New commits:
commit ec5992bc89cc0eba0ab9f0ea4b07e31df9ed9a6a
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Jul 9 19:36:58 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Sep 2 11:20:18 2021 +0200

    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 at gmail.com>
    (cherry picked from commit ea1818b8ba34378b777b8706069d28fade2cc924)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121111
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 913cfb600fad..ba631b855226 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3092,7 +3092,7 @@ void DesktopLOKTest::testRenderSearchResult()
     Scheduler::ProcessEventsToIdle();
 
     unsigned char* pBuffer = nullptr;
-    OString aJSON = "{ \"node_index\" : 19 }";
+    OString aJSON = "{ \"type\" : 1, \"node_index\" : 19 }";
 
     int nWidth = 0;
     int nHeight = 0;
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;
 


More information about the Libreoffice-commits mailing list