simplify cond format copy&paste code, fdo#58677
This should also help with fdo#57896 and some other problems I found Change-Id: I8cb3eb69a7ec1413cb57ce81c5f4d806250474e5
This commit is contained in:
@@ -74,6 +74,8 @@ public:
|
|||||||
size_t GetCellCount() const;
|
size_t GetCellCount() const;
|
||||||
ScAddress GetTopLeftCorner() const;
|
ScAddress GetTopLeftCorner() const;
|
||||||
|
|
||||||
|
ScRangeList GetIntersectedRange(const ScRange& rRange) const;
|
||||||
|
|
||||||
ScRange* Remove(size_t nPos);
|
ScRange* Remove(size_t nPos);
|
||||||
void RemoveAll();
|
void RemoveAll();
|
||||||
|
|
||||||
|
@@ -955,6 +955,8 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
|
|||||||
pSrcDoc->maTabs[nSrcPos]->CopyToTable(0, 0, MAXCOL, MAXROW,
|
pSrcDoc->maTabs[nSrcPos]->CopyToTable(0, 0, MAXCOL, MAXROW,
|
||||||
( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL),
|
( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL),
|
||||||
false, maTabs[nDestPos] );
|
false, maTabs[nDestPos] );
|
||||||
|
maTabs[nDestPos]->CopyConditionalFormat(0, 0, MAXCOL, MAXROW,
|
||||||
|
0, 0, pSrcDoc->maTabs[nSrcPos]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maTabs[nDestPos]->SetTabNo(nDestPos);
|
maTabs[nDestPos]->SetTabNo(nDestPos);
|
||||||
|
@@ -656,62 +656,33 @@ void ScTable::CopyToClip(const ScRangeList& rRanges, ScTable* pTable,
|
|||||||
void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
|
void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
|
||||||
SCsCOL nDx, SCsROW nDy, ScTable* pTable)
|
SCsCOL nDx, SCsROW nDy, ScTable* pTable)
|
||||||
{
|
{
|
||||||
std::map<sal_Int32, sal_Int32> aOldIdToNewId;
|
ScRange aOldRange( nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab);
|
||||||
std::map<sal_Int32, ScRangeList> aIdToRange;
|
ScRange aNewRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
|
||||||
|
|
||||||
ScConditionalFormatList* pOldCondFormatList = pTable->mpCondFormatList.get();
|
for(ScConditionalFormatList::const_iterator itr = pTable->mpCondFormatList->begin(),
|
||||||
for(SCCOL i = nCol1; i <= nCol2; ++i)
|
itrEnd = pTable->mpCondFormatList->end(); itr != itrEnd; ++itr)
|
||||||
{
|
{
|
||||||
ScAttrIterator* pIter = pTable->aCol[i-nDx].CreateAttrIterator( nRow1-nDy, nRow2-nDy );
|
const ScRangeList& rCondFormatRange = itr->GetRange();
|
||||||
SCROW nStartRow = 0, nEndRow = 0;
|
if(!rCondFormatRange.Intersects( aOldRange ))
|
||||||
const ScPatternAttr* pPattern = pIter->Next( nStartRow, nEndRow );
|
|
||||||
const std::vector<sal_uInt32>& rCondFormatData = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData();
|
|
||||||
for(std::vector<sal_uInt32>::const_iterator itr = rCondFormatData.begin(), itrEnd = rCondFormatData.end();
|
|
||||||
itr != itrEnd; ++itr)
|
|
||||||
{
|
|
||||||
if (aOldIdToNewId.find(*itr) == aOldIdToNewId.end())
|
|
||||||
{
|
|
||||||
ScConditionalFormat* pFormat = pOldCondFormatList->GetFormat(*itr);
|
|
||||||
if(!pFormat)
|
|
||||||
{
|
|
||||||
// may happen in some strange circumstances where cell storage and
|
|
||||||
// cond format storage are not in sync
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ScConditionalFormat* pNewFormat = pFormat->Clone(pDocument);
|
|
||||||
pNewFormat->SetKey(0);
|
|
||||||
//not in list => create entries in both maps and new format
|
|
||||||
sal_uLong nMax = 0;
|
|
||||||
for(ScConditionalFormatList::const_iterator itrCond = mpCondFormatList->begin();
|
|
||||||
itrCond != mpCondFormatList->end(); ++itrCond)
|
|
||||||
{
|
|
||||||
if(itrCond->GetKey() > nMax)
|
|
||||||
nMax = itrCond->GetKey();
|
|
||||||
}
|
|
||||||
pNewFormat->SetKey(nMax + 1);
|
|
||||||
mpCondFormatList->InsertNew(pNewFormat);
|
|
||||||
sal_Int32 nNewId = pNewFormat->GetKey();
|
|
||||||
aOldIdToNewId.insert( std::pair<sal_Int32, sal_Int32>( *itr, nNewId ) );
|
|
||||||
aIdToRange.insert( std::pair<sal_Int32, ScRangeList>( *itr, ScRangeList() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
aIdToRange.find(*itr)->second.Join( ScRange( i, nStartRow + nDy, nTab, i, nEndRow + nDy, nTab ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(std::map<sal_Int32, ScRangeList>::const_iterator itr = aIdToRange.begin();
|
|
||||||
itr != aIdToRange.end(); ++itr)
|
|
||||||
{
|
|
||||||
sal_uInt32 nNewKey = aOldIdToNewId.find(itr->first)->second;
|
|
||||||
ScConditionalFormat* pFormat = mpCondFormatList->GetFormat( nNewKey );
|
|
||||||
if(!pFormat)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pFormat->UpdateReference(URM_MOVE, ScRange(nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab),
|
ScRangeList aIntersectedRange = rCondFormatRange.GetIntersectedRange(aOldRange);
|
||||||
nDx, nDy, pTable->nTab - nTab);
|
ScConditionalFormat* pNewFormat = itr->Clone(pDocument);
|
||||||
pFormat->AddRange(itr->second);
|
|
||||||
|
|
||||||
pDocument->AddCondFormatData( itr->second, nTab, nNewKey );
|
pNewFormat->AddRange(aIntersectedRange);
|
||||||
|
pNewFormat->UpdateReference(URM_MOVE, aNewRange, nDx, nDy, pTable->nTab - nTab);
|
||||||
|
|
||||||
|
sal_uLong nMax = 0;
|
||||||
|
for(ScConditionalFormatList::const_iterator itrCond = mpCondFormatList->begin();
|
||||||
|
itrCond != mpCondFormatList->end(); ++itrCond)
|
||||||
|
{
|
||||||
|
if(itrCond->GetKey() > nMax)
|
||||||
|
nMax = itrCond->GetKey();
|
||||||
|
}
|
||||||
|
pNewFormat->SetKey(nMax + 1);
|
||||||
|
mpCondFormatList->InsertNew(pNewFormat);
|
||||||
|
|
||||||
|
pDocument->AddCondFormatData( pNewFormat->GetRange(), nTab, pNewFormat->GetKey() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1148,6 +1148,32 @@ ScAddress ScRangeList::GetTopLeftCorner() const
|
|||||||
return aAddr;
|
return aAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScRangeList ScRangeList::GetIntersectedRange(const ScRange& rRange) const
|
||||||
|
{
|
||||||
|
ScRangeList aReturn;
|
||||||
|
for(const_iterator itr = maRanges.begin(), itrEnd = maRanges.end();
|
||||||
|
itr != itrEnd; ++itr)
|
||||||
|
{
|
||||||
|
if((*itr)->Intersects(rRange))
|
||||||
|
{
|
||||||
|
SCCOL nColStart1, nColEnd1, nColStart2, nColEnd2;
|
||||||
|
SCROW nRowStart1, nRowEnd1, nRowStart2, nRowEnd2;
|
||||||
|
SCTAB nTabStart1, nTabEnd1, nTabStart2, nTabEnd2;
|
||||||
|
(*itr)->GetVars(nColStart1, nRowStart1, nTabStart1,
|
||||||
|
nColEnd1, nRowEnd1, nTabEnd1);
|
||||||
|
rRange.GetVars(nColStart2, nRowStart2, nTabStart2,
|
||||||
|
nColEnd2, nRowEnd2, nTabEnd2);
|
||||||
|
|
||||||
|
ScRange aNewRange(std::max<SCCOL>(nColStart1, nColStart2), std::max<SCROW>(nRowStart1, nRowStart2),
|
||||||
|
std::max<SCTAB>(nTabStart1, nTabStart2), std::min<SCCOL>(nColEnd1, nColEnd2),
|
||||||
|
std::min<SCROW>(nRowEnd1, nRowEnd2), std::min<SCTAB>(nTabEnd1, nTabEnd2));
|
||||||
|
aReturn.Join(aNewRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return aReturn;
|
||||||
|
}
|
||||||
|
|
||||||
// === ScRangePairList ========================================================
|
// === ScRangePairList ========================================================
|
||||||
|
|
||||||
ScRangePairList::~ScRangePairList()
|
ScRangePairList::~ScRangePairList()
|
||||||
|
Reference in New Issue
Block a user