28#include <osl/diagnose.h>
32#include <document.hxx>
38#include <stlsheet.hxx>
40#include <unonames.hxx>
45#include <com/sun/star/beans/XPropertySet.hpp>
46#include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
47#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
48#include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
49#include <com/sun/star/sheet/DataPilotTableResultData.hpp>
50#include <com/sun/star/sheet/MemberResultFlags.hpp>
51#include <com/sun/star/sheet/DataResultFlags.hpp>
52#include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
53#include <com/sun/star/sheet/GeneralFunction2.hpp>
54#include <com/sun/star/sheet/MemberResult.hpp>
55#include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
56#include <com/sun/star/sheet/XDataPilotResults.hpp>
57#include <com/sun/star/sheet/XDimensionsSupplier.hpp>
58#include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
59#include <com/sun/star/sheet/XLevelsSupplier.hpp>
60#include <com/sun/star/sheet/XMembersAccess.hpp>
61#include <com/sun/star/sheet/XMembersSupplier.hpp>
70using ::com::sun::star::beans::XPropertySet;
71using ::com::sun::star::uno::Sequence;
72using ::com::sun::star::uno::UNO_QUERY;
73using ::com::sun::star::uno::Reference;
74using ::com::sun::star::sheet::DataPilotTablePositionData;
75using ::com::sun::star::sheet::DataPilotTableResultData;
77#define SC_DP_FRAME_INNER_BOLD 20
78#define SC_DP_FRAME_OUTER_BOLD 40
80#define SC_DP_FRAME_COLOR Color(0,0,0)
97 OUString aName, OUString aCaption,
bool bHasHiddenMember,
bool bDataLayout,
bool bPageDim) :
110 struct ScDPOutLevelDataComparator
124 ::std::vector< bool > mbNeedLineCols;
125 ::std::vector< SCCOL > mnCols;
127 ::std::vector< bool > mbNeedLineRows;
128 ::std::vector< SCROW > mnRows;
133 SCCOL mnDataStartCol;
134 SCROW mnDataStartRow;
139 ScDPOutputImpl(
ScDocument* pDoc, sal_uInt16 nTab,
146 bool AddRow(
SCROW nRow );
147 bool AddCol(
SCCOL nCol );
149 void OutputDataArea();
150 void OutputBlockFrame (
SCCOL nStartCol,
SCROW nStartRow,
SCCOL nEndCol,
SCROW nEndRow,
bool bHori =
false );
154void ScDPOutputImpl::OutputDataArea()
156 AddRow( mnDataStartRow );
157 AddCol( mnDataStartCol );
159 mnCols.push_back( mnTabEndCol+1);
160 mnRows.push_back( mnTabEndRow+1);
162 bool bAllRows = ( ( mnTabEndRow - mnDataStartRow + 2 ) ==
static_cast<SCROW>(mnRows.size()) );
164 std::sort( mnCols.begin(), mnCols.end());
165 std::sort( mnRows.begin(), mnRows.end());
167 for(
SCCOL nCol = 0; nCol < static_cast<SCCOL>(mnCols.size())-1; nCol ++ )
171 if ( nCol <
static_cast<SCCOL>(mnCols.size())-2)
173 for (
SCROW i = nCol%2; i < static_cast<SCROW>(mnRows.size())-2;
i +=2 )
174 OutputBlockFrame( mnCols[nCol], mnRows[i], mnCols[nCol+1]-1, mnRows[i+1]-1 );
175 if ( mnRows.size()>=2 )
176 OutputBlockFrame( mnCols[nCol], mnRows[mnRows.size()-2], mnCols[nCol+1]-1, mnRows[mnRows.size()-1]-1 );
180 for (
SCROW i = 0 ; i < static_cast<SCROW>(mnRows.size())-1;
i++ )
181 OutputBlockFrame( mnCols[nCol], mnRows[i], mnCols[nCol+1]-1, mnRows[i+1]-1 );
185 OutputBlockFrame( mnCols[nCol], mnRows.front(), mnCols[nCol+1]-1, mnRows.back()-1, bAllRows );
188 if ( mnTabStartCol != mnDataStartCol )
190 if ( mnTabStartRow != mnDataStartRow )
191 OutputBlockFrame( mnTabStartCol, mnTabStartRow, mnDataStartCol-1, mnDataStartRow-1 );
192 OutputBlockFrame( mnTabStartCol, mnDataStartRow, mnDataStartCol-1, mnTabEndRow );
195 OutputBlockFrame( mnDataStartCol, mnTabStartRow, mnTabEndCol, mnDataStartRow-1 );
198ScDPOutputImpl::ScDPOutputImpl(
ScDocument* pDoc, sal_uInt16 nTab,
207 mnTabStartCol( nTabStartCol ),
208 mnTabStartRow( nTabStartRow ),
209 mnDataStartCol ( nDataStartCol ),
210 mnDataStartRow ( nDataStartRow ),
211 mnTabEndCol( nTabEndCol ),
212 mnTabEndRow( nTabEndRow )
214 mbNeedLineCols.resize( nTabEndCol-nDataStartCol+1,
false );
215 mbNeedLineRows.resize( nTabEndRow-nDataStartRow+1,
false );
219bool ScDPOutputImpl::AddRow(
SCROW nRow )
221 if ( !mbNeedLineRows[ nRow - mnDataStartRow ] )
223 mbNeedLineRows[ nRow - mnDataStartRow ] =
true;
224 mnRows.push_back( nRow );
231bool ScDPOutputImpl::AddCol(
SCCOL nCol )
234 if ( !mbNeedLineCols[ nCol - mnDataStartCol ] )
236 mbNeedLineCols[ nCol - mnDataStartCol ] =
true;
237 mnCols.push_back( nCol );
244void ScDPOutputImpl::OutputBlockFrame (
SCCOL nStartCol,
SCROW nStartRow,
SCCOL nEndCol,
SCROW nEndRow,
bool bHori )
252 if ( nStartCol == mnTabStartCol )
253 aBox.SetLine(&aOutLine, SvxBoxItemLine::LEFT);
255 aBox.SetLine(&aLine, SvxBoxItemLine::LEFT);
257 if ( nStartRow == mnTabStartRow )
258 aBox.SetLine(&aOutLine, SvxBoxItemLine::TOP);
260 aBox.SetLine(&aLine, SvxBoxItemLine::TOP);
262 if ( nEndCol == mnTabEndCol )
263 aBox.SetLine(&aOutLine, SvxBoxItemLine::RIGHT);
265 aBox.SetLine(&aLine, SvxBoxItemLine::RIGHT);
267 if ( nEndRow == mnTabEndRow )
268 aBox.SetLine(&aOutLine, SvxBoxItemLine::BOTTOM);
270 aBox.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
273 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::VERT,
false );
276 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::HORI);
277 aBoxInfo.SetLine( &aLine, SvxBoxInfoItemLine::HORI );
280 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::HORI,
false );
282 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::DISTANCE,
false);
284 mpDoc->ApplyFrameAreaTab(
ScRange(nStartCol, nStartRow, mnTab, nEndCol, nEndRow , mnTab), aBox, aBoxInfo);
292 if ( nCol1 > nCol2 || nRow1 > nRow2 )
294 OSL_FAIL(
"SetStyleById: invalid range");
298 OUString aStyleName =
ScResId(pStrId);
305 pStyle =
static_cast<ScStyleSheet*
>( &pStlPool->
Make( aStyleName, SfxStyleFamily::Para,
306 SfxStyleSearchBits::UserDefined ) );
309 if (pStrId == STR_PIVOT_STYLENAME_RESULT || pStrId == STR_PIVOT_STYLENAME_TITLE){
314 if (pStrId == STR_PIVOT_STYLENAME_CATEGORY || pStrId == STR_PIVOT_STYLENAME_TITLE)
327 aBox.SetLine(&aLine, SvxBoxItemLine::LEFT);
328 aBox.SetLine(&aLine, SvxBoxItemLine::TOP);
329 aBox.SetLine(&aLine, SvxBoxItemLine::RIGHT);
330 aBox.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
332 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::HORI,
false);
333 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::VERT,
false);
334 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::DISTANCE,
false);
339void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, sal_Int32& rCount,
340 const uno::Reference<sheet::XDataPilotMemberResults>& xLevRes,
341 const uno::Reference<container::XIndexAccess>& xDims )
349 uno::Sequence<sheet::MemberResult> aResult = xLevRes->getResults();
358 std::vector <OUString> aDataNames;
359 std::vector <sal_uInt32> aDataFormats;
364 uno::Reference<uno::XInterface> xDim(xDims->getByIndex(nDim), uno::UNO_QUERY);
365 uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
366 uno::Reference<container::XNamed> xDimName( xDim, uno::UNO_QUERY );
367 if ( xDimProp.is() && xDimName.is() )
369 sheet::DataPilotFieldOrientation eDimOrient =
372 sheet::DataPilotFieldOrientation_HIDDEN );
373 if ( eDimOrient == sheet::DataPilotFieldOrientation_DATA )
375 aDataNames.push_back(xDimName->getName());
379 aDataFormats.push_back(nFormat);
384 if (aDataFormats.empty())
387 const sheet::MemberResult* pArray = aResult.getConstArray();
390 sal_uInt32* pNumFmt =
new sal_uInt32[nSize];
391 if (aDataFormats.size() == 1)
396 pNumFmt[nPos] = nFormat;
404 if ( !(pArray[nPos].Flags & sheet::MemberResultFlags::CONTINUE) )
407 sal_uInt32 nFormat = 0;
408 for (
size_t i=0;
i<aDataFormats.size();
i++)
409 if (aName == aDataNames[i])
411 nFormat = aDataFormats[
i];
414 pNumFmt[
nPos] = nFormat;
418 rFormats.reset( pNumFmt );
422sal_uInt32 lcl_GetFirstNumberFormat(
const uno::Reference<container::XIndexAccess>& xDims )
427 uno::Reference<beans::XPropertySet> xDimProp(xDims->getByIndex(nDim), uno::UNO_QUERY);
430 sheet::DataPilotFieldOrientation eDimOrient =
433 sheet::DataPilotFieldOrientation_HIDDEN );
434 if ( eDimOrient == sheet::DataPilotFieldOrientation_DATA )
448bool lcl_MemberEmpty(
const uno::Sequence<sheet::MemberResult>& rSeq )
452 return std::none_of(rSeq.begin(), rSeq.end(),
453 [](
const sheet::MemberResult& rMem) {
454 return rMem.Flags & sheet::MemberResultFlags::HASMEMBER; });
461uno::Sequence<sheet::MemberResult> getVisiblePageMembersAsResults(
const uno::Reference<uno::XInterface>& xLevel )
464 return uno::Sequence<sheet::MemberResult>();
466 uno::Reference<sheet::XMembersSupplier> xMSupplier(xLevel, UNO_QUERY);
467 if (!xMSupplier.is())
468 return uno::Sequence<sheet::MemberResult>();
470 uno::Reference<sheet::XMembersAccess> xNA = xMSupplier->getMembers();
472 return uno::Sequence<sheet::MemberResult>();
474 std::vector<sheet::MemberResult> aRes;
475 const uno::Sequence<OUString> aNames = xNA->getElementNames();
476 for (
const OUString& rName : aNames)
478 xNA->getByName(rName);
480 uno::Reference<beans::XPropertySet> xMemPS(xNA->getByName(rName), UNO_QUERY);
485 if (aCaption.isEmpty())
493 aRes.emplace_back(rName, aCaption, 0, std::numeric_limits<double>::quiet_NaN());
499 return uno::Sequence<sheet::MemberResult>();
509 xSource(
std::move( xSrc )),
518 bResultsError(false),
520 bSizeOverflow(false),
521 mbHeaderLayout(false)
526 uno::Reference<sheet::XDataPilotResults> xResult(
xSource, uno::UNO_QUERY );
527 if (
xSource.is() && xResult.is() )
531 uno::Reference<container::XIndexAccess> xDims =
536 uno::Reference<uno::XInterface> xDim(xDims->getByIndex(nDim), uno::UNO_QUERY);
537 uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
538 uno::Reference<sheet::XHierarchiesSupplier> xDimSupp( xDim, uno::UNO_QUERY );
539 if ( xDimProp.is() && xDimSupp.is() )
541 sheet::DataPilotFieldOrientation eDimOrient =
544 sheet::DataPilotFieldOrientation_HIDDEN );
554 if ( eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN )
556 uno::Reference<container::XIndexAccess> xHiers =
561 if ( nHierarchy >= xHiers->getCount() )
564 uno::Reference<sheet::XLevelsSupplier> xHierSupp(xHiers->getByIndex(nHierarchy),
566 if ( xHierSupp.is() )
568 uno::Reference<container::XIndexAccess> xLevels =
573 uno::Reference<uno::XInterface> xLevel(xLevels->getByIndex(nLev),
575 uno::Reference<container::XNamed> xLevNam( xLevel, uno::UNO_QUERY );
576 uno::Reference<sheet::XDataPilotMemberResults> xLevRes(
577 xLevel, uno::UNO_QUERY );
578 if ( xLevNam.is() && xLevRes.is() )
580 OUString
aName = xLevNam->getName();
581 Reference<XPropertySet> xPropSet(xLevel, UNO_QUERY);
588 switch ( eDimOrient )
590 case sheet::DataPilotFieldOrientation_COLUMN:
592 uno::Sequence<sheet::MemberResult> aResult = xLevRes->getResults();
593 if (!lcl_MemberEmpty(aResult))
596 aCaption, bHasHiddenMember, bIsDataLayout,
false);
601 case sheet::DataPilotFieldOrientation_ROW:
603 uno::Sequence<sheet::MemberResult> aResult = xLevRes->getResults();
604 if (!lcl_MemberEmpty(aResult))
607 aCaption, bHasHiddenMember, bIsDataLayout,
false);
612 case sheet::DataPilotFieldOrientation_PAGE:
614 uno::Sequence<sheet::MemberResult> aResult = getVisiblePageMembersAsResults(xLevel);
617 aCaption, bHasHiddenMember,
false,
true);
630 OSL_ENSURE( nLevCount == 1,
"data layout: multiple levels?" );
631 if ( eDimOrient == sheet::DataPilotFieldOrientation_COLUMN )
633 else if ( eDimOrient == sheet::DataPilotFieldOrientation_ROW )
640 else if ( bIsDataLayout )
657 aData = xResult->getResults();
659 catch (
const uno::RuntimeException&)
667 uno::Reference<beans::XPropertySet> xSrcProp(
xSource, uno::UNO_QUERY );
668 if ( !xSrcProp.is() )
678 catch(
const uno::Exception&)
696 if ( nFlags & sheet::DataResultFlags::ERROR )
698 pDoc->
SetError( nCol, nRow, nTab, FormulaError::NoValue );
700 else if ( nFlags & sheet::DataResultFlags::HASDATA )
706 OSL_ENSURE(
bSizesValid,
"DataCell: !bSizesValid" );
707 sal_uInt32 nFormat = 0;
708 bool bApplyFormat =
false;
746 const sheet::MemberResult& rData,
bool bColHeader,
tools::Long nLevel )
750 if ( nFlags & sheet::MemberResultFlags::HASMEMBER )
752 bool bNumeric = (nFlags & sheet::MemberResultFlags::NUMERIC) != 0;
753 if (bNumeric && std::isfinite( rData.Value))
769 if ( !(nFlags & sheet::MemberResultFlags::SUBTOTAL) )
772 ScDPOutputImpl outputimp(
pDoc, nTab,
781 STR_PIVOT_STYLENAME_TITLE );
783 STR_PIVOT_STYLENAME_RESULT );
789 STR_PIVOT_STYLENAME_TITLE );
791 STR_PIVOT_STYLENAME_RESULT );
806 lcl_SetFrame(
pDoc,nTab, nCol,nRow, nCol,nRow, 20 );
827 lcl_SetStyleById(
pDoc,nTab, nCol,nRow, nCol,nRow, STR_PIVOT_STYLENAME_FIELDNAME );
845 const uno::Sequence<sheet::DataResult>* pRowAry =
aData.getConstArray();
897 return DataPilotTablePositionType::NOT_IN_TABLE;
903 return DataPilotTablePositionType::NOT_IN_TABLE;
907 return DataPilotTablePositionType::RESULT;
912 if (bInColHeader && bInRowHeader)
914 return DataPilotTablePositionType::OTHER;
921 return DataPilotTablePositionType::OTHER;
929 return DataPilotTablePositionType::OTHER;
935 const uno::Sequence<sheet::DataResult>* pRowAry =
aData.getConstArray();
953 for (
size_t nField=0; nField<
pPageFields.size(); ++nField)
959 SCCOL nFldCol = nHdrCol + 1;
961 OUString aPageValue =
ScResId(SCSTR_ALL);
962 const uno::Sequence<sheet::MemberResult>& rRes =
pPageFields[nField].maResult;
963 sal_Int32
n = rRes.getLength();
967 aPageValue =
ScResId(STR_EMPTYDATA);
969 aPageValue = rRes[0].Caption;
972 aPageValue =
ScResId(SCSTR_MULTIPLE);
976 pDoc->
SetString(nFldCol, nHdrRow, nTab, aPageValue, &aParam);
978 lcl_SetFrame(
pDoc,nTab, nFldCol,nHdrRow, nFldCol,nHdrRow, 20 );
994 STR_PIVOT_STYLENAME_TOP );
996 STR_PIVOT_STYLENAME_INNER );
999 ScDPOutputImpl outputimp(
pDoc, nTab,
1002 for (
size_t nField=0; nField<
pColFields.size(); nField++)
1008 const uno::Sequence<sheet::MemberResult> rSequence =
pColFields[nField].maResult;
1009 const sheet::MemberResult* pArray = rSequence.getConstArray();
1010 tools::Long nThisColCount = rSequence.getLength();
1011 OSL_ENSURE( nThisColCount ==
nColCount,
"count mismatch" );
1012 for (
tools::Long nCol=0; nCol<nThisColCount; nCol++)
1015 HeaderCell( nColPos, nRowPos, nTab, pArray[nCol],
true, nField );
1016 if ( ( pArray[nCol].
Flags & sheet::MemberResultFlags::HASMEMBER ) &&
1017 !( pArray[nCol].
Flags & sheet::MemberResultFlags::SUBTOTAL ) )
1020 while ( nEnd+1 < nThisColCount && ( pArray[nEnd+1].
Flags & sheet::MemberResultFlags::CONTINUE ) )
1027 outputimp.AddCol( nColPos );
1028 if ( nColPos + 1 == nEndColPos )
1029 outputimp.OutputBlockFrame( nColPos,nRowPos, nEndColPos,nRowPos+1,
true );
1032 outputimp.OutputBlockFrame( nColPos,nRowPos, nEndColPos,nRowPos );
1034 lcl_SetStyleById(
pDoc, nTab, nColPos,nRowPos, nEndColPos,
nDataStartRow-1, STR_PIVOT_STYLENAME_CATEGORY );
1037 lcl_SetStyleById(
pDoc, nTab, nColPos,nRowPos, nColPos,
nDataStartRow-1, STR_PIVOT_STYLENAME_CATEGORY );
1039 else if ( pArray[nCol].
Flags & sheet::MemberResultFlags::SUBTOTAL )
1040 outputimp.AddCol( nColPos );
1050 std::vector<bool> vbSetBorder;
1052 for (
size_t nField=0; nField<
pRowFields.size(); nField++)
1059 const uno::Sequence<sheet::MemberResult> rSequence =
pRowFields[nField].maResult;
1060 const sheet::MemberResult* pArray = rSequence.getConstArray();
1061 sal_Int32 nThisRowCount = rSequence.getLength();
1062 OSL_ENSURE( nThisRowCount ==
nRowCount,
"count mismatch" );
1063 for (sal_Int32 nRow=0; nRow<nThisRowCount; nRow++)
1066 HeaderCell( nColPos, nRowPos, nTab, pArray[nRow],
false, nField );
1067 if ( ( pArray[nRow].
Flags & sheet::MemberResultFlags::HASMEMBER ) &&
1068 !( pArray[nRow].
Flags & sheet::MemberResultFlags::SUBTOTAL ) )
1073 while ( nEnd+1 < nThisRowCount && ( pArray[nEnd+1].
Flags & sheet::MemberResultFlags::CONTINUE ) )
1076 outputimp.AddRow( nRowPos );
1077 if ( !vbSetBorder[ nRow ] )
1079 outputimp.OutputBlockFrame( nColPos, nRowPos,
nTabEndCol, nEndRowPos );
1080 vbSetBorder[ nRow ] =
true;
1082 outputimp.OutputBlockFrame( nColPos, nRowPos, nColPos, nEndRowPos );
1085 outputimp.OutputBlockFrame( nColPos+1, nRowPos, nColPos+1, nEndRowPos );
1087 lcl_SetStyleById(
pDoc, nTab, nColPos,nRowPos,
nDataStartCol-1,nEndRowPos, STR_PIVOT_STYLENAME_CATEGORY );
1090 lcl_SetStyleById(
pDoc, nTab, nColPos,nRowPos,
nDataStartCol-1,nRowPos, STR_PIVOT_STYLENAME_CATEGORY );
1092 else if ( pArray[nRow].
Flags & sheet::MemberResultFlags::SUBTOTAL )
1093 outputimp.AddRow( nRowPos );
1111 for (sal_Int32 nRow=0; nRow<
nRowCount; nRow++)
1114 const sheet::DataResult* pColAry = pRowAry[nRow].getConstArray();
1115 sal_Int32 nThisColCount = pRowAry[nRow].getLength();
1116 OSL_ENSURE( nThisColCount ==
nColCount,
"count mismatch" );
1117 for (sal_Int32 nCol=0; nCol<nThisColCount; nCol++)
1120 DataCell( nColPos, nRowPos, nTab, pColAry[nCol] );
1124 outputimp.OutputDataArea();
1134 switch (nRegionType)
1136 case DataPilotOutputRangeType::RESULT:
1141 OSL_ENSURE(nRegionType == DataPilotOutputRangeType::WHOLE,
"ScDPOutput::GetOutputRange: unknown region type");
1161 void insertNames(
ScDPUniqueStringSet& rNames,
const uno::Sequence<sheet::MemberResult>& rMemberResults)
1163 for (
const sheet::MemberResult& rMemberResult : rMemberResults)
1165 if (rMemberResult.Flags & sheet::MemberResultFlags::HASMEMBER)
1166 rNames.insert(rMemberResult.Name);
1177 auto lFindDimension = [nDimension](
const ScDPOutLevelData& rField) {
return rField.mnDim == nDimension; };
1184 insertNames(rNames, colit->maResult);
1193 insertNames(rNames, rowit->maResult);
1205void lcl_GetTableVars( sal_Int32& rGrandTotalCols, sal_Int32& rGrandTotalRows, sal_Int32& rDataLayoutIndex,
1206 std::vector<OUString>& rDataNames, std::vector<OUString>& rGivenNames,
1207 sheet::DataPilotFieldOrientation& rDataOrient,
1208 const uno::Reference<sheet::XDimensionsSupplier>& xSource )
1210 rDataLayoutIndex = -1;
1211 rGrandTotalCols = 0;
1212 rGrandTotalRows = 0;
1213 rDataOrient = sheet::DataPilotFieldOrientation_HIDDEN;
1215 uno::Reference<beans::XPropertySet> xSrcProp( xSource, uno::UNO_QUERY );
1219 rGrandTotalCols = 1;
1224 rGrandTotalRows = 1;
1226 if ( !xSource.is() )
1231 sal_Int32 nDataCount = 0;
1233 uno::Reference<container::XIndexAccess> xDims =
new ScNameToIndexAccess( xSource->getDimensions() );
1237 uno::Reference<uno::XInterface> xDim(xDims->getByIndex(nDim), uno::UNO_QUERY);
1238 uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
1239 if ( xDimProp.is() )
1241 sheet::DataPilotFieldOrientation eDimOrient =
1244 sheet::DataPilotFieldOrientation_HIDDEN );
1248 rDataLayoutIndex = nDim;
1249 rDataOrient = eDimOrient;
1251 if ( eDimOrient == sheet::DataPilotFieldOrientation_DATA )
1253 OUString aSourceName;
1254 OUString aGivenName;
1262 OUString strLayoutName;
1264 if( ( aValue >>= strLayoutName ) && !strLayoutName.isEmpty() )
1265 aGivenName = strLayoutName;
1268 catch(
const uno::Exception&)
1271 rDataNames.push_back( aSourceName );
1272 rGivenNames.push_back( aGivenName );
1279 if ( ( rDataOrient == sheet::DataPilotFieldOrientation_COLUMN ) && bColGrand )
1280 rGrandTotalCols = nDataCount;
1281 else if ( ( rDataOrient == sheet::DataPilotFieldOrientation_ROW ) && bRowGrand )
1282 rGrandTotalRows = nDataCount;
1302 switch (rPosData.PositionType)
1304 case DataPilotTablePositionType::RESULT:
1306 vector<DataPilotFieldFilter> aFilters;
1309 DataPilotTableResultData aResData;
1311 aResData.DataFieldIndex = 0;
1312 Reference<beans::XPropertySet> xPropSet(
xSource, UNO_QUERY);
1317 if (nDataFieldCount > 0)
1318 aResData.DataFieldIndex = (nRow -
nDataStartRow) % nDataFieldCount;
1326 rPosData.PositionData <<= aResData;
1337 const uno::Sequence<sheet::MemberResult> rSequence =
pColFields[nField].maResult;
1338 if (!rSequence.hasElements())
1340 const sheet::MemberResult* pArray = rSequence.getConstArray();
1344 while (nItem > 0 && ( pArray[nItem].
Flags & sheet::MemberResultFlags::CONTINUE) )
1350 DataPilotTableHeaderData aHeaderData;
1351 aHeaderData.MemberName = pArray[nItem].Name;
1352 aHeaderData.Flags = pArray[nItem].Flags;
1353 aHeaderData.Dimension =
static_cast<sal_Int32
>(
pColFields[nField].mnDim);
1354 aHeaderData.Hierarchy =
static_cast<sal_Int32
>(
pColFields[nField].mnHier);
1355 aHeaderData.Level =
static_cast<sal_Int32
>(
pColFields[nField].mnLevel);
1357 rPosData.PositionData <<= aHeaderData;
1368 const uno::Sequence<sheet::MemberResult> rSequence =
pRowFields[nField].maResult;
1369 if (!rSequence.hasElements())
1371 const sheet::MemberResult* pArray = rSequence.getConstArray();
1375 while ( nItem > 0 && (pArray[nItem].
Flags & sheet::MemberResultFlags::CONTINUE) )
1381 DataPilotTableHeaderData aHeaderData;
1382 aHeaderData.MemberName = pArray[nItem].Name;
1383 aHeaderData.Flags = pArray[nItem].Flags;
1384 aHeaderData.Dimension =
static_cast<sal_Int32
>(
pRowFields[nField].mnDim);
1385 aHeaderData.Hierarchy =
static_cast<sal_Int32
>(
pRowFields[nField].mnHier);
1386 aHeaderData.Level =
static_cast<sal_Int32
>(
pRowFields[nField].mnLevel);
1388 rPosData.PositionData <<= aHeaderData;
1397 Reference<beans::XPropertySet> xPropSet(
xSource, UNO_QUERY);
1403 if (nDataFieldCount == 0)
1408 sal_Int32 nGrandTotalCols;
1409 sal_Int32 nGrandTotalRows;
1410 sal_Int32 nDataLayoutIndex;
1411 std::vector<OUString> aDataNames;
1412 std::vector<OUString> aGivenNames;
1413 sheet::DataPilotFieldOrientation eDataOrient;
1414 lcl_GetTableVars( nGrandTotalCols, nGrandTotalRows, nDataLayoutIndex, aDataNames, aGivenNames, eDataOrient,
xSource );
1431 bool bFilterByCol = (nCol <= static_cast<SCCOL>(
nTabEndCol - nGrandTotalCols));
1432 bool bFilterByRow = (nRow <= static_cast<SCROW>(
nTabEndRow - nGrandTotalRows));
1435 for (
size_t nColField = 0; nColField <
pColFields.size() && bFilterByCol; ++nColField)
1437 if (
pColFields[nColField].mnDim == nDataLayoutIndex)
1441 sheet::DataPilotFieldFilter
filter;
1444 const uno::Sequence<sheet::MemberResult> rSequence =
pColFields[nColField].maResult;
1445 const sheet::MemberResult* pArray = rSequence.getConstArray();
1447 OSL_ENSURE(
nDataStartCol + rSequence.getLength() - 1 ==
nTabEndCol,
"ScDPOutput::GetDataFieldCellData: error in geometric assumption");
1451 while ( nItem > 0 && (pArray[nItem].
Flags & sheet::MemberResultFlags::CONTINUE) )
1454 filter.MatchValueName = pArray[nItem].Name;
1455 rFilters.push_back(
filter);
1459 for (
size_t nRowField = 0; nRowField <
pRowFields.size() && bFilterByRow; ++nRowField)
1461 if (
pRowFields[nRowField].mnDim == nDataLayoutIndex)
1465 sheet::DataPilotFieldFilter
filter;
1468 const uno::Sequence<sheet::MemberResult> rSequence =
pRowFields[nRowField].maResult;
1469 const sheet::MemberResult* pArray = rSequence.getConstArray();
1471 OSL_ENSURE(
nDataStartRow + rSequence.getLength() - 1 ==
nTabEndRow,
"ScDPOutput::GetDataFieldCellData: error in geometric assumption");
1475 while ( nItem > 0 && (pArray[nItem].
Flags & sheet::MemberResultFlags::CONTINUE) )
1478 filter.MatchValueName = pArray[nItem].Name;
1479 rFilters.push_back(
filter);
1487OUString lcl_GetDataFieldName( std::u16string_view rSourceName, sal_Int16 eFunc )
1492 case sheet::GeneralFunction2::SUM: pStrId = STR_FUN_TEXT_SUM;
break;
1494 case sheet::GeneralFunction2::COUNTNUMS: pStrId = STR_FUN_TEXT_COUNT;
break;
1495 case sheet::GeneralFunction2::AVERAGE: pStrId = STR_FUN_TEXT_AVG;
break;
1496 case sheet::GeneralFunction2::MEDIAN: pStrId = STR_FUN_TEXT_MEDIAN;
break;
1497 case sheet::GeneralFunction2::MAX: pStrId = STR_FUN_TEXT_MAX;
break;
1498 case sheet::GeneralFunction2::MIN: pStrId = STR_FUN_TEXT_MIN;
break;
1499 case sheet::GeneralFunction2::PRODUCT: pStrId = STR_FUN_TEXT_PRODUCT;
break;
1500 case sheet::GeneralFunction2::STDEV:
1501 case sheet::GeneralFunction2::STDEVP: pStrId = STR_FUN_TEXT_STDDEV;
break;
1502 case sheet::GeneralFunction2::VAR:
1503 case sheet::GeneralFunction2::VARP: pStrId = STR_FUN_TEXT_VAR;
break;
1505 case sheet::GeneralFunction2::AUTO:
break;
1514 return ScResId(pStrId) +
" - " + rSourceName;
1520 OUString& rSourceName, OUString& rGivenName,
const uno::Reference<uno::XInterface>& xDim )
1522 uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
1523 uno::Reference<container::XNamed> xDimName( xDim, uno::UNO_QUERY );
1524 if ( !(xDimProp.is() && xDimName.is()) )
1537 rGivenName = lcl_GetDataFieldName( rSourceName, eFunc );
1568 rOrient = sheet::DataPilotFieldOrientation_COLUMN;
1577 rOrient = sheet::DataPilotFieldOrientation_ROW;
1587 rOrient = sheet::DataPilotFieldOrientation_PAGE;
1594 rOrient = sheet::DataPilotFieldOrientation_HIDDEN;
1630 bool bFound =
false;
1631 bool bBeforeDrag =
false;
1632 bool bAfterDrag =
false;
1638 if ( nField <
nPos )
1640 else if ( nField >
nPos )
1664 rOrient = sheet::DataPilotFieldOrientation_COLUMN;
1684 bool bFound =
false;
1685 bool bBeforeDrag =
false;
1686 bool bAfterDrag =
false;
1692 if ( nField <
nPos )
1694 else if ( nField >
nPos )
1718 rOrient = sheet::DataPilotFieldOrientation_ROW;
1740 bool bFound =
false;
1741 bool bBeforeDrag =
false;
1742 bool bAfterDrag =
false;
1748 if ( nField <
nPos )
1750 else if ( nField >
nPos )
1774 rOrient = sheet::DataPilotFieldOrientation_PAGE;
@ HiddenMember
dp button with popup arrow
bool GetHeaderDrag(const ScAddress &rPos, bool bMouseLeft, bool bMouseTop, tools::Long nDragDim, tools::Rectangle &rPosRect, css::sheet::DataPilotFieldOrientation &rOrient, tools::Long &rDimPos)
void HeaderCell(SCCOL nCol, SCROW nRow, SCTAB nTab, const css::sheet::MemberResult &rData, bool bColHeader, tools::Long nLevel)
bool GetHeaderLayout() const
ScRange GetOutputRange(sal_Int32 nRegionType=css::sheet::DataPilotOutputRangeType::WHOLE)
Refresh?
std::unique_ptr< sal_uInt32[]> pRowNumFmt
void GetPositionData(const ScAddress &rPos, css::sheet::DataPilotTablePositionData &rPosData)
void GetMemberResultNames(ScDPUniqueStringSet &rNames, tools::Long nDimension)
css::uno::Sequence< css::uno::Sequence< css::sheet::DataResult > > aData
void SetPosition(const ScAddress &rPos)
css::uno::Reference< css::sheet::XDimensionsSupplier > xSource
bool GetDataResultPositionData(::std::vector< css::sheet::DataPilotFieldFilter > &rFilters, const ScAddress &rPos)
Get filtering criteria based on the position of the cell within data field region.
void FieldCell(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScDPOutLevelData &rData, bool bInTable)
tools::Long GetHeaderDim(const ScAddress &rPos, css::sheet::DataPilotFieldOrientation &rOrient)
std::vector< ScDPOutLevelData > pColFields
bool IsFilterButton(const ScAddress &rPos)
std::vector< ScDPOutLevelData > pPageFields
ScDPOutput(ScDocument *pD, css::uno::Reference< css::sheet::XDimensionsSupplier > xSrc, const ScAddress &rPos, bool bFilter)
static void GetDataDimensionNames(OUString &rSourceName, OUString &rGivenName, const css::uno::Reference< css::uno::XInterface > &xDim)
OUString aDataDescription
std::unique_ptr< sal_uInt32[]> pColNumFmt
std::vector< ScDPOutLevelData > pRowFields
sal_Int32 GetHeaderRows() const
void SetHeaderLayout(bool bUseGrid)
void DataCell(SCCOL nCol, SCROW nRow, SCTAB nTab, const css::sheet::DataResult &rData)
sal_Int32 GetPositionType(const ScAddress &rPos)
Query which sub-area of the table the cell is in.
static SC_DLLPUBLIC OUString getSourceDimensionName(std::u16string_view rName)
void ApplyFrameAreaTab(const ScRange &rRange, const SvxBoxItem &rLineOuter, const SvxBoxInfoItem &rLineInner)
SC_DLLPUBLIC SCCOL MaxCol() const
SC_DLLPUBLIC SCROW MaxRow() const
SC_DLLPUBLIC bool ApplyFlagsTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, ScMF nFlags)
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
void SetError(SCCOL nCol, SCROW nRow, SCTAB nTab, const FormulaError nError)
SC_DLLPUBLIC void SetValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rVal)
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
SC_DLLPUBLIC void DeleteAreaTab(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, InsertDeleteFlags nDelFlag)
SC_DLLPUBLIC void ApplyStyleAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScStyleSheet &rStyle)
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits nMask=SfxStyleSearchBits::All) override
virtual SC_DLLPUBLIC SfxItemSet & GetItemSet() override
virtual bool SetParent(const OUString &rParentName) override
static bool GetBoolProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName, bool bDefault=false)
static EnumT GetEnumProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName, EnumT nDefault)
static sal_Int16 GetShortProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName, sal_Int16 nDefault)
static OUString GetStringProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName, const OUString &rDefault)
static sal_Int32 GetLongProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName)
static css::uno::Sequence< ValueType > VectorToSequence(const std::vector< ValueType > &rVector)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All) const
#define SC_DP_FRAME_OUTER_BOLD
#define SC_DP_FRAME_COLOR
#define SC_DP_FRAME_INNER_BOLD
static void lcl_DoFilterButton(ScDocument *pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab)
std::unordered_set< OUString > ScDPUniqueStringSet
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
OUString ScResId(TranslateId aId)
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
constexpr TypedWhichId< SvxWeightItem > ATTR_CJK_FONT_WEIGHT(113)
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
constexpr TypedWhichId< SvxBoxInfoItem > ATTR_BORDER_INNER(151)
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
constexpr TypedWhichId< SvxWeightItem > ATTR_CTL_FONT_WEIGHT(118)
uno::Sequence< sheet::MemberResult > maResult
Prevailing number format used in the source data.
ScDPOutLevelData(tools::Long nDim, tools::Long nHier, tools::Long nLevel, tools::Long nDimPos, sal_uInt32 nSrcNumFmt, const uno::Sequence< sheet::MemberResult > &aResult, OUString aName, OUString aCaption, bool bHasHiddenMember, bool bDataLayout, bool bPageDim)
OUString maCaption
Name is the internal field name.
bool mbHasHiddenMember
Caption is the name visible in the output table.
Store parameters used in the ScDocument::SetString() method.
bool mbHandleApostrophe
When true, treat input with a leading apostrophe as an escape character for all content,...
void setTextInput()
Call this whenever you need to unconditionally set input as text, no matter what the input is.
void setNumericInput()
Call this whenever you need to maximize the chance of input being detected as a numeric value (number...
bool mbDetectNumberFormat
When true, we try to detect special number format (dates etc) from the input string,...
@ Always
Set Text number format if the input string can be parsed as a number or formula text.
TextFormatPolicy meSetTextNumFormat
Determine when to set the 'Text' number format to the cell where the input string is being set.
constexpr OUStringLiteral SC_UNO_DP_HAS_HIDDEN_MEMBER
constexpr OUStringLiteral SC_UNONAME_NUMFMT
constexpr OUStringLiteral SC_UNO_DP_COLGRAND
constexpr OUStringLiteral SC_UNO_DP_POSITION
constexpr OUStringLiteral SC_UNO_DP_DATAFIELDCOUNT
constexpr OUStringLiteral SC_UNO_DP_ISDATALAYOUT
constexpr OUStringLiteral SC_UNO_DP_LAYOUTNAME
constexpr OUStringLiteral SC_UNO_DP_FUNCTION2
constexpr OUStringLiteral SC_UNO_DP_DATADESC
constexpr OUStringLiteral SC_UNO_DP_ROWGRAND
#define SC_UNO_DP_NUMBERFO
constexpr OUStringLiteral SC_UNO_DP_USEDHIERARCHY
constexpr OUStringLiteral SC_UNO_DP_ORIENTATION
constexpr OUStringLiteral SC_UNO_DP_ISVISIBLE