[Libreoffice-commits] core.git: sc/inc sc/source

Noel Grandin noel.grandin at collabora.co.uk
Thu Aug 31 16:37:57 UTC 2017


 sc/inc/document.hxx              |    5 ++---
 sc/inc/table.hxx                 |   32 +++++++++++++++++++++++++-------
 sc/source/core/data/document.cxx |    9 ++++-----
 sc/source/core/data/drwlayer.cxx |   12 ++++++------
 sc/source/core/data/table1.cxx   |   11 ++++++-----
 sc/source/core/data/table2.cxx   |    3 +--
 sc/source/core/data/table3.cxx   |    8 ++++----
 sc/source/core/data/table5.cxx   |    4 ++--
 sc/source/ui/view/tabview.cxx    |    3 ++-
 9 files changed, 52 insertions(+), 35 deletions(-)

New commits:
commit 1cdaec1931e0012506726c773373e46fa6ef81c0
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Aug 30 08:51:50 2017 +0200

    make the ScColumnsRange iterator return SCCOL
    
    since we don't want to expose internal details like the ScColumn to most
    of the code, make the ScColumnsRange iterators return SCCOL instead of
    ScColumn*
    
    Change-Id: I67a58df90959170105255d18e7dd38ef0d6e3c11
    Reviewed-on: https://gerrit.libreoffice.org/41719
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index bc1f4ea2f5cf..45f450e59462 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -296,7 +296,6 @@ friend class sc::ColumnSpanSet;
 friend class sc::EditTextIterator;
 friend class sc::FormulaGroupAreaListener;
 friend class sc::TableColumnBlockPositionSet;
-friend class ScDrawLayer;
 
     typedef std::vector<ScTable*> TableContainer;
 
@@ -2323,6 +2322,8 @@ public:
     void                SwapNonEmpty( sc::TableValues& rValues );
     void                finalizeOutlineImport();
 
