Kaydet (Commit) f26bf2ba authored tarafından Markus Mohrhard's avatar Markus Mohrhard

first part for min/max in color scales

Change-Id: Ib397b93ac0a5a72052fdaa5bf41199e5967ad559
üst d16c1b92
......@@ -39,21 +39,37 @@ class SC_DLLPUBLIC ScColorScaleEntry
private:
double mnVal;
Color maColor;
bool mbMin;
bool mbMax;
bool mbPercent;
public:
ScColorScaleEntry(double nVal, const Color& rCol);
ScColorScaleEntry(const ScColorScaleEntry& rEntry);
const Color& GetColor() const;
double GetValue() const;
bool GetMin() const;
bool GetMax() const;
bool GetPercent() const;
void SetMin(bool bMin);
void SetMax(bool bMax);
void SetPercent(bool bPercent);
};
class SC_DLLPUBLIC ScColorScaleFormat
{
private:
ScRangeList maRange;
ScRangeList maRanges;
ScDocument* mpDoc;
typedef boost::ptr_vector<ScColorScaleEntry> ColorScaleEntries;
ColorScaleEntries maColorScales;
double GetMinValue() const;
double GetMaxValue() const;
void calcMinMax(double& nMin, double nMax) const;
public:
ScColorScaleFormat(ScDocument* pDoc);
......
......@@ -64,6 +64,152 @@ void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
maColorScales.push_back( pEntry );
}
bool ScColorScaleEntry::GetMin() const
{
return mbMin;
}
bool ScColorScaleEntry::GetMax() const
{
return mbMax;
}
bool ScColorScaleEntry::GetPercent() const
{
return mbPercent;
}
void ScColorScaleEntry::SetMin(bool bMin)
{
mbMin = bMin;
}
void ScColorScaleEntry::SetMax(bool bMax)
{
mbMax = bMax;
}
void ScColorScaleEntry::SetPercent(bool bPercent)
{
mbPercent = bPercent;
}
namespace {
double getMinValue(const ScRange& rRange, ScDocument* pDoc)
{
double aMinValue = std::numeric_limits<double>::max();
//iterate through columns
SCTAB nTab = rRange.aStart.Tab();
for(SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
{
for(SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
{
ScAddress aAddr(nCol, nRow, rRange.aStart.Tab());
CellType eType = pDoc->GetCellType(aAddr);
if(eType == CELLTYPE_VALUE)
{
double aVal = pDoc->GetValue(nCol, nRow, nTab);
if( aVal < aMinValue )
aMinValue = aVal;
}
else if(eType == CELLTYPE_FORMULA)
{
if(static_cast<ScFormulaCell*>(pDoc->GetCell(aAddr))->IsValue())
{
double aVal = pDoc->GetValue(nCol, nRow, nTab);
if( aVal < aMinValue )
aMinValue = aVal;
}
}
}
}
return aMinValue;
}
double getMaxValue(const ScRange& rRange, ScDocument* pDoc)
{
double aMaxValue = std::numeric_limits<double>::min();
//iterate through columns
SCTAB nTab = rRange.aStart.Tab();
for(SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
{
for(SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
{
ScAddress aAddr(nCol, nRow, rRange.aStart.Tab());
CellType eType = pDoc->GetCellType(aAddr);
if(eType == CELLTYPE_VALUE)
{
double aVal = pDoc->GetValue(nCol, nRow, nTab);
if( aVal > aMaxValue )
aMaxValue = aVal;
}
else if(eType == CELLTYPE_FORMULA)
{
if(static_cast<ScFormulaCell*>(pDoc->GetCell(aAddr))->IsValue())
{
double aVal = pDoc->GetValue(nCol, nRow, nTab);
if( aVal > aMaxValue )
aMaxValue = aVal;
}
}
}
}
return aMaxValue;
}
}
double ScColorScaleFormat::GetMinValue() const
{
const_iterator itr = maColorScales.begin();
double aMinValue = std::numeric_limits<double>::max();
if(!itr->GetMin())
return itr->GetValue();
else
{
size_t n = maRanges.size();
for(size_t i = 0; i < n; ++i)
{
const ScRange* pRange = maRanges[i];
double aVal = getMinValue(*pRange, mpDoc);
if( aVal < aMinValue )
aMinValue = aVal;
}
}
return aMinValue;
}
double ScColorScaleFormat::GetMaxValue() const
{
ColorScaleEntries::const_reverse_iterator itr = maColorScales.rbegin();
double aMaxVal = std::numeric_limits<double>::min();
if(!itr->GetMax())
return itr->GetValue();
else
{
size_t n = maRanges.size();
for(size_t i = 0; i < n; ++i)
{
const ScRange* pRange = maRanges[i];
double aVal = getMaxValue(*pRange, mpDoc);
if( aVal > aMaxVal )
aMaxVal = aVal;
}
}
return aMaxVal;;
}
void ScColorScaleFormat::calcMinMax(double& rMin, double rMax) const
{
rMin = GetMinValue();
rMax = GetMaxValue();
}
namespace {
sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double nVal2, sal_uInt8 nColVal2 )
......@@ -114,6 +260,10 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
double nValMax = itr->GetValue();
Color rColMax = itr->GetColor();
double nMin;
double nMax;
calcMinMax(nMin, nMax);
++itr;
while(itr != end() && nVal > nValMin)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment