[Libreoffice-commits] .: 2 commits - sc/inc sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Dec 25 12:04:48 PST 2012
sc/inc/rangelst.hxx | 2 +
sc/source/core/data/documen2.cxx | 2 +
sc/source/core/data/table2.cxx | 71 +++++++++++----------------------------
sc/source/core/tool/rangelst.cxx | 26 ++++++++++++++
sc/source/ui/view/cellsh1.cxx | 4 +-
5 files changed, 54 insertions(+), 51 deletions(-)
New commits:
commit eaecc7971f7024a0f5aa7df1d933bd60a9f1357c
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Tue Dec 25 21:04:15 2012 +0100
simplify cond format copy&paste code, fdo#58677
This should also help with fdo#57896 and some other problems I found
Change-Id: I8cb3eb69a7ec1413cb57ce81c5f4d806250474e5
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index 06cebec..b67445b 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 095b41a..79f90f4 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 6ebfd61..073f726 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 bd93b7c..6f0093d 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()
commit a06a44c3b342648139e7fa0ff850a4176df60538
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Tue Dec 25 20:56:28 2012 +0100
one more fix for fdo#58686
Change-Id: I02e29441fa5d9573cb179dfde2357416102ff341
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index a805661..ec105f3 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1786,6 +1786,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
boost::scoped_ptr<ScCondFormatDlg> pCondFormatDlg;
if(bContainsCondFormat)
{
+ bool bContainsExistingCondFormat = false;
ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end();
itr != itrEnd; ++itr)
@@ -1795,6 +1796,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
if(!pCondFormat)
continue;
+ bContainsExistingCondFormat = true;
const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
if(rCondFormatRange == aRangeList)
{
@@ -1807,7 +1809,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
// if not found a conditional format ask whether we should edit one of the existing
// or should create a new overlapping conditional format
- if(!pCondFormatDlg)
+ if(!pCondFormatDlg && bContainsExistingCondFormat)
{
QueryBox aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
More information about the Libreoffice-commits
mailing list