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

2012-12-07 Thread Libreoffice Gerrit user
 sc/inc/dpsave.hxx|2 +
 sc/qa/unit/ucalc.cxx |   29 ++
 sc/source/core/data/dpobject.cxx |   12 +-
 sc/source/core/data/dpsave.cxx   |   37 +
 sc/source/ui/view/dbfunc3.cxx|   43 ++-
 5 files changed, 86 insertions(+), 37 deletions(-)

New commits:
commit f421e804371670001bc5af25b8b66d67dfdb3261
Author: Kohei Yoshida kohei.yosh...@gmail.com
Date:   Wed Dec 5 12:53:03 2012 -0500

fdo#57497: Remove group table data when all group dimensions are gone.

Otherwise ungrouping date grouped dimension may crash, or produce
incorrect results.

Change-Id: I3634e3c0bf8336fc1221f5d234cb7e01eb1f07c6
Reviewed-on: https://gerrit.libreoffice.org/1247
Reviewed-by: Markus Mohrhard markus.mohrh...@googlemail.com
Tested-by: Markus Mohrhard markus.mohrh...@googlemail.com

diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index 14a0032..4225d1b 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -345,6 +345,8 @@ public:
 const ScDPDimensionSaveData* GetExistingDimensionData() const
 { return pDimensionData; }
 
+void RemoveAllGroupDimensions( const rtl::OUString rSrcDimName, 
std::vectorrtl::OUString* pDeletedNames = NULL );
+
 SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not 
there
 void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
 void BuildAllDimensionMembers(ScDPTableData* pData);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index cab47a6..795bea3 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2688,6 +2688,35 @@ void Test::testPivotTableDateGrouping()
 CPPUNIT_ASSERT_MESSAGE(Table output check failed, bSuccess);
 }
 
+// Remove all date grouping. The source dimension Date has two
+// external dimensions (Years and Quarters) and one internal (Date
+// the same name but different hierarchy).  Remove all of them.
+pSaveData = pDPObj-GetSaveData();
+pSaveData-RemoveAllGroupDimensions(aBaseDimName);
+pDPObj-SetSaveData(*pSaveData);
+pDPObj-ReloadGroupTableData();
+pDPObj-InvalidateData();
+
+aOutRange = refresh(pDPObj);
+{
+// Expected output table content.  0 = empty cell
+const char* aOutputCheck[][2] = {
+{ Date, 0 },
+{ 2011-01-01, 1 },
+{ 2011-03-02, 2 },
+{ 2011-09-03, 7 },
+{ 2012-01-04, 3 },
+{ 2012-02-23, 4 },
+{ 2012-02-24, 5 },
+{ 2012-03-15, 6 },
+{ 2012-12-25, 8 },
+{ Total Result, 36 }
+};
+
+bSuccess = checkDPTableOutput2(m_pDoc, aOutRange, aOutputCheck, 
Remove all date grouping.);
+CPPUNIT_ASSERT_MESSAGE(Table output check failed, bSuccess);
+}
+
 pDPs-FreeTable(pDPObj);
 CPPUNIT_ASSERT_EQUAL_MESSAGE(There should be no more tables., 
pDPs-GetCount(), static_castsize_t(0));
 CPPUNIT_ASSERT_EQUAL_MESSAGE(There shouldn't be any more cache stored.,
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index f4b39ff..8db3c16 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -567,8 +567,18 @@ void ScDPObject::ReloadGroupTableData()
 
 const ScDPDimensionSaveData* pDimData = 
pSaveData-GetExistingDimensionData();
 if (!pDimData || !pDimData-HasGroupDimensions())
-// No group dimensions exist.
+{
+// No group dimensions exist.  Check if it currently has group
+// dimensions, and if so, remove all of them.
+ScDPGroupTableData* pData = 
dynamic_castScDPGroupTableData*(mpTableData.get());
+if (pData)
+{
+// Replace the existing group table data with the source data.
+shared_ptrScDPTableData pSource = pData-GetSourceTableData();
+mpTableData = pSource;
+}
 return;
+}
 
 ScDPGroupTableData* pData = 
dynamic_castScDPGroupTableData*(mpTableData.get());
 if (pData)
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 5c987da..f86dce4 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -1221,6 +1221,43 @@ bool ScDPSaveData::IsEmpty() const
 return true; // no entries that are not hidden
 }
 
