LCOV - code coverage report
Current view: top level - sc/source/ui/condformat - condformathelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 92 1.1 %
Date: 2014-11-03 Functions: 2 7 28.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <rtl/ustrbuf.hxx>
      11             : #include "condformathelper.hxx"
      12             : #include "globstr.hrc"
      13             : 
      14             : namespace {
      15             : 
      16           0 : OUString getTextForType(ScCondFormatEntryType eType)
      17             : {
      18           0 :     switch(eType)
      19             :     {
      20             :         case CONDITION:
      21           0 :             return ScGlobal::GetRscString(STR_COND_CONDITION);
      22             :         case COLORSCALE:
      23           0 :             return ScGlobal::GetRscString(STR_COND_COLORSCALE);
      24             :         case DATABAR:
      25           0 :             return ScGlobal::GetRscString(STR_COND_DATABAR);
      26             :         case FORMULA:
      27           0 :             return ScGlobal::GetRscString(STR_COND_FORMULA);
      28             :         case ICONSET:
      29           0 :             return ScGlobal::GetRscString(STR_COND_ICONSET);
      30             :         case DATE:
      31           0 :             return ScGlobal::GetRscString(STR_COND_DATE);
      32             :         default:
      33           0 :             break;
      34             :     }
      35             : 
      36           0 :     return OUString("");
      37             : }
      38             : 
      39           0 : OUString getExpression(sal_Int32 nIndex)
      40             : {
      41           0 :     switch(nIndex)
      42             :     {
      43             :         case 0:
      44           0 :             return OUString("=");
      45             :         case 1:
      46           0 :             return OUString("<");
      47             :         case 2:
      48           0 :             return OUString(">");
      49             :         case 3:
      50           0 :             return OUString("<=");
      51             :         case 4:
      52           0 :             return OUString(">=");
      53             :         case 5:
      54           0 :             return OUString("!=");
      55             :         case 6:
      56           0 :             return ScGlobal::GetRscString(STR_COND_BETWEEN);
      57             :         case 7:
      58           0 :             return ScGlobal::GetRscString(STR_COND_NOTBETWEEN);
      59             :         case 8:
      60           0 :             return ScGlobal::GetRscString(STR_COND_DUPLICATE);
      61             :         case 9:
      62           0 :             return ScGlobal::GetRscString(STR_COND_UNIQUE);
      63             :         case 10:
      64             :             assert(false);
      65             :         case 11:
      66           0 :             return ScGlobal::GetRscString(STR_COND_TOP10);
      67             :         case 12:
      68           0 :             return ScGlobal::GetRscString(STR_COND_BOTTOM10);
      69             :         case 13:
      70           0 :             return ScGlobal::GetRscString(STR_COND_TOP_PERCENT);
      71             :         case 14:
      72           0 :             return ScGlobal::GetRscString(STR_COND_BOTTOM_PERCENT);
      73             :         case 15:
      74           0 :             return ScGlobal::GetRscString(STR_COND_ABOVE_AVERAGE);
      75             :         case 16:
      76           0 :             return ScGlobal::GetRscString(STR_COND_BELOW_AVERAGE);
      77             :         case 17:
      78           0 :             return ScGlobal::GetRscString(STR_COND_ABOVE_EQUAL_AVERAGE);
      79             :         case 18:
      80           0 :             return ScGlobal::GetRscString(STR_COND_BELOW_EQUAL_AVERAGE);
      81             :         case 19:
      82           0 :             return ScGlobal::GetRscString(STR_COND_ERROR);
      83             :         case 20:
      84           0 :             return ScGlobal::GetRscString(STR_COND_NOERROR);
      85             :         case 21:
      86           0 :             return ScGlobal::GetRscString(STR_COND_BEGINS_WITH);
      87             :         case 22:
      88           0 :             return ScGlobal::GetRscString(STR_COND_ENDS_WITH);
      89             :         case 23:
      90           0 :             return ScGlobal::GetRscString(STR_COND_CONTAINS);
      91             :         case 24:
      92           0 :             return ScGlobal::GetRscString(STR_COND_NOT_CONTAINS);
      93             :     }
      94           0 :     return OUString();
      95             : }
      96             : 
      97           0 : OUString getDateString(sal_Int32 nIndex)
      98             : {
      99           0 :     sal_Int32 nStringIndex = STR_COND_TODAY + nIndex;
     100           0 :     if(nStringIndex <= STR_COND_NEXTYEAR)
     101           0 :         return ScGlobal::GetRscString(nStringIndex);
     102             : 
     103             :     assert(false);
     104           0 :     return OUString();
     105             : }
     106             : 
     107             : }
     108             : 
     109           0 : OUString ScCondFormatHelper::GetExpression(const ScConditionalFormat& rFormat, const ScAddress& rPos)
     110             : {
     111           0 :     OUStringBuffer aBuffer;
     112           0 :     if(!rFormat.IsEmpty())
     113             :     {
     114           0 :         switch(rFormat.GetEntry(0)->GetType())
     115             :         {
     116             :             case condformat::CONDITION:
     117             :                 {
     118           0 :                     const ScConditionEntry* pEntry = static_cast<const ScConditionEntry*>(rFormat.GetEntry(0));
     119           0 :                     ScConditionMode eMode = pEntry->GetOperation();
     120           0 :                     if(eMode == SC_COND_DIRECT)
     121             :                     {
     122           0 :                         aBuffer.append(getTextForType(FORMULA));
     123           0 :                         aBuffer.append(" ");
     124           0 :                         aBuffer.append(pEntry->GetExpression(rPos, 0));
     125             :                     }
     126             :                     else
     127             :                     {
     128           0 :                         aBuffer.append(getTextForType(CONDITION));
     129           0 :                         aBuffer.append(" ");
     130           0 :                         aBuffer.append(getExpression(static_cast<sal_Int32>(eMode)));
     131           0 :                         aBuffer.append(" ");
     132           0 :                         if(eMode == SC_COND_BETWEEN || eMode == SC_COND_NOTBETWEEN)
     133             :                         {
     134           0 :                             aBuffer.append(pEntry->GetExpression(rPos, 0));
     135           0 :                             aBuffer.append(" and ");
     136           0 :                             aBuffer.append(pEntry->GetExpression(rPos, 1));
     137             :                         }
     138           0 :                         else if(eMode <= SC_COND_NOTEQUAL || eMode >= SC_COND_BEGINS_WITH)
     139             :                         {
     140           0 :                             aBuffer.append(pEntry->GetExpression(rPos, 0));
     141             :                         }
     142             :                     }
     143             :                 }
     144             : 
     145           0 :                 break;
     146             :             case condformat::DATABAR:
     147           0 :                 aBuffer.append(getTextForType(DATABAR));
     148           0 :                 break;
     149             :             case condformat::COLORSCALE:
     150           0 :                 aBuffer.append(getTextForType(COLORSCALE));
     151           0 :                 break;
     152             :             case condformat::ICONSET:
     153           0 :                 aBuffer.append(getTextForType(ICONSET));
     154           0 :                 break;
     155             :             case condformat::DATE:
     156             :                 {
     157           0 :                     aBuffer.append(getTextForType(DATE));
     158           0 :                     aBuffer.append(" ");
     159           0 :                     sal_Int32 nDateEntry = static_cast<sal_Int32>(static_cast<const ScCondDateFormatEntry*>(rFormat.GetEntry(0))->GetDateType());
     160           0 :                     aBuffer.append(getDateString(nDateEntry));
     161             :                 }
     162           0 :                 break;
     163             :         }
     164             :     }
     165           0 :     return aBuffer.makeStringAndClear();
     166             : }
     167             : 
     168           0 : OUString ScCondFormatHelper::GetExpression( ScCondFormatEntryType eType, sal_Int32 nIndex,
     169             :         const OUString& aStr1, const OUString& aStr2 )
     170             : {
     171           0 :     OUStringBuffer aBuffer(getTextForType(eType));
     172           0 :     aBuffer.append(" ");
     173           0 :     if(eType == CONDITION)
     174             :     {
     175             :         // workaround missing FORMULA option in the conditions case
     176             :         // FORMULA is handled later
     177           0 :         if(nIndex > 9)
     178           0 :             ++nIndex;
     179           0 :         aBuffer.append(getExpression(nIndex));
     180           0 :         if(nIndex <= 7 || nIndex >= 19)
     181             :         {
     182           0 :             aBuffer.append(" ").append(aStr1);
     183           0 :             if(nIndex == 6 || nIndex == 7)
     184             :             {
     185           0 :                 aBuffer.append(" and ").append(aStr2);
     186             :             }
     187             :         }
     188             :     }
     189           0 :     else if(eType == FORMULA)
     190             :     {
     191           0 :         aBuffer.append(" ").append(aStr1);
     192             :     }
     193           0 :     else if(eType == DATE)
     194             :     {
     195           0 :         aBuffer.append(getDateString(nIndex));
     196             :     }
     197             : 
     198           0 :     return aBuffer.makeStringAndClear();
     199         228 : }
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10