/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "sortparam.hxx" #include "global.hxx" #include "address.hxx" #include "queryparam.hxx" #include "subtotalparam.hxx" //------------------------------------------------------------------------ ScSortParam::ScSortParam() { Clear(); } //------------------------------------------------------------------------ ScSortParam::ScSortParam( const ScSortParam& r ) : nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex), bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens), bNaturalSort(r.bNaturalSort),bUserDef(r.bUserDef), bIncludePattern(r.bIncludePattern),bInplace(r.bInplace), nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow), maKeyState( r.maKeyState ), aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm ), nCompatHeader( r.nCompatHeader ) { } ScSortParam::~ScSortParam() {} //------------------------------------------------------------------------ void ScSortParam::Clear() { ScSortKeyState aKeyState; nCol1=nCol2=nDestCol = 0; nRow1=nRow2=nDestRow = 0; nCompatHeader = 2; nDestTab = 0; nUserIndex = 0; bHasHeader=bCaseSens=bUserDef=bNaturalSort = false; bByRow=bIncludePattern=bInplace = true; aCollatorLocale = ::com::sun::star::lang::Locale(); aCollatorAlgorithm = OUString(); aKeyState.bDoSort = false; aKeyState.nField = 0; aKeyState.bAscending = true; // Initialize to default size maKeyState.assign( DEFSORT, aKeyState ); } //------------------------------------------------------------------------ ScSortParam& ScSortParam::operator=( const ScSortParam& r ) { nCol1 = r.nCol1; nRow1 = r.nRow1; nCol2 = r.nCol2; nRow2 = r.nRow2; nUserIndex = r.nUserIndex; bHasHeader = r.bHasHeader; bByRow = r.bByRow; bCaseSens = r.bCaseSens; bNaturalSort = r.bNaturalSort; bUserDef = r.bUserDef; bIncludePattern = r.bIncludePattern; bInplace = r.bInplace; nDestTab = r.nDestTab; nDestCol = r.nDestCol; nDestRow = r.nDestRow; maKeyState = r.maKeyState; aCollatorLocale = r.aCollatorLocale; aCollatorAlgorithm = r.aCollatorAlgorithm; nCompatHeader = r.nCompatHeader; return *this; } //------------------------------------------------------------------------ bool ScSortParam::operator==( const ScSortParam& rOther ) const { bool bEqual = false; // Anzahl der Sorts gleich? sal_uInt16 nLast = 0; sal_uInt16 nOtherLast = 0; sal_uInt16 nSortSize = GetSortKeyCount(); if ( !maKeyState.empty() ) { while ( maKeyState[nLast++].bDoSort && nLast < nSortSize ) ; nLast--; } if ( !rOther.maKeyState.empty() ) { while ( rOther.maKeyState[nOtherLast++].bDoSort && nOtherLast < nSortSize ) ; nOtherLast--; } if ( (nLast == nOtherLast) && (nCol1 == rOther.nCol1) && (nRow1 == rOther.nRow1) && (nCol2 == rOther.nCol2) && (nRow2 == rOther.nRow2) && (bHasHeader == rOther.bHasHeader) && (bByRow == rOther.bByRow) && (bCaseSens == rOther.bCaseSens) && (bNaturalSort == rOther.bNaturalSort) && (bUserDef == rOther.bUserDef) && (nUserIndex == rOther.nUserIndex) && (bIncludePattern == rOther.bIncludePattern) && (bInplace == rOther.bInplace) && (nDestTab == rOther.nDestTab) && (nDestCol == rOther.nDestCol) && (nDestRow == rOther.nDestRow) && (aCollatorLocale.Language == rOther.aCollatorLocale.Language) && (aCollatorLocale.Country == rOther.aCollatorLocale.Country) && (aCollatorLocale.Variant == rOther.aCollatorLocale.Variant) && (aCollatorAlgorithm == rOther.aCollatorAlgorithm) && ( !maKeyState.empty() || !rOther.maKeyState.empty() ) ) { bEqual = true; for ( sal_uInt16 i=0; i<=nLast && bEqual; i++ ) bEqual = ( maKeyState[i].nField == rOther.maKeyState[i].nField ) && ( maKeyState[i].bAscending == rOther.maKeyState[i].bAscending ); } if ( maKeyState.empty() && rOther.maKeyState.empty() ) bEqual = true; return bEqual; } //------------------------------------------------------------------------ ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) : nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),nUserIndex(rSub.nUserIndex), bHasHeader(true),bByRow(true),bCaseSens(rSub.bCaseSens),bNaturalSort(rOld.bNaturalSort), bUserDef(rSub.bUserDef),bIncludePattern(rSub.bIncludePattern), bInplace(true), nDestTab(0),nDestCol(0),nDestRow(0), aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm ), nCompatHeader( rOld.nCompatHeader ) { sal_uInt16 i; // zuerst die Gruppen aus den Teilergebnissen if (rSub.bDoSort) for (i=0; i( nCol1 + nDifX ); nRow1 = sal::static_int_cast( nRow1 + nDifY ); nCol2 = sal::static_int_cast( nCol2 + nDifX ); nRow2 = sal::static_int_cast( nRow2 + nDifY ); for (sal_uInt16 i=0; i { bool operator() ( const ReorderIndex& r1, const ReorderIndex& r2 ) const { return r1.mnPos2 < r2.mnPos2; } }; SCCOLROW mnPos1; SCCOLROW mnPos2; ReorderIndex( SCCOLROW nPos1, SCCOLROW nPos2 ) : mnPos1(nPos1), mnPos2(nPos2) {} }; } void ReorderParam::reverse() { SCCOLROW nStart; if (mbByRow) nStart = maSortRange.aStart.Row(); else nStart = maSortRange.aStart.Col(); size_t n = maOrderIndices.size(); std::vector aBucket; aBucket.reserve(n); for (size_t i = 0; i < n; ++i) { SCCOLROW nPos1 = i + nStart; SCCOLROW nPos2 = maOrderIndices[i]; aBucket.push_back(ReorderIndex(nPos1, nPos2)); } std::sort(aBucket.begin(), aBucket.end(), ReorderIndex::LessByPos2()); std::vector aNew; aNew.reserve(n); for (size_t i = 0; i < n; ++i) aNew.push_back(aBucket[i].mnPos1); maOrderIndices.swap(aNew); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */