diff options
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/chart/SchXMLChartContext.cxx | 14 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLChartContext.hxx | 3 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLExport.cxx | 109 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPlotAreaContext.cxx | 32 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPlotAreaContext.hxx | 16 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLSeries2Context.cxx | 250 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLSeries2Context.hxx | 20 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLTools.cxx | 8 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLTools.hxx | 2 | ||||
-rw-r--r-- | xmloff/source/chart/transporttypes.hxx | 22 |
10 files changed, 250 insertions, 226 deletions
diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx index d6072560297a..02c822afed7d 100644 --- a/xmloff/source/chart/SchXMLChartContext.cxx +++ b/xmloff/source/chart/SchXMLChartContext.cxx @@ -269,7 +269,6 @@ void SchXMLChartContext::StartElement( const uno::Reference< xml::sax::XAttribut awt::Size aChartSize; // this flag is necessarry for pie charts in the core sal_Bool bSetSwitchData = sal_False; - sal_Bool bDomainForDefaultDataNeeded = sal_False; ::rtl::OUString sAutoStyleName; ::rtl::OUString aOldChartTypeName; @@ -302,15 +301,9 @@ void SchXMLChartContext::StartElement( const uno::Reference< xml::sax::XAttribut case XML_CHART_CLASS_CIRCLE: bSetSwitchData = sal_True; break; - case XML_CHART_CLASS_SCATTER: - bDomainForDefaultDataNeeded = sal_True; - break; case XML_CHART_CLASS_STOCK: mbIsStockChart = true; break; - case XML_CHART_CLASS_BUBBLE: - DBG_ERROR( "Bubble chart not supported yet" ); - break; default: break; } @@ -321,10 +314,6 @@ void SchXMLChartContext::StartElement( const uno::Reference< xml::sax::XAttribut // service is taken from add-in-name attribute bHasAddin = true; - // for service charts assume domain in base type - // if base type doesn't use a domain this is ok, - // the data just grows bigger - bDomainForDefaultDataNeeded = sal_True; aOldChartTypeName = sClassName; maChartTypeServiceName = sClassName; } @@ -361,7 +350,7 @@ void SchXMLChartContext::StartElement( const uno::Reference< xml::sax::XAttribut maChartTypeServiceName = SchXMLTools::GetChartTypeByClassName( aChartClass_Bar, false /* bUseOldNames */ ); } - InitChart (aChartSize, bDomainForDefaultDataNeeded, aOldChartTypeName, bSetSwitchData); + InitChart (aChartSize, aOldChartTypeName, bSetSwitchData); if( bHasAddin ) { @@ -1116,7 +1105,6 @@ SvXMLImportContext* SchXMLChartContext::CreateChildContext( */ void SchXMLChartContext::InitChart( awt::Size aChartSize, - sal_Bool /* bDomainForDefaultDataNeeded */, const OUString & rChartTypeServiceName, // currently the old service name sal_Bool /* bSetSwitchData */ ) { diff --git a/xmloff/source/chart/SchXMLChartContext.hxx b/xmloff/source/chart/SchXMLChartContext.hxx index 596646e6b35a..5bc20b3e862b 100644 --- a/xmloff/source/chart/SchXMLChartContext.hxx +++ b/xmloff/source/chart/SchXMLChartContext.hxx @@ -139,14 +139,11 @@ private: a locked controller. This includes setting the draw page size and setting the chart type. @param aChartSize The size the draw page will be set to. - @param bDomainForDefaultDataNeeded This flag indicates wether the chart's data set - has to contain a domain value. @param aServiceName The name of the service the diagram is initialized with. @param bSetWitchData Indicates wether the data set takes it's data series from rows or from columns. */ void InitChart (com::sun::star::awt::Size aChartSize, - sal_Bool bDomainForDefaultDataNeeded, const ::rtl::OUString & rChartTypeServiceName, sal_Bool bSetSwitchData); diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index 46dd7e3da973..8f6c0bbf12e9 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -837,6 +837,28 @@ void lcl_exportNumberFormat( const OUString& rPropertyName, const Reference< bea return aResult; } +bool lcl_exportDomainForThisSequence( const Reference< chart2::data::XDataSequence > xValues, rtl::OUString& rFirstRangeForThisDomainIndex, SvXMLExport& rExport ) +{ + bool bDomainExported = false; + if( xValues.is()) + { + Reference< chart2::XChartDocument > xNewDoc( rExport.GetModel(), uno::UNO_QUERY ); + OUString aRange( lcl_ConvertRange( xValues->getSourceRangeRepresentation(), xNewDoc ) ); + + //work around error in OOo 2.0 (problems with multiple series having a domain element) + if( !rFirstRangeForThisDomainIndex.getLength() || !aRange.equals(rFirstRangeForThisDomainIndex) ) + { + rExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, aRange); + SvXMLElementExport aDomain( rExport, XML_NAMESPACE_CHART, XML_DOMAIN, sal_True, sal_True ); + bDomainExported = true; + } + + if( !rFirstRangeForThisDomainIndex.getLength() ) + rFirstRangeForThisDomainIndex = aRange; + } + return bDomainExported; +} + } // anonymous namespace struct SchXMLDataPointStruct @@ -2488,7 +2510,8 @@ void SchXMLExportHelper::exportSeries( return; Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY ); - OUString aFirstXRange; + OUString aFirstXDomainRange; + OUString aFirstYDomainRange; std::vector< XMLPropertyState > aPropertyStates; @@ -2537,7 +2560,6 @@ void SchXMLExportHelper::exportSeries( xSource->getDataSequences()); sal_Int32 nMainSequenceIndex = -1; sal_Int32 nSeriesLength = 0; - sal_Int32 nSeqIdx=0; sal_Int32 nAttachedAxis = chart::ChartAxisAssign::PRIMARY_Y; sal_Bool bHasMeanValueLine = false; chart::ChartRegressionCurveType eRegressionType( chart::ChartRegressionCurveType_NONE ); @@ -2550,29 +2572,32 @@ void SchXMLExportHelper::exportSeries( { Reference< chart2::data::XDataSequence > xValuesSeq; Reference< chart2::data::XDataSequence > xLabelSeq; - for( ;nMainSequenceIndex==-1 && nSeqIdx<aSeqCnt.getLength(); - ++nSeqIdx ) + sal_Int32 nSeqIdx=0; + for( ; nSeqIdx<aSeqCnt.getLength(); ++nSeqIdx ) { OUString aRole; Reference< chart2::data::XDataSequence > xTempValueSeq( aSeqCnt[nSeqIdx]->getValues() ); - Reference< beans::XPropertySet > xSeqProp( xTempValueSeq, uno::UNO_QUERY ); - if( xSeqProp.is()) - xSeqProp->getPropertyValue(OUString::createFromAscii("Role")) >>= aRole; - // "main" sequence - if( aRole.equals( aLabelRole )) + if( nMainSequenceIndex==-1 ) { - xValuesSeq.set( xTempValueSeq ); - xLabelSeq.set( aSeqCnt[nSeqIdx]->getLabel()); - // "main" sequence attributes exported, now go on with domains - nMainSequenceIndex = nSeqIdx; - break; + Reference< beans::XPropertySet > xSeqProp( xTempValueSeq, uno::UNO_QUERY ); + if( xSeqProp.is()) + xSeqProp->getPropertyValue(OUString::createFromAscii("Role")) >>= aRole; + // "main" sequence + if( aRole.equals( aLabelRole )) + { + xValuesSeq.set( xTempValueSeq ); + xLabelSeq.set( aSeqCnt[nSeqIdx]->getLabel()); + nMainSequenceIndex = nSeqIdx; + } } + sal_Int32 nSequenceLength = (xTempValueSeq.is()? xTempValueSeq->getData().getLength() : sal_Int32(0)); + if( nSeriesLength < nSequenceLength ) + nSeriesLength = nSequenceLength; } // have found the main sequence, then xValuesSeq and // xLabelSeq contain those. Otherwise both are empty { - nSeriesLength = (xValuesSeq.is()? xValuesSeq->getData().getLength() : sal_Int32(0)); // get property states for autostyles try { @@ -2688,46 +2713,36 @@ void SchXMLExportHelper::exportSeries( } // export domain elements if we have a series parent element - if( nMainSequenceIndex>-1 ) + if( pSeries ) { // domain elements if( bExportContent ) { - for( nSeqIdx=0; nSeqIdx<aSeqCnt.getLength(); ++nSeqIdx ) + bool bIsScatterChart = aChartType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.ScatterChartType")); + bool bIsBubbleChart = aChartType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.BubbleChartType")); + Reference< chart2::data::XDataSequence > xYValuesForBubbleChart; + if( bIsBubbleChart ) + { + Reference< chart2::data::XLabeledDataSequence > xSequence( lcl_getDataSequenceByRole( aSeqCnt, OUString::createFromAscii("values-y" ) ) ); + if( xSequence.is() ) + { + xYValuesForBubbleChart = xSequence->getValues(); + if( !lcl_exportDomainForThisSequence( xYValuesForBubbleChart, aFirstYDomainRange, mrExport ) ) + xYValuesForBubbleChart = 0; + } + } + if( bIsScatterChart || bIsBubbleChart ) { - if( nSeqIdx != nMainSequenceIndex ) + Reference< chart2::data::XLabeledDataSequence > xSequence( lcl_getDataSequenceByRole( aSeqCnt, OUString::createFromAscii("values-x" ) ) ); + if( xSequence.is() ) { - bool bExportDomain = false; - //@todo: roles should be exported - Reference< chart2::data::XDataSequence > xSeq( aSeqCnt[nSeqIdx]->getValues() ); - if( xSeq.is()) - { - OUString aXRange( lcl_ConvertRange( - xSeq->getSourceRangeRepresentation(), xNewDoc ) ); - //work around error in OOo 2.0 (problems with multiple series having a domain element) - if( !aFirstXRange.getLength() || !aXRange.equals(aFirstXRange) ) - { - bExportDomain = true; - mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, aXRange); - m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xSeq )); - } - - if( !aFirstXRange.getLength() ) - aFirstXRange = aXRange; - } -// xSeq.set( aSeqCnt[nSeqIdx]->getLabel()); -// if( xSeq.is()) -// mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS, -// lcl_ConvertRange( -// xSeq->getSourceRangeRepresentation(), -// xNewDoc )); - if( bExportDomain ) - { - SvXMLElementExport aDomain( mrExport, XML_NAMESPACE_CHART, - XML_DOMAIN, sal_True, sal_True ); - } + Reference< chart2::data::XDataSequence > xValues( xSequence->getValues() ); + 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/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx index bcf1f7abb3bf..46254192571a 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx @@ -195,10 +195,9 @@ SchXMLPlotAreaContext::SchXMLPlotAreaContext( mrCategoriesAddress( rCategoriesAddress ), mrSeriesDefaultsAndStyles( rSeriesDefaultsAndStyles ), mnNumOfLinesProp( 0 ), - mnNumOfLinesReadBySeries( 0 ), mbStockHasVolume( sal_False ), mnSeries( 0 ), - mnMaxSeriesLength( 0 ), + m_aGlobalSeriesImportInfo( rAllRangeAddressesAvailable ), maSceneImportHelper( rImport ), mbHasSize(false), mbHasPosition(false), @@ -206,14 +205,11 @@ SchXMLPlotAreaContext::SchXMLPlotAreaContext( m_bAxisPositionAttributeImported(false), mrChartAddress( rChartAddress ), mrHasOwnTable( rHasOwnTable ), - mrAllRangeAddressesAvailable( rAllRangeAddressesAvailable ), mrColHasLabels( rColHasLabels ), mrRowHasLabels( rRowHasLabels ), mrDataRowSource( rDataRowSource ), - mnFirstFirstDomainIndex( -1 ), maChartTypeServiceName( aChartTypeServiceName ), mrLSequencesPerIndex( rLSequencesPerIndex ), - mnCurrentDataIndex( 0 ), mbGlobalChartTypeUsedBySeries( false ), maChartSize( rChartSize ) { @@ -578,14 +574,11 @@ SvXMLImportContext* SchXMLPlotAreaContext::CreateChildContext( mrImportHelper, GetImport(), rLocalName, mxNewDoc, maAxes, mrSeriesDefaultsAndStyles.maSeriesStyleList, - mnSeries, mnMaxSeriesLength, - mnNumOfLinesReadBySeries, mbStockHasVolume, - maFirstFirstDomainAddress, - mnFirstFirstDomainIndex, - mrAllRangeAddressesAvailable, + mnSeries, + mbStockHasVolume, + m_aGlobalSeriesImportInfo, maChartTypeServiceName, mrLSequencesPerIndex, - mnCurrentDataIndex, mbGlobalChartTypeUsedBySeries, maChartSize ); } mnSeries++; @@ -659,15 +652,8 @@ void SchXMLPlotAreaContext::EndElement() maSceneImportHelper.setSceneAttributes( xDiaProp ); } - // if the property NumberOfLines and the number of series containing - // class="chart:line" as attribute are both different from 0 they must - // be equal - OSL_ASSERT( mnNumOfLinesProp == 0 || mnNumOfLinesReadBySeries == 0 || - mnNumOfLinesProp == mnNumOfLinesReadBySeries ); - // set correct number of lines at series - if( ! mrAllRangeAddressesAvailable && - mnNumOfLinesReadBySeries == 0 && + if( ! m_aGlobalSeriesImportInfo.rbAllRangeAddressesAvailable && mnNumOfLinesProp > 0 && maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" ))) { @@ -1533,7 +1519,7 @@ SvXMLImportContext* SchXMLAxisContext::CreateChildContext( break; case XML_TOK_AXIS_CATEGORIES: - pContext = new SchXMLCategoriesDomainContext( mrImportHelper, GetImport(), + pContext = new SchXMLCategoriesContext( mrImportHelper, GetImport(), p_nPrefix, rLocalName, mrCategoriesAddress ); maCurrentAxis.bHasCategories = true; @@ -1640,7 +1626,7 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr // ======================================== -SchXMLCategoriesDomainContext::SchXMLCategoriesDomainContext( +SchXMLCategoriesContext::SchXMLCategoriesContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, sal_uInt16 nPrefix, @@ -1652,11 +1638,11 @@ SchXMLCategoriesDomainContext::SchXMLCategoriesDomainContext( { } -SchXMLCategoriesDomainContext::~SchXMLCategoriesDomainContext() +SchXMLCategoriesContext::~SchXMLCategoriesContext() { } -void SchXMLCategoriesDomainContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +void SchXMLCategoriesContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) { sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.hxx b/xmloff/source/chart/SchXMLPlotAreaContext.hxx index 2d14f9c644dc..403a87192c54 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.hxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.hxx @@ -107,10 +107,10 @@ private: rtl::OUString& mrCategoriesAddress; SeriesDefaultsAndStyles& mrSeriesDefaultsAndStyles; sal_Int32 mnNumOfLinesProp; - sal_Int32 mnNumOfLinesReadBySeries; sal_Bool mbStockHasVolume; sal_Int32 mnSeries; - sal_Int32 mnMaxSeriesLength; + GlobalSeriesImportInfo m_aGlobalSeriesImportInfo; + SchXML3DSceneAttributesHelper maSceneImportHelper; ::com::sun::star::awt::Size maSize; ::com::sun::star::awt::Point maPosition; @@ -121,17 +121,13 @@ private: ::rtl::OUString msAutoStyleName; ::rtl::OUString& mrChartAddress; sal_Bool & mrHasOwnTable; - sal_Bool & mrAllRangeAddressesAvailable; sal_Bool & mrColHasLabels; sal_Bool & mrRowHasLabels; ::com::sun::star::chart::ChartDataRowSource & mrDataRowSource; - ::rtl::OUString maFirstFirstDomainAddress; - sal_Int32 mnFirstFirstDomainIndex; - ::rtl::OUString maChartTypeServiceName; tSchXMLLSequencesPerIndex & mrLSequencesPerIndex; - sal_Int32 mnCurrentDataIndex; + bool mbGlobalChartTypeUsedBySeries; ::com::sun::star::awt::Size maChartSize; }; @@ -203,19 +199,19 @@ public: // ---------------------------------------- -class SchXMLCategoriesDomainContext : public SvXMLImportContext +class SchXMLCategoriesContext : public SvXMLImportContext { private: SchXMLImportHelper& mrImportHelper; rtl::OUString& mrAddress; public: - SchXMLCategoriesDomainContext( SchXMLImportHelper& rImpHelper, + SchXMLCategoriesContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, sal_uInt16 nPrefix, const rtl::OUString& rLocalName, rtl::OUString& rAddress ); - virtual ~SchXMLCategoriesDomainContext(); + virtual ~SchXMLCategoriesContext(); virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); }; diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx index 07dda88800c4..ca325fe3bafe 100644 --- a/xmloff/source/chart/SchXMLSeries2Context.cxx +++ b/xmloff/source/chart/SchXMLSeries2Context.cxx @@ -81,11 +81,10 @@ using ::rtl::OUStringBuffer; namespace { -OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const Reference< chart2::XChartDocument > & xDoc ) +OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const Reference< chart2::data::XDataProvider >& xDataProvider ) { OUString aResult = rRange; - Reference< chart2::data::XRangeXMLConversion > xConversion( - SchXMLImportHelper::GetDataProvider( xDoc ), uno::UNO_QUERY ); + Reference< chart2::data::XRangeXMLConversion > xConversion( xDataProvider, uno::UNO_QUERY ); if( xConversion.is()) aResult = xConversion->convertRangeFromXML( rRange ); return aResult; @@ -234,6 +233,54 @@ void lcl_insertErrorBarLSequencesToMap( } } +Reference< chart2::data::XLabeledDataSequence > lcl_createAndAddSequenceToSeries( const rtl::OUString& rRole + , const rtl::OUString& rRange + , const Reference< chart2::data::XDataProvider >& xDataProvider + , const Reference< chart2::XDataSeries >& xSeries ) +{ + Reference< chart2::data::XLabeledDataSequence > xLabeledSeq; + + Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY ); + Reference< chart2::data::XDataSink > xSeriesSink( xSeries, uno::UNO_QUERY ); + + if( !(rRange.getLength() && xDataProvider.is() && xSeriesSource.is() && xSeriesSink.is()) ) + return xLabeledSeq; + + // create a new sequence + xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence(); + + // set values at the new sequence + Reference< chart2::data::XDataSequence > xSeq; + try + { + xSeq.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( rRange, xDataProvider ))); + SchXMLTools::setXMLRangePropertyAtDataSequence( xSeq, rRange ); + } + catch( const lang::IllegalArgumentException & ex ) + { + (void)ex; // avoid warning for pro build + OSL_ENSURE( false, ::rtl::OUStringToOString( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IllegalArgumentException caught, Message: " )) + + ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); + } + + Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY ); + if( xSeqProp.is()) + xSeqProp->setPropertyValue(OUString::createFromAscii("Role"), uno::makeAny( rRole)); + xLabeledSeq->setValues( xSeq ); + + // add new sequence to data series / push to front to have the correct sequence order if charttype is changed afterwards + Sequence< Reference< chart2::data::XLabeledDataSequence > > aOldSeq( xSeriesSource->getDataSequences()); + sal_Int32 nOldCount = aOldSeq.getLength(); + Sequence< Reference< chart2::data::XLabeledDataSequence > > aNewSeq( nOldCount + 1 ); + aNewSeq[0]=xLabeledSeq; + for( sal_Int32 nN=0; nN<nOldCount; nN++ ) + aNewSeq[nN+1] = aOldSeq[nN]; + xSeriesSink->setData( aNewSeq ); + + return xLabeledSeq; +} + } // anonymous namespace // ================================================================================ @@ -245,15 +292,10 @@ SchXMLSeries2Context::SchXMLSeries2Context( std::vector< SchXMLAxis >& rAxes, ::std::list< DataRowPointStyle >& rStyleList, sal_Int32 nSeriesIndex, - sal_Int32& rMaxSeriesLength, - sal_Int32& rNumOfLines, - sal_Bool& rStockHasVolume, - ::rtl::OUString& rFirstFirstDomainAddress, - sal_Int32& rFirstFirstDomainIndex, - sal_Bool& rAllRangeAddressesAvailable, + sal_Bool bStockHasVolume, + GlobalSeriesImportInfo& rGlobalSeriesImportInfo, const OUString & aGlobalChartTypeName, tSchXMLLSequencesPerIndex & rLSequencesPerIndex, - sal_Int32& rCurrentDataIndex, bool& rGlobalChartTypeUsedBySeries, const awt::Size & rChartSize ) : SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), @@ -264,18 +306,13 @@ SchXMLSeries2Context::SchXMLSeries2Context( m_xSeries(0), mnSeriesIndex( nSeriesIndex ), mnDataPointIndex( 0 ), - mrMaxSeriesLength( rMaxSeriesLength ), - mrNumOfLines( rNumOfLines ), - mrStockHasVolume( rStockHasVolume ), - mrFirstFirstDomainAddress(rFirstFirstDomainAddress), - mrFirstFirstDomainIndex(rFirstFirstDomainIndex), - mrAllRangeAddressesAvailable( rAllRangeAddressesAvailable ), + m_bStockHasVolume( bStockHasVolume ), + m_rGlobalSeriesImportInfo(rGlobalSeriesImportInfo), mpAttachedAxis( NULL ), maGlobalChartTypeName( aGlobalChartTypeName ), maSeriesChartTypeName( aGlobalChartTypeName ), m_bHasDomainContext(false), mrLSequencesPerIndex( rLSequencesPerIndex ), - mrCurrentDataIndex( rCurrentDataIndex ), mrGlobalChartTypeUsedBySeries( rGlobalChartTypeUsedBySeries ), mbSymbolSizeIsMissingInFile(false), maChartSize( rChartSize ) @@ -369,8 +406,8 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib OSL_ASSERT( mxNewDoc.is()); if( mxNewDoc.is()) { - if( mrAllRangeAddressesAvailable && ! bHasRange ) - mrAllRangeAddressesAvailable = sal_False; + if( m_rGlobalSeriesImportInfo.rbAllRangeAddressesAvailable && ! bHasRange ) + m_rGlobalSeriesImportInfo.rbAllRangeAddressesAvailable = sal_False; Reference< chart2::data::XDataProvider > xDataProvider( mrImportHelper.GetDataProvider( mxNewDoc )); if( xDataProvider.is()) @@ -383,7 +420,7 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib else { if( bIsCandleStick - && mrStockHasVolume + && m_bStockHasVolume && mnSeriesIndex == 0 ) { maSeriesChartTypeName = OUString::createFromAscii( "com.sun.star.chart2.ColumnChartType" ); @@ -424,7 +461,7 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib if( bHasRange ) try { - xSeq.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( m_aSeriesRange, mxNewDoc ))); + xSeq.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( m_aSeriesRange, xDataProvider ))); SchXMLTools::setXMLRangePropertyAtDataSequence( xSeq, m_aSeriesRange ); } catch( const lang::IllegalArgumentException & ex ) @@ -438,16 +475,17 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY ); if( xSeqProp.is()) { - //@todo: set correct role ("main role" dependent on chart type) - xSeqProp->setPropertyValue(OUString::createFromAscii("Role"), - uno::makeAny( OUString::createFromAscii("values-y"))); + OUString aMainRole( OUString::createFromAscii("values-y") ); + if( maSeriesChartTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.BubbleChartType") ) ) + aMainRole = OUString::createFromAscii("values-size"); + xSeqProp->setPropertyValue(OUString::createFromAscii("Role"), uno::makeAny( aMainRole )); } xLabeledSeq->setValues( xSeq ); // register for setting local data if external data provider is not present maPostponedSequences.insert( tSchXMLLSequencesPerIndex::value_type( - tSchXMLIndexWithPart( mrCurrentDataIndex, SCH_XML_PART_VALUES ), xLabeledSeq )); + tSchXMLIndexWithPart( m_rGlobalSeriesImportInfo.nCurrentDataIndex, SCH_XML_PART_VALUES ), xLabeledSeq )); // label if( bHasLabelRange ) @@ -456,7 +494,7 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib { Reference< chart2::data::XDataSequence > xLabelSequence( xDataProvider->createDataSequenceByRangeRepresentation( - lcl_ConvertRange( m_aSeriesLabelRange, mxNewDoc ))); + lcl_ConvertRange( m_aSeriesLabelRange, xDataProvider ))); xLabeledSeq->setLabel( xLabelSequence ); SchXMLTools::setXMLRangePropertyAtDataSequence( xLabelSequence, m_aSeriesLabelRange ); } @@ -475,7 +513,7 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib // used for the internal data. maPostponedSequences.insert( tSchXMLLSequencesPerIndex::value_type( - tSchXMLIndexWithPart( mrCurrentDataIndex, SCH_XML_PART_LABEL ), xLabeledSeq )); + tSchXMLIndexWithPart( m_rGlobalSeriesImportInfo.nCurrentDataIndex, SCH_XML_PART_LABEL ), xLabeledSeq )); Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( &xLabeledSeq, 1 ); @@ -519,47 +557,91 @@ void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttrib } } +struct DomainInfo +{ + DomainInfo( const rtl::OUString& rRole, const rtl::OUString& rRange, sal_Int32 nIndex ) + : aRole(rRole), aRange(rRange), nIndexForLocalData(nIndex) + {} + + rtl::OUString aRole; + rtl::OUString aRange; + sal_Int32 nIndexForLocalData; +}; + void SchXMLSeries2Context::EndElement() { // special handling for different chart types. This is necessary as the // roles are not yet saved in the file format - OUString aXValuesRange( mrFirstFirstDomainAddress ); - sal_Int32 nCurrentDataIndexBeforeDomains = mrCurrentDataIndex; - sal_Int32 nDomainOffset = 0; - bool bCreateXValues = false; - bool bHasOwnDomains = false; + sal_Int32 nDomainCount = maDomainAddresses.size(); + bool bIsScatterChart = maSeriesChartTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.ScatterChartType")); + bool bIsBubbleChart = maSeriesChartTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.BubbleChartType")); bool bDeleteSeries = false; - if( maDomainAddresses.size() == 1 || - maSeriesChartTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.ScatterChartType")) ) + std::vector< DomainInfo > aDomainInfos; + + //different handling for different chart types necessary + if( bIsScatterChart || ( nDomainCount==1 && !bIsBubbleChart ) ) { - bCreateXValues = true; + DomainInfo aDomainInfo( OUString::createFromAscii("values-x"), m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress, m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex ) ; + bool bCreateXValues = true; if( !maDomainAddresses.empty() ) { - aXValuesRange = maDomainAddresses.front(); - bHasOwnDomains = true; - if(!mrFirstFirstDomainAddress.getLength()) + if( !m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.getLength() ) { - mrFirstFirstDomainAddress=aXValuesRange; - mrFirstFirstDomainIndex=mrCurrentDataIndex; + m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = maDomainAddresses.front(); + m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex; } + aDomainInfo.aRange = maDomainAddresses.front(); + aDomainInfo.nIndexForLocalData = m_rGlobalSeriesImportInfo.nCurrentDataIndex; + m_rGlobalSeriesImportInfo.nCurrentDataIndex++; } - else if( !mrFirstFirstDomainAddress.getLength() && !m_bHasDomainContext && mnSeriesIndex==0 ) + else if( !m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.getLength() && !m_bHasDomainContext && mnSeriesIndex==0 ) { if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) ) //wrong old chart files: { //for xy charts the first series needs to have a domain //if this by error iss not the case the first series is taken s x values //needed for wrong files created while having an addin (e.g. BoxPlot) - mrFirstFirstDomainAddress = m_aSeriesRange; - mrFirstFirstDomainIndex = mrCurrentDataIndex; + m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = m_aSeriesRange; + m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex++; bDeleteSeries = true; bCreateXValues = false;//they will be created for the next series } } + if( bCreateXValues ) + aDomainInfos.push_back( aDomainInfo ); + } + else if( bIsBubbleChart ) + { + if( nDomainCount>1 ) + { + DomainInfo aDomainInfo( OUString::createFromAscii("values-x"), maDomainAddresses[1], m_rGlobalSeriesImportInfo.nCurrentDataIndex ) ; + if( !m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress.getLength() ) + { + //for bubble chart the second domain contains the x values which should become an index smaller than y values for own data table + //->so second first + m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress = maDomainAddresses[1]; + m_rGlobalSeriesImportInfo.nFirstSecondDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex; + } + aDomainInfos.push_back( aDomainInfo ); + m_rGlobalSeriesImportInfo.nCurrentDataIndex++; + } + else if( m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress.getLength() ) + { + DomainInfo aDomainInfo( OUString::createFromAscii("values-x"), m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress, m_rGlobalSeriesImportInfo.nFirstSecondDomainIndex ) ; + aDomainInfos.push_back( aDomainInfo ); + } + if( nDomainCount>0) + { + DomainInfo aDomainInfo( OUString::createFromAscii("values-y"), maDomainAddresses.front(), m_rGlobalSeriesImportInfo.nCurrentDataIndex ) ; + if( !m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.getLength() ) + { + m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = maDomainAddresses.front(); + m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex; + } + aDomainInfos.push_back( aDomainInfo ); + m_rGlobalSeriesImportInfo.nCurrentDataIndex++; + } } - - if( mrMaxSeriesLength < mnDataPointIndex ) - mrMaxSeriesLength = mnDataPointIndex; if( bDeleteSeries ) { @@ -583,71 +665,19 @@ void SchXMLSeries2Context::EndElement() } } - if( bCreateXValues && aXValuesRange.getLength()) + Reference< chart2::data::XDataProvider > xDataProvider( mrImportHelper.GetDataProvider( mxNewDoc )); + for( std::vector< DomainInfo >::reverse_iterator aIt( aDomainInfos.rbegin() ); aIt!= aDomainInfos.rend(); ++aIt ) { - Reference< chart2::data::XDataProvider > xDataProvider( mrImportHelper.GetDataProvider( mxNewDoc )); - if( !(m_xSeries.is() && xDataProvider.is())) - return; - - Reference< chart2::data::XDataSource > xSeriesSource( m_xSeries,uno::UNO_QUERY ); - if( ! xSeriesSource.is()) - return; - - // assume we have a scatter chart - - // create new sequence for x-values - Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( - SchXMLTools::GetNewLabeledDataSequence()); - - // values - Reference< chart2::data::XDataSequence > xSeq; - try - { - xSeq.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( aXValuesRange, mxNewDoc ))); - SchXMLTools::setXMLRangePropertyAtDataSequence( xSeq, aXValuesRange ); - } - catch( const lang::IllegalArgumentException & ex ) - { - (void)ex; // avoid warning for pro build - OSL_ENSURE( false, ::rtl::OUStringToOString( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IllegalArgumentException caught, Message: " )) + - ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); - } - - Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY ); - if( xSeqProp.is()) - { - xSeqProp->setPropertyValue(OUString::createFromAscii("Role"), - uno::makeAny( OUString::createFromAscii("values-x"))); - } - xLabeledSeq->setValues( xSeq ); - - // register for setting local data if external data provider is not present - if( bHasOwnDomains ) - { - mrLSequencesPerIndex.insert( - tSchXMLLSequencesPerIndex::value_type( - tSchXMLIndexWithPart( mrCurrentDataIndex, SCH_XML_PART_VALUES ), xLabeledSeq )); - ++mrCurrentDataIndex; - - nDomainOffset = mrCurrentDataIndex - nCurrentDataIndexBeforeDomains; - } - else + DomainInfo aDomainInfo( *aIt ); + Reference< chart2::data::XLabeledDataSequence > xLabeledSeq = + lcl_createAndAddSequenceToSeries( aDomainInfo.aRole, aDomainInfo.aRange, xDataProvider, m_xSeries ); + if( xLabeledSeq.is() ) { + // register for setting local data if external data provider is not present mrLSequencesPerIndex.insert( tSchXMLLSequencesPerIndex::value_type( - tSchXMLIndexWithPart( mrFirstFirstDomainIndex, SCH_XML_PART_VALUES ), xLabeledSeq )); + tSchXMLIndexWithPart( aDomainInfo.nIndexForLocalData, SCH_XML_PART_VALUES ), xLabeledSeq )); } - - // @todo? export and import labels for domains? - - // add new sequence to data series - Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( xSeriesSource->getDataSequences()); - aSeq.realloc( aSeq.getLength() + 1 ); - aSeq[aSeq.getLength()-1] = xLabeledSeq; - Reference< chart2::data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY ); - if( xSink.is()) - xSink->setData( aSeq ); } if( !bDeleteSeries ) @@ -655,18 +685,14 @@ void SchXMLSeries2Context::EndElement() for( tSchXMLLSequencesPerIndex::const_iterator aIt( maPostponedSequences.begin()); aIt != maPostponedSequences.end(); ++aIt ) { - sal_Int32 nNewIndex = aIt->first.first + nDomainOffset; + sal_Int32 nNewIndex = aIt->first.first + nDomainCount; mrLSequencesPerIndex.insert( tSchXMLLSequencesPerIndex::value_type( tSchXMLIndexWithPart( nNewIndex, aIt->first.second ), aIt->second )); } + m_rGlobalSeriesImportInfo.nCurrentDataIndex++; } maPostponedSequences.clear(); - - if( bHasOwnDomains ) - mrCurrentDataIndex += nDomainOffset; - else - ++mrCurrentDataIndex; } SvXMLImportContext* SchXMLSeries2Context::CreateChildContext( diff --git a/xmloff/source/chart/SchXMLSeries2Context.hxx b/xmloff/source/chart/SchXMLSeries2Context.hxx index f540179186ca..f0c8996de539 100644 --- a/xmloff/source/chart/SchXMLSeries2Context.hxx +++ b/xmloff/source/chart/SchXMLSeries2Context.hxx @@ -62,12 +62,10 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > m_xSeries; sal_Int32 mnSeriesIndex; sal_Int32 mnDataPointIndex; - sal_Int32& mrMaxSeriesLength; - sal_Int32& mrNumOfLines; - sal_Bool& mrStockHasVolume; - ::rtl::OUString& mrFirstFirstDomainAddress; - sal_Int32& mrFirstFirstDomainIndex; - sal_Bool& mrAllRangeAddressesAvailable; + sal_Bool m_bStockHasVolume; + + GlobalSeriesImportInfo& m_rGlobalSeriesImportInfo; + SchXMLAxis* mpAttachedAxis; sal_Int32 mnAttachedAxis; ::rtl::OUString msAutoStyleName; @@ -78,7 +76,6 @@ private: ::rtl::OUString m_aSeriesLabelRange; bool m_bHasDomainContext; tSchXMLLSequencesPerIndex & mrLSequencesPerIndex; - sal_Int32& mrCurrentDataIndex; tSchXMLLSequencesPerIndex maPostponedSequences; bool& mrGlobalChartTypeUsedBySeries; bool mbSymbolSizeIsMissingInFile; @@ -92,15 +89,10 @@ public: std::vector< SchXMLAxis >& rAxes, ::std::list< DataRowPointStyle >& rStyleList, sal_Int32 nSeriesIndex, - sal_Int32& rMaxSeriesLength, - sal_Int32& rNumOfLines, - sal_Bool& rStockHasVolume, - ::rtl::OUString& rFirstFirstDomainAddress, - sal_Int32& rFirstFirstDomainIndex, - sal_Bool& rAllRangeAddressesAvailable, + sal_Bool bStockHasVolume, + GlobalSeriesImportInfo& rGlobalSeriesImportInfo, const ::rtl::OUString & aGlobalChartTypeName, tSchXMLLSequencesPerIndex & rLSequencesPerIndex, - sal_Int32& rCurrentDataIndex, bool& rGlobalChartTypeUsedBySeries, const ::com::sun::star::awt::Size & rChartSize ); virtual ~SchXMLSeries2Context(); diff --git a/xmloff/source/chart/SchXMLTools.cxx b/xmloff/source/chart/SchXMLTools.cxx index 7915c9e4e8c1..627d88f58a2e 100644 --- a/xmloff/source/chart/SchXMLTools.cxx +++ b/xmloff/source/chart/SchXMLTools.cxx @@ -185,6 +185,9 @@ const tMakeStringStringMap& lcl_getChartTypeNameMap() ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.StockDiagram" ) , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.CandleStickChartType" ) ) + ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.BubbleDiagram" ) + , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.BubbleChartType" ) ) + ; return g_aChartTypeNameMap; } @@ -241,6 +244,9 @@ OUString GetChartTypeByClassName( else aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Scatter")); } + + else if( IsXMLToken( rClassName, XML_BUBBLE )) + aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Bubble")); else if( IsXMLToken( rClassName, XML_RADAR )) aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Net")); else if( IsXMLToken( rClassName, XML_STOCK )) @@ -306,6 +312,8 @@ XMLTokenEnum getTokenByChartType( else if( (bUseOldNames && aServiceName.equalsAscii("XY")) || (!bUseOldNames && aServiceName.equalsAscii("Scatter"))) eResult = XML_SCATTER; + else if( aServiceName.equalsAscii("Bubble")) + eResult = XML_BUBBLE; else if( aServiceName.equalsAscii("Net")) eResult = XML_RADAR; else if( (bUseOldNames && aServiceName.equalsAscii("Stock")) || diff --git a/xmloff/source/chart/SchXMLTools.hxx b/xmloff/source/chart/SchXMLTools.hxx index dad5a396b6c4..21a286783aad 100644 --- a/xmloff/source/chart/SchXMLTools.hxx +++ b/xmloff/source/chart/SchXMLTools.hxx @@ -67,7 +67,7 @@ namespace SchXMLTools XML_CHART_CLASS_RADAR, XML_CHART_CLASS_BAR, XML_CHART_CLASS_STOCK, - XML_CHART_CLASS_BUBBLE, // not yet implemented + XML_CHART_CLASS_BUBBLE, XML_CHART_CLASS_ADDIN, XML_CHART_CLASS_UNKNOWN }; diff --git a/xmloff/source/chart/transporttypes.hxx b/xmloff/source/chart/transporttypes.hxx index 41bb93fe4401..6046ec4606fc 100644 --- a/xmloff/source/chart/transporttypes.hxx +++ b/xmloff/source/chart/transporttypes.hxx @@ -136,9 +136,25 @@ struct SchXMLAxis // ---------------------------------------- -// struct PostponedStyleObject -// { -// }; +struct GlobalSeriesImportInfo +{ + GlobalSeriesImportInfo( sal_Bool& rAllRangeAddressesAvailable ) + : rbAllRangeAddressesAvailable( rAllRangeAddressesAvailable ) + , nCurrentDataIndex( 0 ) + , nFirstFirstDomainIndex( -1 ) + , nFirstSecondDomainIndex( -1 ) + {} + + sal_Bool& rbAllRangeAddressesAvailable; + + sal_Int32 nCurrentDataIndex; + + ::rtl::OUString aFirstFirstDomainAddress; + sal_Int32 nFirstFirstDomainIndex; + + ::rtl::OUString aFirstSecondDomainAddress; + sal_Int32 nFirstSecondDomainIndex; +}; struct DataRowPointStyle { |