+    ScColumnsRange      GetColumnsRange(SCTAB nTab, SCCOL nColBegin, SCCOL nColEnd) const;
+
 private:
 
     /**
@@ -2385,8 +2386,6 @@ private:
 
     void EndListeningGroups( const std::vector<ScAddress>& rPosArray );
     void SetNeedsListeningGroups( const std::vector<ScAddress>& rPosArray );
-
-    ScColumnsRange       GetColumnsRange(SCTAB nTab, SCCOL nColBegin, SCCOL nColEnd) const;
 };
 
 #endif
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index d41d67d10a1c..3113ef6d8cd0 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -119,13 +119,31 @@ class ScHint;
 
 class ScColumnsRange final
 {
-    typedef std::vector<ScColumn*>::const_iterator const_iterator;
-    const const_iterator maBegin;
-    const const_iterator maEnd;
-public:
-    ScColumnsRange(const_iterator nBegin, const_iterator nEnd) : maBegin(nBegin), maEnd(nEnd) {}
-    const const_iterator & begin() { return maBegin; }
-    const const_iterator & end() { return maEnd; }
+ public:
+    class Iterator final : public std::iterator<
+                            std::input_iterator_tag,  // iterator_category
+                            SCCOL,                    // value_type
+                            SCCOL,                    // difference_type
+                            const SCCOL*,             // pointer
+                            SCCOL>                    // reference
+    {
+        std::vector<ScColumn*>::const_iterator maColIter;
+    public:
+        explicit Iterator(std::vector<ScColumn*>::const_iterator colIter) : maColIter(colIter) {}
+
+        Iterator& operator++() { maColIter++; return *this;}
+
+        bool operator==(Iterator other) const {return maColIter == other.maColIter;}
+        bool operator!=(Iterator other) const {return !(*this == other);}
+        reference operator*() const {return (*maColIter)->GetCol();}
+    };
+
+    ScColumnsRange(Iterator nBegin, Iterator nEnd) : maBegin(nBegin), maEnd(nEnd) {}
+    const Iterator & begin() { return maBegin; }
+    const Iterator & end() { return maEnd; }
+private:
+    const Iterator maBegin;
+    const Iterator maEnd;
 };
 
 class ScTable
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 6bb050d6dcf0..94a91edd96e7 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2523,7 +2523,8 @@ ScColumnsRange ScDocument::GetColumnsRange( SCTAB nTab, SCCOL nColBegin, SCCOL n
     if (!TableExists(nTab))
     {
         std::vector<ScColumn*> aEmptyVector;
-        return ScColumnsRange(aEmptyVector.begin(), aEmptyVector.end());
+        return ScColumnsRange(ScColumnsRange::Iterator(aEmptyVector.begin()),
+                              ScColumnsRange::Iterator(aEmptyVector.end()));
     }
 
     return maTabs[nTab]->GetColumnsRange(nColBegin, nColEnd);
@@ -6591,9 +6592,8 @@ ScAddress ScDocument::GetNotePosition( size_t nIndex ) const
 {
     for (size_t nTab = 0; nTab < maTabs.size(); ++nTab)
     {
-        for (const ScColumn* pCol : GetColumnsRange(nTab, 0, MAXCOL))
+        for (SCCOL nCol : GetColumnsRange(nTab, 0, MAXCOL))
         {
-            SCCOL nCol = pCol->GetCol();
             size_t nColNoteCount = GetNoteCount(nTab, nCol);
             if (!nColNoteCount)
                 continue;
@@ -6619,9 +6619,8 @@ ScAddress ScDocument::GetNotePosition( size_t nIndex ) const
 
 ScAddress ScDocument::GetNotePosition( size_t nIndex, SCTAB nTab ) const
 {
-    for (const ScColumn * pCol : GetColumnsRange(nTab, 0, MAXCOL))
+    for (SCCOL nCol : GetColumnsRange(nTab, 0, MAXCOL))
     {
-        SCCOL nCol = pCol->GetCol();
         size_t nColNoteCount = GetNoteCount(nTab, nCol);
         if (!nColNoteCount)
             continue;
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index ddf2cf41dfb6..0d84f78ff146 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -1070,12 +1070,12 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co
             rRange.aStart.SetCol( 0 );
             if (nWidth <= nStartX)
             {
-                for (const ScColumn* pCol : pDoc->GetColumnsRange(nTab, 0, MAXCOL))
+                for (SCCOL nCol : pDoc->GetColumnsRange(nTab, 0, MAXCOL))
                 {
-                    nWidth += pDoc->GetColWidth(pCol->GetCol(),nTab);
+                    nWidth += pDoc->GetColWidth(nCol,nTab);
                     if (nWidth > nStartX)
                     {
-                        rRange.aStart.SetCol( pCol->GetCol() );
+                        rRange.aStart.SetCol( nCol );
                         break;
                     }
                 }
@@ -1085,12 +1085,12 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co
             rRange.aEnd.SetCol( 0 );
             if (nWidth <= nEndX)
             {
-                for (const ScColumn* pCol : pDoc->GetColumnsRange(nTab, 0, MAXCOL)) //TODO: start at Start
+                for (SCCOL nCol : pDoc->GetColumnsRange(nTab, 0, MAXCOL)) //TODO: start at Start
                 {
-                    nWidth += pDoc->GetColWidth(pCol->GetCol(),nTab);
+                    nWidth += pDoc->GetColWidth(nCol,nTab);
                     if (nWidth > nEndX)
                     {
-                        rRange.aEnd.SetCol( pCol->GetCol() );
+                        rRange.aEnd.SetCol( nCol );
                         break;
                     }
                 }
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index c10100d4777b..c2416406abb4 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1681,14 +1681,14 @@ void ScTable::UpdateReference(
 void ScTable::UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
                                     ScDocument* pUndoDoc )
 {
-    for (ScColumn* pCol : GetColumnsRange(0, MAXCOL))
-        pCol->UpdateTranspose( rSource, rDest, pUndoDoc );
+    for (auto const & rpCol : aCol)
+        rpCol->UpdateTranspose( rSource, rDest, pUndoDoc );
 }
 
 void ScTable::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
 {
-    for (ScColumn* pCol : GetColumnsRange(0, MAXCOL))
-        pCol->UpdateGrow( rArea, nGrowX, nGrowY );
+    for (auto const & rpCol : aCol)
+        rpCol->UpdateGrow( rArea, nGrowX, nGrowY );
 }
 
 void ScTable::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
@@ -2386,7 +2386,8 @@ const ScConditionalFormatList* ScTable::GetCondFormList() const
 ScColumnsRange ScTable::GetColumnsRange(SCCOL nColBegin, SCCOL nColEnd) const
 {
     // because the range is inclusive, some code will pass nColEnd<nColBegin to indicate an empty range
-    return ScColumnsRange(aCol.begin() + nColBegin, nColEnd < nColBegin ? (aCol.begin() + nColBegin) : (aCol.begin() + nColEnd + 1));
+    return ScColumnsRange(ScColumnsRange::Iterator(aCol.begin() + nColBegin),
+                          ScColumnsRange::Iterator(nColEnd < nColBegin ? (aCol.begin() + nColBegin) : (aCol.begin() + nColEnd + 1)));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 7871f04318fb..8ae63775f3c4 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2107,9 +2107,8 @@ void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCC
     SCROW nY1 = pRowInfo[0].nRowNo;
     SCROW nY2 = pRowInfo[nArrCount-1].nRowNo;
 
-    for (ScColumn* pCol : GetColumnsRange(0, MAXCOL))
+    for (SCCOL nCol : GetColumnsRange(0, MAXCOL))
     {
-        SCCOL nCol = pCol->GetCol();
         if (!ColHidden(nCol))
         {
             SCSIZE nArrY = 0;
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 926301cd4582..5f4a101e2e3d 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1849,14 +1849,14 @@ public:
         SCCOL nStartCol = mrParam.nCol1;
         SCCOL nEndCol = mrParam.nCol2;
 
-        for (const ScColumn* pCol : mrTab.GetColumnsRange(0, nStartCol - 1))
+        for (SCCOL nCol : mrTab.GetColumnsRange(0, nStartCol - 1))
         {
-            if (mrTab.HasData(pCol->GetCol(), nRow))
+            if (mrTab.HasData(nCol, nRow))
                 return true;
         }
-        for (const ScColumn* pCol : mrTab.GetColumnsRange(nEndCol + 1, MAXCOL))
+        for (SCCOL nCol : mrTab.GetColumnsRange(nEndCol + 1, MAXCOL))
         {
-            if (mrTab.HasData(pCol->GetCol(), nRow))
+            if (mrTab.HasData(nCol, nRow))
                 return true;
         }
         return false;
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 46f36b11bba0..14d38e5be129 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -290,8 +290,8 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
     if (nEndCol < MAXCOL)
     {
         SetColBreak(nEndCol+1, true, false);  // AREABREAK
-        for (const ScColumn* pCol : GetColumnsRange(nEndCol + 2, MAXCOL))
-            RemoveColBreak(pCol->GetCol(), true, false);
+        for (SCCOL nCol : GetColumnsRange(nEndCol + 2, MAXCOL))
+            RemoveColBreak(nCol, true, false);
     }
     if (nEndRow < MAXROW)
     {
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 27e9e45cc1e3..576c564ec2b3 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -44,6 +44,7 @@
 #include "AccessibilityHints.hxx"
 #include "appoptio.hxx"
 #include "attrib.hxx"
+#include "table.hxx"
 #include <comphelper/lok.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <sfx2/lokhelper.hxx>
@@ -2454,7 +2455,7 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
         long nLeftBoundPx = rRectangle.Left() / TWIPS_PER_PIXEL;
         long nRightBoundPx = rRectangle.Right() / TWIPS_PER_PIXEL;
         nEndCol = MAXCOL;
-        for (SCCOL nCol = 0; nCol <= MAXCOL; ++nCol)
+        for (SCCOL nCol : pDoc->GetColumnsRange(aViewData.GetTabNo(), 0, MAXCOL))
         {
             if (nTotalPixels > nRightBoundPx)
             {


More information about the Libreoffice-commits mailing list