diff options
Diffstat (limited to 'chart2/source/tools/DataSeriesHelper.cxx')
-rw-r--r-- | chart2/source/tools/DataSeriesHelper.cxx | 457 |
1 files changed, 139 insertions, 318 deletions
diff --git a/chart2/source/tools/DataSeriesHelper.cxx b/chart2/source/tools/DataSeriesHelper.cxx index af3c16190633..45f235cd2810 100644 --- a/chart2/source/tools/DataSeriesHelper.cxx +++ b/chart2/source/tools/DataSeriesHelper.cxx @@ -18,34 +18,36 @@ */ #include <DataSeriesHelper.hxx> +#include <DataSeries.hxx> +#include <DataSeriesProperties.hxx> #include <DataSource.hxx> +#include <ChartType.hxx> #include <unonames.hxx> +#include <Diagram.hxx> +#include <BaseCoordinateSystem.hxx> +#include <Axis.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/chart2/DataPointLabel.hpp> -#include <com/sun/star/chart2/data/XTextualDataSequence.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> -#include <com/sun/star/chart2/data/LabelOrigin.hpp> #include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/chart2/SymbolStyle.hpp> #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart2/XDiagram.hpp> #include <com/sun/star/drawing/LineStyle.hpp> -#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> -#include <com/sun/star/chart2/XChartTypeContainer.hpp> -#include <com/sun/star/chart2/XDataSeriesContainer.hpp> #include <comphelper/sequence.hxx> -#include <rtl/ustrbuf.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <algorithm> #include <iterator> +#include <utility> #include <vector> #include <set> using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; +using namespace ::chart::DataSeriesProperties; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; @@ -56,8 +58,8 @@ namespace class lcl_MatchesRole { public: - explicit lcl_MatchesRole( const OUString & aRole, bool bMatchPrefix ) : - m_aRole( aRole ), + explicit lcl_MatchesRole( OUString aRole, bool bMatchPrefix ) : + m_aRole(std::move( aRole )), m_bMatchPrefix( bMatchPrefix ) {} @@ -83,80 +85,50 @@ private: bool m_bMatchPrefix; }; -Reference< chart2::data::XLabeledDataSequence > lcl_findLSequenceWithOnlyLabel( - const Reference< chart2::data::XDataSource > & xDataSource ) -{ - Reference< chart2::data::XLabeledDataSequence > xResult; - const Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences()); - - for( auto const & labeledData : aSequences ) - { - OSL_ENSURE( labeledData.is(), "empty LabeledDataSequence" ); - // no values are set but a label exists - if( labeledData.is() && - ( ! labeledData->getValues().is() && - labeledData->getLabel().is())) - { - xResult.set( labeledData ); - break; - } - } - - return xResult; -} - void lcl_getCooSysAndChartTypeOfSeries( - const Reference< chart2::XDataSeries > & xSeries, + const rtl::Reference< ::chart::DataSeries > & xSeries, const Reference< chart2::XDiagram > & xDiagram, - Reference< chart2::XCoordinateSystem > & xOutCooSys, - Reference< chart2::XChartType > & xOutChartType ) + rtl::Reference< ::chart::BaseCoordinateSystem > & xOutCooSys, + rtl::Reference< ::chart::ChartType > & xOutChartType ) { - Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY ); - if( !xCooSysCnt.is()) + if( !xDiagram.is()) return; + ::chart::Diagram* pDiagram = dynamic_cast<::chart::Diagram*>(xDiagram.get()); - const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); - for( Reference< chart2::XCoordinateSystem > const & coords : aCooSysSeq ) + for( rtl::Reference< ::chart::BaseCoordinateSystem > const & coords : pDiagram->getBaseCoordinateSystems() ) { - Reference< chart2::XChartTypeContainer > xCTCnt( coords, uno::UNO_QUERY_THROW ); - const Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes()); - for( Reference< chart2::XChartType > const & chartType : aChartTypes ) + for( rtl::Reference< ::chart::ChartType > const & chartType : coords->getChartTypes2() ) { - Reference< chart2::XDataSeriesContainer > xSeriesCnt( chartType, uno::UNO_QUERY ); - if( xSeriesCnt.is()) + for( rtl::Reference< ::chart::DataSeries > const & dataSeries : chartType->getDataSeries2() ) { - const Sequence< Reference< chart2::XDataSeries > > aSeries( xSeriesCnt->getDataSeries()); - for( Reference< chart2::XDataSeries > const & dataSeries : aSeries ) + if( dataSeries == xSeries ) { - if( dataSeries == xSeries ) - { - xOutCooSys.set( coords ); - xOutChartType.set( chartType ); - } + xOutCooSys = coords; + xOutChartType = chartType; } } } } } -void lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries, bool bInsert ) +void lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( const rtl::Reference< ::chart::DataSeries >& xSeries, bool bInsert ) { try { - Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); - if( xSeriesProperties.is() ) + if( xSeries.is() ) { DataPointLabel aLabelAtSeries; - xSeriesProperties->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabelAtSeries; + xSeries->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabelAtSeries; aLabelAtSeries.ShowNumber = bInsert; if( !bInsert ) { aLabelAtSeries.ShowNumberInPercent = false; aLabelAtSeries.ShowCategoryName = false; } - xSeriesProperties->setPropertyValue(CHART_UNONAME_LABEL, uno::Any(aLabelAtSeries)); + xSeries->setPropertyValue(CHART_UNONAME_LABEL, uno::Any(aLabelAtSeries)); uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; - if( xSeriesProperties->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList ) + // "AttributedDataPoints" + if( xSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aAttributedDataPointIndexList ) { for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) { @@ -203,186 +175,79 @@ OUString getRole( const uno::Reference< chart2::data::XLabeledDataSequence >& xL return aRet; } -Reference< chart2::data::XLabeledDataSequence > +uno::Reference< chart2::data::XLabeledDataSequence > getDataSequenceByRole( const Reference< chart2::data::XDataSource > & xSource, const OUString& aRole, bool bMatchPrefix /* = false */ ) { - Reference< chart2::data::XLabeledDataSequence > aNoResult; + uno::Reference< chart2::data::XLabeledDataSequence > aNoResult; if( ! xSource.is()) return aNoResult; - Sequence< Reference< chart2::data::XLabeledDataSequence > > aLabeledSeq( xSource->getDataSequences()); - - const Reference< chart2::data::XLabeledDataSequence > * pBegin = aLabeledSeq.getConstArray(); - const Reference< chart2::data::XLabeledDataSequence > * pEnd = pBegin + aLabeledSeq.getLength(); - const Reference< chart2::data::XLabeledDataSequence > * pMatch = - std::find_if( pBegin, pEnd, lcl_MatchesRole( aRole, bMatchPrefix )); - - if( pMatch != pEnd ) - return *pMatch; + const Sequence< Reference< chart2::data::XLabeledDataSequence > > aLabeledSeq( xSource->getDataSequences()); + try + { + for (auto const & i : aLabeledSeq) + { + if (lcl_MatchesRole(aRole, bMatchPrefix)(i)) + return i; + } + } + catch (const lang::DisposedException&) + { + TOOLS_WARN_EXCEPTION( "chart2", "unexpected exception caught" ); + } return aNoResult; } -std::vector< Reference< chart2::data::XLabeledDataSequence > > +std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > getAllDataSequencesByRole( const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aDataSequences, const OUString& aRole ) { - std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVec; - std::copy_if( aDataSequences.begin(), aDataSequences.end(), - std::back_inserter( aResultVec ), - lcl_MatchesRole(aRole, /*bMatchPrefix*/true) ); - return aResultVec; -} - -std::vector<Reference<css::chart2::data::XLabeledDataSequence> > -getAllDataSequences( const uno::Sequence<uno::Reference<chart2::XDataSeries> >& aSeries ) -{ - std::vector< Reference< chart2::data::XLabeledDataSequence > > aSeqVec; - - for( uno::Reference<chart2::XDataSeries> const & dataSeries : aSeries ) + std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResultVec; + for (const auto & i : aDataSequences) { - Reference< chart2::data::XDataSource > xSource( dataSeries, uno::UNO_QUERY ); - if( xSource.is()) - { - const Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( xSource->getDataSequences()); - aSeqVec.insert( aSeqVec.end(), aSeq.begin(), aSeq.end() ); - } + if (lcl_MatchesRole(aRole, /*bMatchPrefix*/true)(i)) + aResultVec.push_back(i); } - - return aSeqVec; + return aResultVec; } -Reference< chart2::data::XDataSource > - getDataSource( const Sequence< Reference< chart2::XDataSeries > > & aSeries ) +std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > + getAllDataSequencesByRole( const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > & aDataSequences, + const OUString& aRole ) { - return Reference< chart2::data::XDataSource >( - new DataSource(comphelper::containerToSequence(getAllDataSequences(aSeries)))); + std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > aResultVec; + std::copy_if( aDataSequences.begin(), aDataSequences.end(), + std::back_inserter( aResultVec ), + lcl_MatchesRole(aRole, /*bMatchPrefix*/true) ); + return aResultVec; } -namespace -{ -OUString lcl_getDataSequenceLabel( const Reference< chart2::data::XDataSequence > & xSequence ) +std::vector<uno::Reference<chart2::data::XLabeledDataSequence> > +getAllDataSequences( const std::vector<rtl::Reference<DataSeries> >& aSeries ) { - OUString aResult; + std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aSeqVec; - Reference< chart2::data::XTextualDataSequence > xTextSeq( xSequence, uno::UNO_QUERY ); - if( xTextSeq.is()) + for( rtl::Reference<DataSeries> const & dataSeries : aSeries ) { - Sequence< OUString > aSeq( xTextSeq->getTextualData()); - - const sal_Int32 nMax = aSeq.getLength() - 1; - OUStringBuffer aBuf; - - for( sal_Int32 i = 0; i <= nMax; ++i ) - { - aBuf.append( aSeq[i] ); - if( i < nMax ) - aBuf.append( ' '); - } - aResult = aBuf.makeStringAndClear(); + const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > & aSeq( dataSeries->getDataSequences2()); + aSeqVec.insert( aSeqVec.end(), aSeq.begin(), aSeq.end() ); } - else if( xSequence.is()) - { - Sequence< uno::Any > aSeq( xSequence->getData()); - const sal_Int32 nMax = aSeq.getLength() - 1; - OUString aVal; - OUStringBuffer aBuf; - double fNum = 0; - - for( sal_Int32 i = 0; i <= nMax; ++i ) - { - if( aSeq[i] >>= aVal ) - { - aBuf.append( aVal ); - if( i < nMax ) - aBuf.append( ' '); - } - else if( aSeq[ i ] >>= fNum ) - { - aBuf.append( fNum ); - if( i < nMax ) - aBuf.append( ' '); - } - } - aResult = aBuf.makeStringAndClear(); - } - - return aResult; -} -} - -OUString getLabelForLabeledDataSequence( - const Reference< chart2::data::XLabeledDataSequence > & xLabeledSeq ) -{ - OUString aResult; - if( xLabeledSeq.is()) - { - Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getLabel()); - if( xSeq.is() ) - aResult = lcl_getDataSequenceLabel( xSeq ); - if( !xSeq.is() || aResult.isEmpty() ) - { - // no label set or label content is empty -> use auto-generated one - Reference< chart2::data::XDataSequence > xValueSeq( xLabeledSeq->getValues() ); - if( xValueSeq.is() ) - { - Sequence< OUString > aLabels( xValueSeq->generateLabel( - chart2::data::LabelOrigin_SHORT_SIDE ) ); - // no labels returned is interpreted as: auto-generation not - // supported by sequence - if( aLabels.hasElements() ) - aResult=aLabels[0]; - else - { - //todo?: maybe use the index of the series as name - //but as the index may change it would be better to have such a name persistent - //what is not possible at the moment - //--> maybe use the identifier as part of the name ... - aResult = lcl_getDataSequenceLabel( xValueSeq ); - } - } - } - } - return aResult; + return aSeqVec; } -OUString getDataSeriesLabel( - const Reference< chart2::XDataSeries > & xSeries, - const OUString & rLabelSequenceRole ) +rtl::Reference< DataSource > + getDataSource( const std::vector< rtl::Reference< DataSeries > > & aSeries ) { - OUString aResult; - - Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); - if( xSource.is()) - { - Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( - ::chart::DataSeriesHelper::getDataSequenceByRole( xSource, rLabelSequenceRole )); - if( xLabeledSeq.is()) - aResult = getLabelForLabeledDataSequence( xLabeledSeq ); - else - { - // special case: labeled data series with only a label and no values may - // serve as label - xLabeledSeq.set( lcl_findLSequenceWithOnlyLabel( xSource )); - if( xLabeledSeq.is()) - { - Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getLabel()); - if( xSeq.is()) - aResult = lcl_getDataSequenceLabel( xSeq ); - } - } - - } - - return aResult; + return new DataSource(getAllDataSequences(aSeries)); } void setStackModeAtSeries( - const Sequence< Reference< chart2::XDataSeries > > & aSeries, - const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem, + const std::vector< rtl::Reference< DataSeries > > & aSeries, + const rtl::Reference< BaseCoordinateSystem > & xCorrespondingCoordinateSystem, StackMode eStackMode ) { const uno::Any aPropValue( @@ -394,17 +259,16 @@ void setStackModeAtSeries( : chart2::StackingDirection_NO_STACKING ); std::set< sal_Int32 > aAxisIndexSet; - for( Reference< chart2::XDataSeries > const & dataSeries : aSeries ) + for( rtl::Reference< DataSeries > const & dataSeries : aSeries ) { try { - Reference< beans::XPropertySet > xProp( dataSeries, uno::UNO_QUERY ); - if( xProp.is() ) + if( dataSeries.is() ) { - xProp->setPropertyValue( "StackingDirection", aPropValue ); + dataSeries->setPropertyValue( "StackingDirection", aPropValue ); - sal_Int32 nAxisIndex; - xProp->getPropertyValue( "AttachedAxisIndex" ) >>= nAxisIndex; + sal_Int32 nAxisIndex = 0; + dataSeries->getPropertyValue( "AttachedAxisIndex" ) >>= nAxisIndex; aAxisIndexSet.insert(nAxisIndex); } } @@ -425,8 +289,8 @@ void setStackModeAtSeries( for (auto const& axisIndex : aAxisIndexSet) { - Reference< chart2::XAxis > xAxis( - xCorrespondingCoordinateSystem->getAxisByDimension(1, axisIndex)); + rtl::Reference< Axis > xAxis = + xCorrespondingCoordinateSystem->getAxisByDimension2(1, axisIndex); if( xAxis.is()) { bool bPercent = (eStackMode == StackMode::YStackedPercent); @@ -444,15 +308,14 @@ void setStackModeAtSeries( } } -sal_Int32 getAttachedAxisIndex( const Reference< chart2::XDataSeries > & xSeries ) +sal_Int32 getAttachedAxisIndex( const rtl::Reference< DataSeries > & xSeries ) { sal_Int32 nRet = 0; try { - Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); - if( xProp.is() ) + if( xSeries.is() ) { - xProp->getPropertyValue( "AttachedAxisIndex" ) >>= nRet; + xSeries->getFastPropertyValue( PROP_DATASERIES_ATTACHED_AXIS_INDEX ) >>= nRet; } } catch( const uno::Exception & ) @@ -463,8 +326,8 @@ sal_Int32 getAttachedAxisIndex( const Reference< chart2::XDataSeries > & xSeries } sal_Int32 getNumberFormatKeyFromAxis( - const Reference< chart2::XDataSeries > & xSeries, - const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem, + const rtl::Reference< DataSeries > & xSeries, + const rtl::Reference< BaseCoordinateSystem > & xCorrespondingCoordinateSystem, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex /* = -1 */ ) { @@ -473,8 +336,8 @@ sal_Int32 getNumberFormatKeyFromAxis( nAxisIndex = getAttachedAxisIndex( xSeries ); try { - Reference< beans::XPropertySet > xAxisProp( - xCorrespondingCoordinateSystem->getAxisByDimension( nDimensionIndex, nAxisIndex ), uno::UNO_QUERY ); + rtl::Reference< Axis > xAxisProp = + xCorrespondingCoordinateSystem->getAxisByDimension2( nDimensionIndex, nAxisIndex ); if( xAxisProp.is()) xAxisProp->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nResult; } @@ -486,43 +349,40 @@ sal_Int32 getNumberFormatKeyFromAxis( return nResult; } -Reference< chart2::XCoordinateSystem > getCoordinateSystemOfSeries( - const Reference< chart2::XDataSeries > & xSeries, - const Reference< chart2::XDiagram > & xDiagram ) +rtl::Reference< ::chart::BaseCoordinateSystem > getCoordinateSystemOfSeries( + const rtl::Reference< DataSeries > & xSeries, + const rtl::Reference< Diagram > & xDiagram ) { - Reference< chart2::XCoordinateSystem > xResult; - Reference< chart2::XChartType > xDummy; + rtl::Reference< ::chart::BaseCoordinateSystem > xResult; + rtl::Reference< ::chart::ChartType > xDummy; lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xResult, xDummy ); return xResult; } -Reference< chart2::XChartType > getChartTypeOfSeries( - const Reference< chart2::XDataSeries > & xSeries, - const Reference< chart2::XDiagram > & xDiagram ) +rtl::Reference< ::chart::ChartType > getChartTypeOfSeries( + const rtl::Reference< DataSeries > & xSeries, + const rtl::Reference< Diagram > & xDiagram ) { - Reference< chart2::XChartType > xResult; - Reference< chart2::XCoordinateSystem > xDummy; + rtl::Reference< ::chart::ChartType > xResult; + rtl::Reference< ::chart::BaseCoordinateSystem > xDummy; lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xDummy, xResult ); return xResult; } void deleteSeries( - const Reference< chart2::XDataSeries > & xSeries, - const Reference< chart2::XChartType > & xChartType ) + const rtl::Reference< ::chart::DataSeries > & xSeries, + const rtl::Reference< ::chart::ChartType > & xChartType ) { try { - Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY_THROW ); - auto aSeries( - comphelper::sequenceToContainer<std::vector< Reference< chart2::XDataSeries > > >( xSeriesCnt->getDataSeries())); - std::vector< Reference< chart2::XDataSeries > >::iterator aIt = - std::find( aSeries.begin(), aSeries.end(), xSeries ); + std::vector< rtl::Reference< DataSeries > > aSeries = xChartType->getDataSeries2(); + auto aIt = std::find( aSeries.begin(), aSeries.end(), xSeries ); if( aIt != aSeries.end()) { aSeries.erase( aIt ); - xSeriesCnt->setDataSeries( comphelper::containerToSequence( aSeries )); + xChartType->setDataSeries( aSeries ); } } catch( const uno::Exception & ) @@ -531,14 +391,14 @@ void deleteSeries( } } -void switchSymbolsOnOrOff( const Reference< beans::XPropertySet > & xSeriesProperties, +void switchSymbolsOnOrOff( const rtl::Reference< DataSeries > & xSeries, bool bSymbolsOn, sal_Int32 nSeriesIndex ) { - if( !xSeriesProperties.is() ) + if( !xSeries ) return; chart2::Symbol aSymbProp; - if( xSeriesProperties->getPropertyValue( "Symbol") >>= aSymbProp ) + if( xSeries->getPropertyValue( "Symbol") >>= aSymbProp ) { if( !bSymbolsOn ) aSymbProp.Style = chart2::SymbolStyle_NONE; @@ -547,55 +407,55 @@ void switchSymbolsOnOrOff( const Reference< beans::XPropertySet > & xSeriesPrope aSymbProp.Style = chart2::SymbolStyle_STANDARD; aSymbProp.StandardSymbol = nSeriesIndex; } - xSeriesProperties->setPropertyValue( "Symbol", uno::Any( aSymbProp )); + xSeries->setPropertyValue( "Symbol", uno::Any( aSymbProp )); } //todo: check attributed data points } -void switchLinesOnOrOff( const Reference< beans::XPropertySet > & xSeriesProperties, bool bLinesOn ) +void switchLinesOnOrOff( const rtl::Reference< DataSeries > & xSeries, bool bLinesOn ) { - if( !xSeriesProperties.is() ) + if( !xSeries ) return; if( bLinesOn ) { // keep line-styles that are not NONE drawing::LineStyle eLineStyle; - if( (xSeriesProperties->getPropertyValue( "LineStyle") >>= eLineStyle ) && + if( (xSeries->getPropertyValue( "LineStyle") >>= eLineStyle ) && eLineStyle == drawing::LineStyle_NONE ) { - xSeriesProperties->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_SOLID ) ); + xSeries->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_SOLID ) ); } } else - xSeriesProperties->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_NONE ) ); + xSeries->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_NONE ) ); } -void makeLinesThickOrThin( const Reference< beans::XPropertySet > & xSeriesProperties, bool bThick ) +void makeLinesThickOrThin( const rtl::Reference< ::chart::DataSeries > & xSeries, bool bThick ) { - if( !xSeriesProperties.is() ) + if( !xSeries ) return; sal_Int32 nNewValue = bThick ? 80 : 0; sal_Int32 nOldValue = 0; - if( (xSeriesProperties->getPropertyValue( "LineWidth") >>= nOldValue ) && + if( (xSeries->getPropertyValue( "LineWidth") >>= nOldValue ) && nOldValue != nNewValue ) { if( !(bThick && nOldValue>0)) - xSeriesProperties->setPropertyValue( "LineWidth", uno::Any( nNewValue ) ); + xSeries->setPropertyValue( "LineWidth", uno::Any( nNewValue ) ); } } -void setPropertyAlsoToAllAttributedDataPoints( const Reference< chart2::XDataSeries >& xSeries, +void setPropertyAlsoToAllAttributedDataPoints( const rtl::Reference< ::chart::DataSeries >& xSeries, const OUString& rPropertyName, const uno::Any& rPropertyValue ) { - Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); - if( !xSeriesProperties.is() ) + if( !xSeries.is() ) return; - xSeriesProperties->setPropertyValue( rPropertyName, rPropertyValue ); + xSeries->setPropertyValue( rPropertyName, rPropertyValue ); uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; - if( xSeriesProperties->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList ) + // "AttributedDataPoints" + if( xSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aAttributedDataPointIndexList ) { for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) { @@ -604,20 +464,23 @@ void setPropertyAlsoToAllAttributedDataPoints( const Reference< chart2::XDataSer continue; xPointProp->setPropertyValue( rPropertyName, rPropertyValue ); if( rPropertyName == "LabelPlacement" ) + { xPointProp->setPropertyValue("CustomLabelPosition", uno::Any()); + xPointProp->setPropertyValue("CustomLabelSize", uno::Any()); + } } } } -bool hasAttributedDataPointDifferentValue( const Reference< chart2::XDataSeries >& xSeries, +bool hasAttributedDataPointDifferentValue( const rtl::Reference< DataSeries >& xSeries, const OUString& rPropertyName, const uno::Any& rPropertyValue ) { - Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); - if( !xSeriesProperties.is() ) + if( !xSeries.is() ) return false; uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; - if( xSeriesProperties->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList ) + // "AttributedDataPoints" + if( xSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aAttributedDataPointIndexList ) { for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) { @@ -635,46 +498,6 @@ bool hasAttributedDataPointDifferentValue( const Reference< chart2::XDataSeries namespace { -bool lcl_SequenceHasUnhiddenData( const uno::Reference< chart2::data::XDataSequence >& xDataSequence ) -{ - if( !xDataSequence.is() ) - return false; - uno::Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY ); - if( xProp.is() ) - { - uno::Sequence< sal_Int32 > aHiddenValues; - try - { - xProp->getPropertyValue( "HiddenValues" ) >>= aHiddenValues; - if( !aHiddenValues.hasElements() ) - return true; - } - catch( const uno::Exception& ) - { - return true; - } - } - return xDataSequence->getData().hasElements(); -} - -} - -bool hasUnhiddenData( const uno::Reference< chart2::XDataSeries >& xSeries ) -{ - uno::Reference< chart2::data::XDataSource > xDataSource( xSeries, uno::UNO_QUERY ); - - uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aDataSequences = xDataSource->getDataSequences(); - - for(sal_Int32 nN = aDataSequences.getLength();nN--;) - { - if( !aDataSequences[nN].is() ) - continue; - if( lcl_SequenceHasUnhiddenData( aDataSequences[nN]->getValues() ) ) - return true; - if( lcl_SequenceHasUnhiddenData( aDataSequences[nN]->getLabel() ) ) - return true; - } - return false; } sal_Int32 translateIndexFromHiddenToFullSequence( sal_Int32 nIndex, const Reference< chart2::data::XDataSequence >& xDataSequence, bool bTranslate ) @@ -711,16 +534,15 @@ sal_Int32 translateIndexFromHiddenToFullSequence( sal_Int32 nIndex, const Refere return nIndex; } -bool hasDataLabelsAtSeries( const Reference< chart2::XDataSeries >& xSeries ) +bool hasDataLabelsAtSeries( const rtl::Reference< DataSeries >& xSeries ) { bool bRet = false; try { - Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); - if( xProp.is() ) + if( xSeries.is() ) { DataPointLabel aLabel; - if( xProp->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel ) + if( xSeries->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel ) bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName || aLabel.ShowSeriesName; } @@ -732,16 +554,16 @@ bool hasDataLabelsAtSeries( const Reference< chart2::XDataSeries >& xSeries ) return bRet; } -bool hasDataLabelsAtPoints( const Reference< chart2::XDataSeries >& xSeries ) +bool hasDataLabelsAtPoints( const rtl::Reference< DataSeries >& xSeries ) { bool bRet = false; try { - Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); - if( xSeriesProperties.is() ) + if( xSeries.is() ) { uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; - if( xSeriesProperties->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList ) + // "AttributedDataPoints" + if( xSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aAttributedDataPointIndexList ) { for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) { @@ -767,24 +589,23 @@ bool hasDataLabelsAtPoints( const Reference< chart2::XDataSeries >& xSeries ) return bRet; } -bool hasDataLabelAtPoint( const Reference< chart2::XDataSeries >& xSeries, sal_Int32 nPointIndex ) +bool hasDataLabelAtPoint( const rtl::Reference< DataSeries >& xSeries, sal_Int32 nPointIndex ) { bool bRet = false; try { Reference< beans::XPropertySet > xProp; - Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); - if( xSeriesProperties.is() ) + if( xSeries.is() ) { uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; - if( xSeriesProperties->getPropertyValue( "AttributedDataPoints" ) >>= aAttributedDataPointIndexList ) + // "AttributedDataPoints" + if( xSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aAttributedDataPointIndexList ) { - auto aIndices( comphelper::sequenceToContainer<std::vector< sal_Int32 >>( aAttributedDataPointIndexList ) ); - std::vector< sal_Int32 >::iterator aIt = std::find( aIndices.begin(), aIndices.end(), nPointIndex ); - if( aIt != aIndices.end()) + auto aIt = std::find( aAttributedDataPointIndexList.begin(), aAttributedDataPointIndexList.end(), nPointIndex ); + if (aIt != aAttributedDataPointIndexList.end()) xProp = xSeries->getDataPointByIndex(nPointIndex); else - xProp = xSeriesProperties; + xProp = xSeries; } if( xProp.is() ) { @@ -803,12 +624,12 @@ bool hasDataLabelAtPoint( const Reference< chart2::XDataSeries >& xSeries, sal_I return bRet; } -void insertDataLabelsToSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries ) +void insertDataLabelsToSeriesAndAllPoints( const rtl::Reference< DataSeries >& xSeries ) { lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries, true /*bInsert*/ ); } -void deleteDataLabelsFromSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries ) +void deleteDataLabelsFromSeriesAndAllPoints( const rtl::Reference< DataSeries >& xSeries ) { lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries, false /*bInsert*/ ); } |