summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2017-01-31 00:25:12 +0100
committerBartosz Kosiorek <gang65@poczta.onet.pl>2017-02-24 23:15:48 +0000
commita1b1ed766d1110acf843b807d554f9375963234c (patch)
tree916d4b6e8bcc401a81d76f2893d51d344f42610c /sc
parentcffa23b8d0c0b2d660505a11784addb7715a9937 (diff)
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@libreoffice.org> Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/colcontainer.hxx2
-rw-r--r--sc/inc/table.hxx17
-rw-r--r--sc/source/core/data/colcontainer.cxx10
-rw-r--r--sc/source/core/data/table2.cxx35
4 files changed, 56 insertions, 8 deletions
diff --git a/sc/inc/colcontainer.hxx b/sc/inc/colcontainer.hxx
index c3e03989fa48..925104df2278 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 3d446adce941..5f8711c786f5 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 7433240c8999..fa2a18feb257 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 d740767ba7cd..f1f03f8a577a 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