[Libreoffice-commits] core.git: sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Sep 3 12:39:36 UTC 2018


 sc/source/core/data/dpshttab.cxx |   28 +++++++++++++++++++++++++++-
 sc/source/ui/view/cellsh1.cxx    |   30 +++++++++++++++++++++++++-----
 2 files changed, 52 insertions(+), 6 deletions(-)

New commits:
commit 73af06a6a7fcb2d92d36a45bbe54395bcba8dfb0
Author:     Julien Nabet <serval2412 at yahoo.fr>
AuthorDate: Thu Jul 26 11:36:08 2018 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Mon Sep 3 14:39:15 2018 +0200

    tdf#37268: use also sheet local range in Pivot
    
    There are 2 types of range names:
    - those global to the document
    - those specific to a sheet
    Before this patch, Pivot could only see global range names
    
    There are 2 parts on the patch:
    1) ScCellShell::ExecuteDataPilotDialog()
    Retrieve all the range names and use:
    - for sheets range names: <scope>.<range name>
    - for global range names: <range name>
    
    2) ScSheetSourceDesc::GetSourceRange()
    Search about the presence of . to know if it's a global or sheet
    name range
    
    Change-Id: I92ac321e1475516cce7ee42b6e6038c231d0514b
    Reviewed-on: https://gerrit.libreoffice.org/58070
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index fd50d2dfca9d..54efc6b9e5ae 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -234,13 +234,39 @@ const ScRange& ScSheetSourceDesc::GetSourceRange() const
     {
         // Obtain the source range from the range name first.
         maSourceRange = ScRange();
+
+        // Range names referring a sheet contain a .
+        // See comment of ScCellShell::ExecuteDataPilotDialog
+        // paragraph "Populate named ranges"
+        sal_Int32 nAfterSheetName = ScGlobal::FindUnquoted( maRangeName, '.');
+
+        // let's consider the range name is global to the doc by default
         ScRangeName* pRangeName = mpDoc->GetRangeName();
+        OUString searchRangeName(maRangeName);
+
+        // the range name concerns a specificsheet
+        if (nAfterSheetName != -1)
+        {
+            OUString sheetName = maRangeName.copy(0, nAfterSheetName);
+            ScGlobal::EraseQuotes( sheetName, '\'', false);
+            searchRangeName = maRangeName.copy(nAfterSheetName+1);
+
+            SCTAB nTab = 0;
+            if (!mpDoc->GetTable(sheetName, nTab))
+            {
+                // the sheetname should exist
+                assert(false);
+                return maSourceRange;
+            }
+            pRangeName = mpDoc->GetRangeName(nTab);
+        }
+
         do
         {
             if (!pRangeName)
                 break;
 
-            OUString aUpper = ScGlobal::pCharClass->uppercase(maRangeName);
+            OUString aUpper = ScGlobal::pCharClass->uppercase(searchRangeName);
             const ScRangeData* pData = pRangeName->findByUpperName(aUpper);
             if (!pData)
                 break;
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 7722f9ca1c1b..45c47ef492b7 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <globalnames.hxx>
 #include <config_features.h>
 
 #include <com/sun/star/i18n/TextConversionOption.hpp>
@@ -2794,12 +2795,31 @@ void ScCellShell::ExecuteDataPilotDialog()
                 pTabViewShell->GetFrameWeld(), bEnableExt));
 
         // Populate named ranges (if any).
-        ScRangeName* pRangeName = pDoc->GetRangeName();
-        if (pRangeName)
+        // We must take into account 2 types of scope : global doc and sheets
+        // for global doc: <name of the range>
+        // for sheets: <sheetname>.<name of the range>
+        std::map<OUString, ScRangeName*> aRangeMap;
+        pDoc->GetRangeNameMap(aRangeMap);
+        for (auto const& elemRangeMap : aRangeMap)
         {
-            ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
-            for (; itr != itrEnd; ++itr)
-                pTypeDlg->AppendNamedRange(itr->second->GetName());
+            ScRangeName* pRangeName = elemRangeMap.second;
+            if (pRangeName)
+            {
+                if (elemRangeMap.first == STR_GLOBAL_RANGE_NAME)
+                {
+                    for (auto const& elem : *pRangeName)
+                        pTypeDlg->AppendNamedRange(elem.second->GetName());
+                }
+                else
+                {
+                    OUString aScope(elemRangeMap.first);
+                    ScGlobal::AddQuotes(aScope, '\'');
+                    for (auto const& elem : *pRangeName)
+                    {
+                        pTypeDlg->AppendNamedRange(aScope + "." + elem.second->GetName());
+                    }
+                }
+            }
         }
 
         if ( pTypeDlg->Execute() == RET_OK )


More information about the Libreoffice-commits mailing list