sc/source/ui/dialogs/searchresults.cxx |   49 ++++++++++-----------------------
 1 file changed, 16 insertions(+), 33 deletions(-)

New commits:
commit 2ba64848bb375b6825fc59e1300c1c228a432a39
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jan 15 11:27:51 2025 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jan 15 16:30:18 2025 +0100

    Simplify a bit
    
    Change-Id: Idbc96dc2db8202326dd7a40033e0b94df6de9ef0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180270
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/source/ui/dialogs/searchresults.cxx 
b/sc/source/ui/dialogs/searchresults.cxx
index 96821b58573d..c0ec382cdb98 100644
--- a/sc/source/ui/dialogs/searchresults.cxx
+++ b/sc/source/ui/dialogs/searchresults.cxx
@@ -65,11 +65,13 @@ namespace
 {
     class ListWrapper {
         weld::TreeView& mrList;
+        const ScDocument& mrDoc;
     public:
         size_t mnCount = 0;
         static const size_t mnMaximum = 1000;
-        ListWrapper(weld::TreeView& rList)
+        ListWrapper(weld::TreeView& rList, const ScDocument& rDoc)
             : mrList(rList)
+            , mrDoc(rDoc)
         {
             mrList.clear();
             mrList.freeze();
@@ -78,17 +80,16 @@ namespace
         {
             mrList.thaw();
         }
-        void Insert(const OUString &rTabName,
-                    const ScAddress &rPos,
-                    formula::FormulaGrammar::AddressConvention eConvention,
-                    const OUString &rText)
+        void Insert(const ScAddress &rPos, const OUString &rText)
         {
             if (mnCount++ < mnMaximum)
             {
-                mrList.append_text(rTabName);
+                OUString aTabName;
+                mrDoc.GetName(rPos.Tab(), aTabName);
+                mrList.append_text(aTabName);
                 int nPos = mrList.n_children() - 1;
                 mrList.set_text(nPos, rPos.Format(ScRefFlags::ADDR_ABS,
-                                      nullptr, eConvention), 1);
+                                      nullptr, mrDoc.GetAddressConvention()), 
1);
                 mrList.set_text(nPos, rText, 2);
             }
         }
@@ -98,22 +99,17 @@ namespace
 void SearchResultsDlg::FillResults( ScDocument& rDoc, const ScRangeList 
&rMatchedRanges, bool bCellNotes,
         bool bEmptyCells, bool bMatchedRangesWereClamped )
 {
-    ListWrapper aList(*mxList);
-    std::vector<OUString> aTabNames = rDoc.GetAllTableNames();
-    SCTAB nTabCount = aTabNames.size();
+    ListWrapper aList(*mxList, rDoc);
 
-    if (bCellNotes || bEmptyCells)
+    for (const auto& rRange : rMatchedRanges)
     {
-        for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
+        if (bCellNotes || bEmptyCells)
         {
-            ScRange const & rRange( rMatchedRanges[i] );
             // Bear in mind that mostly the range is one address position
             // or a column or a row joined.
             ScAddress aPos( rRange.aStart );
             for ( ; aPos.Tab() <= rRange.aEnd.Tab(); aPos.IncTab())
             {
-                if (aPos.Tab() >= nTabCount)
-                    break;  // can this even happen? we just searched on 
existing sheets ...
                 for (aPos.SetCol( rRange.aStart.Col()); aPos.Col() <= 
rRange.aEnd.Col(); aPos.IncCol())
                 {
                     for (aPos.SetRow( rRange.aStart.Row()); aPos.Row() <= 
rRange.aEnd.Row(); aPos.IncRow())
@@ -122,36 +118,23 @@ void SearchResultsDlg::FillResults( ScDocument& rDoc, 
const ScRangeList &rMatche
                         {
                             const ScPostIt* pNote = rDoc.GetNote( aPos);
                             if (pNote)
-                                aList.Insert(aTabNames[aPos.Tab()], aPos,
-                                        rDoc.GetAddressConvention(),
-                                        pNote->GetText());
+                                aList.Insert(aPos, pNote->GetText());
                         }
                         else  // bEmptyCells
                         {
-                            aList.Insert(aTabNames[aPos.Tab()], aPos,
-                                    rDoc.GetAddressConvention(),
-                                    rDoc.GetString(aPos));
+                            aList.Insert(aPos, rDoc.GetString(aPos));
                         }
                     }
                 }
             }
         }
-    }
-    else
-    {
-        for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
+        else
         {
-            ScCellIterator aIter(rDoc, rMatchedRanges[i]);
+            ScCellIterator aIter(rDoc, rRange);
             for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
             {
                 const ScAddress& aPos = aIter.GetPos();
-                if (aPos.Tab() >= nTabCount)
-                    // Out-of-bound sheet index.
-                    continue;
-
-                aList.Insert(aTabNames[aPos.Tab()], aPos,
-                             rDoc.GetAddressConvention(),
-                             rDoc.GetString(aPos));
+                aList.Insert(aPos, rDoc.GetString(aPos));
             }
         }
     }

Reply via email to