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

New commits:
commit 021712f9500910c3433360ec54d35f3564f540ce
Author:     luigiiucci <luigi.iu...@collabora.com>
AuthorDate: Wed May 17 11:02:37 2023 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Jun 29 04:52:40 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/+/153686
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index f9c7af04a813..d21571def5a3 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -32,6 +32,7 @@
 #include <scitems.hxx>
 #include <stringutil.hxx>
 #include <tokenarray.hxx>
+#include <o3tl/safeint.hxx>
 
 #include <orcus/csv_parser.hpp>
 
@@ -404,6 +405,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 301e2c83ba4f..ff4335a81420 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