sc/qa/unit/helper/qahelper.cxx   |   38 ++++++++++++++++++++++++++++++++++++++
 sc/source/core/data/dpoutput.cxx |    6 +++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit 09d0898b358b368fbe644eb5acbcfdab4af58751
Author:     luigiiucci <luigi.iu...@collabora.com>
AuthorDate: Wed May 17 11:02:37 2023 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Jun 28 06:46:05 2023 +0200

    Header columns can disappear with filtered data in pivot tables
    
    When we set on a pivot table a filter that filters all the rows,
    the pivot table showed only the first header columns and computed
    column, but all the columns headers should still be shown so we can
    adjust the filter for the column. This fixes this issue.
    
    Also add more debug output and prevent a crash when running pivot
    table tests.
    
    Change-Id: I30b4ee72cf8436c4522ab4ba0781462b214816dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151871
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 3551d18404cb19cdaa8edb170a549f5c5405d0cb)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153692

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index efb2e68c4fbc..82227ec12006 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -38,6 +38,7 @@
 #include <tokenarray.hxx>
 #include <vcl/keycodes.hxx>
 #include <vcl/scheduler.hxx>
+#include <o3tl/safeint.hxx>
 
 #include <orcus/csv_parser.hpp>
 
@@ -481,6 +482,43 @@ bool checkOutput(
     svl::GridPrinter printer(e.Row() - s.Row() + 1, e.Col() - s.Col() + 1, 
CALC_DEBUG_OUTPUT != 0);
     SCROW nOutRowSize = e.Row() - s.Row() + 1;
     SCCOL nOutColSize = e.Col() - s.Col() + 1;
+
+    // Check if expected size iz smaller than actual size (and prevent a crash)
+    if (aCheck.size() < o3tl::make_unsigned(nOutRowSize) || aCheck[0].size() < 
o3tl::make_unsigned(nOutColSize))
+    {
+        // Dump the arrays to console, so we can compare
+        std::cout << "Expected data:" << std::endl;
+        for (size_t nRow = 0; nRow < aCheck.size(); ++nRow)
+        {
+            for (size_t nCol = 0; nCol < aCheck[nRow].size(); ++nCol)
+            {
+                const char* p = aCheck[nRow][nCol];
+                if (p)
+                {
+                    OUString aCheckVal = OUString::createFromAscii(p);
+                    std::cout << "'" << aCheckVal << "', ";
+                }
+                else
+                    std::cout << "null, ";
+            }
+            std::cout << std::endl;
+        }
+
+        std::cout << "Actual data:" << std::endl;
+        for (SCROW nRow = 0; nRow < nOutRowSize; ++nRow)
+        {
+            for (SCCOL nCol = 0; nCol < nOutColSize; ++nCol)
+            {
+                OUString aVal = pDoc->GetString(nCol + s.Col(), nRow + 
s.Row(), s.Tab());
+                std::cout << "'" << aVal << "', ";
+            }
+            std::cout << std::endl;
+        }
+        std::cout << std::endl;
+
+        return false;
+    }
+
     for (SCROW nRow = 0; nRow < nOutRowSize; ++nRow)
     {
         for (SCCOL nCol = 0; nCol < nOutColSize; ++nCol)
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index 00d8f2aabeb4..c964dda14c7a 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -608,7 +608,11 @@ ScDPOutput::ScDPOutput( ScDocument* pD, 
uno::Reference<sheet::XDimensionsSupplie
                                     {
                                         uno::Sequence<sheet::MemberResult> 
aResult = xLevRes->getResults();
                                         ++nRowDims;
-                                        if (!lcl_MemberEmpty(aResult))
+                                        // We want only to remove the DATA 
column if it is empty
+                                        // and not any other empty columns (to 
still show the
+                                        // header columns)
+                                        bool bSkip = lcl_MemberEmpty(aResult) 
&& bIsDataLayout;
+                                        if (!bSkip)
                                         {
                                             bool bFieldCompact = false;
                                             try

Reply via email to