[Libreoffice-commits] .: 4 commits - sc/inc sc/source
Markus Mohrhard
mmohrhard at kemper.freedesktop.org
Sun May 13 22:52:31 PDT 2012
sc/inc/document.hxx | 1
sc/inc/table.hxx | 4 +
sc/source/core/data/colorscale.cxx | 8 +-
sc/source/core/data/documen4.cxx | 5 +
sc/source/core/data/table2.cxx | 116 ++++++++++++++++++++++++++++++++++---
5 files changed, 125 insertions(+), 9 deletions(-)
New commits:
commit 5a5d80ce5483696e0b05c31a0c4134c8ae4b82eb
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon May 14 07:43:02 2012 +0200
copy color scales correctly
Change-Id: I I I0f3ce313928ffa85f563e4162398816bf3ab2fdc
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 53adc39..0fecf8d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1213,6 +1213,7 @@ public:
void SetCondFormList(ScConditionalFormatList* pNew);
SC_DLLPUBLIC const ScColorScaleFormatList* GetColorScaleList() const;
+ SC_DLLPUBLIC ScColorScaleFormatList* GetColorScaleList();
ScValidationDataList* GetValidationList() const
{ return pValidationList; }
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 6393bfa..d684c8f 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -374,6 +374,10 @@ public:
sal_uInt16 nFlags, bool bMarked, ScTable* pDestTab,
const ScMarkData* pMarkData = NULL);
+ void CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
+ SCsCOL nDx, SCsROW nDy, ScTable* pTable);
+ void CopyColorScales( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
+ SCsCOL nDx, SCsROW nDy, ScTable* pTable);
void TransposeClip( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
ScTable* pTransClip, sal_uInt16 nFlags, bool bAsLink );
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index cb7d887..cae9473 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -633,6 +633,11 @@ const ScColorScaleFormatList* ScDocument::GetColorScaleList() const
return mpColorScaleList.get();
}
+ScColorScaleFormatList* ScDocument::GetColorScaleList()
+{
+ return mpColorScaleList.get();
+}
+
//takes ownership
// returns a 1-based index, 0 is reserved for no entry
sal_uLong ScDocument::AddColorScaleFormat( ScColorScaleFormat* pNew )
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 4ad71ac..9674c2a 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -61,6 +61,7 @@
#include "queryparam.hxx"
#include "queryentry.hxx"
#include "dbdata.hxx"
+#include "colorscale.hxx"
// STATIC DATA -----------------------------------------------------------
@@ -692,7 +693,54 @@ void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCRO
ScMarkData aMarkData;
aMarkData.MarkFromRangeList(itr->second, true);
pDocument->ApplySelectionPattern( aPattern, aMarkData );
+ }
+}
+
+void ScTable::CopyColorScales( 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;
+
+ ScColorScaleFormatList* pColorScaleList = pDocument->GetColorScaleList();
+ ScColorScaleFormatList* pOldColorScaleList = pTable->pDocument->GetColorScaleList();
+ for(SCCOL i = nCol1; i <= nCol2; ++i)
+ {
+ ScAttrIterator* pIter = aCol[i-nDx].CreateAttrIterator( nRow1-nDy, nRow2-nDy );
+ SCROW nStartRow = 0, nEndRow = 0;
+ const ScPatternAttr* pPattern = pIter->Next( nStartRow, nEndRow );
+ sal_uInt32 nId = ((SfxUInt32Item&)pPattern->GetItem(ATTR_COLORSCALE)).GetValue();
+ if ( nId != 0)
+ {
+ if (aOldIdToNewId.find(nId) == aOldIdToNewId.end())
+ {
+ ScColorScaleFormat* pFormat = pOldColorScaleList->GetFormat(nId);
+ ScColorScaleFormat* pNewFormat = new ScColorScaleFormat(pDocument, *pFormat);
+ sal_Int32 nNewId = pColorScaleList->size() + 1;
+ //not in list => create entries in both maps and new format
+ pColorScaleList->AddFormat(pNewFormat);
+ aOldIdToNewId.insert( std::pair<sal_Int32, sal_Int32>( nId, nNewId ) );
+ aIdToRange.insert( std::pair<sal_Int32, ScRangeList>( nId, ScRangeList() ) );
+ }
+
+ aIdToRange.find(nId)->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;
+ ScColorScaleFormat* pFormat = pColorScaleList->GetFormat( nNewKey );
+ pFormat->UpdateReference(URM_MOVE, ScRange(nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab),
+ nDx, nDy, pTable->nTab - nTab);
+ pFormat->SetRange(itr->second);
+ ScPatternAttr aPattern( pDocument->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_COLORSCALE, nNewKey ) );
+ ScMarkData aMarkData;
+ aMarkData.MarkFromRangeList(itr->second, true);
+ pDocument->ApplySelectionPattern( aPattern, aMarkData );
}
}
@@ -754,6 +802,7 @@ void ScTable::CopyFromClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
// create deep copies for conditional formatting
CopyConditionalFormat( nCol1, nRow1, nCol2, nRow2, nDx, nDy, pTable);
+ CopyColorScales( nCol1, nRow1, nCol2, nRow2, nDx, nDy, pTable);
}
DecRecalcLevel();
}
commit 596e40f9a230f9af918ab1b7d3a4be3d79abc058
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon May 14 07:47:19 2012 +0200
fix crash in ScColorScaleEntry's c'tor
Change-Id: I1cf60db16e5e6c82589b6b315680a6dff1761815
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index a81b748..35cdb20 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -43,7 +43,7 @@ ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol):
ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
mnVal(rEntry.mnVal),
maColor(rEntry.maColor),
- mpCell(NULL),
+ mpCell(),
mbMin(rEntry.mbMin),
mbMax(rEntry.mbMax),
mbPercent(rEntry.mbPercent)
@@ -53,11 +53,15 @@ ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry):
mnVal(rEntry.mnVal),
maColor(rEntry.maColor),
- mpCell(static_cast<ScFormulaCell*>(rEntry.mpCell->Clone(*pDoc))),
+ mpCell(),
mbMin(rEntry.mbMin),
mbMax(rEntry.mbMax),
mbPercent(rEntry.mbPercent)
{
+ if(rEntry.mpCell)
+ {
+ mpCell.reset(static_cast<ScFormulaCell*>(rEntry.mpCell->Clone(*pDoc)));
+ }
}
ScColorScaleEntry::~ScColorScaleEntry()
commit 63bfed7bceb610b938e84edfa4b60801a2b83d1b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon May 14 07:05:56 2012 +0200
create real copies for conditional formats
This fixes problems with unique value/ duplicate value entries. The old
falt copy process did not respect that the copy needs to point to its
own range and therefore the copy was totally useless.
This is also necessary for several future new conditional formats like:
top n%, top n elements, above average, ...
Change-Id: I51b868968812a4e00dca9af2aa51d50b5ef8b855
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 8df5dc8..4ad71ac 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -646,6 +646,56 @@ 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;
+
+ ScConditionalFormatList* pCondFormatList = pDocument->GetCondFormList();
+ ScConditionalFormatList* pOldCondFormatList = pTable->pDocument->GetCondFormList();
+ for(SCCOL i = nCol1; i <= nCol2; ++i)
+ {
+ ScAttrIterator* pIter = aCol[i-nDx].CreateAttrIterator( nRow1-nDy, nRow2-nDy );
+ SCROW nStartRow = 0, nEndRow = 0;
+ const ScPatternAttr* pPattern = pIter->Next( nStartRow, nEndRow );
+ sal_uInt32 nId = ((SfxUInt32Item&)pPattern->GetItem(ATTR_CONDITIONAL)).GetValue();
+ if ( nId != 0)
+ {
+ if (aOldIdToNewId.find(nId) == aOldIdToNewId.end())
+ {
+ ScConditionalFormat* pFormat = pOldCondFormatList->GetFormat(nId);
+ ScConditionalFormat* pNewFormat = pFormat->Clone(pDocument);
+ pNewFormat->SetKey(pCondFormatList->size()+1);
+ //not in list => create entries in both maps and new format
+ pCondFormatList->InsertNew(pNewFormat);
+ sal_Int32 nNewId = pNewFormat->GetKey();
+ aOldIdToNewId.insert( std::pair<sal_Int32, sal_Int32>( nId, nNewId ) );
+ aIdToRange.insert( std::pair<sal_Int32, ScRangeList>( nId, ScRangeList() ) );
+ }
+
+ aIdToRange.find(nId)->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 = pCondFormatList->GetFormat( nNewKey );
+ pFormat->UpdateReference(URM_MOVE, ScRange(nCol1 - nDx, nRow1 - nDy, pTable->nTab, nCol2 - nDx, nRow2 - nDy, pTable->nTab),
+ nDx, nDy, pTable->nTab - nTab);
+ pFormat->AddRangeInfo(new ScRangeList(itr->second));
+
+ ScPatternAttr aPattern( pDocument->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nNewKey ) );
+ ScMarkData aMarkData;
+ aMarkData.MarkFromRangeList(itr->second, true);
+ pDocument->ApplySelectionPattern( aPattern, aMarkData );
+
+ }
+}
+
void ScTable::CopyFromClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
SCsCOL nDx, SCsROW nDy, sal_uInt16 nInsFlag,
bool bAsLink, bool bSkipAttrForEmpty, ScTable* pTable)
@@ -701,6 +751,9 @@ void ScTable::CopyFromClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
aPattern.GetItemSet().Put( ScProtectionAttr( false ) );
ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern );
}
+
+ // create deep copies for conditional formatting
+ CopyConditionalFormat( nCol1, nRow1, nCol2, nRow2, nDx, nDy, pTable);
}
DecRecalcLevel();
}
commit 130b2a39492893467d5a8fe38d33256daf25b557
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon May 14 05:12:34 2012 +0200
use correct indentation
Change-Id: I60cb1f1ed4a0068bc39ada14ac629bf20af709f9
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index d13fa9f..8df5dc8 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -585,7 +585,7 @@ void ScTable::DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark )
}
-// pTable = Clipboard
+// pTable = Clipboard
void ScTable::CopyToClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
ScTable* pTable, bool bKeepScenarioFlags, bool bCloneNoteCaptions)
{
@@ -651,8 +651,11 @@ void ScTable::CopyFromClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
bool bAsLink, bool bSkipAttrForEmpty, ScTable* pTable)
{
- if (nCol2 > MAXCOL) nCol2 = MAXCOL;
- if (nRow2 > MAXROW) nRow2 = MAXROW;
+ if (nCol2 > MAXCOL)
+ nCol2 = MAXCOL;
+ if (nRow2 > MAXROW)
+ nRow2 = MAXROW;
+
if (ValidColRow(nCol1, nRow1) && ValidColRow(nCol2, nRow2))
{
IncRecalcLevel();
@@ -691,10 +694,7 @@ void ScTable::CopyFromClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
}
}
- //
- // Zellschutz auf geschuetzter Tabelle nicht setzen
- //
-
+ // Zellschutz auf geschuetzter Tabelle nicht setzen
if ( IsProtected() && (nInsFlag & IDF_ATTRIB) )
{
ScPatternAttr aPattern(pDocument->GetPool());
More information about the Libreoffice-commits
mailing list