Lines 986-991
void ScDPOutput::GetPositionData( ScDPPo
Link Here
|
986 |
} |
986 |
} |
987 |
} |
987 |
} |
988 |
|
988 |
|
|
|
989 |
#undef DEBUG_GETPIVOTTABLE |
990 |
#ifdef DEBUG_GETPIVOTTABLE |
991 |
#include <stdio.h> |
992 |
static const sal_Char* dbg_dump( const ByteString& rStr) |
993 |
{ |
994 |
static ByteString aStr; |
995 |
aStr = rStr; |
996 |
aStr.Append(static_cast< char >(0)); |
997 |
return aStr.GetBuffer(); |
998 |
} |
999 |
static const sal_Char* dbg_dump( const UniString& rStr) |
1000 |
{ |
1001 |
return dbg_dump(ByteString(rStr, RTL_TEXTENCODING_UTF8)); |
1002 |
} |
1003 |
|
1004 |
static void lcl_dumpOutputLevel( const char* name, char id_char, |
1005 |
long n, const ScDPOutLevelData* pFields ) |
1006 |
{ |
1007 |
fprintf(stderr, "=================================\n"); |
1008 |
fprintf(stderr, "#%s = %03ld\n", name, n); |
1009 |
for (long i=0; i<n; i++) |
1010 |
{ |
1011 |
fprintf(stderr, "\t%c%03ld) : %s\n", id_char, i, |
1012 |
dbg_dump( pFields[i].aCaption )); |
1013 |
|
1014 |
const uno::Sequence<sheet::MemberResult> rSequence = pFields[i].aResult; |
1015 |
const sheet::MemberResult* pArray = rSequence.getConstArray(); |
1016 |
for (long j = 0 ; j < rSequence.getLength(); j++) |
1017 |
{ |
1018 |
fprintf(stderr, "\t\t%3ld) : \'%s\' %lx\n", j, |
1019 |
dbg_dump( pArray[j].Name ), rSequence[j].Flags ); |
1020 |
} |
1021 |
} |
1022 |
} |
1023 |
#endif |
1024 |
|
1025 |
// Returns TRUE if the filter matched |
1026 |
static BOOL lcl_getPivotDataApplyFilter( const ScDPGetPivotDataField & rFilter, |
1027 |
long n, const ScDPOutLevelData* pFields, |
1028 |
std::vector< BOOL >& rResult ) |
1029 |
{ |
1030 |
for( long int i=0 ; i < n ; i++ ) |
1031 |
{ |
1032 |
// WORRY : Can Caption be different from Name ? |
1033 |
if( rFilter.maFieldName == pFields[i].aCaption) |
1034 |
{ |
1035 |
BOOL bPrev = FALSE; |
1036 |
|
1037 |
const uno::Sequence<sheet::MemberResult> rSequence = pFields[i].aResult; |
1038 |
const sheet::MemberResult* pArray = rSequence.getConstArray(); |
1039 |
|
1040 |
DBG_ASSERT( rResult.size() == rSequence.getLength(), |
1041 |
"Number of fields do not match result count" ); |
1042 |
|
1043 |
for( signed long int j=0 ; j < rResult.size(); j++ ) |
1044 |
{ |
1045 |
if( rResult[j] ) |
1046 |
{ |
1047 |
if( rSequence[j].Flags & sheet::MemberResultFlags::SUBTOTAL ) |
1048 |
rResult[j] = FALSE; |
1049 |
else if( rSequence[j].Flags & sheet::MemberResultFlags::CONTINUE ) |
1050 |
rResult[j] = bPrev; |
1051 |
else if( rSequence[j].Flags & sheet::MemberResultFlags::HASMEMBER ) |
1052 |
rResult[j] = bPrev = |
1053 |
( String( pArray[j].Name ) == rFilter.maValStr ); |
1054 |
} |
1055 |
} |
1056 |
return TRUE; |
1057 |
} |
1058 |
} |
1059 |
|
1060 |
return FALSE; |
1061 |
} |
1062 |
|
1063 |
// Returns TRUE on success and stores the result in rTarget |
1064 |
// Returns FALSE if rFilters or rTarget describes something that is not visible |
1065 |
BOOL ScDPOutput::GetPivotData( ScDPGetPivotDataField& rTarget, |
1066 |
const std::vector< ScDPGetPivotDataField >& rFilters ) |
1067 |
{ |
1068 |
CalcSizes(); |
1069 |
|
1070 |
#ifdef DEBUG_GETPIVOTTABLE |
1071 |
{ |
1072 |
lcl_dumpOutputLevel ("PageHeaders", 'P', nPageFieldCount, pPageFields); |
1073 |
lcl_dumpOutputLevel ("ColHeaders", 'C', nColFieldCount, pColFields); |
1074 |
lcl_dumpOutputLevel ("RowHeaders", 'R', nRowFieldCount, pRowFields); |
1075 |
|
1076 |
fprintf(stderr, "=================================\n"); |
1077 |
fprintf(stderr, "#Rows = %03ld\n", nRowCount); |
1078 |
const uno::Sequence<sheet::DataResult>* pRowAry = aData.getConstArray(); |
1079 |
for (long nRow=0; nRow<nRowCount; nRow++) |
1080 |
{ |
1081 |
const sheet::DataResult* pColAry = pRowAry[nRow].getConstArray(); |
1082 |
long nThisColCount = pRowAry[nRow].getLength(); |
1083 |
fprintf(stderr, "R %03ld\n", nRow); |
1084 |
for (long nCol=0; nCol<nThisColCount; nCol++) |
1085 |
{ |
1086 |
const sheet::DataResult& rData = pColAry[nCol]; |
1087 |
const long nFlags = rData.Flags; |
1088 |
|
1089 |
fprintf(stderr, "\tC%03ld) %4lx ->", nCol, nFlags); |
1090 |
|
1091 |
if ( nFlags & sheet::DataResultFlags::ERROR ) |
1092 |
{ |
1093 |
fprintf(stderr, "ERR" ); |
1094 |
} |
1095 |
else if ( nFlags & (sheet::DataResultFlags::HASDATA | |
1096 |
sheet::DataResultFlags::SUBTOTAL )) |
1097 |
{ |
1098 |
fprintf(stderr, "%g", rData.Value ); |
1099 |
} |
1100 |
fprintf(stderr, "\n" ); |
1101 |
} |
1102 |
} |
1103 |
} |
1104 |
#endif |
1105 |
|
1106 |
std::vector< BOOL > aIncludeCol( nColCount, TRUE ); |
1107 |
std::vector< BOOL > aIncludeRow( nRowCount, TRUE ); |
1108 |
BOOL aFilterApplied; |
1109 |
signed long int i; |
1110 |
|
1111 |
for( long int nFilter=0 ; nFilter < rFilters.size() ; nFilter++ ) |
1112 |
{ |
1113 |
aFilterApplied = FALSE; |
1114 |
for( long int i=0 ; i < nPageFieldCount ; i++ ) |
1115 |
{ |
1116 |
// WORRY : Can Caption be different from Name ? |
1117 |
if( rFilters[nFilter].maFieldName == pPageFields[i].aCaption ) |
1118 |
{ |
1119 |
signed long int j; |
1120 |
|
1121 |
DBG_ASSERT( aFilters[i].mbValIsStr , "Numeric Page filter ?" ); |
1122 |
|
1123 |
const uno::Sequence<sheet::MemberResult> rSequence = pPageFields[i].aResult; |
1124 |
const sheet::MemberResult* pArray = rSequence.getConstArray(); |
1125 |
for( j = rSequence.getLength(); j-- > 0 ; ) |
1126 |
{ |
1127 |
if( String( pArray[j].Name) == rFilters[nFilter].maValStr ) |
1128 |
break; |
1129 |
} |
1130 |
|
1131 |
// We operate on VISIBLE data only. |
1132 |
// Selecting a hidden page is an error |
1133 |
if( j < 0 ) |
1134 |
return FALSE; |
1135 |
aFilterApplied = TRUE; |
1136 |
break; |
1137 |
} |
1138 |
} |
1139 |
if( aFilterApplied ) |
1140 |
continue; |
1141 |
|
1142 |
if( !lcl_getPivotDataApplyFilter( rFilters[nFilter], nColFieldCount, |
1143 |
pColFields, aIncludeCol ) && |
1144 |
!lcl_getPivotDataApplyFilter( rFilters[nFilter], nRowFieldCount, |
1145 |
pRowFields, aIncludeRow ) ) |
1146 |
{ |
1147 |
// All filter fields must be used |
1148 |
return FALSE; |
1149 |
} |
1150 |
} |
1151 |
|
1152 |
// ensure that at least 1 col is visible |
1153 |
for( i = aIncludeCol.size() ; i-- > 0 ; ) |
1154 |
{ |
1155 |
if( aIncludeCol[i] ) |
1156 |
break; |
1157 |
} |
1158 |
if( i < 0 ) |
1159 |
return FALSE; |
1160 |
|
1161 |
// ensure that at least 1 row is visible |
1162 |
for( i = aIncludeRow.size() ; i-- > 0 ; ) |
1163 |
{ |
1164 |
if( aIncludeRow[i] ) |
1165 |
break; |
1166 |
} |
1167 |
if( i < 0 ) |
1168 |
return FALSE; |
1169 |
|
1170 |
double accum = 0.; |
1171 |
std::vector< BOOL > aRowPrev( nRowFieldCount, TRUE ); |
1172 |
|
1173 |
const uno::Sequence<sheet::DataResult>* pRowAry = aData.getConstArray(); |
1174 |
for (long nRow=0; nRow<nRowCount; nRow++) |
1175 |
{ |
1176 |
if( aIncludeRow[nRow] ) |
1177 |
{ |
1178 |
const sheet::DataResult* pColAry = pRowAry[nRow].getConstArray(); |
1179 |
long nThisColCount = pRowAry[nRow].getLength(); |
1180 |
for (long nCol=0; nCol<nThisColCount; nCol++) |
1181 |
{ |
1182 |
if( aIncludeCol[nCol] ) |
1183 |
{ |
1184 |
const sheet::DataResult& rData = pColAry[nCol]; |
1185 |
|
1186 |
// If there are no filters for cols or no filters for rows |
1187 |
// then subtotals still appear |
1188 |
if( (rData.Flags & (sheet::DataResultFlags::HASDATA| |
1189 |
sheet::DataResultFlags::SUBTOTAL| |
1190 |
sheet::DataResultFlags::ERROR)) == sheet::DataResultFlags::HASDATA ) |
1191 |
{ |
1192 |
accum += rData.Value; |
1193 |
} |
1194 |
} |
1195 |
} |
1196 |
} |
1197 |
} |
1198 |
|
1199 |
rTarget.mbValIsStr = FALSE; |
1200 |
rTarget.mnValNum = accum; |
1201 |
return TRUE; |
1202 |
} |
1203 |
|
989 |
BOOL ScDPOutput::IsFilterButton( const ScAddress& rPos ) |
1204 |
BOOL ScDPOutput::IsFilterButton( const ScAddress& rPos ) |
990 |
{ |
1205 |
{ |
991 |
SCCOL nCol = rPos.Col(); |
1206 |
SCCOL nCol = rPos.Col(); |