Kaydet (Commit) 73af06a6 authored tarafından Julien Nabet's avatar Julien Nabet Kaydeden (comit) Eike Rathke

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: 's avatarEike Rathke <erack@redhat.com>
üst 6c21fb25
...@@ -234,13 +234,39 @@ const ScRange& ScSheetSourceDesc::GetSourceRange() const ...@@ -234,13 +234,39 @@ const ScRange& ScSheetSourceDesc::GetSourceRange() const
{ {
// Obtain the source range from the range name first. // Obtain the source range from the range name first.
maSourceRange = ScRange(); 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(); 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 do
{ {
if (!pRangeName) if (!pRangeName)
break; break;
OUString aUpper = ScGlobal::pCharClass->uppercase(maRangeName); OUString aUpper = ScGlobal::pCharClass->uppercase(searchRangeName);
const ScRangeData* pData = pRangeName->findByUpperName(aUpper); const ScRangeData* pData = pRangeName->findByUpperName(aUpper);
if (!pData) if (!pData)
break; break;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <globalnames.hxx>
#include <config_features.h> #include <config_features.h>
#include <com/sun/star/i18n/TextConversionOption.hpp> #include <com/sun/star/i18n/TextConversionOption.hpp>
...@@ -2794,12 +2795,31 @@ void ScCellShell::ExecuteDataPilotDialog() ...@@ -2794,12 +2795,31 @@ void ScCellShell::ExecuteDataPilotDialog()
pTabViewShell->GetFrameWeld(), bEnableExt)); pTabViewShell->GetFrameWeld(), bEnableExt));
// Populate named ranges (if any). // Populate named ranges (if any).
ScRangeName* pRangeName = pDoc->GetRangeName(); // We must take into account 2 types of scope : global doc and sheets
if (pRangeName) // 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(); ScRangeName* pRangeName = elemRangeMap.second;
for (; itr != itrEnd; ++itr) if (pRangeName)
pTypeDlg->AppendNamedRange(itr->second->GetName()); {
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 ) if ( pTypeDlg->Execute() == RET_OK )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment