diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-28 17:31:02 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-28 17:32:47 -0500 |
commit | 1dcb62fe485e8082068679c4167e263b1957d94d (patch) | |
tree | 5cbbedd792b65b0b389f69de34c730bbb7fe2ec8 | |
parent | fc4ba6d66ef47747a7f6001284999e1c880e3dfc (diff) |
fdo#43304: Allow empty field labels in pivot tables.
Empty field labels are replaced with the column name.
-rw-r--r-- | sc/inc/dpglobal.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 11 | ||||
-rw-r--r-- | sc/source/core/data/dpshttab.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/dptablecache.cxx | 27 |
4 files changed, 22 insertions, 30 deletions
diff --git a/sc/inc/dpglobal.hxx b/sc/inc/dpglobal.hxx index 8502a305c93f..200672a733df 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 b287486fd5f3..4ff4cd03a15a 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 26cdf0fa766c..a04bb5a8f988 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 98f73c7723c5..d0ca15c959d3 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; } |