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

import min, max and percent entries for color scales from xlsx

Change-Id: I Icebacfd711851c9223ed8f38d6445c82f575a47d
üst f26bf2ba
...@@ -76,20 +76,39 @@ struct CondFormatRuleModel ...@@ -76,20 +76,39 @@ struct CondFormatRuleModel
void setBiff12TextType( sal_Int32 nOperator ); void setBiff12TextType( sal_Int32 nOperator );
}; };
struct ColorScaleRuleModelEntry
{
::Color maColor;
double mnVal;
bool mbMin;
bool mbMax;
bool mbPercent;
ColorScaleRuleModelEntry():
maColor(),
mnVal(0),
mbMin(false),
mbMax(false),
mbPercent(false) {}
};
class ColorScaleRule : public WorksheetHelper class ColorScaleRule : public WorksheetHelper
{ {
public: public:
ColorScaleRule( const CondFormat& rFormat ); ColorScaleRule( const CondFormat& rFormat );
void importValue( const AttributeList& rAttribs ); void importCfvo( const AttributeList& rAttribs );
void importColor( const AttributeList& rAttribs ); void importColor( const AttributeList& rAttribs );
void AddEntries( ScColorScaleFormat* pFormat ); void AddEntries( ScColorScaleFormat* pFormat );
private: private:
const CondFormat& mrCondFormat; const CondFormat& mrCondFormat;
std::vector< ::Color > maColors; std::vector< ColorScaleRuleModelEntry > maColorScaleRuleEntries;
std::vector< double > maValues;
sal_uInt32 mnCfvo;
sal_uInt32 mnCol;
}; };
......
...@@ -145,18 +145,39 @@ void lclAppendProperty( ::std::vector< PropertyValue >& orProps, const OUString& ...@@ -145,18 +145,39 @@ void lclAppendProperty( ::std::vector< PropertyValue >& orProps, const OUString&
ColorScaleRule::ColorScaleRule( const CondFormat& rFormat ): ColorScaleRule::ColorScaleRule( const CondFormat& rFormat ):
WorksheetHelper( rFormat ), WorksheetHelper( rFormat ),
mrCondFormat( rFormat ) mrCondFormat( rFormat ),
mnCfvo(0),
mnCol(0)
{ {
} }
void ColorScaleRule::importValue( const AttributeList& rAttribs ) void ColorScaleRule::importCfvo( const AttributeList& rAttribs )
{ {
if(mnCfvo >= maColorScaleRuleEntries.size())
maColorScaleRuleEntries.push_back(ColorScaleRuleModelEntry());
rtl::OUString aType = rAttribs.getString( XML_type, rtl::OUString() ); rtl::OUString aType = rAttribs.getString( XML_type, rtl::OUString() );
double nVal = rAttribs.getDouble( XML_val, 0.0 );
maColorScaleRuleEntries[mnCfvo].mnVal = nVal;
if (aType == "num") if (aType == "num")
{ {
double nVal = rAttribs.getDouble( XML_val, 0.0 ); // nothing to do
maValues.push_back(nVal); }
else if( aType == "min" )
{
maColorScaleRuleEntries[mnCfvo].mbMin = true;
}
else if( aType == "max" )
{
maColorScaleRuleEntries[mnCfvo].mbMax = true;
} }
else if( aType == "percent" )
{
maColorScaleRuleEntries[mnCfvo].mbPercent = true;
}
++mnCfvo;
} }
namespace { namespace {
...@@ -177,17 +198,31 @@ void ColorScaleRule::importColor( const AttributeList& rAttribs ) ...@@ -177,17 +198,31 @@ void ColorScaleRule::importColor( const AttributeList& rAttribs )
sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT ); sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
::Color aColor = RgbToRgbComponents( nColor ); ::Color aColor = RgbToRgbComponents( nColor );
maColors.push_back(aColor);
if(mnCol >= maColorScaleRuleEntries.size())
maColorScaleRuleEntries.push_back(ColorScaleRuleModelEntry());
maColorScaleRuleEntries[mnCol].maColor = aColor;
++mnCol;
} }
void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat ) void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat )
{ {
//assume that both vectors contain the same entries //assume that both vectors contain the same entries
// TODO: check it // TODO: check it
size_t n = std::min<size_t>(maColors.size(), maValues.size()); for(size_t i = 0; i < maColorScaleRuleEntries.size(); ++i)
for(size_t i = 0; i < n; ++i)
{ {
pFormat->AddEntry( new ScColorScaleEntry(maValues[i], maColors[i]) ); ScColorScaleEntry* pEntry = new ScColorScaleEntry(maColorScaleRuleEntries[i].mnVal, maColorScaleRuleEntries[i].maColor);
const ColorScaleRuleModelEntry& rEntry = maColorScaleRuleEntries[i];
if(rEntry.mbMin)
pEntry->SetMin(true);
if(rEntry.mbMax)
pEntry->SetMax(true);
if(rEntry.mbPercent)
pEntry->SetPercent(true);
pFormat->AddEntry( pEntry );
} }
} }
......
...@@ -66,7 +66,7 @@ void ColorScaleContext::onStartElement( const AttributeList& rAttribs ) ...@@ -66,7 +66,7 @@ void ColorScaleContext::onStartElement( const AttributeList& rAttribs )
switch( getCurrentElement() ) switch( getCurrentElement() )
{ {
case XLS_TOKEN( cfvo ): case XLS_TOKEN( cfvo ):
mxRule->getColorScale()->importValue( rAttribs ); mxRule->getColorScale()->importCfvo( rAttribs );
break; break;
case XLS_TOKEN( color ): case XLS_TOKEN( color ):
mxRule->getColorScale()->importColor( rAttribs ); mxRule->getColorScale()->importColor( rAttribs );
......
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