diff options
author | Rafael Dominguez <venccsralph@gmail.com> | 2012-04-28 14:46:51 -0430 |
---|---|---|
committer | Rafael Dominguez <venccsralph@gmail.com> | 2012-06-03 09:12:35 -0430 |
commit | 27cd9157ac0e824197aa40c67fe6a4bfab3b2e38 (patch) | |
tree | a4ea7f723fcab7e0d443d3cf490942cdf3f291f1 /xmloff/source | |
parent | 5e1dfa9952724c1909acb3679369e3ec8e3f99ae (diff) |
Import X errorbars.
Change-Id: I069271ad1c0f2fc5ec0854d6fb13aa0dc25be01d
Diffstat (limited to 'xmloff/source')
-rw-r--r-- | xmloff/source/chart/PropertyMap.hxx | 6 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPlotAreaContext.cxx | 181 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPlotAreaContext.hxx | 2 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLSeries2Context.cxx | 17 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLSeries2Context.hxx | 2 | ||||
-rw-r--r-- | xmloff/source/chart/transporttypes.hxx | 4 |
6 files changed, 192 insertions, 20 deletions
diff --git a/xmloff/source/chart/PropertyMap.hxx b/xmloff/source/chart/PropertyMap.hxx index f293b790b5af..b295eed1e685 100644 --- a/xmloff/source/chart/PropertyMap.hxx +++ b/xmloff/source/chart/PropertyMap.hxx @@ -182,6 +182,10 @@ const XMLPropertyMapEntry aXMLChartPropMap[] = MAP_FULL( "MarkPosition", CHART, XML_TICK_MARK_POSITION, XML_SCH_TYPE_TICK_MARK_POSITION, 0, SvtSaveOptions::ODFVER_012 ), // statistical properties + + MAP_ENTRY_ODF_EXT( "ShowPositiveError", CHART, XML_ERROR_UPPER_INDICATOR, XML_TYPE_BOOL), + MAP_ENTRY_ODF_EXT( "ShowNegativeError", CHART, XML_ERROR_LOWER_INDICATOR, XML_TYPE_BOOL), + MAP_ENTRY( "MeanValue", CHART, XML_MEAN_VALUE, XML_TYPE_BOOL ), MAP_ENTRY( "ErrorMargin", CHART, XML_ERROR_MARGIN, XML_TYPE_DOUBLE ), MAP_ENTRY( "ConstantErrorLow", CHART, XML_ERROR_LOWER_LIMIT, XML_TYPE_DOUBLE ), @@ -198,8 +202,6 @@ const XMLPropertyMapEntry aXMLChartPropMap[] = MAP_ENTRY_ODF_EXT( "PositiveError", CHART, XML_ERROR_LOWER_LIMIT, XML_TYPE_DOUBLE), MAP_ENTRY_ODF_EXT( "NegativeError", CHART, XML_ERROR_UPPER_LIMIT, XML_TYPE_DOUBLE), MAP_ENTRY_ODF_EXT( "Weigth", CHART, XML_ERROR_STANDARD_WEIGTH, XML_TYPE_DOUBLE), - MAP_ENTRY_ODF_EXT( "ShowPositiveError", CHART, XML_ERROR_UPPER_INDICATOR, XML_TYPE_BOOL), - MAP_ENTRY_ODF_EXT( "ShowNegativeError", CHART, XML_ERROR_LOWER_INDICATOR, XML_TYPE_BOOL), // series/data-point properties MAP_SPECIAL( "DataCaption", CHART, XML_DATA_LABEL_NUMBER, XML_TYPE_NUMBER | MID_FLAG_MERGE_PROPERTY, XML_SCH_CONTEXT_SPECIAL_DATA_LABEL_NUMBER ), // convert one constant diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx index 588d819d7b91..535e6d268550 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx @@ -50,10 +50,14 @@ #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/chart/ChartDataRowSource.hpp> +#include <com/sun/star/chart/ChartErrorCategory.hpp> +#include <com/sun/star/chart/ChartErrorIndicatorType.hpp> +#include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/X3DDisplay.hpp> #include <com/sun/star/chart/XStatisticDisplay.hpp> #include <com/sun/star/chart/XDiagramPositioning.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp> #include <com/sun/star/chart2/XChartTypeContainer.hpp> #include <com/sun/star/chart2/XDataSeriesContainer.hpp> @@ -386,13 +390,6 @@ void SchXMLPlotAreaContext::StartElement( const uno::Reference< xml::sax::XAttri mrSeriesDefaultsAndStyles.maSymbolTypeDefault = xProp->getPropertyValue(::rtl::OUString("SymbolType")); mrSeriesDefaultsAndStyles.maDataCaptionDefault = xProp->getPropertyValue(::rtl::OUString("DataCaption")); - mrSeriesDefaultsAndStyles.maErrorIndicatorDefault = xProp->getPropertyValue(::rtl::OUString("ErrorIndicator")); - mrSeriesDefaultsAndStyles.maErrorCategoryDefault = xProp->getPropertyValue(::rtl::OUString("ErrorCategory")); - mrSeriesDefaultsAndStyles.maConstantErrorLowDefault = xProp->getPropertyValue(::rtl::OUString("ConstantErrorLow")); - mrSeriesDefaultsAndStyles.maConstantErrorHighDefault = xProp->getPropertyValue(::rtl::OUString("ConstantErrorHigh")); - mrSeriesDefaultsAndStyles.maPercentageErrorDefault = xProp->getPropertyValue(::rtl::OUString("PercentageError")); - mrSeriesDefaultsAndStyles.maErrorMarginDefault = xProp->getPropertyValue(::rtl::OUString("ErrorMargin")); - mrSeriesDefaultsAndStyles.maMeanValueDefault = xProp->getPropertyValue(::rtl::OUString("MeanValue")); mrSeriesDefaultsAndStyles.maRegressionCurvesDefault = xProp->getPropertyValue(::rtl::OUString("RegressionCurves")); @@ -971,12 +968,70 @@ void SchXMLStockContext::StartElement( const uno::Reference< xml::sax::XAttribut // ======================================== +void lcl_setErrorBarSequence ( const uno::Reference< chart2::XChartDocument > &xDoc, + const uno::Reference< beans::XPropertySet > &xBarProp, + const rtl::OUString &aRange, + bool bPositiveValue, bool bYError ) +{ + uno::Reference< com::sun::star::chart2::data::XDataProvider > xDataProvider(xDoc->getDataProvider()); + uno::Reference< com::sun::star::chart2::data::XDataSource > xDataSource( xBarProp, uno::UNO_QUERY ); + uno::Reference< com::sun::star::chart2::data::XDataSink > xDataSink( xDataSource, uno::UNO_QUERY ); + + assert( xDataSink.is() && xDataSource.is() && xDataProvider.is() ); + + rtl::OUString aXMLRange(lcl_ConvertRange(aRange,xDoc)); + + uno::Reference< chart2::data::XDataSequence > xNewSequence( + xDataProvider->createDataSequenceByRangeRepresentation( aRange )); + + if( xNewSequence.is()) + { + SchXMLTools::setXMLRangePropertyAtDataSequence(xNewSequence,aXMLRange); + + rtl::OUStringBuffer aRoleBuffer("error-bars-"); + if( bYError ) + aRoleBuffer.append( sal_Unicode( 'y' )); + else + aRoleBuffer.append( sal_Unicode( 'x' )); + + rtl::OUString aPlainRole = aRoleBuffer.makeStringAndClear(); + aRoleBuffer.append( aPlainRole ); + aRoleBuffer.append( sal_Unicode( '-' )); + + if( bPositiveValue ) + aRoleBuffer = aRoleBuffer.appendAscii( "positive" ); + else + aRoleBuffer = aRoleBuffer.appendAscii( "negative" ); + + rtl::OUString aRole = aRoleBuffer.makeStringAndClear(); + + Reference< beans::XPropertySet > xSeqProp( xNewSequence, uno::UNO_QUERY ); + + xSeqProp->setPropertyValue("Role", uno::makeAny( aRole )); + + Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + + Reference< chart2::data::XLabeledDataSequence > xLabelSeq( + xFact->createInstance("com.sun.star.chart2.data.LabeledDataSequence"), uno::UNO_QUERY ); + + xLabelSeq->setValues( xNewSequence ); + + uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( + xDataSource->getDataSequences()); + + aSequences.realloc( aSequences.getLength() + 1 ); + aSequences[ aSequences.getLength() - 1 ] = xLabelSeq; + xDataSink->setData( aSequences ); + } +} + SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, sal_uInt16 nPrefix, const rtl::OUString& rLocalName, + const rtl::OUString &rSeriesStyleName, ::std::list< DataRowPointStyle >& rStyleList, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, @@ -988,7 +1043,8 @@ SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext( mrStyleList( rStyleList ), m_xSeries( xSeries ), meContextType( eContextType ), - maChartSize( rChartSize ) + maChartSize( rChartSize ), + maSeriesStyleName( rSeriesStyleName) {} SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext() @@ -1000,6 +1056,9 @@ void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; ::rtl::OUString aValue; ::rtl::OUString sAutoStyleName; + rtl::OUString aPosRange; + rtl::OUString aNegRange; + bool bYError = true; /// Default errorbar, to be backward compatible with older files! for( sal_Int16 i = 0; i < nAttrCount; i++ ) { @@ -1011,6 +1070,12 @@ void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax { if( IsXMLToken( aLocalName, XML_STYLE_NAME ) ) sAutoStyleName = xAttrList->getValueByIndex( i ); + else if( IsXMLToken( aLocalName, XML_DIMENSION ) ) + bYError = xAttrList->getValueByIndex(i) == "y"; + else if( IsXMLToken( aLocalName, XML_ERROR_UPPER_RANGE) ) + aPosRange = xAttrList->getValueByIndex(i); + else if( IsXMLToken( aLocalName, XML_ERROR_LOWER_RANGE) ) + aNegRange = xAttrList->getValueByIndex(i); } } @@ -1018,21 +1083,109 @@ void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax // auto-style set, because they can contain an equation if( !sAutoStyleName.isEmpty() || meContextType == CONTEXT_TYPE_REGRESSION_CURVE ) { - DataRowPointStyle::StyleType eType = DataRowPointStyle::MEAN_VALUE; + DataRowPointStyle aStyle( DataRowPointStyle::MEAN_VALUE, m_xSeries, -1, 1, sAutoStyleName ); + switch( meContextType ) { case CONTEXT_TYPE_MEAN_VALUE_LINE: - eType = DataRowPointStyle::MEAN_VALUE; + aStyle.meType = DataRowPointStyle::MEAN_VALUE; break; case CONTEXT_TYPE_REGRESSION_CURVE: - eType = DataRowPointStyle::REGRESSION; + aStyle.meType = DataRowPointStyle::REGRESSION; break; case CONTEXT_TYPE_ERROR_INDICATOR: - eType = DataRowPointStyle::ERROR_INDICATOR; + { + aStyle.meType = DataRowPointStyle::ERROR_INDICATOR; + + ; + uno::Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), + uno::UNO_QUERY ); + + uno::Reference< beans::XPropertySet > xBarProp( xFact->createInstance("com.sun.star.chart2.ErrorBar" ), + uno::UNO_QUERY ); + + xBarProp->setPropertyValue("ErrorBarStyle",uno::makeAny(com::sun::star::chart::ErrorBarStyle::NONE)); + xBarProp->setPropertyValue("PositiveError",uno::makeAny(static_cast<double>(0.0))); + xBarProp->setPropertyValue("NegativeError",uno::makeAny(static_cast<double>(0.0))); + xBarProp->setPropertyValue("Weight",uno::makeAny(static_cast<double>(1.0))); + xBarProp->setPropertyValue("ShowPositiveError",uno::makeAny(sal_True)); + xBarProp->setPropertyValue("ShowNegativeError",uno::makeAny(sal_True)); + + const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); + + const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( + mrImportHelper.GetChartFamilyID(), sAutoStyleName ); + // note: SvXMLStyleContext::FillPropertySet is not const + XMLPropStyleContext * pErrorStyleContext = + const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle )); + + pErrorStyleContext->FillPropertySet( xBarProp ); + + uno::Reference< chart2::XChartDocument > xDoc(GetImport().GetModel(),uno::UNO_QUERY); + + if (!aPosRange.isEmpty()) + lcl_setErrorBarSequence(xDoc,xBarProp,aPosRange,true,bYError); + + if (!aNegRange.isEmpty()) + lcl_setErrorBarSequence(xDoc,xBarProp,aNegRange,false,bYError); + + if ( !bYError ) + { + aStyle.m_xErrorXProperties.set( xBarProp ); + } + else + { + /// Keep 0DF12 and below support + pStyle = pStylesCtxt->FindStyleChildContext(mrImportHelper.GetChartFamilyID(), + maSeriesStyleName); + + XMLPropStyleContext * pSeriesStyleContext = + const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle )); + + uno::Any aAny = SchXMLTools::getPropertyFromContext("ErrorBarStyle", + pSeriesStyleContext,pStylesCtxt); + + if ( aAny.hasValue() ) + { + sal_Int32 aBarStyle = com::sun::star::chart::ErrorBarStyle::NONE; + aAny >>= aBarStyle; + + aAny = SchXMLTools::getPropertyFromContext("ShowPositiveError", + pSeriesStyleContext,pStylesCtxt); + + xBarProp->setPropertyValue("ShowPositiveError",aAny); + + aAny = SchXMLTools::getPropertyFromContext("ShowNegativeError", + pSeriesStyleContext,pStylesCtxt); + + xBarProp->setPropertyValue("ShowNegativeError",aAny); + + switch(aBarStyle) + { + case com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN: + { + aAny = SchXMLTools::getPropertyFromContext("NegativeError", + pSeriesStyleContext,pStylesCtxt); + + xBarProp->setPropertyValue("NegativeError",aAny); + + aAny = SchXMLTools::getPropertyFromContext("PositiveError", + pSeriesStyleContext,pStylesCtxt); + + xBarProp->setPropertyValue("PositiveError",aAny); + } + break; + default: + break; + } + } + + aStyle.m_xErrorYProperties.set( xBarProp ); + } + } break; } - DataRowPointStyle aStyle( - eType, m_xSeries, -1, 1, sAutoStyleName ); + mrStyleList.push_back( aStyle ); } } diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.hxx b/xmloff/source/chart/SchXMLPlotAreaContext.hxx index 92a8b484e9e4..7308e69b57e1 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.hxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.hxx @@ -276,6 +276,7 @@ public: SvXMLImport& rImport, sal_uInt16 nPrefix, const rtl::OUString& rLocalName, + const rtl::OUString &rSeriesStyleName, ::std::list< DataRowPointStyle >& rStyleList, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, @@ -297,6 +298,7 @@ private: ::com::sun::star::chart2::XDataSeries > m_xSeries; ContextType meContextType; ::com::sun::star::awt::Size maChartSize; + rtl::OUString maSeriesStyleName; }; // ---------------------------------------- diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx index 8e50d4a3622d..26f10f09c9f3 100644 --- a/xmloff/source/chart/SchXMLSeries2Context.cxx +++ b/xmloff/source/chart/SchXMLSeries2Context.cxx @@ -658,7 +658,7 @@ SvXMLImportContext* SchXMLSeries2Context::CreateChildContext( case XML_TOK_SERIES_MEAN_VALUE_LINE: pContext = new SchXMLStatisticsObjectContext( mrImportHelper, GetImport(), - nPrefix, rLocalName, + nPrefix, rLocalName, msAutoStyleName, mrStyleList, m_xSeries, SchXMLStatisticsObjectContext::CONTEXT_TYPE_MEAN_VALUE_LINE, maChartSize ); @@ -666,7 +666,7 @@ SvXMLImportContext* SchXMLSeries2Context::CreateChildContext( case XML_TOK_SERIES_REGRESSION_CURVE: pContext = new SchXMLStatisticsObjectContext( mrImportHelper, GetImport(), - nPrefix, rLocalName, + nPrefix, rLocalName, msAutoStyleName, mrStyleList, m_xSeries, SchXMLStatisticsObjectContext::CONTEXT_TYPE_REGRESSION_CURVE, maChartSize ); @@ -674,7 +674,7 @@ SvXMLImportContext* SchXMLSeries2Context::CreateChildContext( case XML_TOK_SERIES_ERROR_INDICATOR: pContext = new SchXMLStatisticsObjectContext( mrImportHelper, GetImport(), - nPrefix, rLocalName, + nPrefix, rLocalName, msAutoStyleName, mrStyleList, m_xSeries, SchXMLStatisticsObjectContext::CONTEXT_TYPE_ERROR_INDICATOR, maChartSize ); @@ -878,6 +878,17 @@ void SchXMLSeries2Context::setStylesToStatisticsObjects( SeriesDefaultsAndStyles iStyle->meType == DataRowPointStyle::ERROR_INDICATOR || iStyle->meType == DataRowPointStyle::MEAN_VALUE ) { + if ( iStyle->meType == DataRowPointStyle::ERROR_INDICATOR ) + { + uno::Reference< beans::XPropertySet > xNewSeriesProp(iStyle->m_xSeries,uno::UNO_QUERY); + + if (iStyle->m_xErrorXProperties.is()) + xNewSeriesProp->setPropertyValue("ErrorBarX",uno::makeAny(iStyle->m_xErrorXProperties)); + + if (iStyle->m_xErrorYProperties.is()) + xNewSeriesProp->setPropertyValue("ErrorBarY",uno::makeAny(iStyle->m_xErrorYProperties)); + } + try { uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries ); diff --git a/xmloff/source/chart/SchXMLSeries2Context.hxx b/xmloff/source/chart/SchXMLSeries2Context.hxx index 0bb17b0519ce..4699de42a5ee 100644 --- a/xmloff/source/chart/SchXMLSeries2Context.hxx +++ b/xmloff/source/chart/SchXMLSeries2Context.hxx @@ -119,7 +119,7 @@ public: static void setStylesToStatisticsObjects( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles , const SvXMLStylesContext* pStylesCtxt , const SvXMLStyleContext*& rpStyle - , ::rtl::OUString& rCurrStyleName ); + , rtl::OUString &rCurrStyleName ); static void setStylesToDataPoints( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles , const SvXMLStylesContext* pStylesCtxt diff --git a/xmloff/source/chart/transporttypes.hxx b/xmloff/source/chart/transporttypes.hxx index 7ecf0860d1ba..be60fcd1ce96 100644 --- a/xmloff/source/chart/transporttypes.hxx +++ b/xmloff/source/chart/transporttypes.hxx @@ -176,6 +176,10 @@ struct DataRowPointStyle ::com::sun::star::chart2::XDataSeries > m_xSeries; ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xOldAPISeries; + com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySet > m_xErrorXProperties; + com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySet > m_xErrorYProperties; ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xEquationProperties; sal_Int32 m_nPointIndex; |