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

implement databar import from oox

Change-Id: Id510acbc7291b94610e0e2c769d8cee582baa9a7
üst 862f56d1
......@@ -39,6 +39,8 @@ namespace com { namespace sun { namespace star {
namespace sheet { class XSheetConditionalEntries; }
} } }
class ScColorScaleFormat;
class ScDataBarFormat;
struct ScDataBarFormatData;
namespace oox {
namespace xls {
......@@ -112,6 +114,23 @@ private:
sal_uInt32 mnCol;
};
class DataBarRule : public WorksheetHelper
{
public:
DataBarRule( const CondFormat& rFormat );
void importCfvo( const AttributeList& rAttribs );
void importColor( const AttributeList& rAttribs );
void SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
private:
const CondFormat& mrCondFormat;
ScDataBarFormatData* mpFormat;
boost::scoped_ptr<ColorScaleRuleModelEntry> mpUpperLimit;
boost::scoped_ptr<ColorScaleRuleModelEntry> mpLowerLimit;
};
// ============================================================================
......@@ -138,11 +157,13 @@ public:
inline sal_Int32 getPriority() const { return maModel.mnPriority; }
ColorScaleRule* getColorScale();
DataBarRule* getDataBar();
private:
const CondFormat& mrCondFormat;
CondFormatRuleModel maModel;
boost::scoped_ptr<ColorScaleRule> mpColor;
boost::scoped_ptr<DataBarRule> mpDataBar;
};
typedef ::boost::shared_ptr< CondFormatRule > CondFormatRuleRef;
......
......@@ -48,8 +48,17 @@ public:
virtual void onStartElement( const AttributeList& rAttribs );
virtual void onCharacters( const ::rtl::OUString& rChars );
virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
virtual void onStartRecord( SequenceInputStream& rStrm );
private:
CondFormatRuleRef mxRule;
};
class DataBarContext : public WorksheetContextBase
{
public:
explicit DataBarContext( CondFormatContext& rFormat, CondFormatRuleRef xRule );
virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
virtual void onStartElement( const AttributeList& rAttribs );
private:
CondFormatRuleRef mxRule;
......
......@@ -224,12 +224,11 @@ void ColorScaleRule::importColor( const AttributeList& rAttribs )
++mnCol;
}
void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr )
namespace {
ScColorScaleEntry* ConvertToModel( const ColorScaleRuleModelEntry& rEntry, ScDocument* pDoc, const ScAddress& rAddr )
{
for(size_t i = 0; i < maColorScaleRuleEntries.size(); ++i)
{
ScColorScaleEntry* pEntry = new ScColorScaleEntry(maColorScaleRuleEntries[i].mnVal, maColorScaleRuleEntries[i].maColor);
const ColorScaleRuleModelEntry& rEntry = maColorScaleRuleEntries[i];
ScColorScaleEntry* pEntry = new ScColorScaleEntry(rEntry.mnVal, rEntry.maColor);
if(rEntry.mbMin)
pEntry->SetMin(true);
......@@ -241,10 +240,104 @@ void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc,
if(!rEntry.maFormula.isEmpty())
pEntry->SetFormula(rEntry.maFormula, pDoc, rAddr, formula::FormulaGrammar::GRAM_ENGLISH_XL_A1);
return pEntry;
}
}
void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr )
{
for(size_t i = 0; i < maColorScaleRuleEntries.size(); ++i)
{
const ColorScaleRuleModelEntry& rEntry = maColorScaleRuleEntries[i];
ScColorScaleEntry* pEntry = ConvertToModel( rEntry, pDoc, rAddr );
pFormat->AddEntry( pEntry );
}
}
// ============================================================================
//
DataBarRule::DataBarRule( const CondFormat& rFormat ):
WorksheetHelper( rFormat ),
mrCondFormat( rFormat ),
mpFormat(new ScDataBarFormatData)
{
}
void DataBarRule::importColor( const AttributeList& rAttribs )
{
sal_Int32 nColor = 0;
if( rAttribs.hasAttribute( XML_rgb ) )
nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
else if( rAttribs.hasAttribute( XML_theme ) )
{
sal_uInt32 nThemeIndex = rAttribs.getUnsigned( XML_theme, 0 );
nColor = getTheme().getColorByToken( nThemeIndex );
}
::Color aColor = RgbToRgbComponents( nColor );
mpFormat->maPositiveColor = aColor;
}
void DataBarRule::importCfvo( const AttributeList& rAttribs )
{
ColorScaleRuleModelEntry* pEntry;
if(!mpLowerLimit)
{
mpLowerLimit.reset(new ColorScaleRuleModelEntry);
pEntry = mpLowerLimit.get();
}
else
{
mpUpperLimit.reset(new ColorScaleRuleModelEntry);
pEntry = mpUpperLimit.get();
}
rtl::OUString aType = rAttribs.getString( XML_type, rtl::OUString() );
double nVal = rAttribs.getDouble( XML_val, 0.0 );
pEntry->mnVal = nVal;
if (aType == "num")
{
// nothing to do
}
else if( aType == "min" )
{
pEntry->mbMin = true;
}
else if( aType == "max" )
{
pEntry->mbMax = true;
}
else if( aType == "percent" )
{
pEntry->mbPercent = true;
}
else if( aType == "percentile" )
{
// this is most likely wrong but I have no idea what the difference
// between percent and percentile should be when calculating colors
pEntry->mbPercent = true;
}
else if( aType == "formula" )
{
rtl::OUString aFormula = rAttribs.getString( XML_val, rtl::OUString() );
pEntry->maFormula = aFormula;
}
}
void DataBarRule::SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr )
{
ScColorScaleEntry* pUpperEntry = ConvertToModel( *mpUpperLimit.get(), pDoc, rAddr);
ScColorScaleEntry* pLowerEntry = ConvertToModel( *mpLowerLimit.get(), pDoc, rAddr);
mpFormat->mpUpperLimit.reset( pUpperEntry );
mpFormat->mpLowerLimit.reset( pLowerEntry );
pFormat->SetDataBarData(mpFormat);
}
// ============================================================================
CondFormatRuleModel::CondFormatRuleModel() :
......@@ -712,7 +805,7 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
ScDocument& rDoc = getScDocument();
ScColorScaleFormat* pFormat = new ScColorScaleFormat(&rDoc);
sal_Int32 nIndex = rDoc.AddColorScaleFormat(pFormat);
sal_Int32 nIndex = rDoc.AddColorFormat(pFormat);
ScRangeList aList;
// apply attributes to cells
......@@ -736,15 +829,52 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
else
mpColor->AddEntries( pFormat, &rDoc, ScAddress() );
}
else if (mpDataBar)
{
ScRangeList aList;
ScDocument& rDoc = getScDocument();
ScDataBarFormat* pFormat = new ScDataBarFormat(&rDoc);
sal_Int32 nIndex = rDoc.AddColorFormat(pFormat);
// apply attributes to cells
//
const ApiCellRangeList& rRanges = mrCondFormat.getRanges();
for( ApiCellRangeList::const_iterator itr = rRanges.begin(); itr != rRanges.end(); ++itr)
{
ScRange aRange;
ScUnoConversion::FillScRange(aRange, *itr);
ScPatternAttr aPattern( rDoc.GetPool() );
aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_COLORSCALE, nIndex ) );
ScMarkData aMarkData;
aMarkData.SetMarkArea(aRange);
rDoc.ApplySelectionPattern( aPattern , aMarkData);
aList.Append(aRange);
}
pFormat->SetRange(aList);
mpDataBar->SetData( pFormat, &rDoc, aList.front()->aStart );
}
}
ColorScaleRule* CondFormatRule::getColorScale()
{
if(!mpColor)
mpColor.reset( new ColorScaleRule(mrCondFormat) );
return mpColor.get();
}
DataBarRule* CondFormatRule::getDataBar()
{
if(!mpDataBar)
mpDataBar.reset( new DataBarRule(mrCondFormat) );
return mpDataBar.get();
}
// ============================================================================
CondFormatModel::CondFormatModel() :
......
......@@ -79,15 +79,46 @@ void ColorScaleContext::onCharacters( const OUString& )
}
ContextHandlerRef ColorScaleContext::onCreateRecordContext( sal_Int32, SequenceInputStream& )
// ============================================================================
DataBarContext::DataBarContext( CondFormatContext& rFragment, CondFormatRuleRef xRule ) :
WorksheetContextBase( rFragment ),
mxRule( xRule )
{
}
ContextHandlerRef DataBarContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
{
switch( getCurrentElement() )
{
case XLS_TOKEN( cfRule ):
return (nElement == XLS_TOKEN( colorScale )) ? this : 0;
case XLS_TOKEN( dataBar ):
if (nElement == XLS_TOKEN( cfvo ))
return this;
else if (nElement == XLS_TOKEN( color ))
return this;
else
return 0;
}
return 0;
}
void ColorScaleContext::onStartRecord( SequenceInputStream& )
void DataBarContext::onStartElement( const AttributeList& rAttribs )
{
switch( getCurrentElement() )
{
case XLS_TOKEN( cfvo ):
mxRule->getDataBar()->importCfvo( rAttribs );
break;
case XLS_TOKEN( color ):
mxRule->getDataBar()->importColor( rAttribs );
break;
}
}
// ============================================================================
CondFormatContext::CondFormatContext( WorksheetFragmentBase& rFragment ) :
WorksheetContextBase( rFragment )
{
......@@ -104,6 +135,8 @@ ContextHandlerRef CondFormatContext::onCreateContext( sal_Int32 nElement, const
return this;
else if (nElement == XLS_TOKEN( colorScale ) )
return new ColorScaleContext( *this, mxRule );
else if (nElement == XLS_TOKEN( dataBar ) )
return new DataBarContext( *this, mxRule );
else
return 0;
}
......
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