[Libreoffice-commits] .: 3 commits - sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Mar 9 10:30:59 PST 2012


 sc/source/core/data/dpdimsave.cxx  |   14 +++---
 sc/source/core/data/dpgroup.cxx    |   77 -------------------------------------
 sc/source/core/data/dpitemdata.cxx |   23 ++++++-----
 3 files changed, 23 insertions(+), 91 deletions(-)

New commits:
commit 4c2370c0a5dd20c226ce0f12823c125f0c07589f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Mar 9 13:29:31 2012 -0500

    Fix infinite looping memory devouring on refreshing table with date grouping.
    
    It so happens that both group info and date info can be enabled, in which
    case the date info takes precedence.

diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx
index cc02b15..9d02594 100644
--- a/sc/source/core/data/dpdimsave.cxx
+++ b/sc/source/core/data/dpdimsave.cxx
@@ -466,7 +466,13 @@ void ScDPSaveNumGroupDimension::AddToData( ScDPGroupTableData& rData ) const
 void ScDPSaveNumGroupDimension::AddToCache(ScDPCache& rCache) const
 {
     long nDim = rCache.GetDimensionIndex(aDimensionName);
-    if (aGroupInfo.mbEnable)
+    if (aDateInfo.mbEnable)
+    {
+        // Date grouping
+        SvNumberFormatter* pFormatter = rCache.GetDoc()->GetFormatTable();
+        fillDateGroupDimension(rCache, aDateInfo, nDim, nDim, nDatePart, pFormatter);
+    }
+    else if (aGroupInfo.mbEnable)
     {
         // Number-range grouping
 
@@ -558,12 +564,6 @@ void ScDPSaveNumGroupDimension::AddToCache(ScDPCache& rCache) const
         aItem.SetRangeLast();
         rCache.SetGroupItem(nDim, aItem);
     }
-    else if (aDateInfo.mbEnable)
-    {
-        // Date grouping
-        SvNumberFormatter* pFormatter = rCache.GetDoc()->GetFormatTable();
-        fillDateGroupDimension(rCache, aDateInfo, nDim, nDim, nDatePart, pFormatter);
-    }
 }
 
 void ScDPSaveNumGroupDimension::SetGroupInfo( const ScDPNumGroupInfo& rNew )
commit 0ee9a1c07ed69e21d0dad4f71791f51ae4c13bc0
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Mar 9 13:13:33 2012 -0500

    Use the common method over the local clone.

diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx
index 98816b0..73a9d10 100644
--- a/sc/source/core/data/dpgroup.cxx
+++ b/sc/source/core/data/dpgroup.cxx
@@ -217,78 +217,6 @@ ScDPDateGroupHelper::~ScDPDateGroupHelper()
 
 namespace {
 
-sal_Int32 lcl_GetDatePartValue( double fValue, sal_Int32 nDatePart, SvNumberFormatter* pFormatter,
-                                const ScDPNumGroupInfo* pNumInfo )
-{
-    // Start and end are inclusive
-    // (End date without a time value is included, with a time value it's not)
-
-    if ( pNumInfo )
-    {
-        if ( fValue < pNumInfo->mfStart && !rtl::math::approxEqual( fValue, pNumInfo->mfStart ) )
-            return ScDPItemData::DateFirst;
-        if ( fValue > pNumInfo->mfEnd && !rtl::math::approxEqual( fValue, pNumInfo->mfEnd ) )
-            return ScDPItemData::DateLast;
-    }
-
-    sal_Int32 nResult = 0;
-
-    if ( nDatePart == com::sun::star::sheet::DataPilotFieldGroupBy::HOURS || nDatePart == com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES || nDatePart == com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS )
-    {
-        // handle time
-        // (as in the cell functions, ScInterpreter::ScGetHour etc.: seconds are rounded)
-
-        double fTime = fValue - ::rtl::math::approxFloor(fValue);
-        long nSeconds = (long)::rtl::math::approxFloor(fTime*D_TIMEFACTOR+0.5);
-
-        switch ( nDatePart )
-        {
-            case com::sun::star::sheet::DataPilotFieldGroupBy::HOURS:
-                nResult = nSeconds / 3600;
-                break;
-            case com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES:
-                nResult = ( nSeconds % 3600 ) / 60;
-                break;
-            case com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS:
-                nResult = nSeconds % 60;
-                break;
-        }
-    }
-    else
-    {
-        Date aDate = *(pFormatter->GetNullDate());
-        aDate += (long)::rtl::math::approxFloor( fValue );
-
-        switch ( nDatePart )
-        {
-            case com::sun::star::sheet::DataPilotFieldGroupBy::YEARS:
-                nResult = aDate.GetYear();
-                break;
-            case com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS:
-                nResult = 1 + ( aDate.GetMonth() - 1 ) / 3;     // 1..4
-                break;
-            case com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS:
-                nResult = aDate.GetMonth();     // 1..12
-                break;
-            case com::sun::star::sheet::DataPilotFieldGroupBy::DAYS:
-                {
-                    Date aYearStart( 1, 1, aDate.GetYear() );
-                    nResult = ( aDate - aYearStart ) + 1;       // Jan 01 has value 1
-                    if ( nResult >= 60 && !aDate.IsLeapYear() )
-                    {
-                        // days are counted from 1 to 366 - if not from a leap year, adjust
-                        ++nResult;
-                    }
-                }
-                break;
-            default:
-                OSL_FAIL("invalid date part");
-        }
-    }
-
-    return nResult;
-}
-
 bool isDateInGroup(const ScDPItemData& rGroupItem, const ScDPItemData& rChildItem)
 {
     if (rGroupItem.GetType() != ScDPItemData::GroupValue || rChildItem.GetType() != ScDPItemData::GroupValue)
@@ -931,9 +859,8 @@ void ScDPGroupTableData::FillGroupValues(SCROW* pItemDataIndex, long nCount, con
             {
                 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
                 const ScDPNumGroupInfo& rNumInfo = pDateHelper->GetNumInfo();
-                sal_Int32 nPartValue = lcl_GetDatePartValue(
-                    pData->GetValue(), pDateHelper->GetDatePart(), pFormatter,
-                    &rNumInfo);
+                sal_Int32 nPartValue = ScDPUtil::getDatePartValue(
+                    pData->GetValue(), rNumInfo, pDateHelper->GetDatePart(), pFormatter);
                 rtl::OUString aName = ScDPUtil::getDateGroupName(
                     pDateHelper->GetDatePart(), nPartValue, pFormatter, rNumInfo.mfStart, rNumInfo.mfEnd);
 
commit 57e531eff640c7e41bf14c54d02000f45d63d6c4
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Mar 9 12:51:07 2012 -0500

    Bit more organized & Error item has string too.

diff --git a/sc/source/core/data/dpitemdata.cxx b/sc/source/core/data/dpitemdata.cxx
index 2870a5c..77c01b9 100644
--- a/sc/source/core/data/dpitemdata.cxx
+++ b/sc/source/core/data/dpitemdata.cxx
@@ -248,14 +248,19 @@ ScDPItemData& ScDPItemData::operator= (const ScDPItemData& r)
 
 sal_uInt8 ScDPItemData::GetCellType() const
 {
-    if (meType == Error)
-        return SC_VALTYPE_ERROR;
-    else if (meType == Empty)
-        return SC_VALTYPE_EMPTY;
-    else if ( IsValue())
-        return SC_VALTYPE_VALUE;
-    else
-        return SC_VALTYPE_STRING;
+    switch (meType)
+    {
+        case Error:
+            return SC_VALTYPE_ERROR;
+        case Empty:
+            return SC_VALTYPE_EMPTY;
+        case Value:
+            return SC_VALTYPE_VALUE;
+        default:
+            ;
+    }
+
+    return SC_VALTYPE_STRING;
 }
 
 #if DEBUG_DP_ITEM_DATA
@@ -342,7 +347,7 @@ ScDPItemData::GroupValueAttr ScDPItemData::GetGroupValue() const
 
 bool ScDPItemData::HasStringData() const
 {
-    return meType == String;
+    return meType == String || meType == Error;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list