+void ScDPSaveData::RemoveAllGroupDimensions( const OUString rSrcDimName, 
std::vectorOUString* pDeletedNames )
+{
+if (!pDimensionData)
+// No group dimensions exist.  Nothing to do.
+return;
+
+// Remove numeric group dimension (exists once at most). No need to delete
+// anything in save data (grouping was done inplace in an existing base
+// dimension).
+pDimensionData-RemoveNumGroupDimension(rSrcDimName);
+
+// Remove named group dimension(s). Dimensions have to be removed from
+// dimension save data and from save data too.
+const 

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

2012-08-14 Thread Eike Rathke
 sc/inc/stringutil.hxx  |   26 ++
 sc/qa/unit/ucalc.cxx   |9 +
 sc/source/core/data/column3.cxx|4 ++--
 sc/source/core/data/dpoutput.cxx   |6 +++---
 sc/source/core/tool/stringutil.cxx |2 +-
 sc/source/filter/rtf/eeimpars.cxx  |2 +-
 sc/source/ui/docshell/impex.cxx|4 ++--
 7 files changed, 40 insertions(+), 13 deletions(-)

New commits:
commit 22571981cdae59bce508dfd2af4c873aa216d885
Author: Kohei Yoshida kohei.yosh...@gmail.com
Date:   Mon Aug 13 14:20:13 2012 -0400

fdo#53089: Avoid setting valid numbers as text during html import.

(cherry picked from commit 51f1fc69aa539dec8035195b98e0b128026388e9)

Conflicts:

sc/qa/unit/ucalc.cxx

Change-Id: I5fa9a54f70e8e4d8aac42687f2a204b2925d4619

diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index 954d4bc..1932f59 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -40,6 +40,25 @@ class SvNumberFormatter;
  */
 struct SC_DLLPUBLIC ScSetStringParam
 {
+enum TextFormatPolicy
+{
+/**
+ * Set Text number format no matter what the input string is.
+ */
+Always,
+
+/**
+ * Set Text number format only when the input string is considered a
+ * special number but we only want to detect a simple number.
+ */
+SpecialNumberOnly,
+
+/**
+ * Never set Text number format.
+ */
+Never
+};
+
 /**
  * Stores the pointer to the number formatter instance to be used during
  * number format detection.  The caller must manage the life cycle of the
@@ -55,11 +74,10 @@ struct SC_DLLPUBLIC ScSetStringParam
 bool mbDetectNumberFormat;
 
 /**
- * When true, set the format of the cell to Text when a string cell is
- * requested for a number input.  We may want to do this during text file
- * import (csv, html etc).
+ * Determine when to set the 'Text' number format to the cell where the
+ * input string is being set.
  */
-bool mbSetTextCellFormat;
+TextFormatPolicy meSetTextNumFormat;
 
 /**
  * When true, treat input with a leading apostrophe / single quote special
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 8d9febe..cab47a6 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -360,6 +360,15 @@ void Test::testInput()
 bTest = test == 'apple';
 CPPUNIT_ASSERT_MESSAGE(Text content should have retained the first 
apostrophe., bTest);
 
+// Customized string handling policy.
+ScSetStringParam aParam;
+aParam.mbDetectNumberFormat = false;
+aParam.meSetTextNumFormat = ScSetStringParam::Always;
+aParam.mbHandleApostrophe = false;
+m_pDoc-SetString(0, 0, 0, 000123, aParam);
+m_pDoc-GetString(0, 0, 0, test);
+CPPUNIT_ASSERT_MESSAGE(Text content should have been treated as string, 
not number., test == 000123);
+
 m_pDoc-DeleteTab(0);
 }
 
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 7e35fe6..aab315c 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1341,7 +1341,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const 
String rString,
 }
 }
 }
-else if (!aParam.mbSetTextCellFormat)
+else if (aParam.meSetTextNumFormat != ScSetStringParam::Always)
 {
 // Only check if the string is a regular number.
 const LocaleDataWrapper* pLocale = 
aParam.mpNumFormatter-GetLocaleData();
@@ -1367,7 +1367,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const 
String rString,
 
 if (!pNewCell)
 {
-if (aParam.mbSetTextCellFormat  
aParam.mpNumFormatter-IsNumberFormat(rString, nIndex, nVal))
+if (aParam.meSetTextNumFormat != ScSetStringParam::Never  
aParam.mpNumFormatter-IsNumberFormat(rString, nIndex, nVal))
 {
 // Set the cell format type to Text.
 sal_uInt32 nFormat = 
aParam.mpNumFormatter-GetStandardFormat(NUMBERFORMAT_TEXT);
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index 34ae9d6..2b86a69 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -793,13 +793,13 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, 
SCTAB nTab,
 if (bNumeric)
 {
 aParam.mbDetectNumberFormat = true;
-aParam.mbSetTextCellFormat = false;
+aParam.meSetTextNumFormat = ScSetStringParam::Never;
 aParam.mbHandleApostrophe = true;
 }
 else
 {
 aParam.mbDetectNumberFormat = false;
-aParam.mbSetTextCellFormat = true;
+aParam.meSetTextNumFormat = ScSetStringParam::Always;