summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-08-30 12:19:01 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-02 13:04:57 +0200
commit1463625ae26900d2461fd72a5a2c894b9f1b8726 (patch)
tree7639fb6a495920de972f1cae4c9c99a7aaaa77db
parentfae405c522ce95bdfaedcbcae407226b4e1c487d (diff)
dynamic column container: fix some more for loops
and add reverse-iterator functionality Change-Id: Ide7ee9d2152871d414246303d76c91da36557524 Reviewed-on: https://gerrit.libreoffice.org/41727 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sc/inc/document.hxx2
-rw-r--r--sc/inc/table.hxx3
-rw-r--r--sc/source/core/data/document.cxx2
-rw-r--r--sc/source/core/data/table2.cxx20
-rw-r--r--sc/source/core/data/table5.cxx7
-rw-r--r--sc/source/filter/dif/difimp.cxx3
-rw-r--r--sc/source/filter/excel/colrowst.cxx5
-rw-r--r--sc/source/ui/miscdlgs/datatableview.cxx3
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx6
-rw-r--r--sc/source/ui/unoobj/docuno.cxx3
10 files changed, 31 insertions, 23 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 45f450e59462..6e91927719a4 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2322,7 +2322,7 @@ public:
void SwapNonEmpty( sc::TableValues& rValues );
void finalizeOutlineImport();
- ScColumnsRange GetColumnsRange(SCTAB nTab, SCCOL nColBegin, SCCOL nColEnd) const;
+ SC_DLLPUBLIC ScColumnsRange GetColumnsRange(SCTAB nTab, SCCOL nColBegin, SCCOL nColEnd) const;
private:
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 3113ef6d8cd0..4c734c7d7823 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -132,6 +132,7 @@ class ScColumnsRange final
explicit Iterator(std::vector<ScColumn*>::const_iterator colIter) : maColIter(colIter) {}
Iterator& operator++() { maColIter++; return *this;}
+ Iterator& operator--() { maColIter--; return *this;}
bool operator==(Iterator other) const {return maColIter == other.maColIter;}
bool operator!=(Iterator other) const {return !(*this == other);}
@@ -141,6 +142,8 @@ class ScColumnsRange final
ScColumnsRange(Iterator nBegin, Iterator nEnd) : maBegin(nBegin), maEnd(nEnd) {}
const Iterator & begin() { return maBegin; }
const Iterator & end() { return maEnd; }
+ std::reverse_iterator<Iterator> rbegin() { return std::reverse_iterator<Iterator>(maEnd); }
+ std::reverse_iterator<Iterator> rend() { return std::reverse_iterator<Iterator>(maBegin); }
private:
const Iterator maBegin;
const Iterator maEnd;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 94a91edd96e7..9079c92d67f6 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -4569,7 +4569,7 @@ SCCOL ScDocument::GetNextDifferentChangedCol( SCTAB nTab, SCCOL nStart) const
{
CRFlags nStartFlags = maTabs[nTab]->GetColFlags(nStart);
sal_uInt16 nStartWidth = maTabs[nTab]->GetOriginalWidth(nStart);
- for (SCCOL nCol = nStart + 1; nCol <= MAXCOL; nCol++)
+ for (SCCOL nCol : maTabs[nTab]->GetColumnsRange( nStart + 1, MAXCOL))
{
if (((nStartFlags & CRFlags::ManualBreak) != (maTabs[nTab]->GetColFlags(nCol) & CRFlags::ManualBreak)) ||
(nStartWidth != maTabs[nTab]->GetOriginalWidth(nCol)) ||
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 8ae63775f3c4..d14e699db9a3 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <algorithm>
#include <memory>
#include "table.hxx"
#include "patattr.hxx"
@@ -263,18 +264,19 @@ void ScTable::DeleteRow(
bool ScTable::TestInsertCol( SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ) const
{
- bool bTest = true;
-
- if ( nStartRow==0 && nEndRow==MAXROW && pOutlineTable )
- bTest = pOutlineTable->TestInsertCol(nSize);
-
if ( nSize > static_cast<SCSIZE>(MAXCOL) )
- bTest = false;
+ return false;
- for (SCCOL i=MAXCOL; (i+static_cast<SCCOL>(nSize)>MAXCOL) && bTest; i--)
- bTest = aCol[i].TestInsertCol(nStartRow, nEndRow);
+ if ( nStartRow==0 && nEndRow==MAXROW && pOutlineTable
+ && ! pOutlineTable->TestInsertCol(nSize) )
+ return false;
- return bTest;
+ auto range = GetColumnsRange( MAXCOL - static_cast<SCCOL>(nSize) + 1, MAXCOL );
+ for (auto it = range.rbegin(); it != range.rend(); ++it )
+ if (! aCol[*it].TestInsertCol(nStartRow, nEndRow))
+ return false;
+
+ return true;
}
void ScTable::InsertCol(
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 14d38e5be129..de411231e13e 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -80,7 +80,6 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
SfxItemSet* pStyleSet = &pStyle->GetItemSet();
const SfxPoolItem* pItem;
- SCCOL nX;
SCCOL nStartCol = 0;
SCROW nStartRow = 0;
SCCOL nEndCol = MAXCOL;
@@ -99,7 +98,7 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
{
// Show nothing, when multiple ranges
- for (nX=0; nX<MAXCOL; nX++)
+ for (SCCOL nX : GetColumnsRange(0, MAXCOL))
RemoveColBreak(nX, true, false);
RemoveRowPageBreaks(0, MAXROW-1);
@@ -150,7 +149,7 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
// Beginning: Remove breaks
- for (nX=0; nX<nStartCol; nX++)
+ for (SCCOL nX : GetColumnsRange(0, nStartCol-1))
RemoveColBreak(nX, true, false);
RemoveRowPageBreaks(0, nStartRow-1);
@@ -164,7 +163,7 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
bool bRepeatCol = ( nRepeatStartX != SCCOL_REPEAT_NONE );
bool bColFound = false;
long nSizeX = 0;
- for (nX=nStartCol; nX<=nEndCol; nX++)
+ for (SCCOL nX=nStartCol; nX<=nEndCol; nX++)
{
bool bStartOfPage = false;
long nThisX = ColHidden(nX) ? 0 : pColWidth[nX];
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index 4d8c7084d632..7cd8190ecd3a 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -32,6 +32,7 @@
#include "scerrors.hxx"
#include "scitems.hxx"
#include "stringutil.hxx"
+#include "table.hxx"
#include <memory>
const sal_Unicode pKeyTABLE[] = { 'T', 'A', 'B', 'L', 'E', 0 };
@@ -686,7 +687,7 @@ void DifAttrCache::SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_u
void DifAttrCache::Apply( ScDocument& rDoc, SCTAB nTab )
{
- for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ )
+ for( SCCOL nCol : rDoc.GetColumnsRange(nTab, 0, MAXCOL) )
{
if( mvCols[ nCol ] )
mvCols[ nCol ]->Apply( rDoc, nCol, nTab );
diff --git a/sc/source/filter/excel/colrowst.cxx b/sc/source/filter/excel/colrowst.cxx
index e1d12a0098cf..10563791fc9e 100644
--- a/sc/source/filter/excel/colrowst.cxx
+++ b/sc/source/filter/excel/colrowst.cxx
@@ -29,6 +29,7 @@
#include "xistyle.hxx"
#include "queryparam.hxx"
#include "excimp8.hxx"
+#include "table.hxx"
XclImpColRowSettings::XclImpColRowSettings( const XclImpRoot& rRoot ) :
XclImpRoot( rRoot ),
@@ -188,7 +189,7 @@ void XclImpColRowSettings::Convert( SCTAB nScTab )
// column widths ----------------------------------------------------------
maColWidths.build_tree();
- for( SCCOL nCol = 0; nCol <= MAXCOL; ++nCol )
+ for( SCCOL nCol : rDoc.GetColumnsRange(nScTab, 0, MAXCOL) )
{
sal_uInt16 nWidth = mnDefWidth;
if (GetColFlag(nCol, ExcColRowFlags::Used))
@@ -280,7 +281,7 @@ void XclImpColRowSettings::ConvertHiddenFlags( SCTAB nScTab )
ScDocument& rDoc = GetDoc();
// hide the columns
- for( SCCOL nCol = 0; nCol <= MAXCOL; ++nCol )
+ for( SCCOL nCol : rDoc.GetColumnsRange(nScTab, 0, MAXCOL) )
if (GetColFlag(nCol, ExcColRowFlags::Hidden))
rDoc.ShowCol( nCol, nScTab, false );
diff --git a/sc/source/ui/miscdlgs/datatableview.cxx b/sc/source/ui/miscdlgs/datatableview.cxx
index d149713ca347..fc0e68aa363a 100644
--- a/sc/source/ui/miscdlgs/datatableview.cxx
+++ b/sc/source/ui/miscdlgs/datatableview.cxx
@@ -23,6 +23,7 @@
#include "viewdata.hxx"
#include "output.hxx"
#include "fillinfo.hxx"
+#include "table.hxx"
constexpr double nPPTX = 0.06666;
constexpr double nPPTY = 0.06666;
@@ -178,7 +179,7 @@ SCCOL findColFromPos(sal_uInt16 nPixelPos, const ScDocument* pDoc, SCCOL nStartC
{
nPixelPos -= nRowHeaderWidth;
sal_uInt32 nPixelLength = 0;
- for (SCCOL nCol = nStartCol; nCol <= MAXCOL; ++nCol)
+ for (SCCOL nCol : pDoc->GetColumnsRange(0, nStartCol, MAXCOL))
{
sal_uInt16 nColWidth = pDoc->GetColWidth(nCol, 0, true);
sal_uInt32 nPixel = ScViewData::ToPixel(nColWidth, nPPTX);
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 5dece97adb2f..d51b82663b3d 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -131,6 +131,7 @@
#include <sortparam.hxx>
#include "condformatuno.hxx"
#include "TablePivotCharts.hxx"
+#include "table.hxx"
#include <list>
#include <memory>
@@ -6932,8 +6933,7 @@ uno::Sequence<sheet::TablePageBreakData> SAL_CALL ScTableSheetObj::getColumnPage
}
SCCOL nCount = 0;
- SCCOL nCol;
- for (nCol=0; nCol<=MAXCOL; nCol++)
+ for (SCCOL nCol : rDoc.GetColumnsRange(nTab, 0, MAXCOL))
if (rDoc.HasColBreak(nCol, nTab) != ScBreakType::NONE)
++nCount;
@@ -6941,7 +6941,7 @@ uno::Sequence<sheet::TablePageBreakData> SAL_CALL ScTableSheetObj::getColumnPage
uno::Sequence<sheet::TablePageBreakData> aSeq(nCount);
sheet::TablePageBreakData* pAry = aSeq.getArray();
sal_uInt16 nPos = 0;
- for (nCol=0; nCol<=MAXCOL; nCol++)
+ for (SCCOL nCol : rDoc.GetColumnsRange(nTab, 0, MAXCOL))
{
ScBreakType nBreak = rDoc.HasColBreak(nCol, nTab);
if (nBreak != ScBreakType::NONE)
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index b7b55293edd9..c6445c73d0dd 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -122,6 +122,7 @@
#include "drtxtob.hxx"
#include "transobj.hxx"
#include "chgtrack.hxx"
+#include "table.hxx"
#include "strings.hrc"
@@ -4315,7 +4316,7 @@ sal_Int32 SAL_CALL ScAnnotationsObj::getCount()
if (pDocShell)
{
const ScDocument& rDoc = pDocShell->GetDocument();
- for (SCCOL nCol = 0; nCol <= MAXCOL; ++nCol)
+ for (SCCOL nCol : rDoc.GetColumnsRange(nTab, 0, MAXCOL))
nCount += rDoc.GetNoteCount(nTab, nCol);
}
return nCount;