[Libreoffice-commits] .: 2 commits - sc/inc sc/qa sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Nov 28 14:43:08 PST 2011


 sc/inc/dpglobal.hxx                  |    2 +-
 sc/qa/unit/ucalc.cxx                 |   11 -----------
 sc/source/core/data/dpshttab.cxx     |   12 ------------
 sc/source/core/data/dptablecache.cxx |   27 +++++++++++++++++++++------
 sc/source/ui/unoobj/dapiuno.cxx      |    6 ++++++
 5 files changed, 28 insertions(+), 30 deletions(-)

New commits:
commit 1dcb62fe485e8082068679c4167e263b1957d94d
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Mon Nov 28 17:31:02 2011 -0500

    fdo#43304: Allow empty field labels in pivot tables.
    
    Empty field labels are replaced with the column name.

diff --git a/sc/inc/dpglobal.hxx b/sc/inc/dpglobal.hxx
index 8502a30..200672a 100644
--- a/sc/inc/dpglobal.hxx
+++ b/sc/inc/dpglobal.hxx
@@ -125,7 +125,7 @@ public:
     ScDPItemData() : nNumFormat( 0 ), fValue(0.0), mbFlag( 0 ){}
     ScDPItemData( sal_uLong nNF, const String & rS, double fV, sal_uInt8 bF ):nNumFormat(nNF), aString(rS), fValue(fV), mbFlag( bF ){}
     ScDPItemData( const String& rS, double fV = 0.0, bool bHV = false, const sal_uLong nNumFormat = 0 , bool bData = true) ;
-    ScDPItemData( ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uInt16 nDocTab );
+    ScDPItemData(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nDocTab, bool bLabel);
 
     void        SetString( const String& rS ) { aString = rS; mbFlag &= ~(MK_VAL|MK_DATE); nNumFormat = 0; mbFlag |= MK_DATA; }
     bool        IsCaseInsEqual( const ScDPItemData& r ) const;
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index b287486..4ff4cd0 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1323,17 +1323,6 @@ void Test::testDataPilot()
         CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
     }
 
-    // Now, intentionally delete one of the field header names from the source range.
-    ScMarkData aMarkData;
-    aMarkData.SelectOneTable(0);
-    m_pDoc->DeleteArea(1, 0, 1, 0, aMarkData, IDF_CONTENTS);
-    printRange(m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), "Data sheet content (header removed)");
-
-    // An attempt to clear the cache whose original data now has an invalid
-    // field name (empty name) should not succeed.
-    nErrId = pDPs->ClearCache(pDPObj2);
-    CPPUNIT_ASSERT_MESSAGE("Clearing the cache while the source data is invalid should not be allowed.", nErrId != 0);
-
     pDPs->FreeTable(pDPObj2);
     CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
                            pDPs->GetCount() == 0);
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 26cdf0f..a04bb5a 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -331,18 +331,6 @@ sal_uLong ScSheetSourceDesc::CheckSourceRange() const
     if (!mpDoc)
         return STR_ERR_DATAPILOTSOURCE;
 
-    const ScRange& aSrcRange = GetSourceRange();
-    const ScAddress& s = aSrcRange.aStart;
-    const ScAddress& e = aSrcRange.aEnd;
-    for (SCCOL nCol = aSrcRange.aStart.Col(); nCol <= e.Col(); ++nCol)
-    {
-        if (mpDoc->IsBlockEmpty(s.Tab(), nCol, s.Row(), nCol, s.Row()))
-            return STR_PIVOT_FIRSTROWEMPTYERR;
-    }
-
-    if (mpDoc->IsBlockEmpty(s.Tab(), s.Col(), s.Row()+1, e.Col(), e.Row()))
-        return STR_PIVOT_ONLYONEROWERR;
-
     return 0;
 }
 
diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx
index 98f73c7..d0ca15c 100644
--- a/sc/source/core/data/dptablecache.cxx
+++ b/sc/source/core/data/dptablecache.cxx
@@ -189,7 +189,7 @@ ScDPItemData::ScDPItemData(const String& rS, double fV, bool bHV, const sal_uLon
 {
 }
 
-ScDPItemData::ScDPItemData(ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uInt16 nDocTab) :
+ScDPItemData::ScDPItemData(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nDocTab, bool bLabel) :
     nNumFormat( 0 ), fValue(0.0), mbFlag( 0 )
 {
     String aDocStr;
@@ -217,8 +217,24 @@ ScDPItemData::ScDPItemData(ScDocument* pDoc, SCROW nRow, sal_uInt16 nCol, sal_uI
         nNumFormat = pDoc->GetNumberFormat( ScAddress( nCol, nRow, nDocTab ) );
         isDate( nFormat ) ? ( mbFlag |= MK_DATE ) : (mbFlag &= ~MK_DATE);
     }
-    else if ( pDoc->HasData( nCol,nRow, nDocTab ) )
-        SetString ( aDocStr );
+    else if (bLabel || pDoc->HasData(nCol, nRow, nDocTab))
+    {
+        if (bLabel && !aDocStr.Len())
+        {
+            // Replace an empty label string with column name.
+            rtl::OUStringBuffer aBuf;
+            aBuf.append(ScGlobal::GetRscString(STR_COLUMN));
+            aBuf.append(sal_Unicode(' '));
+
+            ScAddress aColAddr(nCol, 0, 0);
+            rtl::OUString aColStr;
+            aColAddr.Format(aColStr, SCA_VALID_COL, NULL);
+            aBuf.append(aColStr);
+            aDocStr = aBuf.makeStringAndClear();
+        }
+
+        SetString(aDocStr);
+    }
 }
 
 bool ScDPItemData::IsCaseInsEqual( const ScDPItemData& r ) const
@@ -484,13 +500,12 @@ bool ScDPCache::InitFromDoc(ScDocument* pDoc, const ScRange& rRange)
         maGlobalOrder.push_back(new vector<SCROW>());
         maIndexOrder.push_back(new vector<SCROW>());
     }
-    //check valid
 
     for (sal_uInt16 nCol = nStartCol; nCol <= nEndCol; ++nCol)
     {
-        AddLabel(new ScDPItemData(pDoc, nStartRow, nCol, nDocTab));
+        AddLabel(new ScDPItemData(pDoc, nCol, nStartRow, nDocTab, true));
         for (SCROW nRow = nStartRow + 1; nRow <= nEndRow; ++nRow)
-            AddData(nCol - nStartCol, new ScDPItemData(pDoc, nRow, nCol, nDocTab));
+            AddData(nCol - nStartCol, new ScDPItemData(pDoc, nCol, nRow, nDocTab, false));
     }
     return true;
 }
commit fc4ba6d66ef47747a7f6001284999e1c880e3dfc
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Mon Nov 28 11:57:49 2011 -0500

    fdo#43304: Safeguard ourselves from potential crashes.
    
    This is not a real fix, however.  Import of pivot table still fails
    but is at least better than crashing.  A real fix is still being
    worked on.

diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index b0f2a8d..5a5bed3 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -1585,6 +1585,9 @@ ScDataPilotFieldsObj::~ScDataPilotFieldsObj()
 
 sal_Int32 lcl_GetFieldCount( const Reference<XDimensionsSupplier>& rSource, const Any& rOrient )
 {
+    if (!rSource.is())
+        throw RuntimeException();
+
     sal_Int32 nRet = 0;
 
     Reference<XNameAccess> xDimsName(rSource->getDimensions());
@@ -1620,6 +1623,9 @@ sal_Int32 lcl_GetFieldCount( const Reference<XDimensionsSupplier>& rSource, cons
 sal_Bool lcl_GetFieldDataByIndex( const Reference<XDimensionsSupplier>& rSource,
                                 const Any& rOrient, SCSIZE nIndex, ScFieldIdentifier& rFieldId )
 {
+    if (!rSource.is())
+        throw RuntimeException();
+
     sal_Bool bOk = false;
     SCSIZE nPos = 0;
     sal_Int32 nDimIndex = 0;


More information about the Libreoffice-commits mailing list