summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-18 10:33:16 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-18 10:51:21 +0200
commitd961b694348a0dd048761a6046de7393ac077f31 (patch)
tree1c18cdf513c5bc765fadefa1825d03e1be05dc83
parent862f56d19e1c57d3d648275877fc434fb119e80f (diff)
implement databar import from oox
Change-Id: Id510acbc7291b94610e0e2c769d8cee582baa9a7
-rw-r--r--sc/source/filter/inc/condformatbuffer.hxx21
-rw-r--r--sc/source/filter/inc/condformatcontext.hxx13
-rw-r--r--sc/source/filter/oox/condformatbuffer.cxx142
-rw-r--r--sc/source/filter/oox/condformatcontext.cxx37
4 files changed, 203 insertions, 10 deletions
diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx
index b8b2d653fb41..de2c906166cc 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -41,2 +41,4 @@ namespace com { namespace sun { namespace star {
class ScColorScaleFormat;
+class ScDataBarFormat;
+struct ScDataBarFormatData;
@@ -114,2 +116,19 @@ private:
+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;
+};
+
@@ -140,2 +159,3 @@ public:
ColorScaleRule* getColorScale();
+ DataBarRule* getDataBar();
@@ -145,2 +165,3 @@ private:
boost::scoped_ptr<ColorScaleRule> mpColor;
+ boost::scoped_ptr<DataBarRule> mpDataBar;
};
diff --git a/sc/source/filter/inc/condformatcontext.hxx b/sc/source/filter/inc/condformatcontext.hxx
index 7af625808bb4..08f53418fa59 100644
--- a/sc/source/filter/inc/condformatcontext.hxx
+++ b/sc/source/filter/inc/condformatcontext.hxx
@@ -50,4 +50,13 @@ public:
- 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 );
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index 719f3a5d1c43..655b264364bc 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -226,8 +226,7 @@ void ColorScaleRule::importColor( const AttributeList& rAttribs )
-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);
@@ -243,2 +242,15 @@ void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc,
+ 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 );
@@ -248,2 +260,83 @@ void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc,
// ============================================================================
+//
+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);
+}
+
+// ============================================================================
@@ -714,3 +807,3 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
- sal_Int32 nIndex = rDoc.AddColorScaleFormat(pFormat);
+ sal_Int32 nIndex = rDoc.AddColorFormat(pFormat);
@@ -738,2 +831,30 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
}
+ 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 );
+ }
}
@@ -744,2 +865,3 @@ ColorScaleRule* CondFormatRule::getColorScale()
mpColor.reset( new ColorScaleRule(mrCondFormat) );
+
return mpColor.get();
@@ -747,2 +869,10 @@ ColorScaleRule* CondFormatRule::getColorScale()
+DataBarRule* CondFormatRule::getDataBar()
+{
+ if(!mpDataBar)
+ mpDataBar.reset( new DataBarRule(mrCondFormat) );
+
+ return mpDataBar.get();
+}
+
// ============================================================================
diff --git a/sc/source/filter/oox/condformatcontext.cxx b/sc/source/filter/oox/condformatcontext.cxx
index ff73a8ee21ab..01ad6a46e245 100644
--- a/sc/source/filter/oox/condformatcontext.cxx
+++ b/sc/source/filter/oox/condformatcontext.cxx
@@ -81,4 +81,24 @@ 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;
@@ -86,6 +106,17 @@ ContextHandlerRef ColorScaleContext::onCreateRecordContext( sal_Int32, SequenceI
-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 ) :
@@ -106,2 +137,4 @@ ContextHandlerRef CondFormatContext::onCreateContext( sal_Int32 nElement, const
return new ColorScaleContext( *this, mxRule );
+ else if (nElement == XLS_TOKEN( dataBar ) )
+ return new DataBarContext( *this, mxRule );
else