[Libreoffice-commits] .: Branch 'feature/chart_errorbars' - xmloff/source

Rafael Dominguez rdominguez at kemper.freedesktop.org
Fri Jun 1 15:33:54 PDT 2012


 xmloff/source/chart/PropertyMap.hxx           |    6 
 xmloff/source/chart/SchXMLPlotAreaContext.cxx |  181 +++++++++++++++++++++++---
 xmloff/source/chart/SchXMLPlotAreaContext.hxx |    2 
 xmloff/source/chart/SchXMLSeries2Context.cxx  |   17 ++
 xmloff/source/chart/SchXMLSeries2Context.hxx  |    2 
 xmloff/source/chart/transporttypes.hxx        |    4 
 6 files changed, 192 insertions(+), 20 deletions(-)

New commits:
commit 89d71c7a0a35f3e9e82efd1af19804096edc9787
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Sat Apr 28 14:46:51 2012 -0430

    Import X errorbars.

diff --git a/xmloff/source/chart/PropertyMap.hxx b/xmloff/source/chart/PropertyMap.hxx
index f293b79..b295eed 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 5df79c9..8783bf3 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>
@@ -387,13 +391,6 @@ void SchXMLPlotAreaContext::StartElement( const uno::Reference< xml::sax::XAttri
         mrSeriesDefaultsAndStyles.maSymbolTypeDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolType")));
         mrSeriesDefaultsAndStyles.maDataCaptionDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCaption")));
 
-        mrSeriesDefaultsAndStyles.maErrorIndicatorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorIndicator")));
-        mrSeriesDefaultsAndStyles.maErrorCategoryDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorCategory")));
-        mrSeriesDefaultsAndStyles.maConstantErrorLowDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorLow")));
-        mrSeriesDefaultsAndStyles.maConstantErrorHighDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorHigh")));
-        mrSeriesDefaultsAndStyles.maPercentageErrorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PercentageError")));
-        mrSeriesDefaultsAndStyles.maErrorMarginDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorMargin")));
-
         mrSeriesDefaultsAndStyles.maMeanValueDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MeanValue")));
         mrSeriesDefaultsAndStyles.maRegressionCurvesDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RegressionCurves")));
 
@@ -975,12 +972,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,
@@ -992,7 +1047,8 @@ SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext(
         mrStyleList( rStyleList ),
         m_xSeries( xSeries ),
         meContextType( eContextType ),
-        maChartSize( rChartSize )
+        maChartSize( rChartSize ),
+        maSeriesStyleName( rSeriesStyleName)
 {}
 
 SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext()
@@ -1004,6 +1060,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++ )
     {
@@ -1015,6 +1074,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);
         }
     }
 
@@ -1022,21 +1087,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 92a8b48..7308e69 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 8aad943..f7a5a1c 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 0bb17b0..4699de4 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 7ecf086..be60fcd 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;


More information about the Libreoffice-commits mailing list