[Libreoffice-commits] .: sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Dec 8 20:05:12 PST 2011


 sc/source/core/data/column3.cxx |   46 ++++++++++++++++++++++++++--------------
 sc/source/core/data/table3.cxx  |    7 +++++-
 2 files changed, 36 insertions(+), 17 deletions(-)

New commits:
commit 49b6cbe96b6655cd35366283f239af516cc2644d
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Dec 8 23:02:26 2011 -0500

    bnc#656073: Allow filtering by error value.
    
    The old way was that an error cell was evaulated as having a value of 0.
    The error cell also showed up as blank in the popup.  Using the error
    string is much more intuitive (and some users apparently want this
    behavior).

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 898edfd..fbeb951 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1575,9 +1575,9 @@ void ScColumn::GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollec
 
     while ( (nIndex < nCount) ? ((nRow=pItems[nIndex].nRow) <= nEndRow) : false )
     {
-        ScBaseCell*          pCell    = pItems[nIndex].pCell;
-        TypedStrData*        pData;
-        sal_uLong                nFormat  = GetNumberFormat( nRow );
+        ScBaseCell* pCell = pItems[nIndex].pCell;
+        TypedStrData* pData = NULL;
+        sal_uLong nFormat = GetNumberFormat( nRow );
 
         ScCellFormat::GetInputString( pCell, nFormat, aString, *pFormatter );
 
@@ -1585,7 +1585,7 @@ void ScColumn::GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollec
             pData = new TypedStrData( aString );
         else
         {
-            double nValue;
+            double nValue = 0.0;
 
             switch ( pCell->GetCellType() )
             {
@@ -1594,26 +1594,40 @@ void ScColumn::GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollec
                     break;
 
                 case CELLTYPE_FORMULA:
-                    nValue = ((ScFormulaCell*)pCell)->GetValue();
-                    break;
+                {
+                    ScFormulaCell* pFC = static_cast<ScFormulaCell*>(pCell);
+                    sal_uInt16 nErr = pFC->GetErrCode();
+                    if (nErr)
+                    {
+                        // Error cell is evaluated as string (for now).
+                        String aErr = ScGlobal::GetErrorString(nErr);
+                        if (aErr.Len())
+                            pData = new TypedStrData(aErr);
+                    }
+                    else
+                        nValue = pFC->GetValue();
+                }
+                break;
 
                 default:
-                    nValue = 0.0;
+                    ;
             }
 
-            if (pFormatter)
+            if (!pData)
             {
-                short nType = pFormatter->GetType(nFormat);
-                if ((nType & NUMBERFORMAT_DATE) && !(nType & NUMBERFORMAT_TIME))
+                if (pFormatter)
                 {
-                    // special case for date values.  Disregard the time
-                    // element if the number format is of date type.
-                    nValue = ::rtl::math::approxFloor(nValue);
-                    bHasDates = true;
+                    short nType = pFormatter->GetType(nFormat);
+                    if ((nType & NUMBERFORMAT_DATE) && !(nType & NUMBERFORMAT_TIME))
+                    {
+                        // special case for date values.  Disregard the time
+                        // element if the number format is of date type.
+                        nValue = ::rtl::math::approxFloor(nValue);
+                        bHasDates = true;
+                    }
                 }
+                pData = new TypedStrData( aString, nValue, SC_STRTYPE_VALUE );
             }
-
-            pData = new TypedStrData( aString, nValue, SC_STRTYPE_VALUE );
         }
 
         if ( !rStrings.Insert( pData ) )
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 1be106f..ffd5d6f 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1277,7 +1277,12 @@ public:
 
         if ( pCell )
         {
-            if (pCell->GetCellType() != CELLTYPE_NOTE)
+            if (pCell->GetCellType() == CELLTYPE_FORMULA && pCell->GetErrorCode())
+            {
+                // Error cell is evaluated as string (for now).
+                aCellStr = ScGlobal::GetErrorString(pCell->GetErrorCode());
+            }
+            else if (pCell->GetCellType() != CELLTYPE_NOTE)
             {
                 sal_uLong nFormat = mrTab.GetNumberFormat( static_cast<SCCOL>(rEntry.nField), nRow );
                 ScCellFormat::GetInputString(pCell, nFormat, aCellStr, *mrDoc.GetFormatTable());


More information about the Libreoffice-commits mailing list