LCOV - code coverage report
Current view: top level - sc/source/core/data - sortparam.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 55 129 42.6 %
Date: 2014-04-11 Functions: 6 9 66.7 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sortparam.hxx"
      21             : #include "global.hxx"
      22             : #include "address.hxx"
      23             : #include "queryparam.hxx"
      24             : #include "subtotalparam.hxx"
      25             : 
      26             : 
      27        1983 : ScSortParam::ScSortParam()
      28             : {
      29        1983 :     Clear();
      30        1983 : }
      31             : 
      32         482 : ScSortParam::ScSortParam( const ScSortParam& r ) :
      33             :         nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
      34             :         bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),
      35             :         bNaturalSort(r.bNaturalSort),bUserDef(r.bUserDef),
      36             :         bIncludePattern(r.bIncludePattern),bInplace(r.bInplace),
      37             :         nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
      38             :         maKeyState( r.maKeyState ),
      39             :         aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm ),
      40         482 :         nCompatHeader( r.nCompatHeader )
      41             : {
      42         482 : }
      43             : 
      44        2272 : ScSortParam::~ScSortParam() {}
      45             : 
      46        1983 : void ScSortParam::Clear()
      47             : {
      48             :     ScSortKeyState aKeyState;
      49             : 
      50        1983 :     nCol1=nCol2=nDestCol = 0;
      51        1983 :     nRow1=nRow2=nDestRow = 0;
      52        1983 :     nCompatHeader = 2;
      53        1983 :     nDestTab = 0;
      54        1983 :     nUserIndex = 0;
      55        1983 :     bHasHeader=bCaseSens=bUserDef=bNaturalSort = false;
      56        1983 :     bByRow=bIncludePattern=bInplace = true;
      57        1983 :     aCollatorLocale = ::com::sun::star::lang::Locale();
      58        1983 :     aCollatorAlgorithm = OUString();
      59             : 
      60        1983 :     aKeyState.bDoSort = false;
      61        1983 :     aKeyState.nField = 0;
      62        1983 :     aKeyState.bAscending = true;
      63             : 
      64             :     // Initialize to default size
      65        1983 :     maKeyState.assign( DEFSORT, aKeyState );
      66        1983 : }
      67             : 
      68          27 : ScSortParam& ScSortParam::operator=( const ScSortParam& r )
      69             : {
      70          27 :     nCol1           = r.nCol1;
      71          27 :     nRow1           = r.nRow1;
      72          27 :     nCol2           = r.nCol2;
      73          27 :     nRow2           = r.nRow2;
      74          27 :     nUserIndex      = r.nUserIndex;
      75          27 :     bHasHeader      = r.bHasHeader;
      76          27 :     bByRow          = r.bByRow;
      77          27 :     bCaseSens       = r.bCaseSens;
      78          27 :     bNaturalSort    = r.bNaturalSort;
      79          27 :     bUserDef        = r.bUserDef;
      80          27 :     bIncludePattern = r.bIncludePattern;
      81          27 :     bInplace        = r.bInplace;
      82          27 :     nDestTab        = r.nDestTab;
      83          27 :     nDestCol        = r.nDestCol;
      84          27 :     nDestRow        = r.nDestRow;
      85          27 :     maKeyState      = r.maKeyState;
      86          27 :     aCollatorLocale         = r.aCollatorLocale;
      87          27 :     aCollatorAlgorithm      = r.aCollatorAlgorithm;
      88          27 :     nCompatHeader   = r.nCompatHeader;
      89             : 
      90          27 :     return *this;
      91             : }
      92             : 
      93           0 : bool ScSortParam::operator==( const ScSortParam& rOther ) const
      94             : {
      95           0 :     bool bEqual = false;
      96             :     // Anzahl der Sorts gleich?
      97           0 :     sal_uInt16 nLast      = 0;
      98           0 :     sal_uInt16 nOtherLast = 0;
      99           0 :     sal_uInt16 nSortSize = GetSortKeyCount();
     100             : 
     101           0 :     if ( !maKeyState.empty() )
     102             :     {
     103           0 :         while ( maKeyState[nLast++].bDoSort && nLast < nSortSize ) ;
     104           0 :         nLast--;
     105             :     }
     106             : 
     107           0 :     if ( !rOther.maKeyState.empty() )
     108             :     {
     109           0 :         while ( rOther.maKeyState[nOtherLast++].bDoSort && nOtherLast < nSortSize ) ;
     110           0 :         nOtherLast--;
     111             :     }
     112             : 
     113           0 :     if (   (nLast           == nOtherLast)
     114           0 :         && (nCol1           == rOther.nCol1)
     115           0 :         && (nRow1           == rOther.nRow1)
     116           0 :         && (nCol2           == rOther.nCol2)
     117           0 :         && (nRow2           == rOther.nRow2)
     118           0 :         && (bHasHeader      == rOther.bHasHeader)
     119           0 :         && (bByRow          == rOther.bByRow)
     120           0 :         && (bCaseSens       == rOther.bCaseSens)
     121           0 :         && (bNaturalSort    == rOther.bNaturalSort)
     122           0 :         && (bUserDef        == rOther.bUserDef)
     123           0 :         && (nUserIndex      == rOther.nUserIndex)
     124           0 :         && (bIncludePattern == rOther.bIncludePattern)
     125           0 :         && (bInplace        == rOther.bInplace)
     126           0 :         && (nDestTab        == rOther.nDestTab)
     127           0 :         && (nDestCol        == rOther.nDestCol)
     128           0 :         && (nDestRow        == rOther.nDestRow)
     129           0 :         && (aCollatorLocale.Language    == rOther.aCollatorLocale.Language)
     130           0 :         && (aCollatorLocale.Country     == rOther.aCollatorLocale.Country)
     131           0 :         && (aCollatorLocale.Variant     == rOther.aCollatorLocale.Variant)
     132           0 :         && (aCollatorAlgorithm          == rOther.aCollatorAlgorithm)
     133           0 :         && ( !maKeyState.empty() || !rOther.maKeyState.empty() )
     134             :         )
     135             :     {
     136           0 :         bEqual = true;
     137           0 :         for ( sal_uInt16 i=0; i<=nLast && bEqual; i++ )
     138           0 :             bEqual = ( maKeyState[i].nField == rOther.maKeyState[i].nField ) &&
     139           0 :                 ( maKeyState[i].bAscending  == rOther.maKeyState[i].bAscending );
     140             :     }
     141           0 :     if ( maKeyState.empty() && rOther.maKeyState.empty() )
     142           0 :         bEqual = true;
     143             : 
     144           0 :     return bEqual;
     145             : }
     146             : 
     147           1 : ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
     148             :         nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),nUserIndex(rSub.nUserIndex),
     149             :         bHasHeader(true),bByRow(true),bCaseSens(rSub.bCaseSens),bNaturalSort(rOld.bNaturalSort),
     150             :         bUserDef(rSub.bUserDef),bIncludePattern(rSub.bIncludePattern),
     151             :         bInplace(true),
     152             :         nDestTab(0),nDestCol(0),nDestRow(0),
     153             :         aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm ),
     154           1 :         nCompatHeader( rOld.nCompatHeader )
     155             : {
     156             :     sal_uInt16 i;
     157             : 
     158             :     //  zuerst die Gruppen aus den Teilergebnissen
     159           1 :     if (rSub.bDoSort)
     160           4 :         for (i=0; i<MAXSUBTOTAL; i++)
     161           3 :             if (rSub.bGroupActive[i])
     162             :             {
     163             :                 ScSortKeyState key;
     164           1 :                 key.bDoSort = true;
     165           1 :                 key.nField = rSub.nField[i];
     166           1 :                 key.bAscending = rSub.bAscending;
     167           1 :                 maKeyState.push_back(key);
     168             :             }
     169             : 
     170             :     //  dann dahinter die alten Einstellungen
     171           4 :     for (i=0; i < rOld.GetSortKeyCount(); i++)
     172           3 :         if (rOld.maKeyState[i].bDoSort)
     173             :         {
     174           0 :             SCCOLROW nThisField = rOld.maKeyState[i].nField;
     175           0 :             bool bDouble = false;
     176           0 :             for (sal_uInt16 j = 0; j < GetSortKeyCount(); j++)
     177           0 :                 if ( maKeyState[j].nField == nThisField )
     178           0 :                     bDouble = true;
     179           0 :             if (!bDouble)               // ein Feld nicht zweimal eintragen
     180             :             {
     181             :                 ScSortKeyState key;
     182           0 :                 key.bDoSort = true;
     183           0 :                 key.nField = nThisField;
     184           0 :                 key.bAscending = rOld.maKeyState[i].bAscending;
     185           0 :                 maKeyState.push_back(key);
     186             :             }
     187             :         }
     188           1 : }
     189             : 
     190           0 : ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
     191             :         nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),nUserIndex(0),
     192             :         bHasHeader(rParam.bHasHeader),bByRow(true),bCaseSens(rParam.bCaseSens),
     193             :         bNaturalSort(false),
     194             : //! TODO: what about Locale and Algorithm?
     195             :         bUserDef(false),bIncludePattern(false),
     196             :         bInplace(true),
     197           0 :         nDestTab(0),nDestCol(0),nDestRow(0), nCompatHeader(2)
     198             : {
     199             :     ScSortKeyState aKeyState;
     200           0 :     aKeyState.bDoSort = true;
     201           0 :     aKeyState.nField = nCol;
     202           0 :     aKeyState.bAscending = true;
     203             : 
     204           0 :     maKeyState.push_back( aKeyState );
     205             : 
     206             :     // Set the rest
     207           0 :     aKeyState.bDoSort = false;
     208           0 :     aKeyState.nField = 0;
     209             : 
     210           0 :     for (sal_uInt16 i=1; i<GetSortKeyCount(); i++)
     211           0 :         maKeyState.push_back( aKeyState );
     212           0 : }
     213             : 
     214           0 : void ScSortParam::MoveToDest()
     215             : {
     216           0 :     if (!bInplace)
     217             :     {
     218           0 :         SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
     219           0 :         SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
     220             : 
     221           0 :         nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
     222           0 :         nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
     223           0 :         nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
     224           0 :         nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
     225           0 :         for (sal_uInt16 i=0; i<GetSortKeyCount(); i++)
     226           0 :             if (bByRow)
     227           0 :                 maKeyState[i].nField += nDifX;
     228             :             else
     229           0 :                 maKeyState[i].nField += nDifY;
     230             : 
     231           0 :         bInplace = true;
     232             :     }
     233             :     else
     234             :     {
     235             :         OSL_FAIL("MoveToDest, bInplace == TRUE");
     236             :     }
     237           0 : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10