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

Bartosz Kosiorek gang65 at poczta.onet.pl
Fri Feb 24 23:16:14 UTC 2017


 sc/inc/colcontainer.hxx              |    2 ++
 sc/inc/table.hxx                     |   17 ++++++++++++++++-
 sc/source/core/data/colcontainer.cxx |   10 +++++++++-
 sc/source/core/data/table2.cxx       |   35 +++++++++++++++++++++++++++++------
 4 files changed, 56 insertions(+), 8 deletions(-)

New commits:
commit a1b1ed766d1110acf843b807d554f9375963234c
Author: Bartosz Kosiorek <gang65 at poczta.onet.pl>
Date:   Tue Jan 31 00:25:12 2017 +0100

    tdf#50916 Allow dynamically increase number of columns according to needs
    
    Change-Id: I08b1d70b6aafb01738bb5dec3f4eafd7b21e6bb5
    Reviewed-on: https://gerrit.libreoffice.org/33724
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>

diff --git a/sc/inc/colcontainer.hxx b/sc/inc/colcontainer.hxx
index c3e0398..925104d 100644
--- a/sc/inc/colcontainer.hxx
+++ b/sc/inc/colcontainer.hxx
@@ -55,6 +55,8 @@ public:
         return static_cast<SCCOL>( aCols.size() );
     }
 
+    void resize( const size_t aNewSize );
+
     void Clear();
 
     const ScColumn& back() const
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 3d446ad..5f8711c 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -241,6 +241,21 @@ public:
 
     ScOutlineTable* GetOutlineTable()               { return pOutlineTable; }
 
+    ScColumn& CreateColumnIfNotExists( SCCOL nScCol )
+    {
+        if ( nScCol >= aCol.size() )
+        {
+            SCCOL aOldColSize = aCol.size();
+            bool bUseEmptyAttrArray = false;
+            if ( aOldColSize == 0 )
+                bUseEmptyAttrArray = true;
+            aCol.resize( static_cast< size_t >( nScCol + 1 ) );
+            for (SCCOL i = aOldColSize; i <= nScCol; i++)
+                aCol[i].Init( i, nTab, pDocument, bUseEmptyAttrArray );
+
+        }
+        return aCol[nScCol];
+    }
     sal_uLong       GetCellCount() const;
     sal_uLong       GetWeightedCount() const;
     sal_uLong       GetCodeCount() const;       // RPN code in formula
@@ -544,7 +559,7 @@ public:
 
     FormulaError    GetErrCode( const ScAddress& rPos ) const
                     {
-                        return ValidColRow(rPos.Col(),rPos.Row()) ?
+                        return IsColRowValid(rPos.Col(),rPos.Row()) ?
                             aCol[rPos.Col()].GetErrCode( rPos.Row() ) :
                             FormulaError::NONE;
                     }
diff --git a/sc/source/core/data/colcontainer.cxx b/sc/source/core/data/colcontainer.cxx
index 7433240..fa2a18f 100644
--- a/sc/source/core/data/colcontainer.cxx
+++ b/sc/source/core/data/colcontainer.cxx
@@ -35,7 +35,6 @@ ScColContainer::~ScColContainer()
     Clear();
 }
 
-
 void ScColContainer::Clear()
 {
     SCCOL nSize = size();
@@ -46,4 +45,13 @@ void ScColContainer::Clear()
     }
     aCols.clear();
 }
+
+void ScColContainer::resize( const size_t aNewColSize )
+{
+    size_t aOldColSize = aCols.size();
+    aCols.resize( aNewColSize );
+    for ( size_t nCol = aOldColSize; nCol < aNewColSize; ++nCol )
+        aCols[nCol] = new ScColumn;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index d740767..f1f03f8 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2509,7 +2509,8 @@ void ScTable::RemoveCondFormatData( const ScRangeList& rRange, sal_uInt32 nIndex
 void ScTable::ApplyStyle( SCCOL nCol, SCROW nRow, const ScStyleSheet* rStyle )
 {
     if (ValidColRow(nCol,nRow))
-        aCol[nCol].ApplyStyle( nRow, rStyle );
+        // If column not exists then we need to create it
+        CreateColumnIfNotExists( nCol ).ApplyStyle( nRow, rStyle );
 }
 
 void ScTable::ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScStyleSheet& rStyle )
@@ -2518,8 +2519,28 @@ void ScTable::ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, S
     {
         PutInOrder(nStartCol, nEndCol);
         PutInOrder(nStartRow, nEndRow);
-        for (SCCOL i = nStartCol; i <= nEndCol; i++)
-            aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
+        if ( nEndCol == MAXCOL )
+        {
+            if ( nStartCol < aCol.size() )
+            {
+                // If we would like set all columns to specific style, then change only default style for not existing columns
+                nEndCol = aCol.size() - 1;
+                for (SCCOL i = nStartCol; i <= nEndCol; i++)
+                    aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
+                aNextColAttrArray.ApplyStyleArea(nStartRow, nEndRow, const_cast<ScStyleSheet*>( &rStyle ) );
+            }
+            else
+            {
+                CreateColumnIfNotExists( nStartCol - 1 );
+                aNextColAttrArray.ApplyStyleArea(nStartRow, nEndRow, const_cast<ScStyleSheet*>( &rStyle ) );
+            }
+        }
+        else
+        {
+            CreateColumnIfNotExists( nEndCol );
+            for (SCCOL i = nStartCol; i <= nEndCol; i++)
+                aCol[i].ApplyStyleArea(nStartRow, nEndRow, rStyle);
+        }
     }
 }
 
@@ -2541,10 +2562,12 @@ void ScTable::ApplySelectionLineStyle( const ScMarkData& rMark,
 
 const ScStyleSheet* ScTable::GetStyle( SCCOL nCol, SCROW nRow ) const
 {
-    if (ValidColRow(nCol, nRow))
-        return aCol[nCol].GetStyle(nRow);
-    else
+    if ( !ValidColRow( nCol, nRow ) )
         return nullptr;
+    if ( nCol < aCol.size() )
+        return aCol[nCol].GetStyle( nRow );
+    else
+        return aNextColAttrArray.GetPattern( nRow )->GetStyleSheet();
 }
 
 const ScStyleSheet* ScTable::GetSelectionStyle( const ScMarkData& rMark, bool& rFound ) const


More information about the Libreoffice-commits mailing list