diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2021-05-09 10:31:21 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-05-28 12:14:08 +0200 |
commit | fbfb57635b602b50cb22465047ae5bcdbef3dd0a (patch) | |
tree | 8668cab50dde3062bc891547dae937ad36abc8b6 /sc/source | |
parent | 7f60fafe3b54e2cc86d996b3211be7e82fb478a2 (diff) |
tdf#138438 sc: fix "Top 10" autoFilter in multiple columns
Check all QueryItems instead of just the first one. Now
top 10 values are visible (except the values hidden by the
filters of the previous columns).
Change-Id: I317d0c6843e568f8645b744968352a0e895a42dc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115267
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/table3.cxx | 105 |
1 files changed, 54 insertions, 51 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index e8837f6ca95a..216aa98e978a 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2906,48 +2906,50 @@ void ScTable::TopTenQuery( ScQueryParam& rParam ) for ( SCSIZE i=0; (i<nEntryCount) && (rParam.GetEntry(i).bDoQuery); i++ ) { ScQueryEntry& rEntry = rParam.GetEntry(i); - ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); + ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems(); - switch ( rEntry.eOp ) + for (ScQueryEntry::Item& rItem : rItems) { - case SC_TOPVAL: - case SC_BOTVAL: - case SC_TOPPERC: - case SC_BOTPERC: + switch (rEntry.eOp) { - ScSortParam aLocalSortParam( rParam, static_cast<SCCOL>(rEntry.nField) ); - aSortParam = aLocalSortParam; // used in CreateSortInfoArray, Compare - if ( !bSortCollatorInitialized ) - { - bSortCollatorInitialized = true; - InitSortCollator( aLocalSortParam ); - } - std::unique_ptr<ScSortInfoArray> pArray(CreateSortInfoArray(aSortParam, nRow1, rParam.nRow2, bGlobalKeepQuery, false)); - DecoladeRow( pArray.get(), nRow1, rParam.nRow2 ); - QuickSort( pArray.get(), nRow1, rParam.nRow2 ); - std::unique_ptr<ScSortInfo[]> const & ppInfo = pArray->GetFirstArray(); - SCSIZE nValidCount = nCount; - // Don't count note or blank cells, they are sorted to the end - while (nValidCount > 0 && ppInfo[nValidCount-1].maCell.isEmpty()) - nValidCount--; - // Don't count Strings, they are between Value and blank - while (nValidCount > 0 && ppInfo[nValidCount-1].maCell.hasString()) - nValidCount--; - if ( nValidCount > 0 ) + case SC_TOPVAL: + case SC_BOTVAL: + case SC_TOPPERC: + case SC_BOTPERC: { - if ( rItem.meType == ScQueryEntry::ByString ) - { // by string ain't going to work - rItem.meType = ScQueryEntry::ByValue; - rItem.mfVal = 10; // 10 and 10% respectively + ScSortParam aLocalSortParam(rParam, static_cast<SCCOL>(rEntry.nField)); + aSortParam = aLocalSortParam; // used in CreateSortInfoArray, Compare + if (!bSortCollatorInitialized) + { + bSortCollatorInitialized = true; + InitSortCollator(aLocalSortParam); } - SCSIZE nVal = (rItem.mfVal >= 1 ? static_cast<SCSIZE>(rItem.mfVal) : 1); - SCSIZE nOffset = 0; - switch ( rEntry.eOp ) + std::unique_ptr<ScSortInfoArray> pArray(CreateSortInfoArray(aSortParam, nRow1, rParam.nRow2, bGlobalKeepQuery, false)); + DecoladeRow(pArray.get(), nRow1, rParam.nRow2); + QuickSort(pArray.get(), nRow1, rParam.nRow2); + std::unique_ptr<ScSortInfo[]> const& ppInfo = pArray->GetFirstArray(); + SCSIZE nValidCount = nCount; + // Don't count note or blank cells, they are sorted to the end + while (nValidCount > 0 && ppInfo[nValidCount - 1].maCell.isEmpty()) + nValidCount--; + // Don't count Strings, they are between Value and blank + while (nValidCount > 0 && ppInfo[nValidCount - 1].maCell.hasString()) + nValidCount--; + if (nValidCount > 0) { + if (rItem.meType == ScQueryEntry::ByString) + { // by string ain't going to work + rItem.meType = ScQueryEntry::ByValue; + rItem.mfVal = 10; // 10 and 10% respectively + } + SCSIZE nVal = (rItem.mfVal >= 1 ? static_cast<SCSIZE>(rItem.mfVal) : 1); + SCSIZE nOffset = 0; + switch (rEntry.eOp) + { case SC_TOPVAL: { rEntry.eOp = SC_GREATER_EQUAL; - if ( nVal > nValidCount ) + if (nVal > nValidCount) nVal = nValidCount; nOffset = nValidCount - nVal; // 1 <= nVal <= nValidCount } @@ -2955,7 +2957,7 @@ void ScTable::TopTenQuery( ScQueryParam& rParam ) case SC_BOTVAL: { rEntry.eOp = SC_LESS_EQUAL; - if ( nVal > nValidCount ) + if (nVal > nValidCount) nVal = nValidCount; nOffset = nVal - 1; // 1 <= nVal <= nValidCount } @@ -2963,20 +2965,20 @@ void ScTable::TopTenQuery( ScQueryParam& rParam ) case SC_TOPPERC: { rEntry.eOp = SC_GREATER_EQUAL; - if ( nVal > 100 ) + if (nVal > 100) nVal = 100; nOffset = nValidCount - (nValidCount * nVal / 100); - if ( nOffset >= nValidCount ) + if (nOffset >= nValidCount) nOffset = nValidCount - 1; } break; case SC_BOTPERC: { rEntry.eOp = SC_LESS_EQUAL; - if ( nVal > 100 ) + if (nVal > 100) nVal = 100; nOffset = (nValidCount * nVal / 100); - if ( nOffset >= nValidCount ) + if (nOffset >= nValidCount) nOffset = nValidCount - 1; } break; @@ -2984,29 +2986,30 @@ void ScTable::TopTenQuery( ScQueryParam& rParam ) { // added to avoid warnings } + } + ScRefCellValue aCell = ppInfo[nOffset].maCell; + if (aCell.hasNumeric()) + rItem.mfVal = aCell.getValue(); + else + { + OSL_FAIL("TopTenQuery: pCell no ValueData"); + rEntry.eOp = SC_GREATER_EQUAL; + rItem.mfVal = 0; + } } - ScRefCellValue aCell = ppInfo[nOffset].maCell; - if (aCell.hasNumeric()) - rItem.mfVal = aCell.getValue(); else { - OSL_FAIL( "TopTenQuery: pCell no ValueData" ); rEntry.eOp = SC_GREATER_EQUAL; + rItem.meType = ScQueryEntry::ByValue; rItem.mfVal = 0; } } - else + break; + default: { - rEntry.eOp = SC_GREATER_EQUAL; - rItem.meType = ScQueryEntry::ByValue; - rItem.mfVal = 0; + // added to avoid warnings } } - break; - default: - { - // added to avoid warnings - } } } if ( bSortCollatorInitialized ) |