diff options
author | Jochen Nitschke <j.nitschke+logerrit@ok.de> | 2017-01-13 23:05:11 +0100 |
---|---|---|
committer | Jochen Nitschke <j.nitschke+logerrit@ok.de> | 2017-01-23 11:36:26 +0000 |
commit | 1e7947401773b33a1e6072dd60ab681b2ad87800 (patch) | |
tree | c96c69c1f4260aa28664fa5239e1fb876ca3cf97 /sc | |
parent | cb71dc9d36779c32733cd0497d9d799c6608888b (diff) |
tdf#48140 replace ApiCellRangeList in xlsx import (5)
remove now unused ApiCellRangeList
remove duplicate transition code in AddressConverter
Change-Id: I36865fa1cfd69899d79fa6163aaa2cbba33a8763
Reviewed-on: https://gerrit.libreoffice.org/32709
Reviewed-by: Jochen Nitschke <j.nitschke+logerrit@ok.de>
Tested-by: Jochen Nitschke <j.nitschke+logerrit@ok.de>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/inc/addressconverter.hxx | 92 | ||||
-rw-r--r-- | sc/source/filter/inc/formulabase.hxx | 3 | ||||
-rw-r--r-- | sc/source/filter/oox/addressconverter.cxx | 98 | ||||
-rw-r--r-- | sc/source/filter/oox/defnamesbuffer.cxx | 21 | ||||
-rw-r--r-- | sc/source/filter/oox/formulabase.cxx | 20 | ||||
-rw-r--r-- | sc/source/filter/oox/sheetdatabuffer.cxx | 1 |
6 files changed, 27 insertions, 208 deletions
diff --git a/sc/source/filter/inc/addressconverter.hxx b/sc/source/filter/inc/addressconverter.hxx index e79bacaac226..a72e66109106 100644 --- a/sc/source/filter/inc/addressconverter.hxx +++ b/sc/source/filter/inc/addressconverter.hxx @@ -28,58 +28,6 @@ namespace oox { namespace xls { -/** A vector of com.sun.star.table.CellRangeAddress elements and additional - functionality. */ -class ApiCellRangeList -{ -public: - inline explicit ApiCellRangeList() : mvAddresses() {} - - size_t size() const { return mvAddresses.size(); } - - bool empty() const { return mvAddresses.empty(); } - - const css::table::CellRangeAddress& front() const - { return mvAddresses.front(); } - - css::table::CellRangeAddress& operator[]( size_t i ) - { return mvAddresses[ i ]; } - - ::std::vector< css::table::CellRangeAddress >::const_iterator begin() const - { return mvAddresses.begin(); } - ::std::vector< css::table::CellRangeAddress >::iterator begin() - { return mvAddresses.begin(); } - - ::std::vector< css::table::CellRangeAddress >::const_iterator end() const - { return mvAddresses.end(); } - - ::std::vector< css::table::CellRangeAddress >::reverse_iterator rbegin() - { return mvAddresses.rbegin(); } - - ::std::vector< css::table::CellRangeAddress >::reverse_iterator rend() - { return mvAddresses.rend(); } - - void clear() { mvAddresses.clear(); } - - void erase( ::std::vector< css::table::CellRangeAddress >::iterator it ) - { mvAddresses.erase( it ); } - - void pop_back() { mvAddresses.pop_back(); } - - void push_back( const css::table::CellRangeAddress& rAddress ) - { mvAddresses.push_back( rAddress ); } - - /** Returns the base address of this range list (top-left cell of first range). */ - ScAddress getBaseAddress() const; - - /** Converts to a sequence. */ - css::uno::Sequence< css::table::CellRangeAddress > - toSequence() const; - -private: - ::std::vector< css::table::CellRangeAddress > mvAddresses; -}; - /** A 2D cell address struct for binary filters. */ struct BinAddress { @@ -352,10 +300,6 @@ public: overflow is not allowed via parameter bAllowOverflow. */ bool checkCellRange( - const css::table::CellRangeAddress& rRange, - bool bAllowOverflow, bool bTrackOverflow ); - - bool checkCellRange( const ScRange& rRange, bool bAllowOverflow, bool bTrackOverflow ); @@ -386,10 +330,6 @@ public: allowed via parameter bAllowOverflow. */ bool validateCellRange( - css::table::CellRangeAddress& orRange, - bool bAllowOverflow, bool bTrackOverflow ); - - bool validateCellRange( ScRange& orRange, bool bAllowOverflow, bool bTrackOverflow ); @@ -402,11 +342,6 @@ public: @return true = Range address could be parsed from the passed string. */ static bool convertToCellRangeUnchecked( - css::table::CellRangeAddress& orRange, - const OUString& rString, - sal_Int16 nSheet ); - - static bool convertToCellRangeUnchecked( ScRange& orRange, const OUString& rString, sal_Int16 nSheet ); @@ -436,11 +371,6 @@ public: allowed via parameter bAllowOverflow. */ bool convertToCellRange( - css::table::CellRangeAddress& orRange, - const OUString& rString, - sal_Int16 nSheet, - bool bAllowOverflow, bool bTrackOverflow ); - bool convertToCellRange( ScRange& orRange, const OUString& rString, sal_Int16 nSheet, @@ -454,11 +384,6 @@ public: @param nSheet Sheet index to be inserted into orRange. */ static void convertToCellRangeUnchecked( - css::table::CellRangeAddress& orRange, - const BinRange& rBinRange, - sal_Int16 nSheet ); - - static void convertToCellRangeUnchecked( ScRange& orRange, const BinRange& rBinRange, sal_Int16 nSheet ); @@ -486,11 +411,6 @@ public: allowed via parameter bAllowOverflow. */ bool convertToCellRange( - css::table::CellRangeAddress& orRange, - const BinRange& rBinRange, - sal_Int16 nSheet, - bool bAllowOverflow, bool bTrackOverflow ); - bool convertToCellRange( ScRange& orRange, const BinRange& rBinRange, sal_Int16 nSheet, @@ -507,7 +427,7 @@ public: limits. */ void validateCellRangeList( - ApiCellRangeList& orRanges, + ScRangeList& orRanges, bool bTrackOverflow ); /** Tries to convert the passed string to a cell range list. @@ -525,11 +445,6 @@ public: limits. */ void convertToCellRangeList( - ApiCellRangeList& orRanges, - const OUString& rString, - sal_Int16 nSheet, - bool bTrackOverflow ); - void convertToCellRangeList( ScRangeList& orRanges, const OUString& rString, sal_Int16 nSheet, @@ -550,11 +465,6 @@ public: limits. */ void convertToCellRangeList( - ApiCellRangeList& orRanges, - const BinRangeList& rBinRanges, - sal_Int16 nSheet, - bool bTrackOverflow ); - void convertToCellRangeList( ScRangeList& orRanges, const BinRangeList& rBinRanges, sal_Int16 nSheet, diff --git a/sc/source/filter/inc/formulabase.hxx b/sc/source/filter/inc/formulabase.hxx index 746242686b52..e105905485b8 100644 --- a/sc/source/filter/inc/formulabase.hxx +++ b/sc/source/filter/inc/formulabase.hxx @@ -24,7 +24,6 @@ #include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp> #include <com/sun/star/sheet/FormulaToken.hpp> #include <com/sun/star/table/CellAddress.hpp> -#include <com/sun/star/table/CellRangeAddress.hpp> #include <com/sun/star/uno/Sequence.hxx> #include <oox/helper/propertyset.hxx> #include <oox/helper/refvector.hxx> @@ -720,7 +719,7 @@ public: ranges contained in the token sequence. */ void extractCellRangeList( - ApiCellRangeList& orRanges, + ScRangeList& orRanges, const ApiTokenSequence& rTokens, bool bAllowRelative, sal_Int32 nFilterBySheet ) const; diff --git a/sc/source/filter/oox/addressconverter.cxx b/sc/source/filter/oox/addressconverter.cxx index 4e721c011b69..84541bac7306 100644 --- a/sc/source/filter/oox/addressconverter.cxx +++ b/sc/source/filter/oox/addressconverter.cxx @@ -50,18 +50,6 @@ const sal_Int16 OOX_MAXTAB = static_cast< sal_Int16 >( (1 << 15) - 1 ); } // namespace -ScAddress ApiCellRangeList::getBaseAddress() const -{ - if( mvAddresses.empty() ) - return ScAddress(0, 0, 0); - return ScAddress( SCCOL( mvAddresses.front().StartColumn ), SCROW( mvAddresses.front().StartRow ), SCTAB( mvAddresses.front().Sheet ) ); -} - -css::uno::Sequence< CellRangeAddress > ApiCellRangeList::toSequence() const -{ - return ContainerHelper::vectorToSequence( mvAddresses ); -} - void BinAddress::read( SequenceInputStream& rStrm ) { mnRow = rStrm.readInt32(); @@ -366,16 +354,6 @@ bool AddressConverter::checkCellRange( const ScRange& rRange, bool bAllowOverflo checkRow( rRange.aStart.Row(), bTrackOverflow ); } -bool AddressConverter::checkCellRange( const CellRangeAddress& rRange, bool bAllowOverflow, bool bTrackOverflow ) -{ - return - (checkCol( rRange.EndColumn, bTrackOverflow ) || bAllowOverflow) && // bAllowOverflow after checkCol to track overflow! - (checkRow( rRange.EndRow, bTrackOverflow ) || bAllowOverflow) && // bAllowOverflow after checkRow to track overflow! - checkTab( rRange.Sheet, bTrackOverflow ) && - checkCol( rRange.StartColumn, bTrackOverflow ) && - checkRow( rRange.StartRow, bTrackOverflow ); -} - bool AddressConverter::validateCellRange( ScRange& orRange, bool bAllowOverflow, bool bTrackOverflow ) { if( orRange.aStart.Col() > orRange.aEnd.Col() ) @@ -399,21 +377,6 @@ bool AddressConverter::validateCellRange( ScRange& orRange, bool bAllowOverflow, return true; } -bool AddressConverter::validateCellRange( CellRangeAddress& orRange, bool bAllowOverflow, bool bTrackOverflow ) -{ - if( orRange.StartColumn > orRange.EndColumn ) - ::std::swap( orRange.StartColumn, orRange.EndColumn ); - if( orRange.StartRow > orRange.EndRow ) - ::std::swap( orRange.StartRow, orRange.EndRow ); - if( !checkCellRange( orRange, bAllowOverflow, bTrackOverflow ) ) - return false; - if( orRange.EndColumn > maMaxPos.Col() ) - orRange.EndColumn = maMaxPos.Col(); - if( orRange.EndRow > maMaxPos.Row() ) - orRange.EndRow = maMaxPos.Row(); - return true; -} - bool AddressConverter::convertToCellRangeUnchecked( ScRange& orRange, const OUString& rString, sal_Int16 nSheet ) { @@ -431,21 +394,6 @@ bool AddressConverter::convertToCellRangeUnchecked( ScRange& orRange, return bReturnValue; } -bool AddressConverter::convertToCellRangeUnchecked( CellRangeAddress& orRange, - const OUString& rString, sal_Int16 nSheet ) -{ - orRange.Sheet = nSheet; - return parseOoxRange2d( orRange.StartColumn, orRange.StartRow, orRange.EndColumn, orRange.EndRow, rString ); -} - -bool AddressConverter::convertToCellRange( CellRangeAddress& orRange, - const OUString& rString, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow ) -{ - return - convertToCellRangeUnchecked( orRange, rString, nSheet ) && - validateCellRange( orRange, bAllowOverflow, bTrackOverflow ); -} - bool AddressConverter::convertToCellRange( ScRange& orRange, const OUString& rString, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow ) { @@ -454,16 +402,6 @@ bool AddressConverter::convertToCellRange( ScRange& orRange, validateCellRange( orRange, bAllowOverflow, bTrackOverflow ); } -void AddressConverter::convertToCellRangeUnchecked( CellRangeAddress& orRange, - const BinRange& rBinRange, sal_Int16 nSheet ) -{ - orRange.Sheet = nSheet; - orRange.StartColumn = rBinRange.maFirst.mnCol; - orRange.StartRow = rBinRange.maFirst.mnRow; - orRange.EndColumn = rBinRange.maLast.mnCol; - orRange.EndRow = rBinRange.maLast.mnRow; -} - void AddressConverter::convertToCellRangeUnchecked( ScRange& orRange, const BinRange& rBinRange, sal_Int16 nSheet ) { @@ -475,13 +413,6 @@ void AddressConverter::convertToCellRangeUnchecked( ScRange& orRange, orRange.aEnd.SetRow( rBinRange.maLast.mnRow ); } -bool AddressConverter::convertToCellRange( CellRangeAddress& orRange, - const BinRange& rBinRange, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow ) -{ - convertToCellRangeUnchecked( orRange, rBinRange, nSheet ); - return validateCellRange( orRange, bAllowOverflow, bTrackOverflow ); -} - bool AddressConverter::convertToCellRange( ScRange& orRange, const BinRange& rBinRange, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow ) { @@ -489,25 +420,11 @@ bool AddressConverter::convertToCellRange( ScRange& orRange, return validateCellRange( orRange, bAllowOverflow, bTrackOverflow ); } -void AddressConverter::validateCellRangeList( ApiCellRangeList& orRanges, bool bTrackOverflow ) +void AddressConverter::validateCellRangeList( ScRangeList& orRanges, bool bTrackOverflow ) { for( size_t nIndex = orRanges.size(); nIndex > 0; --nIndex ) - if( !validateCellRange( orRanges[ nIndex - 1 ], true, bTrackOverflow ) ) - orRanges.erase( orRanges.begin() + nIndex - 1 ); -} - -void AddressConverter::convertToCellRangeList( ApiCellRangeList& orRanges, - const OUString& rString, sal_Int16 nSheet, bool bTrackOverflow ) -{ - sal_Int32 nPos = 0; - sal_Int32 nLen = rString.getLength(); - CellRangeAddress aRange; - while( (0 <= nPos) && (nPos < nLen) ) - { - OUString aToken = rString.getToken( 0, ' ', nPos ); - if( !aToken.isEmpty() && convertToCellRange( aRange, aToken, nSheet, true, bTrackOverflow ) ) - orRanges.push_back( aRange ); - } + if( !validateCellRange( *orRanges[ nIndex - 1 ], true, bTrackOverflow ) ) + orRanges.Remove( nIndex - 1 ); } void AddressConverter::convertToCellRangeList( ScRangeList& orRanges, @@ -524,15 +441,6 @@ void AddressConverter::convertToCellRangeList( ScRangeList& orRanges, } } -void AddressConverter::convertToCellRangeList( ApiCellRangeList& orRanges, - const BinRangeList& rBinRanges, sal_Int16 nSheet, bool bTrackOverflow ) -{ - CellRangeAddress aRange; - for( ::std::vector< BinRange >::const_iterator aIt = rBinRanges.begin(), aEnd = rBinRanges.end(); aIt != aEnd; ++aIt ) - if( convertToCellRange( aRange, *aIt, nSheet, true, bTrackOverflow ) ) - orRanges.push_back( aRange ); -} - void AddressConverter::convertToCellRangeList( ScRangeList& orRanges, const BinRangeList& rBinRanges, sal_Int16 nSheet, bool bTrackOverflow ) { diff --git a/sc/source/filter/oox/defnamesbuffer.cxx b/sc/source/filter/oox/defnamesbuffer.cxx index 1588ce91ab01..0004f5a90719 100644 --- a/sc/source/filter/oox/defnamesbuffer.cxx +++ b/sc/source/filter/oox/defnamesbuffer.cxx @@ -359,35 +359,40 @@ void DefinedName::convertFormula( const css::uno::Sequence<css::sheet::ExternalL case BIFF_DEFNAME_PRINTAREA: { Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY ); - ApiCellRangeList aPrintRanges; + ScRangeList aPrintRanges; getFormulaParser().extractCellRangeList( aPrintRanges, aFTokenSeq, false, mnCalcSheet ); if( xPrintAreas.is() && !aPrintRanges.empty() ) - xPrintAreas->setPrintAreas( aPrintRanges.toSequence() ); + xPrintAreas->setPrintAreas( AddressConverter::toApiSequence(aPrintRanges) ); } break; case BIFF_DEFNAME_PRINTTITLES: { Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY ); - ApiCellRangeList aTitleRanges; + ScRangeList aTitleRanges; getFormulaParser().extractCellRangeList( aTitleRanges, aFTokenSeq, false, mnCalcSheet ); if( xPrintAreas.is() && !aTitleRanges.empty() ) { bool bHasRowTitles = false; bool bHasColTitles = false; const ScAddress& rMaxPos = getAddressConverter().getMaxAddress(); - for( ::std::vector< CellRangeAddress >::const_iterator aIt = aTitleRanges.begin(), aEnd = aTitleRanges.end(); (aIt != aEnd) && (!bHasRowTitles || !bHasColTitles); ++aIt ) + for (size_t i = 0, nSize = aTitleRanges.size(); i < nSize; ++i) { - bool bFullRow = (aIt->StartColumn == 0) && ( aIt->EndColumn >= rMaxPos.Col() ); - bool bFullCol = (aIt->StartRow == 0) && ( aIt->EndRow >= rMaxPos.Row() ); + const ScRange& rRange = *aTitleRanges[i]; + bool bFullRow = (rRange.aStart.Col() == 0) && ( rRange.aEnd.Col() >= rMaxPos.Col() ); + bool bFullCol = (rRange.aStart.Row() == 0) && ( rRange.aEnd.Row() >= rMaxPos.Row() ); if( !bHasRowTitles && bFullRow && !bFullCol ) { - xPrintAreas->setTitleRows( *aIt ); + xPrintAreas->setTitleRows( CellRangeAddress(rRange.aStart.Tab(), + rRange.aStart.Col(), rRange.aStart.Row(), + rRange.aEnd.Col(), rRange.aEnd.Row()) ); xPrintAreas->setPrintTitleRows( true ); bHasRowTitles = true; } else if( !bHasColTitles && bFullCol && !bFullRow ) { - xPrintAreas->setTitleColumns( *aIt ); + xPrintAreas->setTitleColumns( CellRangeAddress(rRange.aStart.Tab(), + rRange.aStart.Col(), rRange.aStart.Row(), + rRange.aEnd.Col(), rRange.aEnd.Row()) ); xPrintAreas->setPrintTitleColumns( true ); bHasColTitles = true; } diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx index 74b562c30175..01de05aa613e 100644 --- a/sc/source/filter/oox/formulabase.cxx +++ b/sc/source/filter/oox/formulabase.cxx @@ -22,7 +22,6 @@ #include <map> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/table/XCellRange.hpp> #include <com/sun/star/sheet/AddressConvention.hpp> #include <com/sun/star/sheet/ReferenceFlags.hpp> #include <com/sun/star/sheet/SingleReference.hpp> @@ -1480,7 +1479,7 @@ bool lclConvertToCellRange( ScRange& orRange, const ComplexReference& rComplexRe enum TokenToRangeListState { STATE_REF, STATE_SEP, STATE_OPEN, STATE_CLOSE, STATE_ERROR }; -TokenToRangeListState lclProcessRef( ApiCellRangeList& orRanges, const Any& rData, bool bAllowRelative, sal_Int32 nFilterBySheet ) +TokenToRangeListState lclProcessRef( ScRangeList& orRanges, const Any& rData, bool bAllowRelative, sal_Int32 nFilterBySheet ) { using namespace ::com::sun::star::sheet::ReferenceFlags; const sal_Int32 FORBIDDEN_FLAGS_DEL = COLUMN_DELETED | ROW_DELETED | SHEET_DELETED; @@ -1490,10 +1489,10 @@ TokenToRangeListState lclProcessRef( ApiCellRangeList& orRanges, const Any& rDat SingleReference aSingleRef; if( rData >>= aSingleRef ) { - ScAddress aAddress ( 0, 0, 0 ); + ScAddress aAddress; // ignore invalid addresses (with #REF! errors), but do not stop parsing if( lclConvertToCellAddress( aAddress, aSingleRef, nForbiddenFlags, nFilterBySheet ) ) - orRanges.push_back( CellRangeAddress( aAddress.Tab(), aAddress.Col(), aAddress.Row(), aAddress.Col(), aAddress.Row() ) ); + orRanges.Append( ScRange(aAddress, aAddress) ); return STATE_REF; } ComplexReference aComplexRef; @@ -1502,8 +1501,7 @@ TokenToRangeListState lclProcessRef( ApiCellRangeList& orRanges, const Any& rDat ScRange aRange; // ignore invalid ranges (with #REF! errors), but do not stop parsing if( lclConvertToCellRange( aRange, aComplexRef, nForbiddenFlags, nFilterBySheet ) ) - orRanges.push_back( CellRangeAddress(aRange.aStart.Tab(), aRange.aStart.Col(), aRange.aStart.Row(), - aRange.aEnd.Col(), aRange.aEnd.Row()) ); + orRanges.Append( aRange ); return STATE_REF; } return STATE_ERROR; @@ -1601,20 +1599,20 @@ Any FormulaProcessorBase::extractReference( const ApiTokenSequence& rTokens ) co bool FormulaProcessorBase::extractCellRange( ScRange& orRange, const ApiTokenSequence& rTokens, bool bAllowRelative ) const { - ApiCellRangeList aRanges; + ScRangeList aRanges; lclProcessRef( aRanges, extractReference( rTokens ), bAllowRelative, -1 ); if( !aRanges.empty() ) { - orRange = aRanges.getBaseAddress(); + orRange = aRanges.GetTopLeftCorner(); return true; } return false; } -void FormulaProcessorBase::extractCellRangeList( ApiCellRangeList& orRanges, +void FormulaProcessorBase::extractCellRangeList( ScRangeList& orRanges, const ApiTokenSequence& rTokens, bool bAllowRelative, sal_Int32 nFilterBySheet ) const { - orRanges.clear(); + orRanges.RemoveAll(); TokenToRangeListState eState = STATE_OPEN; sal_Int32 nParenLevel = 0; for( ApiTokenIterator aIt( rTokens, OPCODE_SPACES, true ); aIt.is() && (eState != STATE_ERROR); ++aIt ) @@ -1656,7 +1654,7 @@ void FormulaProcessorBase::extractCellRangeList( ApiCellRangeList& orRanges, } if( eState == STATE_ERROR ) - orRanges.clear(); + orRanges.RemoveAll(); else getAddressConverter().validateCellRangeList( orRanges, false ); } diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx index bc20b4fb73a1..e40e47e147f0 100644 --- a/sc/source/filter/oox/sheetdatabuffer.cxx +++ b/sc/source/filter/oox/sheetdatabuffer.cxx @@ -23,7 +23,6 @@ #include <com/sun/star/sheet/XArrayFormulaTokens.hpp> #include <com/sun/star/sheet/XCellRangeData.hpp> #include <com/sun/star/sheet/XMultipleOperation.hpp> -#include <com/sun/star/table/XCell.hpp> #include <com/sun/star/text/XText.hpp> #include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/util/NumberFormat.hpp> |