[Libreoffice-commits] .: Branch 'libreoffice-3-4' - 2 commits - sc/inc sc/qa sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Mon May 2 22:55:12 PDT 2011


 sc/inc/dpcachetable.hxx              |   12 ++++++---
 sc/qa/unit/ucalc.cxx                 |   33 ++++++++++++++++++++++---
 sc/source/core/data/dpcachetable.cxx |   46 +++++++++++++++++++++++------------
 3 files changed, 70 insertions(+), 21 deletions(-)

New commits:
commit 17bf9ff55f2a25aef97881d39f3bb51e3c102bdf
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue May 3 01:53:34 2011 -0400

    Added code to test standard query filter in data pilot tables.

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ba213af..ba8176b 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1084,7 +1084,7 @@ void Test::testDataPilotFilters()
             { "Total Sum - Val2", "80" }
         };
 
-        bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output");
+        bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output (unfiltered)");
         CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
     }
 
@@ -1111,11 +1111,38 @@ void Test::testDataPilotFilters()
             { "Total Sum - Val2", "40" }
         };
 
-        bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output");
+        bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output (filtered by page)");
         CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
     }
 
-    // TODO: Find out how to set standard filter and test it.
+    // Set query filter.
+    ScSheetSourceDesc aDesc(*pDPObj->GetSheetDesc());
+    ScQueryParam aQueryParam(aDesc.GetQueryParam());
+    CPPUNIT_ASSERT_MESSAGE("There should be at least one query entry.", aQueryParam.GetEntryCount() > 0);
+    ScQueryEntry& rEntry = aQueryParam.GetEntry(0);
+    rEntry.bDoQuery = true;
+    rEntry.nField = 1;  // Group1
+    rEntry.nVal = 1;
+    aDesc.SetQueryParam(aQueryParam);
+    pDPObj->SetSheetDesc(aDesc);
+    pDPObj->Output(aOutRange.aStart);
+    aOutRange = pDPObj->GetOutRange();
+    {
+        // Expected output table content.  0 = empty cell
+        const char* aOutputCheck[][2] = {
+            { "Filter", 0 },
+            { "Group2", "A" },
+            { 0, 0 },
+            { "Data", 0 },
+            { "Sum - Val1", "2" },
+            { "Sum - Val2", "20" },
+            { "Total Sum - Val1", "2" },
+            { "Total Sum - Val2", "20" }
+        };
+
+        bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output (filtered by query)");
+        CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+    }
 
     pDPs->FreeTable(pDPObj);
     CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
commit 0060509ae519776c5f112aedf3531505e091ab12
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Mon May 2 23:15:51 2011 -0400

    fdo#36771: Treat filter by "filter" and filter by "page" separate.
    
    The new datapilot cache implementation mixed these two up.  I guess
    it's best to have two separate flags for these.

diff --git a/sc/inc/dpcachetable.hxx b/sc/inc/dpcachetable.hxx
index 4c83ec9..dc67427 100644
--- a/sc/inc/dpcachetable.hxx
+++ b/sc/inc/dpcachetable.hxx
@@ -58,6 +58,13 @@ struct ScQueryParam;
 
 class SC_DLLPUBLIC ScDPCacheTable
 {
+    struct RowFlag
+    {
+        bool mbShowByFilter:1;
+        bool mbShowByPage:1;
+        bool isActive() const;
+        RowFlag();
+    };
 public:
     /** individual filter item used in SingleFilter and GroupFilter. */
     struct FilterItem
@@ -188,9 +195,8 @@ private:
     /** unique field entires for each field (column). */
     ::std::vector< ::std::vector<SCROW> > maFieldEntries;
 
-    /** used to track visibility of rows.  The first row below the header row
-        has the index of 0. */
-    ::std::vector<bool> maRowsVisible;
+    /** Row flags. The first row below the header row has the index of 0. */
+    ::std::vector<RowFlag> maRowFlags;
 
     const ScDPCache* mpCache;
 };
diff --git a/sc/source/core/data/dpcachetable.cxx b/sc/source/core/data/dpcachetable.cxx
index f764272..40d34ac 100644
--- a/sc/source/core/data/dpcachetable.cxx
+++ b/sc/source/core/data/dpcachetable.cxx
@@ -73,6 +73,17 @@ static sal_Bool lcl_HasQueryEntry( const ScQueryParam& rParam )
 
 // ----------------------------------------------------------------------------
 
+bool ScDPCacheTable::RowFlag::isActive() const
+{
+    return mbShowByFilter && mbShowByPage;
+}
+
+ScDPCacheTable::RowFlag::RowFlag() :
+    mbShowByFilter(true),
+    mbShowByPage(true)
+{
+}
+
 ScDPCacheTable::FilterItem::FilterItem() :
     mfValue(0.0),
     mbHasValue(false)
@@ -185,8 +196,8 @@ void ScDPCacheTable::fillTable(
     if ( nRowCount <= 0 || nColCount <= 0)
         return;
 
-    maRowsVisible.clear();
-    maRowsVisible.reserve(nRowCount);
+    maRowFlags.clear();
+    maRowFlags.reserve(nRowCount);
 
     // Initialize field entries container.
     maFieldEntries.clear();
@@ -206,16 +217,19 @@ void ScDPCacheTable::fillTable(
                 SCROW nOrder = getOrder( nCol, nIndex );
                 
                 if ( nCol == 0 )
-                    maRowsVisible.push_back(false);
+                {
+                    maRowFlags.push_back(RowFlag());
+                    maRowFlags.back().mbShowByFilter = false;
+                }
 
                 if ( lcl_HasQueryEntry(rQuery) &&  
                     !getCache()->ValidQuery( nRow , rQuery, pSpecial ) )
                     continue;
                 if ( bIgnoreEmptyRows &&  getCache()->IsRowEmpty( nRow ) )
                     continue;
-                // Insert a new row into cache table.
+
                 if ( nCol == 0 )
-                     maRowsVisible.back() = true;
+                     maRowFlags.back().mbShowByFilter = true;
 
                 aAdded[nOrder] = nIndex;
             }
@@ -236,8 +250,8 @@ void ScDPCacheTable::fillTable()
    if ( nRowCount <= 0 || nColCount <= 0)
         return;
 
-    maRowsVisible.clear();
-    maRowsVisible.reserve(nRowCount);
+    maRowFlags.clear();
+    maRowFlags.reserve(nRowCount);
 
 
     // Initialize field entries container.
@@ -258,8 +272,10 @@ void ScDPCacheTable::fillTable()
                 SCROW nOrder = getOrder( nCol, nIndex );
                 
                 if ( nCol == 0 )
-                     maRowsVisible.push_back(true);
-
+                {
+                     maRowFlags.push_back(RowFlag());
+                     maRowFlags.back().mbShowByFilter = true;
+                }
 
                 pAdded[nOrder] = nIndex;
             }
@@ -275,24 +291,24 @@ void ScDPCacheTable::fillTable()
 
 bool ScDPCacheTable::isRowActive(sal_Int32 nRow) const
 {
-    if (nRow < 0 || static_cast<size_t>(nRow) >= maRowsVisible.size())
+    if (nRow < 0 || static_cast<size_t>(nRow) >= maRowFlags.size())
         // row index out of bound
         return false;
 
-    return maRowsVisible[nRow];
+    return maRowFlags[nRow].isActive();
 }
 
 void ScDPCacheTable::filterByPageDimension(const vector<Criterion>& rCriteria, const boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims)
 {
     sal_Int32 nRowSize = getRowSize();
-    if (nRowSize != static_cast<sal_Int32>(maRowsVisible.size()))
+    if (nRowSize != static_cast<sal_Int32>(maRowFlags.size()))
     {
         // sizes of the two tables differ!
         return;
     }
 
     for (sal_Int32 nRow = 0; nRow < nRowSize; ++nRow)
-        maRowsVisible[nRow] = isRowQualified(nRow, rCriteria, rRepeatIfEmptyDims);
+        maRowFlags[nRow].mbShowByPage = isRowQualified(nRow, rCriteria, rRepeatIfEmptyDims);
 }
 
 const ScDPItemData* ScDPCacheTable::getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const
@@ -358,7 +374,7 @@ void ScDPCacheTable::filterTable(const vector<Criterion>& rCriteria, Sequence< S
 
     for (sal_Int32 nRow = 0; nRow < nRowSize; ++nRow)
     {
-        if (!maRowsVisible[nRow])
+        if (!maRowFlags[nRow].isActive())
             // This row is filtered out.
             continue;
 
@@ -400,7 +416,7 @@ SCROW ScDPCacheTable::getOrder(long nDim, SCROW nIndex) const
 void ScDPCacheTable::clear()
 {
     maFieldEntries.clear();
-    maRowsVisible.clear();
+    maRowFlags.clear();
     mpCache = NULL;
 }
 


More information about the Libreoffice-commits mailing list