summaryrefslogtreecommitdiff
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-17 09:04:56 (GMT)
committer Markus Mohrhard <markus.mohrhard@googlemail.com>2012-05-18 08:51:20 (GMT)
commiteb3d3a0a7d49b51942e7f39cdcde1be0b11349e7 (patch) (side-by-side diff)
treedabb1e9934436cdb5bc57728ed0abffa91b4c9a1
parent914fc75da516218bb072245a5c2e3038a4e3639e (diff)
downloadcore-eb3d3a0a7d49b51942e7f39cdcde1be0b11349e7.zip
core-eb3d3a0a7d49b51942e7f39cdcde1be0b11349e7.tar.gz
restructure colorscale code a bit to allow adding databars
This is just a first step. In a second step we need another layer to allow color scales and databars applied to the same range and finally merge them with normal conditional formatting. Change-Id: I0452ed12dd9b2d5395cf005d75a902fbb7a984ad
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--sc/inc/colorscale.hxx86
-rw-r--r--sc/inc/document.hxx8
-rw-r--r--sc/source/core/data/colorscale.cxx59
-rw-r--r--sc/source/core/data/documen2.cxx4
-rw-r--r--sc/source/core/data/documen4.cxx6
-rw-r--r--sc/source/core/data/fillinfo.cxx6
-rw-r--r--sc/source/core/data/table2.cxx10
-rw-r--r--sc/source/filter/excel/xecontent.cxx11
8 files changed, 139 insertions, 51 deletions
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 61346b6..2596953 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -37,6 +37,13 @@
class ScDocument;
class ScFormulaCell;
class ScTokenArray;
+class ScDataBarInfo;
+
+struct ScDataBarFormatData
+{
+ Color maPositiveColor;
+ bool mbGradient;
+};
class SC_DLLPUBLIC ScColorScaleEntry
{
@@ -71,11 +78,39 @@ public:
void SetPercent(bool bPercent);
};
-class SC_DLLPUBLIC ScColorScaleFormat
+enum ScColorFormatType
{
-private:
+ COLORSCALE,
+ DATABAR
+};
+
+class SC_DLLPUBLIC ScColorFormat
+{
+public:
+ ScColorFormat(ScDocument* pDoc);
+ ScColorFormat(ScDocument* pDoc, const ScColorFormat& rFormat);
+ virtual ~ScColorFormat();
+
+ void SetRange(const ScRangeList& rList);
+ const ScRangeList& GetRange() const;
+
+ virtual void DataChanged(const ScRange& rRange) = 0;
+ virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab) = 0;
+ virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
+ const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ) = 0;
+
+ virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const = 0;
+
+ virtual ScColorFormatType GetType() const = 0;
+
+protected:
ScRangeList maRanges;
ScDocument* mpDoc;
+};
+
+class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
+{
+private:
typedef boost::ptr_vector<ScColorScaleEntry> ColorScaleEntries;
ColorScaleEntries maColorScales;
@@ -87,17 +122,18 @@ private:
public:
ScColorScaleFormat(ScDocument* pDoc);
ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
+ virtual ~ScColorScaleFormat();
+ virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const;
Color* GetColor(const ScAddress& rAddr) const;
void AddEntry(ScColorScaleEntry* pEntry);
- void SetRange(const ScRangeList& rList);
- const ScRangeList& GetRange() const;
- void DataChanged(const ScRange& rRange);
- void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
- void UpdateReference( UpdateRefMode eUpdateRefMode,
+ virtual void DataChanged(const ScRange& rRange);
+ virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
+ virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+ virtual ScColorFormatType GetType() const;
typedef ColorScaleEntries::iterator iterator;
typedef ColorScaleEntries::const_iterator const_iterator;
iterator begin();
@@ -106,20 +142,38 @@ public:
const_iterator end() const;
};
-class SC_DLLPUBLIC ScColorScaleFormatList
+class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
+{
+public:
+ ScDataBarFormat(ScDocument* pDoc);
+ ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
+
+ ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
+
+ virtual void DataChanged(const ScRange& rRange);
+ virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
+ virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
+ const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+
+ virtual ScColorFormatType GetType() const;
+private:
+ ScDataBarFormatData maFormatData;
+};
+
+class SC_DLLPUBLIC ScColorFormatList
{
private:
- typedef boost::ptr_vector<ScColorScaleFormat> ColorScaleFormatContainer;
- boost::ptr_vector<ScColorScaleFormat> maColorScaleFormats;
+ typedef boost::ptr_vector<ScColorFormat> ColorFormatContainer;
+ ColorFormatContainer maColorScaleFormats;
public:
- ScColorScaleFormatList() {};
- ScColorScaleFormatList(ScDocument* pDoc, const ScColorScaleFormatList& rList);
+ ScColorFormatList() {};
+ ScColorFormatList(ScDocument* pDoc, const ScColorFormatList& rList);
- typedef ColorScaleFormatContainer::iterator iterator;
- typedef ColorScaleFormatContainer::const_iterator const_iterator;
+ typedef ColorFormatContainer::iterator iterator;
+ typedef ColorFormatContainer::const_iterator const_iterator;
- ScColorScaleFormat* GetFormat(sal_uInt32 nFormat);
- void AddFormat( ScColorScaleFormat* pFormat );
+ ScColorFormat* GetFormat(sal_uInt32 nFormat);
+ void AddFormat( ScColorFormat* pFormat );
void DataChanged(const ScRange& rRange);
void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 0fecf8d..7e14a5c 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -97,7 +97,7 @@ class ScChartListenerCollection;
class ScConditionalFormat;
class ScConditionalFormatList;
class ScColorScaleFormat;
-class ScColorScaleFormatList;
+class ScColorFormatList;
class ScDBCollection;
class ScDBData;
class ScDetOpData;
@@ -246,7 +246,7 @@ private:
ScDrawLayer* pDrawLayer; // SdrModel
rtl::Reference<XColorList> pColorList;
ScConditionalFormatList* pCondFormList; // conditional formats
- boost::scoped_ptr<ScColorScaleFormatList> mpColorScaleList; //color scales
+ boost::scoped_ptr<ScColorFormatList> mpColorScaleList; //color scales
ScValidationDataList* pValidationList; // validity
SvNumberFormatterIndexTable* pFormatExchangeList; // for application of number formats
TableContainer maTabs;
@@ -1212,8 +1212,8 @@ public:
{ return pCondFormList; }
void SetCondFormList(ScConditionalFormatList* pNew);
- SC_DLLPUBLIC const ScColorScaleFormatList* GetColorScaleList() const;
- SC_DLLPUBLIC ScColorScaleFormatList* GetColorScaleList();
+ SC_DLLPUBLIC const ScColorFormatList* GetColorScaleList() const;
+ SC_DLLPUBLIC ScColorFormatList* GetColorScaleList();
ScValidationDataList* GetValidationList() const
{ return pValidationList; }
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index bad6a14..1892a75 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -120,21 +120,43 @@ const Color& ScColorScaleEntry::GetColor() const
return maColor;
}
-ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc):
+ScColorFormat::ScColorFormat(ScDocument* pDoc):
mpDoc(pDoc)
{
}
-ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat):
+ScColorFormat::ScColorFormat(ScDocument* pDoc, const ScColorFormat& rFormat):
maRanges(rFormat.maRanges),
mpDoc(pDoc)
{
+}
+
+ScColorFormat::~ScColorFormat()
+{
+}
+
+ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc):
+ ScColorFormat(pDoc)
+{
+}
+
+ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat):
+ ScColorFormat(pDoc, rFormat)
+{
for(const_iterator itr = rFormat.begin(); itr != rFormat.end(); ++itr)
{
maColorScales.push_back(new ScColorScaleEntry(pDoc, *itr));
}
}
+ScColorFormat* ScColorScaleFormat::Clone(ScDocument* pDoc) const
+{
+ return new ScColorScaleFormat(pDoc, *this);
+}
+
+ScColorScaleFormat::~ScColorScaleFormat()
+{
+}
void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
{
@@ -292,12 +314,12 @@ void ScColorScaleFormat::calcMinMax(double& rMin, double& rMax) const
rMax = GetMaxValue();
}
-void ScColorScaleFormat::SetRange(const ScRangeList& rList)
+void ScColorFormat::SetRange(const ScRangeList& rList)
{
maRanges = rList;
}
-const ScRangeList& ScColorScaleFormat::GetRange() const
+const ScRangeList& ScColorFormat::GetRange() const
{
return maRanges;
}
@@ -485,6 +507,11 @@ void ScColorScaleFormat::DataChanged(const ScRange& rRange)
}
}
+ScColorFormatType ScColorScaleFormat::GetType() const
+{
+ return COLORSCALE;
+}
+
ScColorScaleFormat::iterator ScColorScaleFormat::begin()
{
return maColorScales.begin();
@@ -505,21 +532,21 @@ ScColorScaleFormat::const_iterator ScColorScaleFormat::end() const
return maColorScales.end();
}
-ScColorScaleFormatList::ScColorScaleFormatList(ScDocument* pDoc, const ScColorScaleFormatList& rList)
+ScColorFormatList::ScColorFormatList(ScDocument* pDoc, const ScColorFormatList& rList)
{
for(const_iterator itr = rList.begin(); itr != rList.end(); ++itr)
{
- maColorScaleFormats.push_back(new ScColorScaleFormat(pDoc, *itr));
+ maColorScaleFormats.push_back(itr->Clone(pDoc));
}
}
-void ScColorScaleFormatList::AddFormat( ScColorScaleFormat* pFormat )
+void ScColorFormatList::AddFormat( ScColorFormat* pFormat )
{
maColorScaleFormats.push_back( pFormat );
}
// attention nFormat is 1 based, 0 is reserved for no format
-ScColorScaleFormat* ScColorScaleFormatList::GetFormat(sal_uInt32 nFormat)
+ScColorFormat* ScColorFormatList::GetFormat(sal_uInt32 nFormat)
{
if( nFormat > size() || !nFormat )
return NULL;
@@ -527,32 +554,32 @@ ScColorScaleFormat* ScColorScaleFormatList::GetFormat(sal_uInt32 nFormat)
return &maColorScaleFormats[nFormat-1];
}
-ScColorScaleFormatList::iterator ScColorScaleFormatList::begin()
+ScColorFormatList::iterator ScColorFormatList::begin()
{
return maColorScaleFormats.begin();
}
-ScColorScaleFormatList::const_iterator ScColorScaleFormatList::begin() const
+ScColorFormatList::const_iterator ScColorFormatList::begin() const
{
return maColorScaleFormats.begin();
}
-ScColorScaleFormatList::iterator ScColorScaleFormatList::end()
+ScColorFormatList::iterator ScColorFormatList::end()
{
return maColorScaleFormats.end();
}
-ScColorScaleFormatList::const_iterator ScColorScaleFormatList::end() const
+ScColorFormatList::const_iterator ScColorFormatList::end() const
{
return maColorScaleFormats.end();
}
-size_t ScColorScaleFormatList::size() const
+size_t ScColorFormatList::size() const
{
return maColorScaleFormats.size();
}
-void ScColorScaleFormatList::DataChanged(const ScRange& rRange)
+void ScColorFormatList::DataChanged(const ScRange& rRange)
{
for(iterator itr = begin(); itr != end(); ++itr)
{
@@ -560,7 +587,7 @@ void ScColorScaleFormatList::DataChanged(const ScRange& rRange)
}
}
-void ScColorScaleFormatList::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
+void ScColorFormatList::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
{
for(iterator itr = begin(); itr != end(); ++itr)
{
@@ -568,7 +595,7 @@ void ScColorScaleFormatList::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
}
}
-void ScColorScaleFormatList::UpdateReference( UpdateRefMode eUpdateRefMode,
+void ScColorFormatList::UpdateReference( UpdateRefMode eUpdateRefMode,
const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
{
for(iterator itr = begin(); itr != end(); ++itr)
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 87ad7d4..0135892 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -476,9 +476,9 @@ void ScDocument::InitClipPtrs( ScDocument* pSourceDoc )
if ( pSourceCond )
pCondFormList = new ScConditionalFormatList(this, *pSourceCond);
- const ScColorScaleFormatList* pSourceColorScaleList = pSourceDoc->mpColorScaleList.get();
+ const ScColorFormatList* pSourceColorScaleList = pSourceDoc->mpColorScaleList.get();
if ( pSourceColorScaleList )
- mpColorScaleList.reset(new ScColorScaleFormatList(this, *pSourceColorScaleList));
+ mpColorScaleList.reset(new ScColorFormatList(this, *pSourceColorScaleList));
const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList;
if ( pSourceValid )
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index cae9473..76d3773 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -628,12 +628,12 @@ sal_uLong ScDocument::AddCondFormat( const ScConditionalFormat& rNew )
return nNewKey;
}
-const ScColorScaleFormatList* ScDocument::GetColorScaleList() const
+const ScColorFormatList* ScDocument::GetColorScaleList() const
{
return mpColorScaleList.get();
}
-ScColorScaleFormatList* ScDocument::GetColorScaleList()
+ScColorFormatList* ScDocument::GetColorScaleList()
{
return mpColorScaleList.get();
}
@@ -646,7 +646,7 @@ sal_uLong ScDocument::AddColorScaleFormat( ScColorScaleFormat* pNew )
return 0;
if(!mpColorScaleList)
- mpColorScaleList.reset(new ScColorScaleFormatList());
+ mpColorScaleList.reset(new ScColorFormatList());
mpColorScaleList->AddFormat( pNew );
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 9d7fc2f..4b227b0 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -489,7 +489,11 @@ void ScDocument::FillInfo( ScTableInfo& rTabInfo, SCCOL nX1, SCROW nY1, SCCOL nX
const ScColorScaleFormat* pColorScale = NULL;
if ( nColorScale && mpColorScaleList )
- pColorScale = mpColorScaleList->GetFormat( nColorScale );
+ {
+ ScColorFormat* pFormat = mpColorScaleList->GetFormat( nColorScale );
+ if(pFormat->GetType() == COLORSCALE)
+ pColorScale = static_cast<ScColorScaleFormat*>(pFormat);
+ }
do
{
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 9674c2a..09a171f 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -702,8 +702,8 @@ void ScTable::CopyColorScales( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow
std::map<sal_Int32, sal_Int32> aOldIdToNewId;
std::map<sal_Int32, ScRangeList> aIdToRange;
- ScColorScaleFormatList* pColorScaleList = pDocument->GetColorScaleList();
- ScColorScaleFormatList* pOldColorScaleList = pTable->pDocument->GetColorScaleList();
+ ScColorFormatList* pColorScaleList = pDocument->GetColorScaleList();
+ ScColorFormatList* pOldColorScaleList = pTable->pDocument->GetColorScaleList();
for(SCCOL i = nCol1; i <= nCol2; ++i)
{
ScAttrIterator* pIter = aCol[i-nDx].CreateAttrIterator( nRow1-nDy, nRow2-nDy );
@@ -714,8 +714,8 @@ void ScTable::CopyColorScales( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow
{
if (aOldIdToNewId.find(nId) == aOldIdToNewId.end())
{
- ScColorScaleFormat* pFormat = pOldColorScaleList->GetFormat(nId);
- ScColorScaleFormat* pNewFormat = new ScColorScaleFormat(pDocument, *pFormat);
+ ScColorFormat* pFormat = pOldColorScaleList->GetFormat(nId);
+ ScColorFormat* pNewFormat = pFormat->Clone(pDocument);
sal_Int32 nNewId = pColorScaleList->size() + 1;
//not in list => create entries in both maps and new format
pColorScaleList->AddFormat(pNewFormat);
@@ -731,7 +731,7 @@ void ScTable::CopyColorScales( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow
itr != aIdToRange.end(); ++itr)
{
sal_uInt32 nNewKey = aOldIdToNewId.find(itr->first)->second;
- ScColorScaleFormat* pFormat = pColorScaleList->GetFormat( nNewKey );
+ ScColorFormat* 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);
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 968aab2..9f42dcb 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -1084,16 +1084,19 @@ XclExpCondFormatBuffer::XclExpCondFormatBuffer( const XclExpRoot& rRoot ) :
maCondfmtList.AppendRecord( xCondfmtRec );
}
}
- if( const ScColorScaleFormatList* pColorScaleList = GetDoc().GetColorScaleList() )
+ if( const ScColorFormatList* pColorScaleList = GetDoc().GetColorScaleList() )
{
- for( ScColorScaleFormatList::const_iterator itr = pColorScaleList->begin();
+ for( ScColorFormatList::const_iterator itr = pColorScaleList->begin();
itr != pColorScaleList->end(); ++itr)
{
const ScRangeList& rList = itr->GetRange();
if (rList.front()->aStart.Tab() == GetCurrScTab())
{
- XclExpColorScaleList::RecordRefType xColorScaleRec( new XclExpColorScale( GetRoot(), *itr ) );
- maColorScaleList.AppendRecord( xColorScaleRec );
+ if(itr->GetType() == COLORSCALE)
+ {
+ XclExpColorScaleList::RecordRefType xColorScaleRec( new XclExpColorScale( GetRoot(), static_cast<const ScColorScaleFormat&>(*itr) ) );
+ maColorScaleList.AppendRecord( xColorScaleRec );
+ }
}
}
}