From e191287ebb212a3d320299d99d5fe03f6e2c09dd Mon Sep 17 00:00:00 2001 From: Ingrid Halama Date: Mon, 15 Nov 2010 19:19:18 +0100 Subject: chart46: #i115590# export used 2nd scale also if hidden --- xmloff/source/chart/SchXMLExport.cxx | 703 +++++++++++------------------------ 1 file changed, 217 insertions(+), 486 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index e6f6fc6d9340..f220cf3dfa9a 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -201,6 +201,11 @@ public: void exportAxes( const com::sun::star::uno::Reference< com::sun::star::chart::XDiagram > & xDiagram, const com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > & xNewDiagram, sal_Bool bExportContent ); + void exportAxis( enum XMLTokenEnum eDimension, enum XMLTokenEnum eAxisName, + const Reference< beans::XPropertySet > xAxisProps, const Reference< beans::XPropertySet > xTitleProps, const OUString& rCategoriesRanges, + const Reference< beans::XPropertySet > xMajorGridProps, const Reference< beans::XPropertySet > xMinorGridProps, bool bExportContent ); + void exportGrid( const Reference< beans::XPropertySet > xGridProperties, bool bMajor, bool bExportContent ); + void exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent ); void exportSeries( const com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > & xNewDiagram, @@ -1760,6 +1765,55 @@ void SchXMLExportHelper_Impl::exportTable() OSL_ASSERT( bHasOwnData || (aRowDescriptions_RangeIter == aRowDescriptions_RangeEnd) ); } +namespace +{ + +Reference< chart2::XCoordinateSystem > lcl_getCooSys( const Reference< chart2::XDiagram > & xNewDiagram ) +{ + Reference< chart2::XCoordinateSystem > xCooSys; + Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDiagram, uno::UNO_QUERY ); + if(xCooSysCnt.is()) + { + Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() ); + if(aCooSysSeq.getLength()>0) + xCooSys = aCooSysSeq[0]; + } + return xCooSys; +} + +Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem >& xCooSys, + enum XMLTokenEnum eDimension, bool bPrimary=true ) +{ + Reference< chart2::XAxis > xNewAxis; + try + { + if( xCooSys.is() ) + { + sal_Int32 nDimensionIndex=0; + switch( eDimension ) + { + case XML_X: + nDimensionIndex=0; + break; + case XML_Y: + nDimensionIndex=1; + break; + case XML_Z: + nDimensionIndex=2; + break; + } + + xNewAxis = xCooSys->getAxisByDimension( nDimensionIndex, bPrimary ? 0 : 1 ); + } + } + catch( const uno::Exception & ) + { + } + return xNewAxis; +} + +} + void SchXMLExportHelper_Impl::exportPlotArea( Reference< chart::XDiagram > xDiagram, Reference< chart2::XDiagram > xNewDiagram, @@ -1775,8 +1829,6 @@ void SchXMLExportHelper_Impl::exportPlotArea( Reference< beans::XPropertySet > xPropSet; std::vector< XMLPropertyState > aPropertyStates; - OUString aASName; - sal_Bool bHasTwoYAxes = sal_False; sal_Bool bIs3DChart = sal_False; drawing::HomogenMatrix aTransMatrix; @@ -1884,16 +1936,6 @@ void SchXMLExportHelper_Impl::exportPlotArea( if( xPropSet.is()) { Any aAny; - try - { - aAny = xPropSet->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryYAxis" ))); - aAny >>= bHasTwoYAxes; - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property HasSecondaryYAxis not found in Diagram" ); - } // 3d attributes try @@ -1944,7 +1986,8 @@ void SchXMLExportHelper_Impl::exportPlotArea( // series elements // --------------- - exportSeries( xNewDiagram, rPageSize, bExportContent, bHasTwoYAxes ); + Reference< chart2::XAxis > xSecondYAxis = lcl_getAxis( lcl_getCooSys( xNewDiagram ), XML_Y, false ); + exportSeries( xNewDiagram, rPageSize, bExportContent, xSecondYAxis.is() ); // stock-chart elements OUString sChartType ( xDiagram->getDiagramType()); @@ -2106,6 +2149,110 @@ void SchXMLExportHelper_Impl::exportCoordinateRegion( const uno::Reference< char SvXMLElementExport aCoordinateRegion( mrExport, XML_NAMESPACE_CHART_EXT, XML_COORDINATE_REGION, sal_True, sal_True );//#i100778# todo: change to chart namespace in future - dependent on fileformat } +void SchXMLExportHelper_Impl::exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent ) +{ + if( !xTitleProps.is() ) + return; + std::vector< XMLPropertyState > aPropertyStates = mxExpPropMapper->Filter( xTitleProps ); + if( bExportContent ) + { + OUString aText; + Any aAny( xTitleProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )))); + aAny >>= aText; + + Reference< drawing::XShape > xShape( xTitleProps, uno::UNO_QUERY ); + if( xShape.is()) + addPosition( xShape ); + + AddAutoStyleAttribute( aPropertyStates ); + SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True ); + + // paragraph containing title + exportText( aText ); + } + else + { + CollectAutoStyle( aPropertyStates ); + } + aPropertyStates.clear(); +} + +void SchXMLExportHelper_Impl::exportGrid( const Reference< beans::XPropertySet > xGridProperties, bool bMajor, bool bExportContent ) +{ + if( !xGridProperties.is() ) + return; + std::vector< XMLPropertyState > aPropertyStates = mxExpPropMapper->Filter( xGridProperties ); + if( bExportContent ) + { + AddAutoStyleAttribute( aPropertyStates ); + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, bMajor ? XML_MAJOR : XML_MINOR ); + SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); + } + else + { + CollectAutoStyle( aPropertyStates ); + } + aPropertyStates.clear(); +} + +void SchXMLExportHelper_Impl::exportAxis( + enum XMLTokenEnum eDimension, + enum XMLTokenEnum eAxisName, + const Reference< beans::XPropertySet > xAxisProps, + const Reference< beans::XPropertySet > xTitleProps, + const OUString& rCategoriesRange, + const Reference< beans::XPropertySet > xMajorGridProps, + const Reference< beans::XPropertySet > xMinorGridProps, + bool bExportContent ) +{ + static const OUString sNumFormat( OUString::createFromAscii( "NumberFormat" )); + std::vector< XMLPropertyState > aPropertyStates; + SvXMLElementExport* pAxis = NULL; + + // get property states for autostyles + if( xAxisProps.is() && mxExpPropMapper.is() ) + { + lcl_exportNumberFormat( sNumFormat, xAxisProps, mrExport ); + aPropertyStates = mxExpPropMapper->Filter( xAxisProps ); + } + + if( bExportContent ) + { + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, eDimension ); + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, eAxisName ); + AddAutoStyleAttribute( aPropertyStates ); // write style name + // open axis element + pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); + } + else + { + CollectAutoStyle( aPropertyStates ); + } + aPropertyStates.clear(); + + // axis-title + exportAxisTitle( xTitleProps , bExportContent ); + + // categories if we have a categories chart + if( bExportContent && rCategoriesRange.getLength() ) + { + mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, rCategoriesRange ); + SvXMLElementExport aCategories( mrExport, XML_NAMESPACE_CHART, XML_CATEGORIES, sal_True, sal_True ); + } + + // grid + exportGrid( xMajorGridProps, true, bExportContent ); + exportGrid( xMinorGridProps, false, bExportContent ); + + if( pAxis ) + { + //close axis element + delete pAxis; + pAxis = NULL; + } +} + void SchXMLExportHelper_Impl::exportAxes( const Reference< chart::XDiagram > & xDiagram, const Reference< chart2::XDiagram > & xNewDiagram, @@ -2115,13 +2262,6 @@ void SchXMLExportHelper_Impl::exportAxes( if( ! xDiagram.is()) return; - // variables for autostyles - const OUString sNumFormat( OUString::createFromAscii( "NumberFormat" )); - Reference< beans::XPropertySet > xPropSet; - std::vector< XMLPropertyState > aPropertyStates; - - OUString aASName; - // get some properties from document first sal_Bool bHasXAxis = sal_False, bHasYAxis = sal_False, @@ -2139,7 +2279,6 @@ void SchXMLExportHelper_Impl::exportAxes( bHasYAxisMinorGrid = sal_False, bHasZAxisMajorGrid = sal_False, bHasZAxisMinorGrid = sal_False; - sal_Bool bIs3DChart = sal_False; // get multiple properties using XMultiPropertySet MultiPropertySetHandler aDiagramProperties (xDiagram); @@ -2205,506 +2344,98 @@ void SchXMLExportHelper_Impl::exportAxes( aDiagramProperties.Add ( OUString (RTL_CONSTASCII_USTRINGPARAM ("HasZAxisHelpGrid")), bHasZAxisMinorGrid); - aDiagramProperties.Add( - OUString (RTL_CONSTASCII_USTRINGPARAM ("Dim3D")), bIs3DChart); - if ( ! aDiagramProperties.GetProperties ()) { DBG_WARNING ("Required properties not found in Chart diagram"); } - SvXMLElementExport* pAxis = NULL; + Reference< chart2::XCoordinateSystem > xCooSys( lcl_getCooSys(xNewDiagram) ); + + // write an axis element also if the axis itself is not visible, but a grid or a title + + Reference< beans::XPropertySet > xAxisProps; + Reference< beans::XPropertySet > xTitleProps; + OUString aCategoriesRange; + Reference< beans::XPropertySet > xMajorGridProps; + Reference< beans::XPropertySet > xMinorGridProps; // x axis // ------- - - // write axis element also if the axis itself is not visible, but a grid or - // title - Reference< chart::XAxisXSupplier > xAxisXSupp( xDiagram, uno::UNO_QUERY ); - if( xAxisXSupp.is()) + Reference< ::com::sun::star::chart2::XAxis > xNewAxis = lcl_getAxis( xCooSys, XML_X ); + if( xNewAxis.is() ) { - bool bHasAxisProperties = false; - // get property states for autostyles - if( mxExpPropMapper.is()) + Reference< chart::XAxisXSupplier > xAxisXSupp( xDiagram, uno::UNO_QUERY ); + xAxisProps = xAxisXSupp.is() ? xAxisXSupp->getXAxis() : 0; + xTitleProps = (bHasXAxisTitle && xAxisXSupp.is()) ? Reference< beans::XPropertySet >( xAxisXSupp->getXAxisTitle(), uno::UNO_QUERY ) : 0; + xMajorGridProps = (bHasXAxisMajorGrid && xAxisXSupp.is()) ? Reference< beans::XPropertySet >( xAxisXSupp->getXMainGrid(), uno::UNO_QUERY ) : 0; + xMinorGridProps = (bHasXAxisMinorGrid && xAxisXSupp.is()) ? Reference< beans::XPropertySet >( xAxisXSupp->getXHelpGrid(), uno::UNO_QUERY ) : 0; + if( mbHasCategoryLabels && bExportContent ) { - xPropSet = xAxisXSupp->getXAxis(); - if( xPropSet.is()) - { - bHasAxisProperties = true; - lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport ); - aPropertyStates = mxExpPropMapper->Filter( xPropSet ); - } - } - - if( bHasXAxis || - bHasXAxisTitle || bHasXAxisMajorGrid || bHasXAxisMinorGrid || - mbHasCategoryLabels || bHasAxisProperties ) - { - if( bExportContent ) - { - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, XML_X ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, XML_PRIMARY_X ); - - // write style name - AddAutoStyleAttribute( aPropertyStates ); - - // element - pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); - } - else // autostyles + Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xNewDiagram ) ); + if( xCategories.is() ) { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - - // axis-title - if( bHasXAxisTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xAxisXSupp->getXAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) + Reference< chart2::data::XDataSequence > xValues( xCategories->getValues() ); + if( xValues.is() ) { - aPropertyStates = mxExpPropMapper->Filter( xTitleProp ); - if( bExportContent ) - { - OUString aText; - Any aAny( xTitleProp->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )))); - aAny >>= aText; - - Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY ); - if( xShape.is()) - addPosition( xShape ); - - AddAutoStyleAttribute( aPropertyStates ); - SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True ); - - // paragraph containing title - exportText( aText ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); + Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY ); + maCategoriesRange = xValues->getSourceRangeRepresentation(); + aCategoriesRange = lcl_ConvertRange( maCategoriesRange, xNewDoc ); } } - - // categories if we have a categories chart - if( bExportContent && - mbHasCategoryLabels ) - { - OUString aCategoriesRange; - // fill msString with cell-range-address of categories - // export own table references - if( xNewDiagram.is()) - { - Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xNewDiagram ) ); - if( xCategories.is() ) - { - Reference< chart2::data::XDataSequence > xValues( xCategories->getValues() ); - if( xValues.is()) - { - Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY ); - maCategoriesRange = xValues->getSourceRangeRepresentation(); - aCategoriesRange = lcl_ConvertRange( maCategoriesRange, xNewDoc ); - } - } - } - - if( aCategoriesRange.getLength()) - mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, aCategoriesRange ); - SvXMLElementExport aCategories( mrExport, XML_NAMESPACE_CHART, XML_CATEGORIES, sal_True, sal_True ); - } - - // grid - Reference< beans::XPropertySet > xMajorGrid( xAxisXSupp->getXMainGrid(), uno::UNO_QUERY ); - if( bHasXAxisMajorGrid && xMajorGrid.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xMajorGrid ); - if( bExportContent ) - { - AddAutoStyleAttribute( aPropertyStates ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, XML_MAJOR ); - SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - Reference< beans::XPropertySet > xMinorGrid( xAxisXSupp->getXHelpGrid(), uno::UNO_QUERY ); - if( bHasXAxisMinorGrid && xMinorGrid.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xMinorGrid ); - if( bExportContent ) - { - AddAutoStyleAttribute( aPropertyStates ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, XML_MINOR ); - SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - if( pAxis ) - { - delete pAxis; - pAxis = NULL; - } } + exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + aCategoriesRange = OUString(); } // secondary x axis - if( bHasSecondaryXAxis || bHasSecondaryXAxisTitle ) + // ------- + Reference< chart::XSecondAxisTitleSupplier > xSecondTitleSupp( xDiagram, uno::UNO_QUERY ); + xNewAxis = lcl_getAxis( xCooSys, XML_X, false ); + if( xNewAxis.is() ) { Reference< chart::XTwoAxisXSupplier > xAxisTwoXSupp( xDiagram, uno::UNO_QUERY ); - if( xAxisTwoXSupp.is()) - { - // get property states for autostyles - if( mxExpPropMapper.is()) - { - xPropSet = xAxisTwoXSupp->getSecondaryXAxis(); - lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport ); - if( xPropSet.is()) - aPropertyStates = mxExpPropMapper->Filter( xPropSet ); - } - if( bExportContent ) - { - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, XML_X ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, XML_SECONDARY_X ); - AddAutoStyleAttribute( aPropertyStates ); - pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); - } - else // autostyles - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - - if( bHasSecondaryXAxisTitle ) - { - Reference< chart::XSecondAxisTitleSupplier > xAxisSupp( xDiagram, uno::UNO_QUERY ); - Reference< beans::XPropertySet > xTitleProp( xAxisSupp->getSecondXAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xTitleProp ); - if( bExportContent ) - { - OUString aText; - Any aAny( xTitleProp->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )))); - aAny >>= aText; - - Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY ); - if( xShape.is()) - addPosition( xShape ); - - AddAutoStyleAttribute( aPropertyStates ); - SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True ); - - exportText( aText ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - } - - if( pAxis ) - { - delete pAxis; - pAxis = NULL; - } - } + xAxisProps = xAxisTwoXSupp.is() ? xAxisTwoXSupp->getSecondaryXAxis() : 0; + xTitleProps = ( bHasSecondaryXAxisTitle && xSecondTitleSupp.is() ) ? Reference< beans::XPropertySet >( xSecondTitleSupp->getSecondXAxisTitle(), uno::UNO_QUERY ) : 0; + xMajorGridProps = xMinorGridProps = 0; + exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } // y axis // ------- - - // write axis element also if the axis itself is not visible, but a grid or - // title - Reference< chart::XAxisYSupplier > xAxisYSupp( xDiagram, uno::UNO_QUERY ); - if( xAxisYSupp.is()) + xNewAxis = lcl_getAxis( xCooSys, XML_Y ); + if( xNewAxis.is() ) { - bool bHasAxisProperties = false; - // get property states for autostyles - if( mxExpPropMapper.is()) - { - xPropSet = xAxisYSupp->getYAxis(); - if( xPropSet.is()) - { - bHasAxisProperties = true; - lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport ); - aPropertyStates = mxExpPropMapper->Filter( xPropSet ); - } - } - - if( bHasYAxis || - bHasYAxisTitle || bHasYAxisMajorGrid || bHasYAxisMinorGrid || bHasAxisProperties ) - { - if( bExportContent ) - { - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, XML_Y ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, XML_PRIMARY_Y ); - AddAutoStyleAttribute( aPropertyStates ); - pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - - // axis-title - if( bHasYAxisTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xAxisYSupp->getYAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xTitleProp ); - if( bExportContent ) - { - OUString aText; - Any aAny( xTitleProp->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )))); - aAny >>= aText; - - Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY ); - if( xShape.is()) - addPosition( xShape ); - - AddAutoStyleAttribute( aPropertyStates ); - SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True ); - - // paragraph containing title - exportText( aText ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - } - - // grid - Reference< beans::XPropertySet > xMajorGrid( xAxisYSupp->getYMainGrid(), uno::UNO_QUERY ); - if( bHasYAxisMajorGrid && xMajorGrid.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xMajorGrid ); - - if( bExportContent ) - { - AddAutoStyleAttribute( aPropertyStates ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, XML_MAJOR ); - SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - // minor grid - Reference< beans::XPropertySet > xMinorGrid( xAxisYSupp->getYHelpGrid(), uno::UNO_QUERY ); - if( bHasYAxisMinorGrid && xMinorGrid.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xMinorGrid ); - - if( bExportContent ) - { - AddAutoStyleAttribute( aPropertyStates ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, XML_MINOR ); - SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - if( pAxis ) - { - delete pAxis; - pAxis = NULL; - } - } + Reference< chart::XAxisYSupplier > xAxisYSupp( xDiagram, uno::UNO_QUERY ); + xAxisProps = xAxisYSupp.is() ? xAxisYSupp->getYAxis() : 0; + xTitleProps = (bHasYAxisTitle && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYAxisTitle(), uno::UNO_QUERY ) : 0; + xMajorGridProps = (bHasYAxisMajorGrid && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYMainGrid(), uno::UNO_QUERY ) : 0; + xMinorGridProps = (bHasYAxisMinorGrid && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYHelpGrid(), uno::UNO_QUERY ) : 0; + exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } - if( bHasSecondaryYAxis || bHasSecondaryYAxisTitle ) + // secondary y axis + // ------- + xNewAxis = lcl_getAxis( xCooSys, XML_Y, false ); + if( xNewAxis.is() ) { Reference< chart::XTwoAxisYSupplier > xAxisTwoYSupp( xDiagram, uno::UNO_QUERY ); - if( xAxisTwoYSupp.is()) - { - // get property states for autostyles - if( mxExpPropMapper.is()) - { - xPropSet = xAxisTwoYSupp->getSecondaryYAxis(); - lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport ); - if( xPropSet.is()) - aPropertyStates = mxExpPropMapper->Filter( xPropSet ); - } - if( bExportContent ) - { - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, XML_Y ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, XML_SECONDARY_Y ); - AddAutoStyleAttribute( aPropertyStates ); - pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); - } - else // autostyles - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - if( bHasSecondaryYAxisTitle ) - { - Reference< chart::XSecondAxisTitleSupplier > xAxisSupp( xDiagram, uno::UNO_QUERY ); - Reference< beans::XPropertySet > xTitleProp( xAxisSupp->getSecondYAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xTitleProp ); - if( bExportContent ) - { - OUString aText; - Any aAny( xTitleProp->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )))); - aAny >>= aText; - - Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY ); - if( xShape.is()) - addPosition( xShape ); - - AddAutoStyleAttribute( aPropertyStates ); - SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True ); - - exportText( aText ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - } - - if( pAxis ) - { - delete pAxis; - pAxis = NULL; - } - } + xAxisProps = xAxisTwoYSupp.is() ? xAxisTwoYSupp->getSecondaryYAxis() : 0; + xTitleProps = ( bHasSecondaryYAxisTitle && xSecondTitleSupp.is() ) ? Reference< beans::XPropertySet >( xSecondTitleSupp->getSecondYAxisTitle(), uno::UNO_QUERY ) : 0; + xMajorGridProps = xMinorGridProps = 0; + exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } // z axis // ------- - - if( bHasZAxis && - bIs3DChart ) + xNewAxis = lcl_getAxis( xCooSys, XML_Z ); + if( xNewAxis.is() ) { Reference< chart::XAxisZSupplier > xAxisZSupp( xDiagram, uno::UNO_QUERY ); - if( xAxisZSupp.is()) - { - // get property states for autostyles - if( mxExpPropMapper.is()) - { - xPropSet = xAxisZSupp->getZAxis(); - lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport ); - if( xPropSet.is()) - aPropertyStates = mxExpPropMapper->Filter( xPropSet ); - } - if( bExportContent ) - { - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, XML_Z ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, XML_PRIMARY_Z ); - - AddAutoStyleAttribute( aPropertyStates ); - pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - - // axis-title - if( bHasZAxisTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xAxisZSupp->getZAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xTitleProp ); - if( bExportContent ) - { - OUString aText; - Any aAny( xTitleProp->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )))); - aAny >>= aText; - - Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY ); - if( xShape.is()) - addPosition( xShape ); - - AddAutoStyleAttribute( aPropertyStates ); - SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True ); - - // paragraph containing title - exportText( aText ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - } - - // grid - Reference< beans::XPropertySet > xMajorGrid( xAxisZSupp->getZMainGrid(), uno::UNO_QUERY ); - if( bHasZAxisMajorGrid && xMajorGrid.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xMajorGrid ); - - if( bExportContent ) - { - AddAutoStyleAttribute( aPropertyStates ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, XML_MAJOR ); - SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - // minor grid - Reference< beans::XPropertySet > xMinorGrid( xAxisZSupp->getZHelpGrid(), uno::UNO_QUERY ); - if( bHasZAxisMinorGrid && xMinorGrid.is()) - { - aPropertyStates = mxExpPropMapper->Filter( xMinorGrid ); - - if( bExportContent ) - { - AddAutoStyleAttribute( aPropertyStates ); - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, XML_MINOR ); - SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True ); - } - else - { - CollectAutoStyle( aPropertyStates ); - } - aPropertyStates.clear(); - } - } - if( pAxis ) - { - delete pAxis; - pAxis = NULL; - } + xAxisProps = xAxisZSupp.is() ? xAxisZSupp->getZAxis() : 0; + xTitleProps = (bHasZAxisTitle && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZAxisTitle(), uno::UNO_QUERY ) : 0; + xMajorGridProps = (bHasZAxisMajorGrid && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZMainGrid(), uno::UNO_QUERY ) : 0; + xMinorGridProps = (bHasZAxisMinorGrid && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZHelpGrid(), uno::UNO_QUERY ) : 0; + exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } } -- cgit From 48d05bbab7dcffa551070070ca27c7e33a2e2bdc Mon Sep 17 00:00:00 2001 From: Ingrid Halama Date: Thu, 18 Nov 2010 15:33:19 +0100 Subject: chart46: #i115651# separate axis import code --- xmloff/source/chart/SchXMLAxisContext.cxx | 1018 +++++++++++++++++++++++++ xmloff/source/chart/SchXMLAxisContext.hxx | 79 ++ xmloff/source/chart/SchXMLPlotAreaContext.cxx | 942 +---------------------- xmloff/source/chart/SchXMLPlotAreaContext.hxx | 61 -- xmloff/source/chart/makefile.mk | 1 + 5 files changed, 1100 insertions(+), 1001 deletions(-) create mode 100755 xmloff/source/chart/SchXMLAxisContext.cxx create mode 100755 xmloff/source/chart/SchXMLAxisContext.hxx (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx new file mode 100755 index 000000000000..95edd71e0b68 --- /dev/null +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -0,0 +1,1018 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include "SchXMLAxisContext.hxx" +#include "SchXMLChartContext.hxx" +#include "SchXMLTools.hxx" +#include "xmlnmspe.hxx" +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +using namespace ::xmloff::token; +using namespace com::sun::star; + +using rtl::OUString; +using com::sun::star::uno::Reference; + +//---------------------------------------- +//---------------------------------------- + +static __FAR_DATA SvXMLEnumMapEntry aXMLAxisClassMap[] = +{ + { XML_X, SCH_XML_AXIS_X }, + { XML_Y, SCH_XML_AXIS_Y }, + { XML_Z, SCH_XML_AXIS_Z }, + { XML_TOKEN_INVALID, 0 } +}; + +//---------------------------------------- +//---------------------------------------- + +class SchXMLCategoriesContext : public SvXMLImportContext +{ +private: + SchXMLImportHelper& mrImportHelper; + OUString& mrAddress; + +public: + SchXMLCategoriesContext( SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + OUString& rAddress ); + virtual ~SchXMLCategoriesContext(); + virtual void StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); +}; + +//---------------------------------------- +//---------------------------------------- + +SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, const OUString& rLocalName, + Reference< chart::XDiagram > xDiagram, + std::vector< SchXMLAxis >& aAxes, + OUString & rCategoriesAddress, + bool bAddMissingXAxisForNetCharts, + bool bAdaptWrongPercentScaleValues, + bool bAdaptXAxisOrientationForOld2DBarCharts, + bool& rbAxisPositionAttributeImported ) : + SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), + mrImportHelper( rImpHelper ), + mxDiagram( xDiagram ), + maAxes( aAxes ), + mrCategoriesAddress( rCategoriesAddress ), + mbAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ), + mbAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ), + mbAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ), + m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported ) +{ +} + +SchXMLAxisContext::~SchXMLAxisContext() +{} + +/* returns a shape for the current axis's title. The property + "Has...AxisTitle" is set to "True" to get the shape + */ +Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() +{ + Reference< drawing::XShape > xResult; + uno::Any aTrueBool; + aTrueBool <<= (sal_Bool)(sal_True); + Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY ); + + switch( maCurrentAxis.eClass ) + { + case SCH_XML_AXIS_X: + if( maCurrentAxis.nIndexInCategory == 0 ) + { + Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii( "HasXAxisTitle" ), aTrueBool ); + xResult = Reference< drawing::XShape >( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); + } + } + else + { + Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() ) + { + if( xDiaProp.is() ) + xDiaProp->setPropertyValue( OUString::createFromAscii( "HasSecondaryXAxisTitle" ), aTrueBool ); + xResult = Reference< drawing::XShape >( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); + } + } + break; + case SCH_XML_AXIS_Y: + if( maCurrentAxis.nIndexInCategory == 0 ) + { + Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii( "HasYAxisTitle" ), aTrueBool ); + xResult = Reference< drawing::XShape >( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); + } + } + else + { + Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() ) + { + if( xDiaProp.is() ) + xDiaProp->setPropertyValue( OUString::createFromAscii( "HasSecondaryYAxisTitle" ), aTrueBool ); + xResult = Reference< drawing::XShape >( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); + } + } + break; + case SCH_XML_AXIS_Z: + { + Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii( "HasZAxisTitle" ), aTrueBool ); + xResult = Reference< drawing::XShape >( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); + } + break; + } + case SCH_XML_AXIS_UNDEF: + DBG_ERROR( "Invalid axis" ); + break; + } + + return xResult; +} + +void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, + sal_Bool bIsMajor ) +{ + Reference< chart::XDiagram > xDia = mrImportHelper.GetChartDocument()->getDiagram(); + Reference< beans::XPropertySet > xGridProp; + OUString sPropertyName; + DBG_ASSERT( xDia.is(), "diagram object is invalid!" ); + + Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY ); + uno::Any aTrueBool( uno::makeAny( true )); + + switch( maCurrentAxis.eClass ) + { + case SCH_XML_AXIS_X: + { + Reference< chart::XAxisXSupplier > xSuppl( xDia, uno::UNO_QUERY ); + if( xSuppl.is()) + { + if( bIsMajor ) + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii("HasXAxisGrid"), aTrueBool ); + xGridProp = xSuppl->getXMainGrid(); + } + else + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii("HasXAxisHelpGrid"), aTrueBool ); + xGridProp = xSuppl->getXHelpGrid(); + } + } + } + break; + case SCH_XML_AXIS_Y: + { + Reference< chart::XAxisYSupplier > xSuppl( xDia, uno::UNO_QUERY ); + if( xSuppl.is()) + { + if( bIsMajor ) + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii("HasYAxisGrid"), aTrueBool ); + xGridProp = xSuppl->getYMainGrid(); + } + else + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii("HasYAxisHelpGrid"), aTrueBool ); + xGridProp = xSuppl->getYHelpGrid(); + } + } + } + break; + case SCH_XML_AXIS_Z: + { + Reference< chart::XAxisZSupplier > xSuppl( xDia, uno::UNO_QUERY ); + if( xSuppl.is()) + { + if( bIsMajor ) + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii("HasZAxisGrid"), aTrueBool ); + xGridProp = xSuppl->getZMainGrid(); + } + else + { + if( xDiaProp.is()) + xDiaProp->setPropertyValue( OUString::createFromAscii("HasZAxisHelpGrid"), aTrueBool ); + xGridProp = xSuppl->getZHelpGrid(); + } + } + } + break; + case SCH_XML_AXIS_UNDEF: + DBG_ERROR( "Invalid axis" ); + break; + } + + // set properties + if( xGridProp.is()) + { + // the line color is black as default, in the model it is a light gray + xGridProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), + uno::makeAny( COL_BLACK )); + if( sAutoStyleName.getLength()) + { + const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); + if( pStylesCtxt ) + { + const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( + mrImportHelper.GetChartFamilyID(), sAutoStyleName ); + + if( pStyle && pStyle->ISA( XMLPropStyleContext )) + (( XMLPropStyleContext* )pStyle )->FillPropertySet( xGridProp ); + } + } + } +} + +void SchXMLAxisContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList ) +{ + // parse attributes + sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; + SchXMLImport& rImport = ( SchXMLImport& )GetImport(); + const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetAxisAttrTokenMap(); + + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + OUString aValue = xAttrList->getValueByIndex( i ); + USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + switch( rAttrTokenMap.Get( nPrefix, aLocalName )) + { + case XML_TOK_AXIS_DIMENSION: + { + USHORT nEnumVal; + if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisClassMap )) + maCurrentAxis.eClass = ( SchXMLAxisClass )nEnumVal; + } + break; + case XML_TOK_AXIS_NAME: + maCurrentAxis.aName = aValue; + break; + case XML_TOK_AXIS_STYLE_NAME: + msAutoStyleName = aValue; + break; + } + } + + // check for number of axes with same category + maCurrentAxis.nIndexInCategory = 0; + sal_Int32 nNumOfAxes = maAxes.size(); + for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ ) + { + if( maAxes[ nCurrent ].eClass == maCurrentAxis.eClass ) + maCurrentAxis.nIndexInCategory++; + } + CreateAxis(); +} +namespace +{ + +Reference< chart2::XAxis > lcl_getAxis( const Reference< frame::XModel >& xChartModel, + sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) +{ + Reference< chart2::XAxis > xAxis; + + try + { + Reference< chart2::XChartDocument > xChart2Document( xChartModel, uno::UNO_QUERY ); + if( xChart2Document.is() ) + { + Reference< chart2::XDiagram > xDiagram( xChart2Document->getFirstDiagram()); + Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW ); + uno::Sequence< Reference< chart2::XCoordinateSystem > > + aCooSysSeq( xCooSysCnt->getCoordinateSystems()); + sal_Int32 nCooSysIndex = 0; + if( nCooSysIndex < aCooSysSeq.getLength() ) + { + Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] ); + if( xCooSys.is() && nDimensionIndex < xCooSys->getDimension() ) + { + const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); + if( nAxisIndex <= nMaxAxisIndex ) + xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ); + } + } + } + } + catch( uno::Exception & ) + { + DBG_ERROR( "Couldn't get axis" ); + } + + return xAxis; +} + +bool lcl_divideBy100( uno::Any& rDoubleAny ) +{ + bool bChanged = false; + double fValue=0.0; + if( (rDoubleAny>>=fValue) && (fValue!=0.0) ) + { + fValue/=100.0; + rDoubleAny = uno::makeAny(fValue); + bChanged = true; + } + return bChanged; +} + +bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData) +{ + bool bChanged = lcl_divideBy100( rScaleData.Minimum ); + bChanged = lcl_divideBy100( rScaleData.Maximum ) || bChanged; + bChanged = lcl_divideBy100( rScaleData.Origin ) || bChanged; + bChanged = lcl_divideBy100( rScaleData.IncrementData.Distance ) || bChanged; + return bChanged; +} + +}//end anonymous namespace + +void SchXMLAxisContext::CreateAxis() +{ + // add new Axis to list + maAxes.push_back( maCurrentAxis ); + + // set axis at chart + Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xProp; + uno::Any aTrueBool; + aTrueBool <<= (sal_Bool)(sal_True); + uno::Any aFalseBool; + aFalseBool <<= (sal_Bool)(sal_False); + Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); + + switch( maCurrentAxis.eClass ) + { + case SCH_XML_AXIS_X: + if( maCurrentAxis.nIndexInCategory == 0 ) + { + try + { + xDiaProp->setPropertyValue( + OUString::createFromAscii( "HasXAxis" ), aTrueBool ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on x axis" ); + } + Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + xProp = xSuppl->getXAxis(); + } + else + { + try + { + xDiaProp->setPropertyValue( + OUString::createFromAscii( "HasSecondaryXAxis" ), aTrueBool ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on second x axis" ); + } + Reference< chart::XTwoAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + xProp = xSuppl->getSecondaryXAxis(); + } + break; + + case SCH_XML_AXIS_Y: + if( maCurrentAxis.nIndexInCategory == 0 ) + { + try + { + xDiaProp->setPropertyValue( + OUString::createFromAscii( "HasYAxis" ), aTrueBool ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on y axis" ); + } + Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + xProp = xSuppl->getYAxis(); + + + if( mbAddMissingXAxisForNetCharts ) + { + if( xDiaProp.is() ) + { + try + { + xDiaProp->setPropertyValue( + OUString::createFromAscii( "HasXAxis" ), uno::makeAny(sal_True) ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on x axis" ); + } + } + } + } + else + { + try + { + xDiaProp->setPropertyValue( + OUString::createFromAscii( "HasSecondaryYAxis" ), aTrueBool ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on second y axis" ); + } + Reference< chart::XTwoAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + xProp = xSuppl->getSecondaryYAxis(); + } + break; + + case SCH_XML_AXIS_Z: + { + bool bSettingZAxisSuccedded = false; + try + { + OUString sHasZAxis( OUString::createFromAscii( "HasZAxis" ) ); + xDiaProp->setPropertyValue( sHasZAxis, aTrueBool ); + xDiaProp->getPropertyValue( sHasZAxis ) >>= bSettingZAxisSuccedded; + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on z axis" ); + } + if( bSettingZAxisSuccedded ) + { + Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is()) + xProp = xSuppl->getZAxis(); + } + } + break; + case SCH_XML_AXIS_UNDEF: + // nothing + break; + } + + // set properties + if( xProp.is()) + { + // #i109879# the line color is black as default, in the model it is a light gray + xProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), + uno::makeAny( COL_BLACK )); + + xProp->setPropertyValue( OUString::createFromAscii( "DisplayLabels" ), aFalseBool ); + + // #88077# AutoOrigin 'on' is default + xProp->setPropertyValue( OUString::createFromAscii( "AutoOrigin" ), aTrueBool ); + + if( msAutoStyleName.getLength()) + { + const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); + if( pStylesCtxt ) + { + const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( + mrImportHelper.GetChartFamilyID(), msAutoStyleName ); + + if( pStyle && pStyle->ISA( XMLPropStyleContext )) + { + // note: SvXMLStyleContext::FillPropertySet is not const + XMLPropStyleContext * pPropStyleContext = const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle )); + if( pPropStyleContext ) + pPropStyleContext->FillPropertySet( xProp ); + + if( mbAdaptWrongPercentScaleValues && maCurrentAxis.eClass==SCH_XML_AXIS_Y ) + { + //set scale data of added x axis back to default + Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), + 1 /*nDimensionIndex*/, maCurrentAxis.nIndexInCategory /*nAxisIndex*/ ) ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData( xAxis->getScaleData()); + if( lcl_AdaptWrongPercentScaleValues(aScaleData) ) + xAxis->setScaleData( aScaleData ); + } + } + + if( mbAddMissingXAxisForNetCharts ) + { + //copy style from y axis to added x axis: + + Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() ) + { + Reference< beans::XPropertySet > xXAxisProp( xSuppl->getXAxis() ); + (( XMLPropStyleContext* )pStyle )->FillPropertySet( xXAxisProp ); + } + + //set scale data of added x axis back to default + Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), + 0 /*nDimensionIndex*/, 0 /*nAxisIndex*/ ) ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData; + aScaleData.AxisType = chart2::AxisType::CATEGORY; + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + xAxis->setScaleData( aScaleData ); + } + + //set line style of added x axis to invisible + Reference< beans::XPropertySet > xNewAxisProp( xAxis, uno::UNO_QUERY ); + if( xNewAxisProp.is() ) + { + xNewAxisProp->setPropertyValue( OUString::createFromAscii("LineStyle") + , uno::makeAny(drawing::LineStyle_NONE)); + } + } + + if( mbAdaptXAxisOrientationForOld2DBarCharts && maCurrentAxis.eClass == SCH_XML_AXIS_X ) + { + bool bIs3DChart = false; + if( xDiaProp.is() && ( xDiaProp->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3DChart ) + && !bIs3DChart ) + { + Reference< chart2::XChartDocument > xChart2Document( GetImport().GetModel(), uno::UNO_QUERY ); + if( xChart2Document.is() ) + { + Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChart2Document->getFirstDiagram(), uno::UNO_QUERY ); + if( xCooSysCnt.is() ) + { + uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() ); + if( aCooSysSeq.getLength() ) + { + bool bSwapXandYAxis = false; + Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] ); + Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY ); + if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("SwapXAndYAxis"))) >>= bSwapXandYAxis ) + && bSwapXandYAxis ) + { + Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, maCurrentAxis.nIndexInCategory ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Orientation = chart2::AxisOrientation_REVERSE; + xAxis->setScaleData( aScaleData ); + } + } + } + } + } + } + } + + m_rbAxisPositionAttributeImported = m_rbAxisPositionAttributeImported || SchXMLTools::getPropertyFromContext( + OUString(RTL_CONSTASCII_USTRINGPARAM("CrossoverPosition")), pPropStyleContext, pStylesCtxt ).hasValue(); + } + } + } + } +} + +void SchXMLAxisContext::SetAxisTitle() +{ + // add new Axis to list + maAxes.push_back( maCurrentAxis ); + + // set axis at chart + sal_Bool bHasTitle = ( maCurrentAxis.aTitle.getLength() > 0 ); + Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); + + switch( maCurrentAxis.eClass ) + { + case SCH_XML_AXIS_X: + if( maCurrentAxis.nIndexInCategory == 0 ) + { + Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && + bHasTitle ) + { + Reference< beans::XPropertySet > xTitleProp( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); + if( xTitleProp.is()) + { + try + { + uno::Any aAny; + aAny <<= maCurrentAxis.aTitle; + xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Property String for Title not available" ); + } + } + } + } + else + { + Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && + bHasTitle ) + { + Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); + if( xTitleProp.is()) + { + try + { + uno::Any aAny; + aAny <<= maCurrentAxis.aTitle; + xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Property String for Title not available" ); + } + } + } + } + break; + + case SCH_XML_AXIS_Y: + if( maCurrentAxis.nIndexInCategory == 0 ) + { + Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && + bHasTitle ) + { + Reference< beans::XPropertySet > xTitleProp( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); + if( xTitleProp.is()) + { + try + { + uno::Any aAny; + aAny <<= maCurrentAxis.aTitle; + xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Property String for Title not available" ); + } + } + } + } + else + { + Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && + bHasTitle ) + { + Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); + if( xTitleProp.is()) + { + try + { + uno::Any aAny; + aAny <<= maCurrentAxis.aTitle; + xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Property String for Title not available" ); + } + } + } + } + break; + + case SCH_XML_AXIS_Z: + { + Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && + bHasTitle ) + { + Reference< beans::XPropertySet > xTitleProp( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); + if( xTitleProp.is()) + { + try + { + uno::Any aAny; + aAny <<= maCurrentAxis.aTitle; + xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Property String for Title not available" ); + } + } + } + } + break; + case SCH_XML_AXIS_UNDEF: + // nothing + break; + } +} + +SvXMLImportContext* SchXMLAxisContext::CreateChildContext( + USHORT p_nPrefix, + const OUString& rLocalName, + const Reference< xml::sax::XAttributeList >& xAttrList ) +{ + SvXMLImportContext* pContext = 0; + const SvXMLTokenMap& rTokenMap = mrImportHelper.GetAxisElemTokenMap(); + + switch( rTokenMap.Get( p_nPrefix, rLocalName )) + { + case XML_TOK_AXIS_TITLE: + { + Reference< drawing::XShape > xTitleShape = getTitleShape(); + pContext = new SchXMLTitleContext( mrImportHelper, GetImport(), rLocalName, + maCurrentAxis.aTitle, + xTitleShape ); + } + break; + + case XML_TOK_AXIS_CATEGORIES: + pContext = new SchXMLCategoriesContext( mrImportHelper, GetImport(), + p_nPrefix, rLocalName, + mrCategoriesAddress ); + maCurrentAxis.bHasCategories = true; + break; + + case XML_TOK_AXIS_GRID: + { + sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; + sal_Bool bIsMajor = sal_True; // default value for class is "major" + OUString sAutoStyleName; + + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + if( nPrefix == XML_NAMESPACE_CHART ) + { + if( IsXMLToken( aLocalName, XML_CLASS ) ) + { + if( IsXMLToken( xAttrList->getValueByIndex( i ), XML_MINOR ) ) + bIsMajor = sal_False; + } + else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) ) + sAutoStyleName = xAttrList->getValueByIndex( i ); + } + } + + CreateGrid( sAutoStyleName, bIsMajor ); + + // don't create a context => use default context. grid elements are empty + pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); + } + break; + + default: + pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); + break; + } + + return pContext; +} + +void SchXMLAxisContext::EndElement() +{ + SetAxisTitle(); +} + +// ======================================== + +namespace +{ + +Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem > xCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) +{ + Reference< chart2::XAxis > xAxis; + try + { + xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ); + } + catch( uno::Exception & ) + { + } + return xAxis; +} + +} // anonymous namespace + +void SchXMLAxisContext::CorrectAxisPositions( const Reference< chart2::XChartDocument >& xNewDoc, + const OUString& rChartTypeServiceName, + const OUString& rODFVersionOfFile, + bool bAxisPositionAttributeImported ) +{ + if( ( !rODFVersionOfFile.getLength() || rODFVersionOfFile.equalsAscii("1.0") + || rODFVersionOfFile.equalsAscii("1.1") + || ( rODFVersionOfFile.equalsAscii("1.2") && !bAxisPositionAttributeImported ) ) ) + { + try + { + Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDoc->getFirstDiagram(), uno::UNO_QUERY_THROW ); + uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); + if( aCooSysSeq.getLength() ) + { + Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] ); + if( xCooSys.is() ) + { + Reference< chart2::XAxis > xMainXAxis = lcl_getAxis( xCooSys, 0, 0 ); + Reference< chart2::XAxis > xMainYAxis = lcl_getAxis( xCooSys, 1, 0 ); + //Reference< chart2::XAxis > xMajorZAxis = lcl_getAxis( xCooSys, 2, 0 ); + Reference< chart2::XAxis > xSecondaryXAxis = lcl_getAxis( xCooSys, 0, 1 ); + Reference< chart2::XAxis > xSecondaryYAxis = lcl_getAxis( xCooSys, 1, 1 ); + + Reference< beans::XPropertySet > xMainXAxisProp( xMainXAxis, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xMainYAxisProp( xMainYAxis, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xSecondaryXAxisProp( xSecondaryXAxis, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xSecondaryYAxisProp( xSecondaryYAxis, uno::UNO_QUERY ); + + if( xMainXAxisProp.is() && xMainYAxisProp.is() ) + { + chart2::ScaleData aMainXScale = xMainXAxis->getScaleData(); + if( 0 == rChartTypeServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ScatterChartType" ) ) ) + { + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) ); + double fCrossoverValue = 0.0; + aMainXScale.Origin >>= fCrossoverValue; + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverValue") + , uno::makeAny( fCrossoverValue ) ); + + if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE ) + { + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("LabelPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) ); + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("MarkPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); + if( xSecondaryYAxisProp.is() ) + xSecondaryYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); + } + else + { + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("LabelPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) ); + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("MarkPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); + if( xSecondaryYAxisProp.is() ) + xSecondaryYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); + } + } + else + { + if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE ) + { + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); + if( xSecondaryYAxisProp.is() ) + xSecondaryYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); + } + else + { + xMainYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); + if( xSecondaryYAxisProp.is() ) + xSecondaryYAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); + } + } + + chart2::ScaleData aMainYScale = xMainYAxis->getScaleData(); + xMainXAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) ); + double fCrossoverValue = 0.0; + aMainYScale.Origin >>= fCrossoverValue; + xMainXAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverValue") + , uno::makeAny( fCrossoverValue ) ); + + if( aMainYScale.Orientation == chart2::AxisOrientation_REVERSE ) + { + xMainXAxisProp->setPropertyValue( OUString::createFromAscii("LabelPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) ); + xMainXAxisProp->setPropertyValue( OUString::createFromAscii("MarkPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); + if( xSecondaryXAxisProp.is() ) + xSecondaryXAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); + } + else + { + xMainXAxisProp->setPropertyValue( OUString::createFromAscii("LabelPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) ); + xMainXAxisProp->setPropertyValue( OUString::createFromAscii("MarkPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); + if( xSecondaryXAxisProp.is() ) + xSecondaryXAxisProp->setPropertyValue( OUString::createFromAscii("CrossoverPosition") + , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); + } + } + } + } + } + catch( uno::Exception & ) + { + } + } +} + +// ======================================== + +SchXMLCategoriesContext::SchXMLCategoriesContext( + SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + OUString& rAddress ) : + SvXMLImportContext( rImport, nPrefix, rLocalName ), + mrImportHelper( rImpHelper ), + mrAddress( rAddress ) +{ +} + +SchXMLCategoriesContext::~SchXMLCategoriesContext() +{ +} + +void SchXMLCategoriesContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList ) +{ + sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; + + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + if( nPrefix == XML_NAMESPACE_TABLE && + IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) ) + { + Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY ); + mrAddress = xAttrList->getValueByIndex( i ); + } + } +} + +// ======================================== diff --git a/xmloff/source/chart/SchXMLAxisContext.hxx b/xmloff/source/chart/SchXMLAxisContext.hxx new file mode 100755 index 000000000000..a2e5d3972879 --- /dev/null +++ b/xmloff/source/chart/SchXMLAxisContext.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _SCH_XMLAXISCONTEXT_HXX_ +#define _SCH_XMLAXISCONTEXT_HXX_ + +#include "SchXMLImport.hxx" +#include "transporttypes.hxx" + +// ---------------------------------------- + +class SchXMLAxisContext : public SvXMLImportContext +{ +private: + SchXMLImportHelper& mrImportHelper; + ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > mxDiagram; + SchXMLAxis maCurrentAxis; + std::vector< SchXMLAxis >& maAxes; + rtl::OUString msAutoStyleName; + rtl::OUString& mrCategoriesAddress; + bool mbAddMissingXAxisForNetCharts; //to correct errors from older versions + bool mbAdaptWrongPercentScaleValues; //to correct errors from older versions + bool mbAdaptXAxisOrientationForOld2DBarCharts; //to correct different behaviour from older versions + bool& m_rbAxisPositionAttributeImported; + + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTitleShape(); + void CreateGrid( ::rtl::OUString sAutoStyleName, sal_Bool bIsMajor ); + void CreateAxis(); + void SetAxisTitle(); + +public: + SchXMLAxisContext( SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, const rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > xDiagram, + std::vector< SchXMLAxis >& aAxes, + ::rtl::OUString& rCategoriesAddress, + bool bAddMissingXAxisForNetCharts, + bool bAdaptWrongPercentScaleValues, + bool bAdaptXAxisOrientationForOld2DBarCharts, + bool& rbAxisPositionAttributeImported ); + virtual ~SchXMLAxisContext(); + + virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual void EndElement(); + virtual SvXMLImportContext* CreateChildContext( + USHORT nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + static void CorrectAxisPositions( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xNewDoc, + const ::rtl::OUString& rChartTypeServiceName, + const ::rtl::OUString& rODFVersionOfFile, + bool bAxisPositionAttributeImported ); +}; + +#endif // _SCH_XMLAXISCONTEXT_HXX_ diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx index 9b6731f78da3..1200863365a5 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx @@ -30,6 +30,7 @@ #include "SchXMLPlotAreaContext.hxx" #include "SchXMLImport.hxx" +#include "SchXMLAxisContext.hxx" #include "SchXMLSeries2Context.hxx" #include "SchXMLTools.hxx" #include @@ -39,7 +40,6 @@ #include #include "xmlnmspe.hxx" -#include #include #include #include @@ -51,29 +51,18 @@ #include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include -#include -#include #include #include #include -#include #include #include #include -#include #include #include #include @@ -84,14 +73,6 @@ using namespace ::xmloff::token; using ::rtl::OUString; using com::sun::star::uno::Reference; -static __FAR_DATA SvXMLEnumMapEntry aXMLAxisClassMap[] = -{ - { XML_X, SCH_XML_AXIS_X }, - { XML_Y, SCH_XML_AXIS_Y }, - { XML_Z, SCH_XML_AXIS_Z }, - { XML_TOKEN_INVALID, 0 } -}; - namespace { @@ -115,19 +96,6 @@ OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const uno::Reference< return aResult; } -Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem > xCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) -{ - Reference< chart2::XAxis > xAxis; - try - { - xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ); - } - catch( uno::Exception & ) - { - } - return xAxis; -} - } // anonymous namespace SchXML3DSceneAttributesHelper::SchXML3DSceneAttributesHelper( SvXMLImport& rImporter ) @@ -708,875 +676,7 @@ void SchXMLPlotAreaContext::EndElement() } } - CorrectAxisPositions(); -} - -void SchXMLPlotAreaContext::CorrectAxisPositions() -{ - ::rtl::OUString aODFVersionOfFile( GetImport().GetODFVersion() ); - - if( ( !aODFVersionOfFile.getLength() || aODFVersionOfFile.equalsAscii("1.0") - || aODFVersionOfFile.equalsAscii("1.1") - || ( aODFVersionOfFile.equalsAscii("1.2") && !m_bAxisPositionAttributeImported ) ) ) - { - uno::Reference< chart2::XChartDocument > xNewDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); - - try - { - Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDoc->getFirstDiagram(), uno::UNO_QUERY_THROW ); - uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); - if( aCooSysSeq.getLength() ) - { - Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] ); - if( xCooSys.is() ) - { - Reference< chart2::XAxis > xMainXAxis = lcl_getAxis( xCooSys, 0, 0 ); - Reference< chart2::XAxis > xMainYAxis = lcl_getAxis( xCooSys, 1, 0 ); - //Reference< chart2::XAxis > xMajorZAxis = lcl_getAxis( xCooSys, 2, 0 ); - Reference< chart2::XAxis > xSecondaryXAxis = lcl_getAxis( xCooSys, 0, 1 ); - Reference< chart2::XAxis > xSecondaryYAxis = lcl_getAxis( xCooSys, 1, 1 ); - - uno::Reference< beans::XPropertySet > xMainXAxisProp( xMainXAxis, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xMainYAxisProp( xMainYAxis, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xSecondaryXAxisProp( xSecondaryXAxis, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xSecondaryYAxisProp( xSecondaryYAxis, uno::UNO_QUERY ); - - if( xMainXAxisProp.is() && xMainYAxisProp.is() ) - { - chart2::ScaleData aMainXScale = xMainXAxis->getScaleData(); - if( 0 == maChartTypeServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ScatterChartType" ) ) ) - { - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) ); - double fCrossoverValue = 0.0; - aMainXScale.Origin >>= fCrossoverValue; - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverValue") - , uno::makeAny( fCrossoverValue ) ); - - if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE ) - { - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) ); - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); - if( xSecondaryYAxisProp.is() ) - xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); - } - else - { - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) ); - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); - if( xSecondaryYAxisProp.is() ) - xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); - } - } - else - { - if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE ) - { - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); - if( xSecondaryYAxisProp.is() ) - xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); - } - else - { - xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); - if( xSecondaryYAxisProp.is() ) - xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); - } - } - - chart2::ScaleData aMainYScale = xMainYAxis->getScaleData(); - xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) ); - double fCrossoverValue = 0.0; - aMainYScale.Origin >>= fCrossoverValue; - xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverValue") - , uno::makeAny( fCrossoverValue ) ); - - if( aMainYScale.Orientation == chart2::AxisOrientation_REVERSE ) - { - xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) ); - xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); - if( xSecondaryXAxisProp.is() ) - xSecondaryXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) ); - } - else - { - xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) ); - xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) ); - if( xSecondaryXAxisProp.is() ) - xSecondaryXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition") - , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) ); - } - } - } - } - } - catch( uno::Exception & ) - { - } - } -} - -// ======================================== - -SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper, - SvXMLImport& rImport, const rtl::OUString& rLocalName, - uno::Reference< chart::XDiagram > xDiagram, - std::vector< SchXMLAxis >& aAxes, - ::rtl::OUString & rCategoriesAddress, - bool bAddMissingXAxisForNetCharts, - bool bAdaptWrongPercentScaleValues, - bool bAdaptXAxisOrientationForOld2DBarCharts, - bool& rbAxisPositionAttributeImported ) : - SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), - mrImportHelper( rImpHelper ), - mxDiagram( xDiagram ), - maAxes( aAxes ), - mrCategoriesAddress( rCategoriesAddress ), - mbAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ), - mbAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ), - mbAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ), - m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported ) -{ -} - -SchXMLAxisContext::~SchXMLAxisContext() -{} - -/* returns a shape for the current axis's title. The property - "Has...AxisTitle" is set to "True" to get the shape - */ -uno::Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() -{ - uno::Reference< drawing::XShape > xResult; - uno::Any aTrueBool; - aTrueBool <<= (sal_Bool)(sal_True); - uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY ); - - switch( maCurrentAxis.eClass ) - { - case SCH_XML_AXIS_X: - if( maCurrentAxis.nIndexInCategory == 0 ) - { - uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasXAxisTitle" ), aTrueBool ); - xResult = uno::Reference< drawing::XShape >( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); - } - } - else - { - uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() ) - { - if( xDiaProp.is() ) - xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSecondaryXAxisTitle" ), aTrueBool ); - xResult = uno::Reference< drawing::XShape >( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); - } - } - break; - case SCH_XML_AXIS_Y: - if( maCurrentAxis.nIndexInCategory == 0 ) - { - uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasYAxisTitle" ), aTrueBool ); - xResult = uno::Reference< drawing::XShape >( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); - } - } - else - { - uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() ) - { - if( xDiaProp.is() ) - xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSecondaryYAxisTitle" ), aTrueBool ); - xResult = uno::Reference< drawing::XShape >( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); - } - } - break; - case SCH_XML_AXIS_Z: - { - uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasZAxisTitle" ), aTrueBool ); - xResult = uno::Reference< drawing::XShape >( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); - } - break; - } - case SCH_XML_AXIS_UNDEF: - DBG_ERROR( "Invalid axis" ); - break; - } - - return xResult; -} - -void SchXMLAxisContext::CreateGrid( ::rtl::OUString sAutoStyleName, - sal_Bool bIsMajor ) -{ - uno::Reference< chart::XDiagram > xDia = mrImportHelper.GetChartDocument()->getDiagram(); - uno::Reference< beans::XPropertySet > xGridProp; - ::rtl::OUString sPropertyName; - DBG_ASSERT( xDia.is(), "diagram object is invalid!" ); - - uno::Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY ); - uno::Any aTrueBool( uno::makeAny( true )); - - switch( maCurrentAxis.eClass ) - { - case SCH_XML_AXIS_X: - { - uno::Reference< chart::XAxisXSupplier > xSuppl( xDia, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( bIsMajor ) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasXAxisGrid"), aTrueBool ); - xGridProp = xSuppl->getXMainGrid(); - } - else - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasXAxisHelpGrid"), aTrueBool ); - xGridProp = xSuppl->getXHelpGrid(); - } - } - } - break; - case SCH_XML_AXIS_Y: - { - uno::Reference< chart::XAxisYSupplier > xSuppl( xDia, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( bIsMajor ) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasYAxisGrid"), aTrueBool ); - xGridProp = xSuppl->getYMainGrid(); - } - else - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasYAxisHelpGrid"), aTrueBool ); - xGridProp = xSuppl->getYHelpGrid(); - } - } - } - break; - case SCH_XML_AXIS_Z: - { - uno::Reference< chart::XAxisZSupplier > xSuppl( xDia, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( bIsMajor ) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasZAxisGrid"), aTrueBool ); - xGridProp = xSuppl->getZMainGrid(); - } - else - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasZAxisHelpGrid"), aTrueBool ); - xGridProp = xSuppl->getZHelpGrid(); - } - } - } - break; - case SCH_XML_AXIS_UNDEF: - DBG_ERROR( "Invalid axis" ); - break; - } - - // set properties - if( xGridProp.is()) - { - // the line color is black as default, in the model it is a light gray - xGridProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), - uno::makeAny( COL_BLACK )); - if( sAutoStyleName.getLength()) - { - const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); - if( pStylesCtxt ) - { - const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( - mrImportHelper.GetChartFamilyID(), sAutoStyleName ); - - if( pStyle && pStyle->ISA( XMLPropStyleContext )) - (( XMLPropStyleContext* )pStyle )->FillPropertySet( xGridProp ); - } - } - } -} - -void SchXMLAxisContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) -{ - // parse attributes - sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; - SchXMLImport& rImport = ( SchXMLImport& )GetImport(); - const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetAxisAttrTokenMap(); - - for( sal_Int16 i = 0; i < nAttrCount; i++ ) - { - rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); - rtl::OUString aLocalName; - rtl::OUString aValue = xAttrList->getValueByIndex( i ); - USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - - switch( rAttrTokenMap.Get( nPrefix, aLocalName )) - { - case XML_TOK_AXIS_DIMENSION: - { - USHORT nEnumVal; - if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisClassMap )) - maCurrentAxis.eClass = ( SchXMLAxisClass )nEnumVal; - } - break; - case XML_TOK_AXIS_NAME: - maCurrentAxis.aName = aValue; - break; - case XML_TOK_AXIS_STYLE_NAME: - msAutoStyleName = aValue; - break; - } - } - - // check for number of axes with same category - maCurrentAxis.nIndexInCategory = 0; - sal_Int32 nNumOfAxes = maAxes.size(); - for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ ) - { - if( maAxes[ nCurrent ].eClass == maCurrentAxis.eClass ) - maCurrentAxis.nIndexInCategory++; - } - CreateAxis(); -} -namespace -{ - -uno::Reference< chart2::XAxis > lcl_getAxis( const uno::Reference< frame::XModel >& xChartModel, - sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) -{ - uno::Reference< chart2::XAxis > xAxis; - - try - { - uno::Reference< chart2::XChartDocument > xChart2Document( xChartModel, uno::UNO_QUERY ); - if( xChart2Document.is() ) - { - uno::Reference< chart2::XDiagram > xDiagram( xChart2Document->getFirstDiagram()); - uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW ); - uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > - aCooSysSeq( xCooSysCnt->getCoordinateSystems()); - sal_Int32 nCooSysIndex = 0; - if( nCooSysIndex < aCooSysSeq.getLength() ) - { - uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] ); - if( xCooSys.is() && nDimensionIndex < xCooSys->getDimension() ) - { - const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); - if( nAxisIndex <= nMaxAxisIndex ) - xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ); - } - } - } - } - catch( uno::Exception & ) - { - DBG_ERROR( "Couldn't get axis" ); - } - - return xAxis; -} - -bool lcl_divideBy100( uno::Any& rDoubleAny ) -{ - bool bChanged = false; - double fValue=0.0; - if( (rDoubleAny>>=fValue) && (fValue!=0.0) ) - { - fValue/=100.0; - rDoubleAny = uno::makeAny(fValue); - bChanged = true; - } - return bChanged; -} - -bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData) -{ - bool bChanged = lcl_divideBy100( rScaleData.Minimum ); - bChanged = lcl_divideBy100( rScaleData.Maximum ) || bChanged; - bChanged = lcl_divideBy100( rScaleData.Origin ) || bChanged; - bChanged = lcl_divideBy100( rScaleData.IncrementData.Distance ) || bChanged; - return bChanged; -} - -}//end anonymous namespace - -void SchXMLAxisContext::CreateAxis() -{ - // add new Axis to list - maAxes.push_back( maCurrentAxis ); - - // set axis at chart - uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xProp; - uno::Any aTrueBool; - aTrueBool <<= (sal_Bool)(sal_True); - uno::Any aFalseBool; - aFalseBool <<= (sal_Bool)(sal_False); - uno::Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); - - switch( maCurrentAxis.eClass ) - { - case SCH_XML_AXIS_X: - if( maCurrentAxis.nIndexInCategory == 0 ) - { - try - { - xDiaProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasXAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on x axis" ); - } - uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - xProp = xSuppl->getXAxis(); - } - else - { - try - { - xDiaProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on second x axis" ); - } - uno::Reference< chart::XTwoAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - xProp = xSuppl->getSecondaryXAxis(); - } - break; - - case SCH_XML_AXIS_Y: - if( maCurrentAxis.nIndexInCategory == 0 ) - { - try - { - xDiaProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasYAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on y axis" ); - } - uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - xProp = xSuppl->getYAxis(); - - - if( mbAddMissingXAxisForNetCharts ) - { - if( xDiaProp.is() ) - { - try - { - xDiaProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasXAxis" ), uno::makeAny(sal_True) ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on x axis" ); - } - } - } - } - else - { - try - { - xDiaProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on second y axis" ); - } - uno::Reference< chart::XTwoAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - xProp = xSuppl->getSecondaryYAxis(); - } - break; - - case SCH_XML_AXIS_Z: - { - bool bSettingZAxisSuccedded = false; - try - { - rtl::OUString sHasZAxis( rtl::OUString::createFromAscii( "HasZAxis" ) ); - xDiaProp->setPropertyValue( sHasZAxis, aTrueBool ); - xDiaProp->getPropertyValue( sHasZAxis ) >>= bSettingZAxisSuccedded; - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on z axis" ); - } - if( bSettingZAxisSuccedded ) - { - uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - xProp = xSuppl->getZAxis(); - } - } - break; - case SCH_XML_AXIS_UNDEF: - // nothing - break; - } - - // set properties - if( xProp.is()) - { - // #i109879# the line color is black as default, in the model it is a light gray - xProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), - uno::makeAny( COL_BLACK )); - - xProp->setPropertyValue( rtl::OUString::createFromAscii( "DisplayLabels" ), aFalseBool ); - - // #88077# AutoOrigin 'on' is default - xProp->setPropertyValue( rtl::OUString::createFromAscii( "AutoOrigin" ), aTrueBool ); - - if( msAutoStyleName.getLength()) - { - const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); - if( pStylesCtxt ) - { - const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( - mrImportHelper.GetChartFamilyID(), msAutoStyleName ); - - if( pStyle && pStyle->ISA( XMLPropStyleContext )) - { - // note: SvXMLStyleContext::FillPropertySet is not const - XMLPropStyleContext * pPropStyleContext = const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle )); - if( pPropStyleContext ) - pPropStyleContext->FillPropertySet( xProp ); - - if( mbAdaptWrongPercentScaleValues && maCurrentAxis.eClass==SCH_XML_AXIS_Y ) - { - //set scale data of added x axis back to default - uno::Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), - 1 /*nDimensionIndex*/, maCurrentAxis.nIndexInCategory /*nAxisIndex*/ ) ); - if( xAxis.is() ) - { - chart2::ScaleData aScaleData( xAxis->getScaleData()); - if( lcl_AdaptWrongPercentScaleValues(aScaleData) ) - xAxis->setScaleData( aScaleData ); - } - } - - if( mbAddMissingXAxisForNetCharts ) - { - //copy style from y axis to added x axis: - - uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() ) - { - uno::Reference< beans::XPropertySet > xXAxisProp( xSuppl->getXAxis() ); - (( XMLPropStyleContext* )pStyle )->FillPropertySet( xXAxisProp ); - } - - //set scale data of added x axis back to default - uno::Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), - 0 /*nDimensionIndex*/, 0 /*nAxisIndex*/ ) ); - if( xAxis.is() ) - { - chart2::ScaleData aScaleData; - aScaleData.AxisType = chart2::AxisType::CATEGORY; - aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; - xAxis->setScaleData( aScaleData ); - } - - //set line style of added x axis to invisible - uno::Reference< beans::XPropertySet > xNewAxisProp( xAxis, uno::UNO_QUERY ); - if( xNewAxisProp.is() ) - { - xNewAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LineStyle") - , uno::makeAny(drawing::LineStyle_NONE)); - } - } - - if( mbAdaptXAxisOrientationForOld2DBarCharts && maCurrentAxis.eClass == SCH_XML_AXIS_X ) - { - bool bIs3DChart = false; - if( xDiaProp.is() && ( xDiaProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3DChart ) - && !bIs3DChart ) - { - uno::Reference< chart2::XChartDocument > xChart2Document( GetImport().GetModel(), uno::UNO_QUERY ); - if( xChart2Document.is() ) - { - uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChart2Document->getFirstDiagram(), uno::UNO_QUERY ); - if( xCooSysCnt.is() ) - { - uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() ); - if( aCooSysSeq.getLength() ) - { - bool bSwapXandYAxis = false; - uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] ); - uno::Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY ); - if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwapXAndYAxis"))) >>= bSwapXandYAxis ) - && bSwapXandYAxis ) - { - uno::Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, maCurrentAxis.nIndexInCategory ); - if( xAxis.is() ) - { - chart2::ScaleData aScaleData = xAxis->getScaleData(); - aScaleData.Orientation = chart2::AxisOrientation_REVERSE; - xAxis->setScaleData( aScaleData ); - } - } - } - } - } - } - } - - m_rbAxisPositionAttributeImported = m_rbAxisPositionAttributeImported || SchXMLTools::getPropertyFromContext( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CrossoverPosition")), pPropStyleContext, pStylesCtxt ).hasValue(); - } - } - } - } -} - -void SchXMLAxisContext::SetAxisTitle() -{ - // add new Axis to list - maAxes.push_back( maCurrentAxis ); - - // set axis at chart - sal_Bool bHasTitle = ( maCurrentAxis.aTitle.getLength() > 0 ); - uno::Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); - - switch( maCurrentAxis.eClass ) - { - case SCH_XML_AXIS_X: - if( maCurrentAxis.nIndexInCategory == 0 ) - { - uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) - { - uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; - xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - else - { - uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) - { - uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; - xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - break; - - case SCH_XML_AXIS_Y: - if( maCurrentAxis.nIndexInCategory == 0 ) - { - uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) - { - uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; - xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - else - { - uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) - { - uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; - xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - break; - - case SCH_XML_AXIS_Z: - { - uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) - { - uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; - xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - break; - case SCH_XML_AXIS_UNDEF: - // nothing - break; - } -} - -SvXMLImportContext* SchXMLAxisContext::CreateChildContext( - USHORT p_nPrefix, - const rtl::OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList ) -{ - SvXMLImportContext* pContext = 0; - const SvXMLTokenMap& rTokenMap = mrImportHelper.GetAxisElemTokenMap(); - - switch( rTokenMap.Get( p_nPrefix, rLocalName )) - { - case XML_TOK_AXIS_TITLE: - { - uno::Reference< drawing::XShape > xTitleShape = getTitleShape(); - pContext = new SchXMLTitleContext( mrImportHelper, GetImport(), rLocalName, - maCurrentAxis.aTitle, - xTitleShape ); - } - break; - - case XML_TOK_AXIS_CATEGORIES: - pContext = new SchXMLCategoriesContext( mrImportHelper, GetImport(), - p_nPrefix, rLocalName, - mrCategoriesAddress ); - maCurrentAxis.bHasCategories = true; - break; - - case XML_TOK_AXIS_GRID: - { - sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; - sal_Bool bIsMajor = sal_True; // default value for class is "major" - rtl::OUString sAutoStyleName; - - for( sal_Int16 i = 0; i < nAttrCount; i++ ) - { - rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); - rtl::OUString aLocalName; - USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - - if( nPrefix == XML_NAMESPACE_CHART ) - { - if( IsXMLToken( aLocalName, XML_CLASS ) ) - { - if( IsXMLToken( xAttrList->getValueByIndex( i ), XML_MINOR ) ) - bIsMajor = sal_False; - } - else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) ) - sAutoStyleName = xAttrList->getValueByIndex( i ); - } - } - - CreateGrid( sAutoStyleName, bIsMajor ); - - // don't create a context => use default context. grid elements are empty - pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); - } - break; - - default: - pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); - break; - } - - return pContext; -} - -void SchXMLAxisContext::EndElement() -{ - SetAxisTitle(); + SchXMLAxisContext::CorrectAxisPositions( uno::Reference< chart2::XChartDocument >( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ), maChartTypeServiceName, GetImport().GetODFVersion(), m_bAxisPositionAttributeImported ); } // ======================================== @@ -1636,44 +736,6 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr // ======================================== -SchXMLCategoriesContext::SchXMLCategoriesContext( - SchXMLImportHelper& rImpHelper, - SvXMLImport& rImport, - sal_uInt16 nPrefix, - const rtl::OUString& rLocalName, - rtl::OUString& rAddress ) : - SvXMLImportContext( rImport, nPrefix, rLocalName ), - mrImportHelper( rImpHelper ), - mrAddress( rAddress ) -{ -} - -SchXMLCategoriesContext::~SchXMLCategoriesContext() -{ -} - -void SchXMLCategoriesContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) -{ - sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; - - for( sal_Int16 i = 0; i < nAttrCount; i++ ) - { - rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); - rtl::OUString aLocalName; - USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - - if( nPrefix == XML_NAMESPACE_TABLE && - IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) ) - { - uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY ); - mrAddress = xAttrList->getValueByIndex( i ); - // lcl_ConvertRange( xAttrList->getValueByIndex( i ), xNewDoc ); - } - } -} - -// ======================================== - SchXMLPositonAttributesHelper::SchXMLPositonAttributesHelper( SvXMLImport& rImporter ) : m_rImport( rImporter ) , m_aPosition(0,0) diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.hxx b/xmloff/source/chart/SchXMLPlotAreaContext.hxx index 1f0de466dcb1..ca44e127cfb8 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.hxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.hxx @@ -131,8 +131,6 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); virtual void EndElement(); - void CorrectAxisPositions(); - private: SchXMLImportHelper& mrImportHelper; ::com::sun::star::uno::Reference< com::sun::star::chart::XDiagram > mxDiagram; @@ -166,47 +164,6 @@ private: ::com::sun::star::awt::Size maChartSize; }; -// ---------------------------------------- - -class SchXMLAxisContext : public SvXMLImportContext -{ -private: - SchXMLImportHelper& mrImportHelper; - ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > mxDiagram; - SchXMLAxis maCurrentAxis; - std::vector< SchXMLAxis >& maAxes; - rtl::OUString msAutoStyleName; - rtl::OUString& mrCategoriesAddress; - bool mbAddMissingXAxisForNetCharts; //to correct errors from older versions - bool mbAdaptWrongPercentScaleValues; //to correct errors from older versions - bool mbAdaptXAxisOrientationForOld2DBarCharts; //to correct different behaviour from older versions - bool& m_rbAxisPositionAttributeImported; - - ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTitleShape(); - void CreateGrid( ::rtl::OUString sAutoStyleName, sal_Bool bIsMajor ); - void CreateAxis(); - void SetAxisTitle(); - -public: - SchXMLAxisContext( SchXMLImportHelper& rImpHelper, - SvXMLImport& rImport, const rtl::OUString& rLocalName, - ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > xDiagram, - std::vector< SchXMLAxis >& aAxes, - ::rtl::OUString& rCategoriesAddress, - bool bAddMissingXAxisForNetCharts, - bool bAdaptWrongPercentScaleValues, - bool bAdaptXAxisOrientationForOld2DBarCharts, - bool& rbAxisPositionAttributeImported ); - virtual ~SchXMLAxisContext(); - - virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); - virtual void EndElement(); - virtual SvXMLImportContext* CreateChildContext( - USHORT nPrefix, - const rtl::OUString& rLocalName, - const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); -}; - //---------------------------------------- class SchXMLDataPointContext : public SvXMLImportContext @@ -233,24 +190,6 @@ public: // ---------------------------------------- -class SchXMLCategoriesContext : public SvXMLImportContext -{ -private: - SchXMLImportHelper& mrImportHelper; - rtl::OUString& mrAddress; - -public: - SchXMLCategoriesContext( SchXMLImportHelper& rImpHelper, - SvXMLImport& rImport, - sal_uInt16 nPrefix, - const rtl::OUString& rLocalName, - rtl::OUString& rAddress ); - virtual ~SchXMLCategoriesContext(); - virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); -}; - -// ---------------------------------------- - class SchXMLCoordinateRegionContext : public SvXMLImportContext { public: diff --git a/xmloff/source/chart/makefile.mk b/xmloff/source/chart/makefile.mk index bfdc9aeb5e22..2f61a3d6f0e5 100644 --- a/xmloff/source/chart/makefile.mk +++ b/xmloff/source/chart/makefile.mk @@ -46,6 +46,7 @@ SLOFILES = $(SLO)$/ColorPropertySet.obj \ $(SLO)$/SchXMLTableContext.obj \ $(SLO)$/SchXMLChartContext.obj \ $(SLO)$/SchXMLPlotAreaContext.obj \ + $(SLO)$/SchXMLAxisContext.obj \ $(SLO)$/SchXMLParagraphContext.obj \ $(SLO)$/SchXMLTextListContext.obj \ $(SLO)$/SchXMLSeriesHelper.obj \ -- cgit From 386772bd509c1300532c74cb04f8e5f89cbfeba8 Mon Sep 17 00:00:00 2001 From: Ingrid Halama Date: Thu, 18 Nov 2010 18:27:27 +0100 Subject: chart46: #i115651# further cleanup --- xmloff/source/chart/SchXMLAxisContext.cxx | 176 +++++++++++++------------- xmloff/source/chart/SchXMLAxisContext.hxx | 34 ++--- xmloff/source/chart/SchXMLPlotAreaContext.cxx | 2 +- xmloff/source/chart/SchXMLSeries2Context.cxx | 4 +- xmloff/source/chart/transporttypes.hxx | 8 +- 5 files changed, 109 insertions(+), 115 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index 95edd71e0b68..e6e677625207 100755 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -63,7 +63,7 @@ using com::sun::star::uno::Reference; //---------------------------------------- //---------------------------------------- -static __FAR_DATA SvXMLEnumMapEntry aXMLAxisClassMap[] = +static __FAR_DATA SvXMLEnumMapEntry aXMLAxisDimensionMap[] = { { XML_X, SCH_XML_AXIS_X }, { XML_Y, SCH_XML_AXIS_Y }, @@ -77,7 +77,7 @@ static __FAR_DATA SvXMLEnumMapEntry aXMLAxisClassMap[] = class SchXMLCategoriesContext : public SvXMLImportContext { private: - SchXMLImportHelper& mrImportHelper; + SchXMLImportHelper& m_rImportHelper; OUString& mrAddress; public: @@ -96,20 +96,20 @@ public: SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, const OUString& rLocalName, Reference< chart::XDiagram > xDiagram, - std::vector< SchXMLAxis >& aAxes, + std::vector< SchXMLAxis >& rAxes, OUString & rCategoriesAddress, bool bAddMissingXAxisForNetCharts, bool bAdaptWrongPercentScaleValues, bool bAdaptXAxisOrientationForOld2DBarCharts, bool& rbAxisPositionAttributeImported ) : SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), - mrImportHelper( rImpHelper ), - mxDiagram( xDiagram ), - maAxes( aAxes ), - mrCategoriesAddress( rCategoriesAddress ), - mbAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ), - mbAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ), - mbAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ), + m_rImportHelper( rImpHelper ), + m_xDiagram( xDiagram ), + m_rAxes( rAxes ), + m_rCategoriesAddress( rCategoriesAddress ), + m_bAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ), + m_bAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ), + m_bAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ), m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported ) { } @@ -125,14 +125,14 @@ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() Reference< drawing::XShape > xResult; uno::Any aTrueBool; aTrueBool <<= (sal_Bool)(sal_True); - Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xDiaProp( m_xDiagram, uno::UNO_QUERY ); - switch( maCurrentAxis.eClass ) + switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: - if( maCurrentAxis.nIndexInCategory == 0 ) + if( m_aCurrentAxis.nAxisIndex == 0 ) { - Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) { if( xDiaProp.is()) @@ -142,7 +142,7 @@ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() } else { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is() ) { if( xDiaProp.is() ) @@ -152,9 +152,9 @@ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() } break; case SCH_XML_AXIS_Y: - if( maCurrentAxis.nIndexInCategory == 0 ) + if( m_aCurrentAxis.nAxisIndex == 0 ) { - Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) { if( xDiaProp.is()) @@ -164,7 +164,7 @@ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() } else { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is() ) { if( xDiaProp.is() ) @@ -175,7 +175,7 @@ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() break; case SCH_XML_AXIS_Z: { - Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) { if( xDiaProp.is()) @@ -192,10 +192,9 @@ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() return xResult; } -void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, - sal_Bool bIsMajor ) +void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, bool bIsMajor ) { - Reference< chart::XDiagram > xDia = mrImportHelper.GetChartDocument()->getDiagram(); + Reference< chart::XDiagram > xDia = m_rImportHelper.GetChartDocument()->getDiagram(); Reference< beans::XPropertySet > xGridProp; OUString sPropertyName; DBG_ASSERT( xDia.is(), "diagram object is invalid!" ); @@ -203,7 +202,7 @@ void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY ); uno::Any aTrueBool( uno::makeAny( true )); - switch( maCurrentAxis.eClass ) + switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: { @@ -278,11 +277,11 @@ void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, uno::makeAny( COL_BLACK )); if( sAutoStyleName.getLength()) { - const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); + const SvXMLStylesContext* pStylesCtxt = m_rImportHelper.GetAutoStylesContext(); if( pStylesCtxt ) { const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( - mrImportHelper.GetChartFamilyID(), sAutoStyleName ); + m_rImportHelper.GetChartFamilyID(), sAutoStyleName ); if( pStyle && pStyle->ISA( XMLPropStyleContext )) (( XMLPropStyleContext* )pStyle )->FillPropertySet( xGridProp ); @@ -296,7 +295,7 @@ void SchXMLAxisContext::StartElement( const Reference< xml::sax::XAttributeList // parse attributes sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; SchXMLImport& rImport = ( SchXMLImport& )GetImport(); - const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetAxisAttrTokenMap(); + const SvXMLTokenMap& rAttrTokenMap = m_rImportHelper.GetAxisAttrTokenMap(); for( sal_Int16 i = 0; i < nAttrCount; i++ ) { @@ -310,26 +309,26 @@ void SchXMLAxisContext::StartElement( const Reference< xml::sax::XAttributeList case XML_TOK_AXIS_DIMENSION: { USHORT nEnumVal; - if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisClassMap )) - maCurrentAxis.eClass = ( SchXMLAxisClass )nEnumVal; + if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisDimensionMap )) + m_aCurrentAxis.eDimension = ( SchXMLAxisDimension )nEnumVal; } break; case XML_TOK_AXIS_NAME: - maCurrentAxis.aName = aValue; + m_aCurrentAxis.aName = aValue; break; case XML_TOK_AXIS_STYLE_NAME: - msAutoStyleName = aValue; + m_aAutoStyleName = aValue; break; } } - // check for number of axes with same category - maCurrentAxis.nIndexInCategory = 0; - sal_Int32 nNumOfAxes = maAxes.size(); + // check for number of axes with same dimension + m_aCurrentAxis.nAxisIndex = 0; + sal_Int32 nNumOfAxes = m_rAxes.size(); for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ ) { - if( maAxes[ nCurrent ].eClass == maCurrentAxis.eClass ) - maCurrentAxis.nIndexInCategory++; + if( m_rAxes[ nCurrent ].eDimension == m_aCurrentAxis.eDimension ) + m_aCurrentAxis.nAxisIndex++; } CreateAxis(); } @@ -398,21 +397,21 @@ bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData) void SchXMLAxisContext::CreateAxis() { // add new Axis to list - maAxes.push_back( maCurrentAxis ); + m_rAxes.push_back( m_aCurrentAxis ); // set axis at chart - Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xDiaProp( m_xDiagram, uno::UNO_QUERY ); Reference< beans::XPropertySet > xProp; uno::Any aTrueBool; aTrueBool <<= (sal_Bool)(sal_True); uno::Any aFalseBool; aFalseBool <<= (sal_Bool)(sal_False); - Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); + Reference< frame::XModel > xDoc( m_rImportHelper.GetChartDocument(), uno::UNO_QUERY ); - switch( maCurrentAxis.eClass ) + switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: - if( maCurrentAxis.nIndexInCategory == 0 ) + if( m_aCurrentAxis.nAxisIndex == 0 ) { try { @@ -423,7 +422,7 @@ void SchXMLAxisContext::CreateAxis() { DBG_ERROR( "Couldn't turn on x axis" ); } - Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) xProp = xSuppl->getXAxis(); } @@ -438,14 +437,14 @@ void SchXMLAxisContext::CreateAxis() { DBG_ERROR( "Couldn't turn on second x axis" ); } - Reference< chart::XTwoAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XTwoAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) xProp = xSuppl->getSecondaryXAxis(); } break; case SCH_XML_AXIS_Y: - if( maCurrentAxis.nIndexInCategory == 0 ) + if( m_aCurrentAxis.nAxisIndex == 0 ) { try { @@ -456,12 +455,12 @@ void SchXMLAxisContext::CreateAxis() { DBG_ERROR( "Couldn't turn on y axis" ); } - Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) xProp = xSuppl->getYAxis(); - if( mbAddMissingXAxisForNetCharts ) + if( m_bAddMissingXAxisForNetCharts ) { if( xDiaProp.is() ) { @@ -488,7 +487,7 @@ void SchXMLAxisContext::CreateAxis() { DBG_ERROR( "Couldn't turn on second y axis" ); } - Reference< chart::XTwoAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XTwoAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) xProp = xSuppl->getSecondaryYAxis(); } @@ -509,7 +508,7 @@ void SchXMLAxisContext::CreateAxis() } if( bSettingZAxisSuccedded ) { - Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) xProp = xSuppl->getZAxis(); } @@ -532,13 +531,13 @@ void SchXMLAxisContext::CreateAxis() // #88077# AutoOrigin 'on' is default xProp->setPropertyValue( OUString::createFromAscii( "AutoOrigin" ), aTrueBool ); - if( msAutoStyleName.getLength()) + if( m_aAutoStyleName.getLength()) { - const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); + const SvXMLStylesContext* pStylesCtxt = m_rImportHelper.GetAutoStylesContext(); if( pStylesCtxt ) { const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( - mrImportHelper.GetChartFamilyID(), msAutoStyleName ); + m_rImportHelper.GetChartFamilyID(), m_aAutoStyleName ); if( pStyle && pStyle->ISA( XMLPropStyleContext )) { @@ -547,11 +546,11 @@ void SchXMLAxisContext::CreateAxis() if( pPropStyleContext ) pPropStyleContext->FillPropertySet( xProp ); - if( mbAdaptWrongPercentScaleValues && maCurrentAxis.eClass==SCH_XML_AXIS_Y ) + if( m_bAdaptWrongPercentScaleValues && m_aCurrentAxis.eDimension==SCH_XML_AXIS_Y ) { //set scale data of added x axis back to default Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), - 1 /*nDimensionIndex*/, maCurrentAxis.nIndexInCategory /*nAxisIndex*/ ) ); + 1 /*nDimensionIndex*/, m_aCurrentAxis.nAxisIndex /*nAxisIndex*/ ) ); if( xAxis.is() ) { chart2::ScaleData aScaleData( xAxis->getScaleData()); @@ -560,11 +559,11 @@ void SchXMLAxisContext::CreateAxis() } } - if( mbAddMissingXAxisForNetCharts ) + if( m_bAddMissingXAxisForNetCharts ) { //copy style from y axis to added x axis: - Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); + Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is() ) { Reference< beans::XPropertySet > xXAxisProp( xSuppl->getXAxis() ); @@ -591,7 +590,7 @@ void SchXMLAxisContext::CreateAxis() } } - if( mbAdaptXAxisOrientationForOld2DBarCharts && maCurrentAxis.eClass == SCH_XML_AXIS_X ) + if( m_bAdaptXAxisOrientationForOld2DBarCharts && m_aCurrentAxis.eDimension == SCH_XML_AXIS_X ) { bool bIs3DChart = false; if( xDiaProp.is() && ( xDiaProp->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3DChart ) @@ -612,7 +611,7 @@ void SchXMLAxisContext::CreateAxis() if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("SwapXAndYAxis"))) >>= bSwapXandYAxis ) && bSwapXandYAxis ) { - Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, maCurrentAxis.nIndexInCategory ); + Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, m_aCurrentAxis.nAxisIndex ); if( xAxis.is() ) { chart2::ScaleData aScaleData = xAxis->getScaleData(); @@ -637,20 +636,19 @@ void SchXMLAxisContext::CreateAxis() void SchXMLAxisContext::SetAxisTitle() { // add new Axis to list - maAxes.push_back( maCurrentAxis ); + m_rAxes.push_back( m_aCurrentAxis ); // set axis at chart - sal_Bool bHasTitle = ( maCurrentAxis.aTitle.getLength() > 0 ); - Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ); + sal_Bool bHasTitle = ( m_aCurrentAxis.aTitle.getLength() > 0 ); + Reference< frame::XModel > xDoc( m_rImportHelper.GetChartDocument(), uno::UNO_QUERY ); - switch( maCurrentAxis.eClass ) + switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: - if( maCurrentAxis.nIndexInCategory == 0 ) + if( m_aCurrentAxis.nAxisIndex == 0 ) { - Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) + Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && bHasTitle ) { Reference< beans::XPropertySet > xTitleProp( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); if( xTitleProp.is()) @@ -658,7 +656,7 @@ void SchXMLAxisContext::SetAxisTitle() try { uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; + aAny <<= m_aCurrentAxis.aTitle; xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); } catch( beans::UnknownPropertyException & ) @@ -670,9 +668,8 @@ void SchXMLAxisContext::SetAxisTitle() } else { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) + Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && bHasTitle ) { Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); if( xTitleProp.is()) @@ -680,7 +677,7 @@ void SchXMLAxisContext::SetAxisTitle() try { uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; + aAny <<= m_aCurrentAxis.aTitle; xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); } catch( beans::UnknownPropertyException & ) @@ -693,11 +690,10 @@ void SchXMLAxisContext::SetAxisTitle() break; case SCH_XML_AXIS_Y: - if( maCurrentAxis.nIndexInCategory == 0 ) + if( m_aCurrentAxis.nAxisIndex == 0 ) { - Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) + Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && bHasTitle ) { Reference< beans::XPropertySet > xTitleProp( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); if( xTitleProp.is()) @@ -705,7 +701,7 @@ void SchXMLAxisContext::SetAxisTitle() try { uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; + aAny <<= m_aCurrentAxis.aTitle; xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); } catch( beans::UnknownPropertyException & ) @@ -717,9 +713,8 @@ void SchXMLAxisContext::SetAxisTitle() } else { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) + Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && bHasTitle ) { Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); if( xTitleProp.is()) @@ -727,7 +722,7 @@ void SchXMLAxisContext::SetAxisTitle() try { uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; + aAny <<= m_aCurrentAxis.aTitle; xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); } catch( beans::UnknownPropertyException & ) @@ -741,9 +736,8 @@ void SchXMLAxisContext::SetAxisTitle() case SCH_XML_AXIS_Z: { - Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && - bHasTitle ) + Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); + if( xSuppl.is() && bHasTitle ) { Reference< beans::XPropertySet > xTitleProp( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); if( xTitleProp.is()) @@ -751,7 +745,7 @@ void SchXMLAxisContext::SetAxisTitle() try { uno::Any aAny; - aAny <<= maCurrentAxis.aTitle; + aAny <<= m_aCurrentAxis.aTitle; xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); } catch( beans::UnknownPropertyException & ) @@ -774,30 +768,30 @@ SvXMLImportContext* SchXMLAxisContext::CreateChildContext( const Reference< xml::sax::XAttributeList >& xAttrList ) { SvXMLImportContext* pContext = 0; - const SvXMLTokenMap& rTokenMap = mrImportHelper.GetAxisElemTokenMap(); + const SvXMLTokenMap& rTokenMap = m_rImportHelper.GetAxisElemTokenMap(); switch( rTokenMap.Get( p_nPrefix, rLocalName )) { case XML_TOK_AXIS_TITLE: { Reference< drawing::XShape > xTitleShape = getTitleShape(); - pContext = new SchXMLTitleContext( mrImportHelper, GetImport(), rLocalName, - maCurrentAxis.aTitle, + pContext = new SchXMLTitleContext( m_rImportHelper, GetImport(), rLocalName, + m_aCurrentAxis.aTitle, xTitleShape ); } break; case XML_TOK_AXIS_CATEGORIES: - pContext = new SchXMLCategoriesContext( mrImportHelper, GetImport(), + pContext = new SchXMLCategoriesContext( m_rImportHelper, GetImport(), p_nPrefix, rLocalName, - mrCategoriesAddress ); - maCurrentAxis.bHasCategories = true; + m_rCategoriesAddress ); + m_aCurrentAxis.bHasCategories = true; break; case XML_TOK_AXIS_GRID: { sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; - sal_Bool bIsMajor = sal_True; // default value for class is "major" + bool bIsMajor = true; // default value for class is "major" OUString sAutoStyleName; for( sal_Int16 i = 0; i < nAttrCount; i++ ) @@ -811,7 +805,7 @@ SvXMLImportContext* SchXMLAxisContext::CreateChildContext( if( IsXMLToken( aLocalName, XML_CLASS ) ) { if( IsXMLToken( xAttrList->getValueByIndex( i ), XML_MINOR ) ) - bIsMajor = sal_False; + bIsMajor = false; } else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) ) sAutoStyleName = xAttrList->getValueByIndex( i ); @@ -987,7 +981,7 @@ SchXMLCategoriesContext::SchXMLCategoriesContext( const OUString& rLocalName, OUString& rAddress ) : SvXMLImportContext( rImport, nPrefix, rLocalName ), - mrImportHelper( rImpHelper ), + m_rImportHelper( rImpHelper ), mrAddress( rAddress ) { } diff --git a/xmloff/source/chart/SchXMLAxisContext.hxx b/xmloff/source/chart/SchXMLAxisContext.hxx index a2e5d3972879..6ad27921024e 100755 --- a/xmloff/source/chart/SchXMLAxisContext.hxx +++ b/xmloff/source/chart/SchXMLAxisContext.hxx @@ -34,23 +34,6 @@ class SchXMLAxisContext : public SvXMLImportContext { -private: - SchXMLImportHelper& mrImportHelper; - ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > mxDiagram; - SchXMLAxis maCurrentAxis; - std::vector< SchXMLAxis >& maAxes; - rtl::OUString msAutoStyleName; - rtl::OUString& mrCategoriesAddress; - bool mbAddMissingXAxisForNetCharts; //to correct errors from older versions - bool mbAdaptWrongPercentScaleValues; //to correct errors from older versions - bool mbAdaptXAxisOrientationForOld2DBarCharts; //to correct different behaviour from older versions - bool& m_rbAxisPositionAttributeImported; - - ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTitleShape(); - void CreateGrid( ::rtl::OUString sAutoStyleName, sal_Bool bIsMajor ); - void CreateAxis(); - void SetAxisTitle(); - public: SchXMLAxisContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, const rtl::OUString& rLocalName, @@ -74,6 +57,23 @@ public: const ::rtl::OUString& rChartTypeServiceName, const ::rtl::OUString& rODFVersionOfFile, bool bAxisPositionAttributeImported ); + +private: + SchXMLImportHelper& m_rImportHelper; + ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > m_xDiagram; + SchXMLAxis m_aCurrentAxis; + std::vector< SchXMLAxis >& m_rAxes; + rtl::OUString m_aAutoStyleName; + rtl::OUString& m_rCategoriesAddress; + bool m_bAddMissingXAxisForNetCharts; //to correct errors from older versions + bool m_bAdaptWrongPercentScaleValues; //to correct errors from older versions + bool m_bAdaptXAxisOrientationForOld2DBarCharts; //to correct different behaviour from older versions + bool& m_rbAxisPositionAttributeImported; + + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTitleShape(); + void CreateGrid( ::rtl::OUString sAutoStyleName, bool bIsMajor ); + void CreateAxis(); + void SetAxisTitle(); }; #endif // _SCH_XMLAXISCONTEXT_HXX_ diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx index 1200863365a5..2bfc8d9048d0 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx @@ -591,7 +591,7 @@ void SchXMLPlotAreaContext::EndElement() ::std::vector< SchXMLAxis >::const_iterator aIt( ::std::find_if( maAxes.begin(), maAxes.end(), lcl_AxisHasCategories())); if( aIt != maAxes.end()) - nDimension = static_cast< sal_Int32 >( (*aIt).eClass ); + nDimension = static_cast< sal_Int32 >( (*aIt).eDimension ); SchXMLTools::CreateCategories( xDataProvider, mxNewDoc, mrCategoriesAddress, 0 /* nCooSysIndex */, diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx index 86e9693ee225..b76026c706cd 100644 --- a/xmloff/source/chart/SchXMLSeries2Context.cxx +++ b/xmloff/source/chart/SchXMLSeries2Context.cxx @@ -336,7 +336,7 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ ) { if( aValue.equals( mrAxes[ nCurrent ].aName ) && - mrAxes[ nCurrent ].eClass == SCH_XML_AXIS_Y ) + mrAxes[ nCurrent ].eDimension == SCH_XML_AXIS_Y ) { mpAttachedAxis = &( mrAxes[ nCurrent ] ); } @@ -364,7 +364,7 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib if( mpAttachedAxis ) { - if( mpAttachedAxis->nIndexInCategory > 0 ) + if( mpAttachedAxis->nAxisIndex > 0 ) { // secondary axis => property has to be set (primary is default) mnAttachedAxis = 2; diff --git a/xmloff/source/chart/transporttypes.hxx b/xmloff/source/chart/transporttypes.hxx index 27c8850e2b81..0cacb3217089 100644 --- a/xmloff/source/chart/transporttypes.hxx +++ b/xmloff/source/chart/transporttypes.hxx @@ -132,7 +132,7 @@ struct SchNumericCellRangeAddress // ---------------------------------------- -enum SchXMLAxisClass +enum SchXMLAxisDimension { SCH_XML_AXIS_X = 0, SCH_XML_AXIS_Y, @@ -142,13 +142,13 @@ enum SchXMLAxisClass struct SchXMLAxis { - enum SchXMLAxisClass eClass; - sal_Int8 nIndexInCategory; + enum SchXMLAxisDimension eDimension; + sal_Int8 nAxisIndex;//0->primary axis; 1->secondary axis rtl::OUString aName; rtl::OUString aTitle; bool bHasCategories; - SchXMLAxis() : eClass( SCH_XML_AXIS_UNDEF ), nIndexInCategory( 0 ), bHasCategories( false ) {} + SchXMLAxis() : eDimension( SCH_XML_AXIS_UNDEF ), nAxisIndex( 0 ), bHasCategories( false ) {} }; // ---------------------------------------- -- cgit From 8ce73a598f172d72c7c1445c202adb1b226c24da Mon Sep 17 00:00:00 2001 From: Ingrid Halama Date: Fri, 19 Nov 2010 14:56:44 +0100 Subject: chart46: #i115651# further cleanup --- xmloff/source/chart/SchXMLAxisContext.cxx | 61 ++++++++++++++++++++++++++++++- xmloff/source/chart/SchXMLImport.cxx | 42 --------------------- 2 files changed, 59 insertions(+), 44 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index e6e677625207..6c3eaae8c864 100755 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -290,12 +290,40 @@ void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, bool bIsMajor ) } } +namespace +{ +enum AxisAttributeTokens +{ + XML_TOK_AXIS_DIMENSION, + XML_TOK_AXIS_NAME, + XML_TOK_AXIS_STYLE_NAME +}; + +SvXMLTokenMapEntry aAxisAttributeTokenMap[] = +{ + { XML_NAMESPACE_CHART, XML_DIMENSION, XML_TOK_AXIS_DIMENSION }, + { XML_NAMESPACE_CHART, XML_NAME, XML_TOK_AXIS_NAME }, + { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_AXIS_STYLE_NAME }, + XML_TOKEN_MAP_END +}; + +class AxisAttributeTokenMap : public SvXMLTokenMap +{ +public: + AxisAttributeTokenMap(): SvXMLTokenMap( aAxisAttributeTokenMap ) {} + virtual ~AxisAttributeTokenMap() {} +}; + +//a AxisAttributeTokenMap Singleton +struct theAxisAttributeTokenMap : public rtl::Static< AxisAttributeTokenMap, theAxisAttributeTokenMap > {}; +} + void SchXMLAxisContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList ) { // parse attributes sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; SchXMLImport& rImport = ( SchXMLImport& )GetImport(); - const SvXMLTokenMap& rAttrTokenMap = m_rImportHelper.GetAxisAttrTokenMap(); + const SvXMLTokenMap& rAttrTokenMap = theAxisAttributeTokenMap::get(); for( sal_Int16 i = 0; i < nAttrCount; i++ ) { @@ -762,13 +790,42 @@ void SchXMLAxisContext::SetAxisTitle() } } +//----------------------------------------------------------------------- +namespace +{ +enum AxisChildTokens +{ + XML_TOK_AXIS_TITLE, + XML_TOK_AXIS_CATEGORIES, + XML_TOK_AXIS_GRID +}; + +SvXMLTokenMapEntry aAxisChildTokenMap[] = +{ + { XML_NAMESPACE_CHART, XML_TITLE, XML_TOK_AXIS_TITLE }, + { XML_NAMESPACE_CHART, XML_CATEGORIES, XML_TOK_AXIS_CATEGORIES }, + { XML_NAMESPACE_CHART, XML_GRID, XML_TOK_AXIS_GRID }, + XML_TOKEN_MAP_END +}; + +class AxisChildTokenMap : public SvXMLTokenMap +{ +public: + AxisChildTokenMap(): SvXMLTokenMap( aAxisChildTokenMap ) {} + virtual ~AxisChildTokenMap() {} +}; + +//a AxisChildTokenMap Singleton +struct theAxisChildTokenMap : public rtl::Static< AxisChildTokenMap, theAxisChildTokenMap > {}; +} + SvXMLImportContext* SchXMLAxisContext::CreateChildContext( USHORT p_nPrefix, const OUString& rLocalName, const Reference< xml::sax::XAttributeList >& xAttrList ) { SvXMLImportContext* pContext = 0; - const SvXMLTokenMap& rTokenMap = m_rImportHelper.GetAxisElemTokenMap(); + const SvXMLTokenMap& rTokenMap = theAxisChildTokenMap::get(); switch( rTokenMap.Get( p_nPrefix, rLocalName )) { diff --git a/xmloff/source/chart/SchXMLImport.cxx b/xmloff/source/chart/SchXMLImport.cxx index 587070202c9c..8f26d28d22da 100644 --- a/xmloff/source/chart/SchXMLImport.cxx +++ b/xmloff/source/chart/SchXMLImport.cxx @@ -143,11 +143,9 @@ SchXMLImportHelper::SchXMLImportHelper() : mpChartElemTokenMap( 0 ), mpPlotAreaElemTokenMap( 0 ), mpSeriesElemTokenMap( 0 ), - mpAxisElemTokenMap( 0 ), mpChartAttrTokenMap( 0 ), mpPlotAreaAttrTokenMap( 0 ), - mpAxisAttrTokenMap( 0 ), mpLegendAttrTokenMap( 0 ), mpAutoStyleAttrTokenMap( 0 ), mpCellAttrTokenMap( 0 ), @@ -169,15 +167,11 @@ SchXMLImportHelper::~SchXMLImportHelper() delete mpPlotAreaElemTokenMap; if( mpSeriesElemTokenMap ) delete mpSeriesElemTokenMap; - if( mpAxisElemTokenMap ) - delete mpAxisElemTokenMap; if( mpChartAttrTokenMap ) delete mpChartAttrTokenMap; if( mpPlotAreaAttrTokenMap ) delete mpPlotAreaAttrTokenMap; - if( mpAxisAttrTokenMap ) - delete mpAxisAttrTokenMap; if( mpLegendAttrTokenMap ) delete mpLegendAttrTokenMap; if( mpAutoStyleAttrTokenMap ) @@ -320,24 +314,6 @@ const SvXMLTokenMap& SchXMLImportHelper::GetSeriesElemTokenMap() return *mpSeriesElemTokenMap; } -const SvXMLTokenMap& SchXMLImportHelper::GetAxisElemTokenMap() -{ - if( ! mpAxisElemTokenMap ) - { - static __FAR_DATA SvXMLTokenMapEntry aAxisElemTokenMap[] = -{ - { XML_NAMESPACE_CHART, XML_TITLE, XML_TOK_AXIS_TITLE }, - { XML_NAMESPACE_CHART, XML_CATEGORIES, XML_TOK_AXIS_CATEGORIES }, - { XML_NAMESPACE_CHART, XML_GRID, XML_TOK_AXIS_GRID }, - XML_TOKEN_MAP_END -}; - - mpAxisElemTokenMap = new SvXMLTokenMap( aAxisElemTokenMap ); - } // if( ! mpAxisElemTokenMap ) - - return *mpAxisElemTokenMap; -} - // ---------------------------------------- const SvXMLTokenMap& SchXMLImportHelper::GetChartAttrTokenMap() @@ -395,24 +371,6 @@ const SvXMLTokenMap& SchXMLImportHelper::GetPlotAreaAttrTokenMap() return *mpPlotAreaAttrTokenMap; } -const SvXMLTokenMap& SchXMLImportHelper::GetAxisAttrTokenMap() -{ - if( ! mpAxisAttrTokenMap ) - { - static __FAR_DATA SvXMLTokenMapEntry aAxisAttrTokenMap[] = -{ - { XML_NAMESPACE_CHART, XML_DIMENSION, XML_TOK_AXIS_DIMENSION }, - { XML_NAMESPACE_CHART, XML_NAME, XML_TOK_AXIS_NAME }, - { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_AXIS_STYLE_NAME }, - XML_TOKEN_MAP_END -}; - - mpAxisAttrTokenMap = new SvXMLTokenMap( aAxisAttrTokenMap ); - } // if( ! mpAxisAttrTokenMap ) - - return *mpAxisAttrTokenMap; -} - const SvXMLTokenMap& SchXMLImportHelper::GetLegendAttrTokenMap() { if( ! mpLegendAttrTokenMap ) -- cgit From 1bbb669aa658744ce8ccafe18abd199dd872a207 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 23 Nov 2010 10:10:21 +0100 Subject: dba34b: removed unused StylePropertyMapper at the importer, removed unused export of the exporter's StylePropertyMapper --- xmloff/source/draw/shapeimport.cxx | 6 ------ xmloff/source/forms/formlayerexport.cxx | 6 ------ xmloff/source/forms/formlayerimport.cxx | 6 ------ xmloff/source/forms/layerimport.cxx | 11 ----------- xmloff/source/forms/layerimport.hxx | 8 -------- 5 files changed, 37 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/draw/shapeimport.cxx b/xmloff/source/draw/shapeimport.cxx index 903b7d99809a..02244c35d4ca 100644 --- a/xmloff/source/draw/shapeimport.cxx +++ b/xmloff/source/draw/shapeimport.cxx @@ -183,12 +183,6 @@ XMLShapeImportHelper::XMLShapeImportHelper( mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImporter)); mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaDefaultExtPropMapper(rImporter)); -/* - // chain form attributes - const UniReference< SvXMLImportPropertyMapper> xFormMapper( rImporter.GetFormImport()->getStylePropertyMapper().getBodyPtr() ); - mpPropertySetMapper->ChainImportMapper(xFormMapper); -*/ - // construct PresPagePropsMapper xMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLSDPresPageProps, mpSdPropHdlFactory); mpPresPagePropsMapper = new SvXMLImportPropertyMapper( xMapper, rImporter ); diff --git a/xmloff/source/forms/formlayerexport.cxx b/xmloff/source/forms/formlayerexport.cxx index ad5ff7eb4dae..8042db7bb6ac 100644 --- a/xmloff/source/forms/formlayerexport.cxx +++ b/xmloff/source/forms/formlayerexport.cxx @@ -92,12 +92,6 @@ namespace xmloff return m_pImpl->getControlNumberStyle(_rxControl); } - //--------------------------------------------------------------------- - ::vos::ORef< SvXMLExportPropertyMapper > OFormLayerXMLExport::getStylePropertyMapper() - { - return m_pImpl->getStylePropertyMapper(); - } - //--------------------------------------------------------------------- void OFormLayerXMLExport::initialize() { diff --git a/xmloff/source/forms/formlayerimport.cxx b/xmloff/source/forms/formlayerimport.cxx index a31b6397f51f..17a0a3bc9bb3 100644 --- a/xmloff/source/forms/formlayerimport.cxx +++ b/xmloff/source/forms/formlayerimport.cxx @@ -59,12 +59,6 @@ namespace xmloff delete m_pImpl; } - //--------------------------------------------------------------------- - ::vos::ORef< SvXMLImportPropertyMapper > OFormLayerXMLImport::getStylePropertyMapper() const - { - return m_pImpl->getStylePropertyMapper(); - } - //--------------------------------------------------------------------- void OFormLayerXMLImport::setAutoStyleContext(SvXMLStylesContext* _pNewContext) { diff --git a/xmloff/source/forms/layerimport.cxx b/xmloff/source/forms/layerimport.cxx index 77d60f83ee49..58ee9dbcab13 100644 --- a/xmloff/source/forms/layerimport.cxx +++ b/xmloff/source/forms/layerimport.cxx @@ -237,11 +237,6 @@ OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter) TabulatorCycle_RECORDS, OEnumMapper::getEnumMap(OEnumMapper::epTabCyle), &::getCppuType( static_cast(NULL) )); - // initialize our style map - m_xPropertyHandlerFactory = new OControlPropertyHandlerFactory(); - ::vos::ORef< XMLPropertySetMapper > xStylePropertiesMapper = new XMLPropertySetMapper(getControlStylePropertyMap(), m_xPropertyHandlerFactory.getBodyPtr()); - m_xImportMapper = new SvXMLImportPropertyMapper(xStylePropertiesMapper.getBodyPtr(), _rImporter); - // 'initialize' m_aCurrentPageIds = m_aControlIds.end(); } @@ -415,12 +410,6 @@ void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPrope m_aControlReferences.push_back( ModelStringPair( _rxControl, _rReferringControls ) ); } -//--------------------------------------------------------------------- -::vos::ORef< SvXMLImportPropertyMapper > OFormLayerXMLImport_Impl::getStylePropertyMapper() const -{ - return m_xImportMapper; -} - //--------------------------------------------------------------------- void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage) { diff --git a/xmloff/source/forms/layerimport.hxx b/xmloff/source/forms/layerimport.hxx index bd88a67975fd..9bbc4c53d9df 100644 --- a/xmloff/source/forms/layerimport.hxx +++ b/xmloff/source/forms/layerimport.hxx @@ -92,10 +92,6 @@ namespace xmloff SvXMLStylesContext* m_pAutoStyles; protected: - // style handling - ::vos::ORef< XMLPropertyHandlerFactory > m_xPropertyHandlerFactory; - ::vos::ORef< SvXMLImportPropertyMapper > m_xImportMapper; - DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, MapString2PropertySet ); DECLARE_STL_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >, MapString2PropertySet, ODrawPageCompare, MapDrawPage2Map); @@ -168,10 +164,6 @@ namespace xmloff OFormLayerXMLImport_Impl(SvXMLImport& _rImporter); virtual ~OFormLayerXMLImport_Impl(); - /** retrieves the property mapper form form related auto styles. - */ - ::vos::ORef< SvXMLImportPropertyMapper > getStylePropertyMapper() const; - /** start importing the forms of the given page */ void startPage( -- cgit From 3c53792503277a3c562834da171451cb95a0c095 Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Tue, 30 Nov 2010 01:45:03 +0100 Subject: chart46: #i25706# implement date axis --- xmloff/source/chart/SchXMLAxisContext.cxx | 248 ++++++++++++++++++++++-- xmloff/source/chart/SchXMLAxisContext.hxx | 4 + xmloff/source/chart/SchXMLExport.cxx | 298 ++++++++++++++++++++++++++--- xmloff/source/chart/SchXMLTableContext.cxx | 28 ++- xmloff/source/core/xmltoken.cxx | 8 + 5 files changed, 525 insertions(+), 61 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index 6c3eaae8c864..6714ea307f42 100755 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -43,6 +43,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -63,7 +67,7 @@ using com::sun::star::uno::Reference; //---------------------------------------- //---------------------------------------- -static __FAR_DATA SvXMLEnumMapEntry aXMLAxisDimensionMap[] = +static SvXMLEnumMapEntry aXMLAxisDimensionMap[] = { { XML_X, SCH_XML_AXIS_X }, { XML_Y, SCH_XML_AXIS_Y }, @@ -71,6 +75,14 @@ static __FAR_DATA SvXMLEnumMapEntry aXMLAxisDimensionMap[] = { XML_TOKEN_INVALID, 0 } }; +static SvXMLEnumMapEntry aXMLAxisTypeMap[] = +{ + { XML_AUTO, ::com::sun::star::chart::ChartAxisType::AUTOMATIC }, + { XML_TEXT, ::com::sun::star::chart::ChartAxisType::CATEGORY }, + { XML_DATE, ::com::sun::star::chart::ChartAxisType::DATE }, + { XML_TOKEN_INVALID, 0 } +}; + //---------------------------------------- //---------------------------------------- @@ -90,6 +102,26 @@ public: virtual void StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); }; +//---------------------------------------- +//---------------------------------------- + + +class DateScaleContext : public SvXMLImportContext +{ +public: + DateScaleContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< beans::XPropertySet > xAxisProps ); + + virtual ~DateScaleContext(); + virtual void StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + +private: + SchXMLImportHelper& m_rImportHelper; + Reference< beans::XPropertySet > m_xAxisProps; +}; + + //---------------------------------------- //---------------------------------------- @@ -107,6 +139,9 @@ SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper, m_xDiagram( xDiagram ), m_rAxes( rAxes ), m_rCategoriesAddress( rCategoriesAddress ), + m_nAxisType(chart::ChartAxisType::AUTOMATIC), + m_bAxisTypeImported(false), + m_bDateScaleImported(false), m_bAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ), m_bAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ), m_bAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ), @@ -296,14 +331,18 @@ enum AxisAttributeTokens { XML_TOK_AXIS_DIMENSION, XML_TOK_AXIS_NAME, - XML_TOK_AXIS_STYLE_NAME + XML_TOK_AXIS_STYLE_NAME, + XML_TOK_AXIS_TYPE, + XML_TOK_AXIS_TYPE_EXT }; SvXMLTokenMapEntry aAxisAttributeTokenMap[] = { - { XML_NAMESPACE_CHART, XML_DIMENSION, XML_TOK_AXIS_DIMENSION }, - { XML_NAMESPACE_CHART, XML_NAME, XML_TOK_AXIS_NAME }, - { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_AXIS_STYLE_NAME }, + { XML_NAMESPACE_CHART, XML_DIMENSION, XML_TOK_AXIS_DIMENSION }, + { XML_NAMESPACE_CHART, XML_NAME, XML_TOK_AXIS_NAME }, + { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_AXIS_STYLE_NAME }, + { XML_NAMESPACE_CHART, XML_AXIS_TYPE, XML_TOK_AXIS_TYPE }, + { XML_NAMESPACE_CHART_EXT, XML_AXIS_TYPE, XML_TOK_AXIS_TYPE_EXT }, XML_TOKEN_MAP_END }; @@ -344,6 +383,15 @@ void SchXMLAxisContext::StartElement( const Reference< xml::sax::XAttributeList case XML_TOK_AXIS_NAME: m_aCurrentAxis.aName = aValue; break; + case XML_TOK_AXIS_TYPE: + case XML_TOK_AXIS_TYPE_EXT: + USHORT nEnumVal; + if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisTypeMap )) + { + m_nAxisType = nEnumVal; + m_bAxisTypeImported = true; + } + break; case XML_TOK_AXIS_STYLE_NAME: m_aAutoStyleName = aValue; break; @@ -429,7 +477,6 @@ void SchXMLAxisContext::CreateAxis() // set axis at chart Reference< beans::XPropertySet > xDiaProp( m_xDiagram, uno::UNO_QUERY ); - Reference< beans::XPropertySet > xProp; uno::Any aTrueBool; aTrueBool <<= (sal_Bool)(sal_True); uno::Any aFalseBool; @@ -452,7 +499,7 @@ void SchXMLAxisContext::CreateAxis() } Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) - xProp = xSuppl->getXAxis(); + m_xAxisProps = xSuppl->getXAxis(); } else { @@ -467,7 +514,7 @@ void SchXMLAxisContext::CreateAxis() } Reference< chart::XTwoAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) - xProp = xSuppl->getSecondaryXAxis(); + m_xAxisProps = xSuppl->getSecondaryXAxis(); } break; @@ -485,7 +532,7 @@ void SchXMLAxisContext::CreateAxis() } Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) - xProp = xSuppl->getYAxis(); + m_xAxisProps = xSuppl->getYAxis(); if( m_bAddMissingXAxisForNetCharts ) @@ -517,7 +564,7 @@ void SchXMLAxisContext::CreateAxis() } Reference< chart::XTwoAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) - xProp = xSuppl->getSecondaryYAxis(); + m_xAxisProps = xSuppl->getSecondaryYAxis(); } break; @@ -538,7 +585,7 @@ void SchXMLAxisContext::CreateAxis() { Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); if( xSuppl.is()) - xProp = xSuppl->getZAxis(); + m_xAxisProps = xSuppl->getZAxis(); } } break; @@ -548,16 +595,19 @@ void SchXMLAxisContext::CreateAxis() } // set properties - if( xProp.is()) + if( m_xAxisProps.is()) { // #i109879# the line color is black as default, in the model it is a light gray - xProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), + m_xAxisProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), uno::makeAny( COL_BLACK )); - xProp->setPropertyValue( OUString::createFromAscii( "DisplayLabels" ), aFalseBool ); + m_xAxisProps->setPropertyValue( OUString::createFromAscii( "DisplayLabels" ), aFalseBool ); // #88077# AutoOrigin 'on' is default - xProp->setPropertyValue( OUString::createFromAscii( "AutoOrigin" ), aTrueBool ); + m_xAxisProps->setPropertyValue( OUString::createFromAscii( "AutoOrigin" ), aTrueBool ); + + if( m_bAxisTypeImported ) + m_xAxisProps->setPropertyValue( OUString::createFromAscii( "AxisType" ), uno::makeAny(m_nAxisType) ); if( m_aAutoStyleName.getLength()) { @@ -572,13 +622,13 @@ void SchXMLAxisContext::CreateAxis() // note: SvXMLStyleContext::FillPropertySet is not const XMLPropStyleContext * pPropStyleContext = const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle )); if( pPropStyleContext ) - pPropStyleContext->FillPropertySet( xProp ); + pPropStyleContext->FillPropertySet( m_xAxisProps ); if( m_bAdaptWrongPercentScaleValues && m_aCurrentAxis.eDimension==SCH_XML_AXIS_Y ) { //set scale data of added x axis back to default Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), - 1 /*nDimensionIndex*/, m_aCurrentAxis.nAxisIndex /*nAxisIndex*/ ) ); + m_aCurrentAxis.eDimension, m_aCurrentAxis.nAxisIndex ) ); if( xAxis.is() ) { chart2::ScaleData aScaleData( xAxis->getScaleData()); @@ -797,14 +847,18 @@ enum AxisChildTokens { XML_TOK_AXIS_TITLE, XML_TOK_AXIS_CATEGORIES, - XML_TOK_AXIS_GRID + XML_TOK_AXIS_GRID, + XML_TOK_AXIS_DATE_SCALE, + XML_TOK_AXIS_DATE_SCALE_EXT }; SvXMLTokenMapEntry aAxisChildTokenMap[] = { - { XML_NAMESPACE_CHART, XML_TITLE, XML_TOK_AXIS_TITLE }, - { XML_NAMESPACE_CHART, XML_CATEGORIES, XML_TOK_AXIS_CATEGORIES }, - { XML_NAMESPACE_CHART, XML_GRID, XML_TOK_AXIS_GRID }, + { XML_NAMESPACE_CHART, XML_TITLE, XML_TOK_AXIS_TITLE }, + { XML_NAMESPACE_CHART, XML_CATEGORIES, XML_TOK_AXIS_CATEGORIES }, + { XML_NAMESPACE_CHART, XML_GRID, XML_TOK_AXIS_GRID }, + { XML_NAMESPACE_CHART, XML_DATE_SCALE, XML_TOK_AXIS_DATE_SCALE }, + { XML_NAMESPACE_CHART_EXT, XML_DATE_SCALE, XML_TOK_AXIS_DATE_SCALE_EXT }, XML_TOKEN_MAP_END }; @@ -845,6 +899,13 @@ SvXMLImportContext* SchXMLAxisContext::CreateChildContext( m_aCurrentAxis.bHasCategories = true; break; + case XML_TOK_AXIS_DATE_SCALE: + case XML_TOK_AXIS_DATE_SCALE_EXT: + pContext = new DateScaleContext( m_rImportHelper, GetImport(), + p_nPrefix, rLocalName, m_xAxisProps ); + m_bDateScaleImported = true; + break; + case XML_TOK_AXIS_GRID: { sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; @@ -886,6 +947,17 @@ SvXMLImportContext* SchXMLAxisContext::CreateChildContext( void SchXMLAxisContext::EndElement() { + if( !m_bDateScaleImported && m_nAxisType==chart::ChartAxisType::AUTOMATIC ) + { + Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), m_aCurrentAxis.eDimension, m_aCurrentAxis.nAxisIndex ) ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData( xAxis->getScaleData()); + aScaleData.AutoDateAxis = false;//different default for older documents + xAxis->setScaleData( aScaleData ); + } + } + SetAxisTitle(); } @@ -1067,3 +1139,137 @@ void SchXMLCategoriesContext::StartElement( const Reference< xml::sax::XAttribut } // ======================================== + +DateScaleContext::DateScaleContext( + SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< beans::XPropertySet > xAxisProps ) : + SvXMLImportContext( rImport, nPrefix, rLocalName ), + m_rImportHelper( rImpHelper ), + m_xAxisProps( xAxisProps ) +{ +} + +DateScaleContext::~DateScaleContext() +{ +} + +namespace +{ +enum DateScaleAttributeTokens +{ + XML_TOK_DATESCALE_BASE_TIME_UNIT, + XML_TOK_DATESCALE_MAJOR_INTERVAL_VALUE, + XML_TOK_DATESCALE_MAJOR_INTERVAL_UNIT, + XML_TOK_DATESCALE_MINOR_INTERVAL_VALUE, + XML_TOK_DATESCALE_MINOR_INTERVAL_UNIT +}; + +SvXMLTokenMapEntry aDateScaleAttributeTokenMap[] = +{ + { XML_NAMESPACE_CHART, XML_BASE_TIME_UNIT, XML_TOK_DATESCALE_BASE_TIME_UNIT }, + { XML_NAMESPACE_CHART, XML_MAJOR_INTERVAL_VALUE, XML_TOK_DATESCALE_MAJOR_INTERVAL_VALUE }, + { XML_NAMESPACE_CHART, XML_MAJOR_INTERVAL_UNIT, XML_TOK_DATESCALE_MAJOR_INTERVAL_UNIT }, + { XML_NAMESPACE_CHART, XML_MINOR_INTERVAL_VALUE, XML_TOK_DATESCALE_MINOR_INTERVAL_VALUE }, + { XML_NAMESPACE_CHART, XML_MINOR_INTERVAL_UNIT, XML_TOK_DATESCALE_MINOR_INTERVAL_UNIT }, + XML_TOKEN_MAP_END +}; + +class DateScaleAttributeTokenMap : public SvXMLTokenMap +{ +public: + DateScaleAttributeTokenMap(): SvXMLTokenMap( aDateScaleAttributeTokenMap ) {} + virtual ~DateScaleAttributeTokenMap() {} +}; + +struct theDateScaleAttributeTokenMap : public rtl::Static< DateScaleAttributeTokenMap, theDateScaleAttributeTokenMap > {}; + +sal_Int32 lcl_getTimeUnit( const OUString& rValue ) +{ + sal_Int32 nTimeUnit = ::com::sun::star::chart::TimeUnit::DAY; + if( IsXMLToken( rValue, XML_DAYS ) ) + nTimeUnit = ::com::sun::star::chart::TimeUnit::DAY; + else if( IsXMLToken( rValue, XML_MONTHS ) ) + nTimeUnit = ::com::sun::star::chart::TimeUnit::MONTH; + else if( IsXMLToken( rValue, XML_YEARS ) ) + nTimeUnit = ::com::sun::star::chart::TimeUnit::YEAR; + return nTimeUnit; +} + +} + +void DateScaleContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList ) +{ + if( !m_xAxisProps.is() ) + return; + + // parse attributes + sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; + SchXMLImport& rImport = ( SchXMLImport& )GetImport(); + const SvXMLTokenMap& rAttrTokenMap = theDateScaleAttributeTokenMap::get(); + + bool bSetNewIncrement=false; + chart::TimeIncrement aIncrement; + m_xAxisProps->getPropertyValue( OUString::createFromAscii( "TimeIncrement" )) >>= aIncrement; + + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + OUString aValue = xAttrList->getValueByIndex( i ); + USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + switch( rAttrTokenMap.Get( nPrefix, aLocalName )) + { + case XML_TOK_DATESCALE_BASE_TIME_UNIT: + { + aIncrement.TimeResolution = uno::makeAny( lcl_getTimeUnit(aValue) ); + bSetNewIncrement = true; + } + break; + case XML_TOK_DATESCALE_MAJOR_INTERVAL_VALUE: + { + chart::TimeInterval aInterval(1,0); + aIncrement.MajorTimeInterval >>= aInterval; + SvXMLUnitConverter::convertNumber( aInterval.Number, aValue ); + aIncrement.MajorTimeInterval = uno::makeAny(aInterval); + bSetNewIncrement = true; + } + break; + case XML_TOK_DATESCALE_MAJOR_INTERVAL_UNIT: + { + chart::TimeInterval aInterval(1,0); + aIncrement.MajorTimeInterval >>= aInterval; + aInterval.TimeUnit = lcl_getTimeUnit(aValue); + aIncrement.MajorTimeInterval = uno::makeAny(aInterval); + bSetNewIncrement = true; + } + break; + case XML_TOK_DATESCALE_MINOR_INTERVAL_VALUE: + { + chart::TimeInterval aInterval(1,0); + aIncrement.MinorTimeInterval >>= aInterval; + SvXMLUnitConverter::convertNumber( aInterval.Number, aValue ); + aIncrement.MinorTimeInterval = uno::makeAny(aInterval); + bSetNewIncrement = true; + } + break; + case XML_TOK_DATESCALE_MINOR_INTERVAL_UNIT: + { + chart::TimeInterval aInterval(1,0); + aIncrement.MinorTimeInterval >>= aInterval; + aInterval.TimeUnit = lcl_getTimeUnit(aValue); + aIncrement.MinorTimeInterval = uno::makeAny(aInterval); + bSetNewIncrement = true; + } + break; + } + } + + if( bSetNewIncrement ) + m_xAxisProps->setPropertyValue( OUString::createFromAscii( "TimeIncrement" ), uno::makeAny( aIncrement ) ); +} + +// ======================================== diff --git a/xmloff/source/chart/SchXMLAxisContext.hxx b/xmloff/source/chart/SchXMLAxisContext.hxx index 6ad27921024e..78ce22415630 100755 --- a/xmloff/source/chart/SchXMLAxisContext.hxx +++ b/xmloff/source/chart/SchXMLAxisContext.hxx @@ -63,8 +63,12 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::chart::XDiagram > m_xDiagram; SchXMLAxis m_aCurrentAxis; std::vector< SchXMLAxis >& m_rAxes; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xAxisProps; rtl::OUString m_aAutoStyleName; rtl::OUString& m_rCategoriesAddress; + sal_Int32 m_nAxisType;//::com::sun::star::chart::ChartAxisType + bool m_bAxisTypeImported; + bool m_bDateScaleImported; bool m_bAddMissingXAxisForNetCharts; //to correct errors from older versions bool m_bAdaptWrongPercentScaleValues; //to correct errors from older versions bool m_bAdaptXAxisOrientationForOld2DBarCharts; //to correct different behaviour from older versions diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index f220cf3dfa9a..580e7dd1f8bf 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -69,15 +69,20 @@ #include #include #include -#include #include #include +#include +#include +#include +#include #include #include #include #include #include +#include +#include #include #include #include @@ -202,9 +207,10 @@ public: const com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > & xNewDiagram, sal_Bool bExportContent ); void exportAxis( enum XMLTokenEnum eDimension, enum XMLTokenEnum eAxisName, - const Reference< beans::XPropertySet > xAxisProps, const Reference< beans::XPropertySet > xTitleProps, const OUString& rCategoriesRanges, + const Reference< beans::XPropertySet > xAxisProps, const Reference< chart2::XAxis >& xChart2Axis, const Reference< beans::XPropertySet > xTitleProps, const OUString& rCategoriesRanges, const Reference< beans::XPropertySet > xMajorGridProps, const Reference< beans::XPropertySet > xMinorGridProps, bool bExportContent ); void exportGrid( const Reference< beans::XPropertySet > xGridProperties, bool bMajor, bool bExportContent ); + void exportDateScale( const Reference< beans::XPropertySet > xAxisProps ); void exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent ); void exportSeries( @@ -699,6 +705,7 @@ bool lcl_SequenceHasUnhiddenData( const uno::Reference< chart2::data::XDataSeque } typedef vector< OUString > tStringVector; +typedef vector< double > tDoubleVector; typedef vector< vector< OUString > > t2DStringVector; typedef vector< vector< double > > t2DNumberContainer; @@ -713,8 +720,8 @@ struct lcl_TableData tStringVector aRowDescriptions; tStringVector aRowDescriptions_Ranges; - Sequence< Sequence< OUString > > aComplexColumnDescriptions;//outer index is columns - inner index is level - Sequence< Sequence< OUString > > aComplexRowDescriptions;//outer index is rows - inner index is level + Sequence< Sequence< uno::Any > > aComplexColumnDescriptions;//outer index is columns - inner index is level + Sequence< Sequence< uno::Any > > aComplexRowDescriptions;//outer index is rows - inner index is level ::std::vector< sal_Int32 > aHiddenColumns; }; @@ -781,7 +788,7 @@ void lcl_ReorderInternalSequencesAccordingToTheirRangeName( lcl_TableData lcl_getDataForLocalTable( const SchXMLExportHelper_Impl::tDataSequenceCont & aSequencesToExport, - const Reference< chart::XComplexDescriptionAccess >& xComplexDescriptionAccess, + const Reference< chart2::XAnyDescriptionAccess >& xAnyDescriptionAccess, const OUString& rCategoriesRange, bool bSeriesFromColumns, const Reference< chart2::data::XRangeXMLConversion > & xRangeConversion ) @@ -791,15 +798,15 @@ lcl_TableData lcl_getDataForLocalTable( try { Sequence< OUString > aSimpleCategories; - if( xComplexDescriptionAccess.is() ) + if( xAnyDescriptionAccess.is() ) { if( bSeriesFromColumns ) - aSimpleCategories = xComplexDescriptionAccess->getRowDescriptions(); + aSimpleCategories = xAnyDescriptionAccess->getRowDescriptions(); else - aSimpleCategories = xComplexDescriptionAccess->getColumnDescriptions(); + aSimpleCategories = xAnyDescriptionAccess->getColumnDescriptions(); - aResult.aComplexColumnDescriptions = xComplexDescriptionAccess->getComplexColumnDescriptions(); - aResult.aComplexRowDescriptions = xComplexDescriptionAccess->getComplexRowDescriptions(); + aResult.aComplexColumnDescriptions = xAnyDescriptionAccess->getAnyColumnDescriptions(); + aResult.aComplexRowDescriptions = xAnyDescriptionAccess->getAnyRowDescriptions(); } SchXMLExportHelper_Impl::tDataSequenceCont::size_type nNumSequences = aSequencesToExport.size(); @@ -1585,7 +1592,7 @@ void SchXMLExportHelper_Impl::parseDocument( Reference< chart::XChartDocument >& delete pElChart; } -void lcl_exportComplexLabel( const Sequence< OUString >& rComplexLabel, SvXMLExport& rExport ) +void lcl_exportComplexLabel( const Sequence< uno::Any >& rComplexLabel, SvXMLExport& rExport ) { sal_Int32 nLength = rComplexLabel.getLength(); if( nLength<=1 ) @@ -1594,7 +1601,12 @@ void lcl_exportComplexLabel( const Sequence< OUString >& rComplexLabel, SvXMLExp for(sal_Int32 nN=0; nN>=aString) ) + { + //todo? + } + SchXMLTools::exportText( rExport, aString, false /*bConvertTabsLFs*/ ); } } @@ -1614,17 +1626,17 @@ void SchXMLExportHelper_Impl::exportTable() xRangeConversion.set( xNewDoc->getDataProvider(), uno::UNO_QUERY ); } - Reference< chart::XComplexDescriptionAccess > xComplexDescriptionAccess; + Reference< chart2::XAnyDescriptionAccess > xAnyDescriptionAccess; { Reference< chart::XChartDocument > xChartDoc( mrExport.GetModel(), uno::UNO_QUERY ); if( xChartDoc.is() ) - xComplexDescriptionAccess = Reference< chart::XComplexDescriptionAccess >( xChartDoc->getData(), uno::UNO_QUERY ); + xAnyDescriptionAccess = Reference< chart2::XAnyDescriptionAccess >( xChartDoc->getData(), uno::UNO_QUERY ); } if( bHasOwnData ) lcl_ReorderInternalSequencesAccordingToTheirRangeName( m_aDataSequencesToExport ); lcl_TableData aData( lcl_getDataForLocalTable( m_aDataSequencesToExport - , xComplexDescriptionAccess, maCategoriesRange + , xAnyDescriptionAccess, maCategoriesRange , mbRowSourceColumns, xRangeConversion )); tStringVector::const_iterator aDataRangeIter( aData.aDataRangeRepresentations.begin()); @@ -1685,17 +1697,40 @@ void SchXMLExportHelper_Impl::exportTable() //export column descriptions tStringVector::const_iterator aColumnDescriptions_RangeIter( aData.aColumnDescriptions_Ranges.begin()); const tStringVector::const_iterator aColumnDescriptions_RangeEnd( aData.aColumnDescriptions_Ranges.end()); - const Sequence< Sequence< OUString > >& rComplexColumnDescriptions = aData.aComplexColumnDescriptions; + const Sequence< Sequence< uno::Any > >& rComplexColumnDescriptions = aData.aComplexColumnDescriptions; sal_Int32 nComplexCount = rComplexColumnDescriptions.getLength(); sal_Int32 nC = 0; - for( tStringVector::const_iterator aIt( aData.aColumnDescriptions.begin()); - aIt != aData.aColumnDescriptions.end(); ++aIt ) + for( tStringVector::const_iterator aIt( aData.aColumnDescriptions.begin()) + ; (aIt != aData.aColumnDescriptions.end()) + ; aIt++, nC++ ) { - mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING ); + bool bExportString = true; + if( nC < nComplexCount ) + { + const Sequence< uno::Any >& rComplexLabel = rComplexColumnDescriptions[nC]; + if( rComplexLabel.getLength()>0 ) + { + double fValue=0.0; + if( rComplexLabel[0] >>=fValue ) + { + bExportString = false; + + SvXMLUnitConverter::convertDouble( msStringBuffer, fValue ); + msString = msStringBuffer.makeStringAndClear(); + mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT ); + mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE, msString ); + } + } + } + if( bExportString ) + { + mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING ); + } + SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True ); exportText( *aIt ); if( nC < nComplexCount ) - lcl_exportComplexLabel( rComplexColumnDescriptions[nC++], mrExport ); + lcl_exportComplexLabel( rComplexColumnDescriptions[nC], mrExport ); if( !bHasOwnData && aColumnDescriptions_RangeIter != aColumnDescriptions_RangeEnd ) { // remind the original range to allow a correct re-association when copying via clipboard @@ -1711,25 +1746,47 @@ void SchXMLExportHelper_Impl::exportTable() { SvXMLElementExport aRows( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROWS, sal_True, sal_True ); tStringVector::const_iterator aRowDescriptionsIter( aData.aRowDescriptions.begin()); - const Sequence< Sequence< OUString > >& rComplexRowDescriptions = aData.aComplexRowDescriptions; + const Sequence< Sequence< uno::Any > >& rComplexRowDescriptions = aData.aComplexRowDescriptions; sal_Int32 nComplexCount = rComplexRowDescriptions.getLength(); sal_Int32 nC = 0; - for( t2DNumberContainer::const_iterator aRowIt( aData.aDataInRows.begin()); - aRowIt != aData.aDataInRows.end(); ++aRowIt ) + for( t2DNumberContainer::const_iterator aRowIt( aData.aDataInRows.begin()) + ; aRowIt != aData.aDataInRows.end() + ; aRowIt++, nC++, aRowDescriptionsIter++ ) { SvXMLElementExport aRow( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True ); //export row descriptions { - mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING ); + bool bExportString = true; + if( nC < nComplexCount ) + { + const Sequence< uno::Any >& rComplexLabel = rComplexRowDescriptions[nC]; + if( rComplexLabel.getLength()>0 ) + { + double fValue=0.0; + if( rComplexLabel[0] >>=fValue ) + { + bExportString = false; + + SvXMLUnitConverter::convertDouble( msStringBuffer, fValue ); + msString = msStringBuffer.makeStringAndClear(); + mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT ); + mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE, msString ); + } + } + } + if( bExportString ) + { + mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING ); + } + SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True ); if( aRowDescriptionsIter != aData.aRowDescriptions.end()) { exportText( *aRowDescriptionsIter ); - ++aRowDescriptionsIter; if( nC < nComplexCount ) - lcl_exportComplexLabel( rComplexRowDescriptions[nC++], mrExport ); + lcl_exportComplexLabel( rComplexRowDescriptions[nC], mrExport ); if( !bHasOwnData && aRowDescriptions_RangeIter != aRowDescriptions_RangeEnd ) { // remind the original range to allow a correct re-association when copying via clipboard @@ -2149,6 +2206,57 @@ void SchXMLExportHelper_Impl::exportCoordinateRegion( const uno::Reference< char SvXMLElementExport aCoordinateRegion( mrExport, XML_NAMESPACE_CHART_EXT, XML_COORDINATE_REGION, sal_True, sal_True );//#i100778# todo: change to chart namespace in future - dependent on fileformat } +namespace +{ + XMLTokenEnum lcl_getTimeUnitToken( sal_Int32 nTimeUnit ) + { + XMLTokenEnum eToken = XML_DAYS; + switch( nTimeUnit ) + { + case ::com::sun::star::chart::TimeUnit::YEAR: + eToken = XML_YEARS; + break; + case ::com::sun::star::chart::TimeUnit::MONTH: + eToken = XML_MONTHS; + break; + default://days + break; + } + return eToken; + } +} + +void SchXMLExportHelper_Impl::exportDateScale( const Reference< beans::XPropertySet > xAxisProps ) +{ + if( !xAxisProps.is() ) + return; + + chart::TimeIncrement aIncrement; + if( (xAxisProps->getPropertyValue( OUString::createFromAscii( "TimeIncrement" )) >>= aIncrement) ) + { + sal_Int32 nTimeResolution = ::com::sun::star::chart::TimeUnit::DAY; + if( aIncrement.TimeResolution >>= nTimeResolution ) + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_BASE_TIME_UNIT, lcl_getTimeUnitToken( nTimeResolution ) ); + + OUStringBuffer aValue; + chart::TimeInterval aInterval; + if( aIncrement.MajorTimeInterval >>= aInterval ) + { + SvXMLUnitConverter::convertNumber( aValue, aInterval.Number ); + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MAJOR_INTERVAL_VALUE, aValue.makeStringAndClear() ); + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MAJOR_INTERVAL_UNIT, lcl_getTimeUnitToken( aInterval.TimeUnit ) ); + } + if( aIncrement.MinorTimeInterval >>= aInterval ) + { + SvXMLUnitConverter::convertNumber( aValue, aInterval.Number ); + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MINOR_INTERVAL_VALUE, aValue.makeStringAndClear() ); + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MINOR_INTERVAL_UNIT, lcl_getTimeUnitToken( aInterval.TimeUnit ) ); + } + + SvXMLElementExport aDateScale( mrExport, XML_NAMESPACE_CHART_EXT, XML_DATE_SCALE, sal_True, sal_True );//#i25706#todo: change namespace for next ODF version + } +} + void SchXMLExportHelper_Impl::exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent ) { if( !xTitleProps.is() ) @@ -2196,10 +2304,54 @@ void SchXMLExportHelper_Impl::exportGrid( const Reference< beans::XPropertySet > aPropertyStates.clear(); } +namespace +{ + +//returns true if a date scale needs to be exported +bool lcl_exportAxisType( const Reference< chart2::XAxis > xChart2Axis, SvXMLExport& rExport) +{ + bool bExportDateScale = false; + if( !xChart2Axis.is() ) + return bExportDateScale; + + const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); + if( nCurrentODFVersion != SvtSaveOptions::ODFVER_LATEST ) //#i25706#todo: change version for next ODF version + return bExportDateScale; + + chart2::ScaleData aScale( xChart2Axis->getScaleData() ); + //#i25706#todo: change namespace for next ODF version + sal_uInt16 nNameSpace = XML_NAMESPACE_CHART_EXT; + + switch(aScale.AxisType) + { + case chart2::AxisType::CATEGORY: + if( aScale.AutoDateAxis ) + { + rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_AUTO ); + bExportDateScale = true; + } + else + rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_TEXT ); + break; + case chart2::AxisType::DATE: + rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_DATE ); + bExportDateScale = true; + break; + default: //AUTOMATIC + rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_AUTO ); + break; + } + + return bExportDateScale; +} + +} + void SchXMLExportHelper_Impl::exportAxis( enum XMLTokenEnum eDimension, enum XMLTokenEnum eAxisName, const Reference< beans::XPropertySet > xAxisProps, + const Reference< chart2::XAxis >& xChart2Axis, const Reference< beans::XPropertySet > xTitleProps, const OUString& rCategoriesRange, const Reference< beans::XPropertySet > xMajorGridProps, @@ -2217,11 +2369,15 @@ void SchXMLExportHelper_Impl::exportAxis( aPropertyStates = mxExpPropMapper->Filter( xAxisProps ); } + bool bExportDateScale = false; if( bExportContent ) { mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, eDimension ); mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, eAxisName ); AddAutoStyleAttribute( aPropertyStates ); // write style name + if( rCategoriesRange.getLength() ) + bExportDateScale = lcl_exportAxisType( xChart2Axis, mrExport ); + // open axis element pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True ); } @@ -2231,6 +2387,10 @@ void SchXMLExportHelper_Impl::exportAxis( } aPropertyStates.clear(); + //date scale + if( bExportDateScale ) + exportDateScale( xAxisProps ); + // axis-title exportAxisTitle( xTitleProps , bExportContent ); @@ -2383,7 +2543,7 @@ void SchXMLExportHelper_Impl::exportAxes( } } } - exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); aCategoriesRange = OUString(); } @@ -2397,7 +2557,7 @@ void SchXMLExportHelper_Impl::exportAxes( xAxisProps = xAxisTwoXSupp.is() ? xAxisTwoXSupp->getSecondaryXAxis() : 0; xTitleProps = ( bHasSecondaryXAxisTitle && xSecondTitleSupp.is() ) ? Reference< beans::XPropertySet >( xSecondTitleSupp->getSecondXAxisTitle(), uno::UNO_QUERY ) : 0; xMajorGridProps = xMinorGridProps = 0; - exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } // y axis @@ -2410,7 +2570,7 @@ void SchXMLExportHelper_Impl::exportAxes( xTitleProps = (bHasYAxisTitle && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYAxisTitle(), uno::UNO_QUERY ) : 0; xMajorGridProps = (bHasYAxisMajorGrid && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYMainGrid(), uno::UNO_QUERY ) : 0; xMinorGridProps = (bHasYAxisMinorGrid && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYHelpGrid(), uno::UNO_QUERY ) : 0; - exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } // secondary y axis @@ -2422,7 +2582,7 @@ void SchXMLExportHelper_Impl::exportAxes( xAxisProps = xAxisTwoYSupp.is() ? xAxisTwoYSupp->getSecondaryYAxis() : 0; xTitleProps = ( bHasSecondaryYAxisTitle && xSecondTitleSupp.is() ) ? Reference< beans::XPropertySet >( xSecondTitleSupp->getSecondYAxisTitle(), uno::UNO_QUERY ) : 0; xMajorGridProps = xMinorGridProps = 0; - exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); } // z axis @@ -2435,7 +2595,69 @@ void SchXMLExportHelper_Impl::exportAxes( xTitleProps = (bHasZAxisTitle && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZAxisTitle(), uno::UNO_QUERY ) : 0; xMajorGridProps = (bHasZAxisMajorGrid && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZMainGrid(), uno::UNO_QUERY ) : 0; xMinorGridProps = (bHasZAxisMinorGrid && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZHelpGrid(), uno::UNO_QUERY ) : 0; - exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + } +} + +namespace +{ + bool lcl_hasNoValuesButText( const uno::Reference< chart2::data::XDataSequence >& xDataSequence ) + { + if( !xDataSequence.is() ) + return false;//have no data + + Sequence< uno::Any > aData; + Reference< chart2::data::XNumericalDataSequence > xNumericalDataSequence( xDataSequence, uno::UNO_QUERY ); + if( xNumericalDataSequence.is() ) + { + Sequence< double > aDoubles( xNumericalDataSequence->getNumericalData() ); + sal_Int32 nCount = aDoubles.getLength(); + for( sal_Int32 i = 0; i < nCount; ++i ) + { + if( !::rtl::math::isNan( aDoubles[i] ) ) + return false;//have double value + } + } + else + { + aData = xDataSequence->getData(); + double fDouble = 0.0; + sal_Int32 nCount = aData.getLength(); + for( sal_Int32 i = 0; i < nCount; ++i ) + { + if( (aData[i] >>= fDouble) && !::rtl::math::isNan( fDouble ) ) + return false;//have double value + } + + } + //no values found + + Reference< chart2::data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY ); + if( xTextualDataSequence.is() ) + { + uno::Sequence< rtl::OUString > aStrings( xTextualDataSequence->getTextualData() ); + sal_Int32 nCount = aStrings.getLength(); + for( sal_Int32 i = 0; i < nCount; ++i ) + { + if( aStrings[i].getLength() ) + return true;//have text + } + } + else + { + if( !aData.getLength() ) + aData = xDataSequence->getData(); + uno::Any aAny; + OUString aString; + sal_Int32 nCount = aData.getLength(); + for( sal_Int32 i = 0; i < nCount; ++i ) + { + if( (aData[i]>>=aString) && aString.getLength() ) + return true;//have text + } + } + //no doubles and no texts + return false; } } @@ -2680,6 +2902,20 @@ void SchXMLExportHelper_Impl::exportSeries( if( lcl_exportDomainForThisSequence( xValues, aFirstXDomainRange, mrExport ) ) m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xValues )); } + else if( nSeriesIdx==0 ) + { + //might be that the categories are used as x-values (e.g. for date axis) -> export them accordingly + Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xNewDiagram ) ); + if( xCategories.is() ) + { + Reference< chart2::data::XDataSequence > xValues( xCategories->getValues() ); + if( !lcl_hasNoValuesButText( xValues ) ) + { + if( lcl_exportDomainForThisSequence( xValues, aFirstXDomainRange, mrExport ) ) + m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xValues )); + } + } + } } if( xYValuesForBubbleChart.is() ) m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xYValuesForBubbleChart )); diff --git a/xmloff/source/chart/SchXMLTableContext.cxx b/xmloff/source/chart/SchXMLTableContext.cxx index bc1b50a908a2..b833e4bc2377 100644 --- a/xmloff/source/chart/SchXMLTableContext.cxx +++ b/xmloff/source/chart/SchXMLTableContext.cxx @@ -42,11 +42,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -839,15 +839,25 @@ void SchXMLTableCellContext::EndElement() // ======================================== -void lcl_ApplyCellToComplexLabel( const SchXMLCell& rCell, Sequence< OUString >& rComplexLabel ) +void lcl_ApplyCellToComplexLabel( const SchXMLCell& rCell, Sequence< uno::Any >& rComplexLabel ) { if( rCell.eType == SCH_CELL_TYPE_STRING ) { rComplexLabel.realloc(1); - rComplexLabel[0] = rCell.aString; + rComplexLabel[0] = uno::makeAny( rCell.aString ); } else if( rCell.pComplexString && rCell.eType == SCH_CELL_TYPE_COMPLEX_STRING ) - rComplexLabel = *rCell.pComplexString; + { + sal_Int32 nCount = rCell.pComplexString->getLength(); + rComplexLabel.realloc( nCount ); + for( sal_Int32 nN=0; nN > aDataInRows( nNumRows ); - Sequence< Sequence< OUString > > aComplexRowDescriptions( nNumRows ); - Sequence< Sequence< OUString > > aComplexColumnDescriptions( nNumColumns ); + Sequence< Sequence< uno::Any > > aComplexRowDescriptions( nNumRows ); + Sequence< Sequence< uno::Any > > aComplexColumnDescriptions( nNumColumns ); for( sal_Int32 i=0; i xDataAccess( xDataProv, uno::UNO_QUERY ); + Reference< chart2::XAnyDescriptionAccess > xDataAccess( xDataProv, uno::UNO_QUERY ); if( !xDataAccess.is() ) return; xDataAccess->setData( aDataInRows ); if( rTable.bHasHeaderColumn ) - xDataAccess->setComplexRowDescriptions( aComplexRowDescriptions ); + xDataAccess->setAnyRowDescriptions( aComplexRowDescriptions ); if( rTable.bHasHeaderRow ) - xDataAccess->setComplexColumnDescriptions( aComplexColumnDescriptions ); + xDataAccess->setAnyColumnDescriptions( aComplexColumnDescriptions ); } void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary( diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 6cfacbd93905..824d28a51a5c 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3113,6 +3113,14 @@ namespace xmloff { namespace token { TOKEN( "outside-minimum", XML_OUTSIDE_MINIMUM ), TOKEN( "outside-maximum", XML_OUTSIDE_MAXIMUM ), + TOKEN( "axis-type", XML_AXIS_TYPE ), //#i25706# + TOKEN( "date-scale", XML_DATE_SCALE ), + TOKEN( "base-time-unit", XML_BASE_TIME_UNIT ), + TOKEN( "major-interval-value", XML_MAJOR_INTERVAL_VALUE ), + TOKEN( "minor-interval-value", XML_MINOR_INTERVAL_VALUE ), + TOKEN( "major-interval-unit", XML_MAJOR_INTERVAL_UNIT ), + TOKEN( "minor-interval-unit", XML_MINOR_INTERVAL_UNIT ), + TOKEN( "min-value", XML_MIN_VALUE ), TOKEN( "max-value", XML_MAX_VALUE ), -- cgit From a72330b7efb98fed5164e201033981d6c677036e Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Tue, 30 Nov 2010 16:24:52 +0100 Subject: chart46: #i25706# implement date axis - remove compiler warnings --- xmloff/source/chart/SchXMLAxisContext.cxx | 1 - xmloff/source/chart/SchXMLExport.cxx | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index 6714ea307f42..9900ec8b697f 100755 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -1207,7 +1207,6 @@ void DateScaleContext::StartElement( const Reference< xml::sax::XAttributeList > // parse attributes sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; - SchXMLImport& rImport = ( SchXMLImport& )GetImport(); const SvXMLTokenMap& rAttrTokenMap = theDateScaleAttributeTokenMap::get(); bool bSetNewIncrement=false; diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index 580e7dd1f8bf..63a09a5b97e5 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -1858,6 +1858,8 @@ Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSyst case XML_Z: nDimensionIndex=2; break; + default: + break; } xNewAxis = xCooSys->getAxisByDimension( nDimensionIndex, bPrimary ? 0 : 1 ); -- cgit From 32fba607b364d773c5ebb389f2e04c5c626c4536 Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Fri, 3 Dec 2010 23:01:44 +0100 Subject: chart46: #i25706# implement date axis - simplify axis access in chart api --- xmloff/source/chart/SchXMLAxisContext.cxx | 465 +++++++------------------- xmloff/source/chart/SchXMLExport.cxx | 112 +++---- xmloff/source/chart/SchXMLPlotAreaContext.cxx | 66 ++-- 3 files changed, 186 insertions(+), 457 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index 9900ec8b697f..0af33a037bd9 100755 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -47,11 +47,8 @@ #include #include #include -#include -#include -#include -#include - +#include +#include #include #include #include @@ -152,157 +149,96 @@ SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper, SchXMLAxisContext::~SchXMLAxisContext() {} +Reference< chart::XAxis > lcl_getChartAxis( SchXMLAxis aCurrentAxis, const Reference< chart::XDiagram > xDiagram ) +{ + Reference< chart::XAxis > xAxis; + Reference< chart::XAxisSupplier > xAxisSuppl( xDiagram, uno::UNO_QUERY ); + if( !xAxisSuppl.is() ) + return xAxis; + if( aCurrentAxis.nAxisIndex == 0 ) + xAxis = xAxisSuppl->getAxis(aCurrentAxis.eDimension); + else + xAxis = xAxisSuppl->getSecondaryAxis(aCurrentAxis.eDimension); + return xAxis; +} + /* returns a shape for the current axis's title. The property "Has...AxisTitle" is set to "True" to get the shape */ Reference< drawing::XShape > SchXMLAxisContext::getTitleShape() { Reference< drawing::XShape > xResult; - uno::Any aTrueBool; - aTrueBool <<= (sal_Bool)(sal_True); - Reference< beans::XPropertySet > xDiaProp( m_xDiagram, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xDiaProp( m_rImportHelper.GetChartDocument()->getDiagram(), uno::UNO_QUERY ); + Reference< chart::XAxis > xAxis( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ) ); + if( !xDiaProp.is() || !xAxis.is() ) + return xResult; + rtl::OUString aPropName; switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: if( m_aCurrentAxis.nAxisIndex == 0 ) - { - Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii( "HasXAxisTitle" ), aTrueBool ); - xResult = Reference< drawing::XShape >( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); - } - } + aPropName = OUString::createFromAscii( "HasXAxisTitle" ); else - { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() ) - { - if( xDiaProp.is() ) - xDiaProp->setPropertyValue( OUString::createFromAscii( "HasSecondaryXAxisTitle" ), aTrueBool ); - xResult = Reference< drawing::XShape >( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); - } - } + aPropName = OUString::createFromAscii( "HasSecondaryXAxisTitle" ); break; case SCH_XML_AXIS_Y: if( m_aCurrentAxis.nAxisIndex == 0 ) - { - Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii( "HasYAxisTitle" ), aTrueBool ); - xResult = Reference< drawing::XShape >( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); - } - } + aPropName = OUString::createFromAscii( "HasYAxisTitle" ); else - { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() ) - { - if( xDiaProp.is() ) - xDiaProp->setPropertyValue( OUString::createFromAscii( "HasSecondaryYAxisTitle" ), aTrueBool ); - xResult = Reference< drawing::XShape >( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); - } - } + aPropName = OUString::createFromAscii( "HasSecondaryYAxisTitle" ); break; case SCH_XML_AXIS_Z: - { - Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii( "HasZAxisTitle" ), aTrueBool ); - xResult = Reference< drawing::XShape >( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); - } + aPropName = OUString::createFromAscii( "HasZAxisTitle" ); break; - } case SCH_XML_AXIS_UNDEF: DBG_ERROR( "Invalid axis" ); break; } - + xDiaProp->setPropertyValue( aPropName, uno::makeAny(sal_True) ); + xResult = Reference< drawing::XShape >( xAxis->getAxisTitle(), uno::UNO_QUERY ); return xResult; } void SchXMLAxisContext::CreateGrid( OUString sAutoStyleName, bool bIsMajor ) { - Reference< chart::XDiagram > xDia = m_rImportHelper.GetChartDocument()->getDiagram(); - Reference< beans::XPropertySet > xGridProp; - OUString sPropertyName; - DBG_ASSERT( xDia.is(), "diagram object is invalid!" ); - - Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY ); - uno::Any aTrueBool( uno::makeAny( true )); + Reference< beans::XPropertySet > xDiaProp( m_rImportHelper.GetChartDocument()->getDiagram(), uno::UNO_QUERY ); + Reference< chart::XAxis > xAxis( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ) ); + if( !xDiaProp.is() || !xAxis.is() ) + return; + rtl::OUString aPropName; switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: - { - Reference< chart::XAxisXSupplier > xSuppl( xDia, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( bIsMajor ) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii("HasXAxisGrid"), aTrueBool ); - xGridProp = xSuppl->getXMainGrid(); - } - else - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii("HasXAxisHelpGrid"), aTrueBool ); - xGridProp = xSuppl->getXHelpGrid(); - } - } - } + if( bIsMajor ) + aPropName = OUString::createFromAscii("HasXAxisGrid"); + else + aPropName = OUString::createFromAscii("HasXAxisHelpGrid"); break; case SCH_XML_AXIS_Y: - { - Reference< chart::XAxisYSupplier > xSuppl( xDia, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( bIsMajor ) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii("HasYAxisGrid"), aTrueBool ); - xGridProp = xSuppl->getYMainGrid(); - } - else - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii("HasYAxisHelpGrid"), aTrueBool ); - xGridProp = xSuppl->getYHelpGrid(); - } - } - } + if( bIsMajor ) + aPropName = OUString::createFromAscii("HasYAxisGrid"); + else + aPropName = OUString::createFromAscii("HasYAxisHelpGrid"); break; case SCH_XML_AXIS_Z: - { - Reference< chart::XAxisZSupplier > xSuppl( xDia, uno::UNO_QUERY ); - if( xSuppl.is()) - { - if( bIsMajor ) - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii("HasZAxisGrid"), aTrueBool ); - xGridProp = xSuppl->getZMainGrid(); - } - else - { - if( xDiaProp.is()) - xDiaProp->setPropertyValue( OUString::createFromAscii("HasZAxisHelpGrid"), aTrueBool ); - xGridProp = xSuppl->getZHelpGrid(); - } - } - } + if( bIsMajor ) + aPropName = OUString::createFromAscii("HasZAxisGrid"); + else + aPropName = OUString::createFromAscii("HasZAxisHelpGrid"); break; case SCH_XML_AXIS_UNDEF: DBG_ERROR( "Invalid axis" ); break; } + xDiaProp->setPropertyValue( aPropName, uno::makeAny(sal_True) ); + + Reference< beans::XPropertySet > xGridProp; + if( bIsMajor ) + xGridProp = xAxis->getMajorGrid(); + else + xGridProp = xAxis->getMinorGrid(); // set properties if( xGridProp.is()) @@ -472,131 +408,80 @@ bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData) void SchXMLAxisContext::CreateAxis() { - // add new Axis to list m_rAxes.push_back( m_aCurrentAxis ); - // set axis at chart - Reference< beans::XPropertySet > xDiaProp( m_xDiagram, uno::UNO_QUERY ); - uno::Any aTrueBool; - aTrueBool <<= (sal_Bool)(sal_True); - uno::Any aFalseBool; - aFalseBool <<= (sal_Bool)(sal_False); - Reference< frame::XModel > xDoc( m_rImportHelper.GetChartDocument(), uno::UNO_QUERY ); - + Reference< beans::XPropertySet > xDiaProp( m_rImportHelper.GetChartDocument()->getDiagram(), uno::UNO_QUERY ); + if( !xDiaProp.is() ) + return; + rtl::OUString aPropName; switch( m_aCurrentAxis.eDimension ) { case SCH_XML_AXIS_X: if( m_aCurrentAxis.nAxisIndex == 0 ) - { - try - { - xDiaProp->setPropertyValue( - OUString::createFromAscii( "HasXAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on x axis" ); - } - Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - m_xAxisProps = xSuppl->getXAxis(); - } + aPropName = OUString::createFromAscii("HasXAxis"); else - { - try - { - xDiaProp->setPropertyValue( - OUString::createFromAscii( "HasSecondaryXAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on second x axis" ); - } - Reference< chart::XTwoAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - m_xAxisProps = xSuppl->getSecondaryXAxis(); - } + aPropName = OUString::createFromAscii("HasSecondaryXAxis"); break; - case SCH_XML_AXIS_Y: if( m_aCurrentAxis.nAxisIndex == 0 ) - { - try - { - xDiaProp->setPropertyValue( - OUString::createFromAscii( "HasYAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on y axis" ); - } - Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - m_xAxisProps = xSuppl->getYAxis(); - - - if( m_bAddMissingXAxisForNetCharts ) - { - if( xDiaProp.is() ) - { - try - { - xDiaProp->setPropertyValue( - OUString::createFromAscii( "HasXAxis" ), uno::makeAny(sal_True) ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on x axis" ); - } - } - } - } + aPropName = OUString::createFromAscii("HasYAxis"); else - { - try - { - xDiaProp->setPropertyValue( - OUString::createFromAscii( "HasSecondaryYAxis" ), aTrueBool ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on second y axis" ); - } - Reference< chart::XTwoAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - m_xAxisProps = xSuppl->getSecondaryYAxis(); - } + aPropName = OUString::createFromAscii("HasSecondaryYAxis"); break; - case SCH_XML_AXIS_Z: - { - bool bSettingZAxisSuccedded = false; - try - { - OUString sHasZAxis( OUString::createFromAscii( "HasZAxis" ) ); - xDiaProp->setPropertyValue( sHasZAxis, aTrueBool ); - xDiaProp->getPropertyValue( sHasZAxis ) >>= bSettingZAxisSuccedded; - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Couldn't turn on z axis" ); - } - if( bSettingZAxisSuccedded ) - { - Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is()) - m_xAxisProps = xSuppl->getZAxis(); - } - } + if( m_aCurrentAxis.nAxisIndex == 0 ) + aPropName = OUString::createFromAscii("HasXAxis"); + else + aPropName = OUString::createFromAscii("HasSecondaryXAxis"); break; case SCH_XML_AXIS_UNDEF: - // nothing + DBG_ERROR( "Invalid axis" ); break; } + try + { + xDiaProp->setPropertyValue( aPropName, uno::makeAny(sal_True) ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on axis" ); + } + if( m_aCurrentAxis.eDimension==SCH_XML_AXIS_Z ) + { + bool bSettingZAxisSuccedded = false; + try + { + xDiaProp->getPropertyValue( aPropName ) >>= bSettingZAxisSuccedded; + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on z axis" ); + } + if( !bSettingZAxisSuccedded ) + return; + } + + + m_xAxisProps = Reference( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ), uno::UNO_QUERY ); + + if( m_bAddMissingXAxisForNetCharts && m_aCurrentAxis.eDimension==SCH_XML_AXIS_Y && m_aCurrentAxis.nAxisIndex==0 ) + { + try + { + xDiaProp->setPropertyValue( OUString::createFromAscii( "HasXAxis" ), uno::makeAny(sal_True) ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Couldn't turn on x axis" ); + } + } // set properties if( m_xAxisProps.is()) { + uno::Any aTrueBool( uno::makeAny( sal_True )); + uno::Any aFalseBool( uno::makeAny( sal_False )); + // #i109879# the line color is black as default, in the model it is a light gray m_xAxisProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )), uno::makeAny( COL_BLACK )); @@ -641,10 +526,10 @@ void SchXMLAxisContext::CreateAxis() { //copy style from y axis to added x axis: - Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() ) + Reference< chart::XAxisSupplier > xAxisSuppl( xDiaProp, uno::UNO_QUERY ); + if( xAxisSuppl.is() ) { - Reference< beans::XPropertySet > xXAxisProp( xSuppl->getXAxis() ); + Reference< beans::XPropertySet > xXAxisProp( xAxisSuppl->getAxis(0), uno::UNO_QUERY ); (( XMLPropStyleContext* )pStyle )->FillPropertySet( xXAxisProp ); } @@ -713,130 +598,24 @@ void SchXMLAxisContext::CreateAxis() void SchXMLAxisContext::SetAxisTitle() { - // add new Axis to list - m_rAxes.push_back( m_aCurrentAxis ); + if( !m_aCurrentAxis.aTitle.getLength() ) + return; - // set axis at chart - sal_Bool bHasTitle = ( m_aCurrentAxis.aTitle.getLength() > 0 ); - Reference< frame::XModel > xDoc( m_rImportHelper.GetChartDocument(), uno::UNO_QUERY ); + Reference< chart::XAxis > xAxis( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ) ); + if( !xAxis.is() ) + return; - switch( m_aCurrentAxis.eDimension ) + Reference< beans::XPropertySet > xTitleProp( xAxis->getAxisTitle() ); + if( xTitleProp.is() ) { - case SCH_XML_AXIS_X: - if( m_aCurrentAxis.nAxisIndex == 0 ) - { - Reference< chart::XAxisXSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && bHasTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xSuppl->getXAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= m_aCurrentAxis.aTitle; - xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - else - { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && bHasTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= m_aCurrentAxis.aTitle; - xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - break; - - case SCH_XML_AXIS_Y: - if( m_aCurrentAxis.nAxisIndex == 0 ) - { - Reference< chart::XAxisYSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && bHasTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xSuppl->getYAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= m_aCurrentAxis.aTitle; - xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - else - { - Reference< chart::XSecondAxisTitleSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && bHasTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= m_aCurrentAxis.aTitle; - xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - break; - - case SCH_XML_AXIS_Z: - { - Reference< chart::XAxisZSupplier > xSuppl( m_xDiagram, uno::UNO_QUERY ); - if( xSuppl.is() && bHasTitle ) - { - Reference< beans::XPropertySet > xTitleProp( xSuppl->getZAxisTitle(), uno::UNO_QUERY ); - if( xTitleProp.is()) - { - try - { - uno::Any aAny; - aAny <<= m_aCurrentAxis.aTitle; - xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny ); - } - catch( beans::UnknownPropertyException & ) - { - DBG_ERROR( "Property String for Title not available" ); - } - } - } - } - break; - case SCH_XML_AXIS_UNDEF: - // nothing - break; + try + { + xTitleProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), uno::makeAny(m_aCurrentAxis.aTitle) ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR( "Property String for Title not available" ); + } } } diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index 63a09a5b97e5..ae89102f9d29 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -64,11 +64,10 @@ #include #include +#include +#include #include #include -#include -#include -#include #include #include #include @@ -207,8 +206,9 @@ public: const com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > & xNewDiagram, sal_Bool bExportContent ); void exportAxis( enum XMLTokenEnum eDimension, enum XMLTokenEnum eAxisName, - const Reference< beans::XPropertySet > xAxisProps, const Reference< chart2::XAxis >& xChart2Axis, const Reference< beans::XPropertySet > xTitleProps, const OUString& rCategoriesRanges, - const Reference< beans::XPropertySet > xMajorGridProps, const Reference< beans::XPropertySet > xMinorGridProps, bool bExportContent ); + const Reference< beans::XPropertySet > xAxisProps, const Reference< chart2::XAxis >& xChart2Axis, + const OUString& rCategoriesRanges, + bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid, bool bExportContent ); void exportGrid( const Reference< beans::XPropertySet > xGridProperties, bool bMajor, bool bExportContent ); void exportDateScale( const Reference< beans::XPropertySet > xAxisProps ); void exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent ); @@ -2354,10 +2354,8 @@ void SchXMLExportHelper_Impl::exportAxis( enum XMLTokenEnum eAxisName, const Reference< beans::XPropertySet > xAxisProps, const Reference< chart2::XAxis >& xChart2Axis, - const Reference< beans::XPropertySet > xTitleProps, const OUString& rCategoriesRange, - const Reference< beans::XPropertySet > xMajorGridProps, - const Reference< beans::XPropertySet > xMinorGridProps, + bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid, bool bExportContent ) { static const OUString sNumFormat( OUString::createFromAscii( "NumberFormat" )); @@ -2393,6 +2391,17 @@ void SchXMLExportHelper_Impl::exportAxis( if( bExportDateScale ) exportDateScale( xAxisProps ); + Reference< beans::XPropertySet > xTitleProps; + Reference< beans::XPropertySet > xMajorGridProps; + Reference< beans::XPropertySet > xMinorGridProps; + Reference< chart::XAxis > xAxis( xAxisProps, uno::UNO_QUERY ); + if( xAxis.is() ) + { + xTitleProps = bHasTitle ? xAxis->getAxisTitle() : 0; + xMajorGridProps = bHasMajorGrid ? xAxis->getMajorGrid() : 0; + xMinorGridProps = bHasMinorGrid ? xAxis->getMinorGrid() : 0; + } + // axis-title exportAxisTitle( xTitleProps , bExportContent ); @@ -2445,41 +2454,16 @@ void SchXMLExportHelper_Impl::exportAxes( // get multiple properties using XMultiPropertySet MultiPropertySetHandler aDiagramProperties (xDiagram); - // Check for supported services and then the properties provided by this service. - Reference xServiceInfo (xDiagram, uno::UNO_QUERY); - if (xServiceInfo.is()) - { - if (xServiceInfo->supportsService( - OUString::createFromAscii ("com.sun.star.chart.ChartAxisXSupplier"))) - { - aDiagramProperties.Add ( - OUString(RTL_CONSTASCII_USTRINGPARAM("HasXAxis")), bHasXAxis); - } - if (xServiceInfo->supportsService( - OUString::createFromAscii ("com.sun.star.chart.ChartAxisYSupplier"))) - { - aDiagramProperties.Add ( - OUString(RTL_CONSTASCII_USTRINGPARAM("HasYAxis")), bHasYAxis); - } - if (xServiceInfo->supportsService( - OUString::createFromAscii ("com.sun.star.chart.ChartAxisZSupplier"))) - { - aDiagramProperties.Add ( - OUString(RTL_CONSTASCII_USTRINGPARAM("HasZAxis")), bHasZAxis); - } - if (xServiceInfo->supportsService( - OUString::createFromAscii ("com.sun.star.chart.ChartTwoAxisXSupplier"))) - { - aDiagramProperties.Add ( - OUString(RTL_CONSTASCII_USTRINGPARAM("HasSecondaryXAxis")), bHasSecondaryXAxis); - } - if (xServiceInfo->supportsService( - OUString::createFromAscii ("com.sun.star.chart.ChartTwoAxisYSupplier"))) - { - aDiagramProperties.Add ( - OUString(RTL_CONSTASCII_USTRINGPARAM("HasSecondaryYAxis")), bHasSecondaryYAxis); - } - } + aDiagramProperties.Add ( + OUString(RTL_CONSTASCII_USTRINGPARAM("HasXAxis")), bHasXAxis); + aDiagramProperties.Add ( + OUString(RTL_CONSTASCII_USTRINGPARAM("HasYAxis")), bHasYAxis); + aDiagramProperties.Add ( + OUString(RTL_CONSTASCII_USTRINGPARAM("HasZAxis")), bHasZAxis); + aDiagramProperties.Add ( + OUString(RTL_CONSTASCII_USTRINGPARAM("HasSecondaryXAxis")), bHasSecondaryXAxis); + aDiagramProperties.Add ( + OUString(RTL_CONSTASCII_USTRINGPARAM("HasSecondaryYAxis")), bHasSecondaryYAxis); aDiagramProperties.Add ( OUString (RTL_CONSTASCII_USTRINGPARAM ("HasXAxisTitle")), bHasXAxisTitle); @@ -2516,21 +2500,15 @@ void SchXMLExportHelper_Impl::exportAxes( // write an axis element also if the axis itself is not visible, but a grid or a title Reference< beans::XPropertySet > xAxisProps; - Reference< beans::XPropertySet > xTitleProps; OUString aCategoriesRange; - Reference< beans::XPropertySet > xMajorGridProps; - Reference< beans::XPropertySet > xMinorGridProps; + Reference< chart::XAxisSupplier > xAxisSupp( xDiagram, uno::UNO_QUERY ); // x axis // ------- Reference< ::com::sun::star::chart2::XAxis > xNewAxis = lcl_getAxis( xCooSys, XML_X ); if( xNewAxis.is() ) { - Reference< chart::XAxisXSupplier > xAxisXSupp( xDiagram, uno::UNO_QUERY ); - xAxisProps = xAxisXSupp.is() ? xAxisXSupp->getXAxis() : 0; - xTitleProps = (bHasXAxisTitle && xAxisXSupp.is()) ? Reference< beans::XPropertySet >( xAxisXSupp->getXAxisTitle(), uno::UNO_QUERY ) : 0; - xMajorGridProps = (bHasXAxisMajorGrid && xAxisXSupp.is()) ? Reference< beans::XPropertySet >( xAxisXSupp->getXMainGrid(), uno::UNO_QUERY ) : 0; - xMinorGridProps = (bHasXAxisMinorGrid && xAxisXSupp.is()) ? Reference< beans::XPropertySet >( xAxisXSupp->getXHelpGrid(), uno::UNO_QUERY ) : 0; + Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(0) : 0, uno::UNO_QUERY ); if( mbHasCategoryLabels && bExportContent ) { Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xNewDiagram ) ); @@ -2545,7 +2523,7 @@ void SchXMLExportHelper_Impl::exportAxes( } } } - exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasXAxisTitle, bHasXAxisMajorGrid, bHasXAxisMinorGrid, bExportContent ); aCategoriesRange = OUString(); } @@ -2555,11 +2533,8 @@ void SchXMLExportHelper_Impl::exportAxes( xNewAxis = lcl_getAxis( xCooSys, XML_X, false ); if( xNewAxis.is() ) { - Reference< chart::XTwoAxisXSupplier > xAxisTwoXSupp( xDiagram, uno::UNO_QUERY ); - xAxisProps = xAxisTwoXSupp.is() ? xAxisTwoXSupp->getSecondaryXAxis() : 0; - xTitleProps = ( bHasSecondaryXAxisTitle && xSecondTitleSupp.is() ) ? Reference< beans::XPropertySet >( xSecondTitleSupp->getSecondXAxisTitle(), uno::UNO_QUERY ) : 0; - xMajorGridProps = xMinorGridProps = 0; - exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getSecondaryAxis(0) : 0, uno::UNO_QUERY ); + exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryXAxisTitle, false, false, bExportContent ); } // y axis @@ -2567,12 +2542,8 @@ void SchXMLExportHelper_Impl::exportAxes( xNewAxis = lcl_getAxis( xCooSys, XML_Y ); if( xNewAxis.is() ) { - Reference< chart::XAxisYSupplier > xAxisYSupp( xDiagram, uno::UNO_QUERY ); - xAxisProps = xAxisYSupp.is() ? xAxisYSupp->getYAxis() : 0; - xTitleProps = (bHasYAxisTitle && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYAxisTitle(), uno::UNO_QUERY ) : 0; - xMajorGridProps = (bHasYAxisMajorGrid && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYMainGrid(), uno::UNO_QUERY ) : 0; - xMinorGridProps = (bHasYAxisMinorGrid && xAxisYSupp.is()) ? Reference< beans::XPropertySet >( xAxisYSupp->getYHelpGrid(), uno::UNO_QUERY ) : 0; - exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(1) : 0, uno::UNO_QUERY ); + exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasYAxisTitle, bHasYAxisMajorGrid, bHasYAxisMinorGrid, bExportContent ); } // secondary y axis @@ -2580,11 +2551,8 @@ void SchXMLExportHelper_Impl::exportAxes( xNewAxis = lcl_getAxis( xCooSys, XML_Y, false ); if( xNewAxis.is() ) { - Reference< chart::XTwoAxisYSupplier > xAxisTwoYSupp( xDiagram, uno::UNO_QUERY ); - xAxisProps = xAxisTwoYSupp.is() ? xAxisTwoYSupp->getSecondaryYAxis() : 0; - xTitleProps = ( bHasSecondaryYAxisTitle && xSecondTitleSupp.is() ) ? Reference< beans::XPropertySet >( xSecondTitleSupp->getSecondYAxisTitle(), uno::UNO_QUERY ) : 0; - xMajorGridProps = xMinorGridProps = 0; - exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getSecondaryAxis(1) : 0, uno::UNO_QUERY ); + exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryYAxisTitle, false, false, bExportContent ); } // z axis @@ -2592,12 +2560,8 @@ void SchXMLExportHelper_Impl::exportAxes( xNewAxis = lcl_getAxis( xCooSys, XML_Z ); if( xNewAxis.is() ) { - Reference< chart::XAxisZSupplier > xAxisZSupp( xDiagram, uno::UNO_QUERY ); - xAxisProps = xAxisZSupp.is() ? xAxisZSupp->getZAxis() : 0; - xTitleProps = (bHasZAxisTitle && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZAxisTitle(), uno::UNO_QUERY ) : 0; - xMajorGridProps = (bHasZAxisMajorGrid && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZMainGrid(), uno::UNO_QUERY ) : 0; - xMinorGridProps = (bHasZAxisMinorGrid && xAxisZSupp.is()) ? Reference< beans::XPropertySet >( xAxisZSupp->getZHelpGrid(), uno::UNO_QUERY ) : 0; - exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xNewAxis, xTitleProps, aCategoriesRange, xMajorGridProps, xMinorGridProps, bExportContent ); + Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(2) : 0, uno::UNO_QUERY ); + exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xNewAxis, aCategoriesRange, bHasZAxisTitle, bHasZAxisMajorGrid, bHasZAxisMinorGrid, bExportContent ); } } diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx index 2bfc8d9048d0..d1248fd6aa43 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx @@ -207,47 +207,33 @@ SchXMLPlotAreaContext::SchXMLPlotAreaContext( { try { - if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisXSupplier" ))) - { - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasXAxis" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasXAxisGrid" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasXAxisDescription" ), aFalseBool ); - } - if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartTwoAxisXSupplier" ))) - { - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasSecondaryXAxisDescription" ), aFalseBool ); - } + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasXAxis" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasXAxisGrid" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasXAxisDescription" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasSecondaryXAxisDescription" ), aFalseBool ); + + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasYAxis" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasYAxisGrid" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasYAxisDescription" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasSecondaryYAxisDescription" ), aFalseBool ); + + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasZAxis" ), aFalseBool ); + xProp->setPropertyValue( + rtl::OUString::createFromAscii( "HasZAxisDescription" ), aFalseBool ); - if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisYSupplier" ))) - { - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasYAxis" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasYAxisGrid" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasYAxisDescription" ), aFalseBool ); - } - if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartTwoAxisYSupplier" ))) - { - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasSecondaryYAxisDescription" ), aFalseBool ); - } - - if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisZSupplier" ))) - { - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasZAxis" ), aFalseBool ); - xProp->setPropertyValue( - rtl::OUString::createFromAscii( "HasZAxisDescription" ), aFalseBool ); - } uno::Any aAny; chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS; aAny <<= eSource; -- cgit From b624534a8f258c022caf4ebc96dc60795c790f33 Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Fri, 3 Dec 2010 23:33:00 +0100 Subject: chart46: #i25706# implement date axis - compiler warnings --- xmloff/source/chart/SchXMLExport.cxx | 1 - 1 file changed, 1 deletion(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index ae89102f9d29..b873132b8d36 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -2499,7 +2499,6 @@ void SchXMLExportHelper_Impl::exportAxes( // write an axis element also if the axis itself is not visible, but a grid or a title - Reference< beans::XPropertySet > xAxisProps; OUString aCategoriesRange; Reference< chart::XAxisSupplier > xAxisSupp( xDiagram, uno::UNO_QUERY ); -- cgit From 9caf587e26ea7bc597884048427340e0c7a0f3b9 Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Fri, 10 Dec 2010 14:10:17 +0100 Subject: chart46: #i25706# implement date axis - cleanup --- xmloff/source/chart/SchXMLChartContext.cxx | 55 ++---------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx index e9e3771eb0d7..c28395802609 100644 --- a/xmloff/source/chart/SchXMLChartContext.cxx +++ b/xmloff/source/chart/SchXMLChartContext.cxx @@ -63,7 +63,6 @@ #include #include -#include #include #include #include @@ -78,48 +77,6 @@ using namespace ::SchXMLTools; namespace { -uno::Reference< chart2::XChartTypeTemplate > lcl_getTemplate( const uno::Reference< chart2::XChartDocument > & xDoc ) -{ - uno::Reference< chart2::XChartTypeTemplate > xResult; - try - { - if( !xDoc.is()) - return xResult; - uno::Reference< lang::XMultiServiceFactory > xChartTypeManager( xDoc->getChartTypeManager(), uno::UNO_QUERY ); - if( !xChartTypeManager.is()) - return xResult; - uno::Reference< chart2::XDiagram > xDiagram( xDoc->getFirstDiagram()); - if( !xDiagram.is()) - return xResult; - - uno::Sequence< ::rtl::OUString > aServiceNames( xChartTypeManager->getAvailableServiceNames()); - const sal_Int32 nLength = aServiceNames.getLength(); - - for( sal_Int32 i = 0; i < nLength; ++i ) - { - try - { - uno::Reference< chart2::XChartTypeTemplate > xTempl( - xChartTypeManager->createInstance( aServiceNames[ i ] ), uno::UNO_QUERY_THROW ); - - if( xTempl->matchesTemplate( xDiagram, sal_True )) - { - xResult.set( xTempl ); - break; - } - } - catch( uno::Exception & ) - { - DBG_ERROR( "Exception during determination of chart type template" ); - } - } - } - catch( uno::Exception & ) - { - DBG_ERROR( "Exception during import lcl_getTemplate" ); - } - return xResult; -} void lcl_setRoleAtLabeledSequence( const uno::Reference< chart2::data::XLabeledDataSequence > & xLSeq, @@ -685,10 +642,6 @@ void lcl_ApplyDataFromRectangularRangeToDiagram( if( !xNewDia.is() || !xDataProvider.is() ) return; - uno::Reference< chart2::XChartTypeTemplate > xTemplate( lcl_getTemplate( xNewDoc )); - if(!xTemplate.is()) - return; - sal_Bool bFirstCellAsLabel = (eDataRowSource==chart::ChartDataRowSource_COLUMNS)? bRowHasLabels : bColHasLabels; sal_Bool bHasCateories = @@ -760,7 +713,7 @@ void lcl_ApplyDataFromRectangularRangeToDiagram( -1, uno::makeAny( bHasCateories ), beans::PropertyState_DIRECT_VALUE ); - xTemplate->changeDiagramData( xNewDia, xDataSource, aArgs ); + xNewDia->setDiagramData( xDataSource, aArgs ); } void SchXMLChartContext::EndElement() @@ -810,8 +763,7 @@ void SchXMLChartContext::EndElement() // cleanup: remove empty chart type groups lcl_removeEmptyChartTypeGroups( xNewDoc ); - // set stack mode before a potential template detection (in case we have a - // rectangular range) + // set stack mode before a potential chart type detection (in case we have a rectangular range) uno::Reference< chart::XDiagram > xDiagram( xDoc->getDiagram() ); uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY ); if( xDiaProp.is()) @@ -890,8 +842,7 @@ void SchXMLChartContext::EndElement() { //apply data from rectangular range - // create datasource from data provider with rectangular range - // parameters and change the diagram via template mechanism + // create datasource from data provider with rectangular range parameters and change the diagram setDiagramData try { if( bOlderThan2_3 && xDiaProp.is() )//for older charts the hidden cells were removed by calc on the fly -- cgit From e1f98d1f25f05891f457b115dadbde0915f47cbe Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Fri, 10 Dec 2010 17:07:53 +0100 Subject: chart46: #i25706# implement date axis - switching to scatter or bubble --- xmloff/source/chart/SchXMLChartContext.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx index c28395802609..53a2421f5e25 100644 --- a/xmloff/source/chart/SchXMLChartContext.cxx +++ b/xmloff/source/chart/SchXMLChartContext.cxx @@ -707,11 +707,15 @@ void lcl_ApplyDataFromRectangularRangeToDiagram( uno::Reference< chart2::data::XDataSource > xDataSource( xDataProvider->createDataSource( aArgs )); - aArgs.realloc( aArgs.getLength() + 1 ); - aArgs[ aArgs.getLength() - 1 ] = beans::PropertyValue( + aArgs.realloc( aArgs.getLength() + 2 ); + aArgs[ aArgs.getLength() - 2 ] = beans::PropertyValue( ::rtl::OUString::createFromAscii("HasCategories"), -1, uno::makeAny( bHasCateories ), beans::PropertyState_DIRECT_VALUE ); + aArgs[ aArgs.getLength() - 1 ] = beans::PropertyValue( + ::rtl::OUString::createFromAscii("UseCategoriesAsX"), + -1, uno::makeAny( sal_False ),//categories in ODF files are not to be used as x values (independent from what is offered in our ui) + beans::PropertyState_DIRECT_VALUE ); xNewDia->setDiagramData( xDataSource, aArgs ); } -- cgit From cf0d061fcc5e45e39f30899b339c70313a5f765d Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Mon, 17 Jan 2011 13:32:18 +0100 Subject: chart46: #i25706# compiler error after rebase --- xmloff/source/chart/SchXMLAxisContext.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index 0af33a037bd9..d08e4937ff22 100755 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -31,7 +31,7 @@ #include "SchXMLAxisContext.hxx" #include "SchXMLChartContext.hxx" #include "SchXMLTools.hxx" -#include "xmlnmspe.hxx" +#include #include #include #include -- cgit From f329f09bb7a24c357cf1608c4b00c978892dc0bb Mon Sep 17 00:00:00 2001 From: "Ingrid Halama [iha]" Date: Wed, 19 Jan 2011 15:38:10 +0100 Subject: chart46: #i25706# implement date axis - #i116519# scatter save --- xmloff/source/chart/SchXMLExport.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'xmloff/source') diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index 5de4486c65c8..c12b1ab3d63e 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -2875,10 +2875,7 @@ void SchXMLExportHelper_Impl::exportSeries( { Reference< chart2::data::XDataSequence > xValues( xCategories->getValues() ); if( !lcl_hasNoValuesButText( xValues ) ) - { - if( lcl_exportDomainForThisSequence( xValues, aFirstXDomainRange, mrExport ) ) - m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xValues )); - } + lcl_exportDomainForThisSequence( xValues, aFirstXDomainRange, mrExport ); } } } -- cgit