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>
This commit is contained in:
Bartosz Kosiorek
2017-01-31 00:25:12 +01:00
parent cffa23b8d0
commit a1b1ed766d
4 changed files with 56 additions and 8 deletions

View File

@@ -55,6 +55,8 @@ public:
return static_cast<SCCOL>( aCols.size() );
}
void resize( const size_t aNewSize );
void Clear();
const ScColumn& back() const

View File

@@ -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;
}

View File

@@ -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: */

View File

@@ -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