diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-12-25 21:04:15 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-12-25 21:06:38 +0100 |
commit | 350ae8294a8df78403fd8cdce56b9aeb8178e130 (patch) | |
tree | b16c06ebf9062be92504fb246140d4eb9e20b053 | |
parent | e9b337456513cf1324a4f3a137ebb3491c2b1c79 (diff) |
simplify cond format copy&paste code, fdo#58677
This should also help with fdo#57896 and some other problems I found
Change-Id: I8cb3eb69a7ec1413cb57ce81c5f4d806250474e5
-rw-r--r-- | sc/inc/rangelst.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 71 | ||||
-rw-r--r-- | sc/source/core/tool/rangelst.cxx | 26 |
4 files changed, 51 insertions, 50 deletions
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx index 06cebecfda82..b67445be5fa2 100644 --- a/sc/inc/rangelst.hxx +++ b/sc/inc/rangelst.hxx @@ -74,6 +74,8 @@ public: size_t GetCellCount() const; ScAddress GetTopLeftCorner() const; + ScRangeList GetIntersectedRange(const ScRange& rRange) const; + ScRange* Remove(size_t nPos); void RemoveAll(); diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 095b41ab5af0..79f90f48854f 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -955,6 +955,8 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos, pSrcDoc->maTabs[nSrcPos]->CopyToTable(0, 0, MAXCOL, MAXROW, ( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL), false, maTabs[nDestPos] ); + maTabs[nDestPos]->CopyConditionalFormat(0, 0, MAXCOL, MAXROW, + 0, 0, pSrcDoc->maTabs[nSrcPos]); } } maTabs[nDestPos]->SetTabNo(nDestPos); diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 6ebfd61a2296..073f7263f60e 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -656,62 +656,33 @@ void ScTable::CopyToClip(const ScRangeList& rRanges, ScTable* pTable, void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCsCOL nDx, SCsROW nDy, ScTable* pTable) { - std::map<sal_Int32, sal_Int32> aOldIdToNewId; - std::map<sal_Int32, ScRangeList> aIdToRange; + ScRange aOldRange( nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab); + ScRange aNewRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab ); - ScConditionalFormatList* pOldCondFormatList = pTable->mpCondFormatList.get(); - for(SCCOL i = nCol1; i <= nCol2; ++i) + for(ScConditionalFormatList::const_iterator itr = pTable->mpCondFormatList->begin(), + itrEnd = pTable->mpCondFormatList->end(); itr != itrEnd; ++itr) { - ScAttrIterator* pIter = pTable->aCol[i-nDx].CreateAttrIterator( nRow1-nDy, nRow2-nDy ); - SCROW nStartRow = 0, nEndRow = 0; - 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() ) ); - } + const ScRangeList& rCondFormatRange = itr->GetRange(); + if(!rCondFormatRange.Intersects( aOldRange )) + continue; - aIdToRange.find(*itr)->second.Join( ScRange( i, nStartRow + nDy, nTab, i, nEndRow + nDy, nTab ) ); - } - } + ScRangeList aIntersectedRange = rCondFormatRange.GetIntersectedRange(aOldRange); + ScConditionalFormat* pNewFormat = itr->Clone(pDocument); - 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; + pNewFormat->AddRange(aIntersectedRange); + pNewFormat->UpdateReference(URM_MOVE, aNewRange, nDx, nDy, pTable->nTab - nTab); - pFormat->UpdateReference(URM_MOVE, ScRange(nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab), - nDx, nDy, pTable->nTab - nTab); - pFormat->AddRange(itr->second); + 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( itr->second, nTab, nNewKey ); + pDocument->AddCondFormatData( pNewFormat->GetRange(), nTab, pNewFormat->GetKey() ); } } diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index bd93b7c9c9bb..6f0093d57e97 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -1148,6 +1148,32 @@ ScAddress ScRangeList::GetTopLeftCorner() const 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() |