diff options
author | Aritz Erkiaga <aerkiaga3@gmail.com> | 2021-03-25 09:25:27 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-21 09:55:36 +0200 |
commit | c8598f28db8ef5ab5f695cf1af645bb43dbc264d (patch) | |
tree | 6cbd9328749473089ec4f8eeefe5e0737049b048 /chart2/source | |
parent | 9431984f8d39a4d7fb9428138ecc6971c212c122 (diff) |
tdf#138556 Don’t add Open Values to stock chart types 1 and 3
A new function was defined, XdataInterpreter::getChartTypeSpecificData.
Being 100% chart-type-agnostic when retrieving chart data is impossible;
candlestick charts can have different numbers of sequences per series,
and this information is not present in any other chart type.
Change-Id: I0f54b09202c42667331b083d54d90e4ceee81083
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113075
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2/source')
5 files changed, 71 insertions, 2 deletions
diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx index 7e7d10896d03..b88d1f205d5d 100644 --- a/chart2/source/controller/dialogs/DialogModel.cxx +++ b/chart2/source/controller/dialogs/DialogModel.cxx @@ -261,6 +261,26 @@ void lcl_SetSequenceRole( xProp->setPropertyValue( "Role" , uno::Any( rRole )); } +Sequence< OUString > lcl_CopyExcludingValuesFirst( + Sequence< OUString > const & i_aInput ) +{ + Sequence< OUString > aOutput( i_aInput.getLength()); + int nSourceIndex, nDestIndex; + for( nSourceIndex = nDestIndex = 0; nSourceIndex < i_aInput.getLength(); nSourceIndex++ ) + { + if( i_aInput[nSourceIndex] == "values-first" ) + { + aOutput.realloc( aOutput.getLength() - 1 ); + } + else + { + aOutput[nDestIndex] = i_aInput[nSourceIndex]; + nDestIndex++; + } + } + return aOutput; +} + Reference< XDataSeries > lcl_CreateNewSeries( const Reference< uno::XComponentContext > & xContext, const Reference< XChartType > & xChartType, @@ -309,8 +329,29 @@ Reference< XDataSeries > lcl_CreateNewSeries( std::vector< Reference< data::XLabeledDataSequence > > aNewSequences; const OUString aRoleOfSeqForSeriesLabel = xChartType->getRoleOfSequenceForSeriesLabel(); const OUString aLabel(::chart::SchResId(STR_DATA_UNNAMED_SERIES)); - const Sequence< OUString > aRoles( xChartType->getSupportedMandatoryRoles()); - const Sequence< OUString > aOptRoles( xChartType->getSupportedOptionalRoles()); + Sequence< OUString > aPossibleRoles( xChartType->getSupportedMandatoryRoles()); + Sequence< OUString > aPossibleOptRoles( xChartType->getSupportedOptionalRoles()); + + //special handling for candlestick type + if( xTemplate.is()) + { + Reference< XDataInterpreter > xInterpreter( xTemplate->getDataInterpreter()); + if( xInterpreter.is()) + { + sal_Int32 nStockVariant; + if( xInterpreter->getChartTypeSpecificData("stock variant") >>= nStockVariant ) + { + if( nStockVariant == 0 || nStockVariant == 2) { + //delete "values-first" role + aPossibleRoles = lcl_CopyExcludingValuesFirst(aPossibleRoles); + aPossibleOptRoles = lcl_CopyExcludingValuesFirst(aPossibleOptRoles); + } + } + } + } + + const Sequence< OUString > aRoles( aPossibleRoles ); + const Sequence< OUString > aOptRoles( aPossibleOptRoles ); for(OUString const & role : aRoles) { diff --git a/chart2/source/model/template/DataInterpreter.cxx b/chart2/source/model/template/DataInterpreter.cxx index ad473df9e8d7..67e5a0b856e4 100644 --- a/chart2/source/model/template/DataInterpreter.cxx +++ b/chart2/source/model/template/DataInterpreter.cxx @@ -298,6 +298,12 @@ Reference< data::XDataSource > SAL_CALL DataInterpreter::mergeInterpretedData( return DataSourceHelper::createDataSource( comphelper::containerToSequence( aResultVec ) ); } +uno::Any SAL_CALL DataInterpreter::getChartTypeSpecificData( + const OUString & ) +{ + return uno::Any(); +} + // convenience methods OUString DataInterpreter::GetRole( const Reference< data::XDataSequence > & xSeq ) diff --git a/chart2/source/model/template/DataInterpreter.hxx b/chart2/source/model/template/DataInterpreter.hxx index 8294f5ca4c9c..5f9a9239202f 100644 --- a/chart2/source/model/template/DataInterpreter.hxx +++ b/chart2/source/model/template/DataInterpreter.hxx @@ -68,6 +68,8 @@ protected: const css::chart2::InterpretedData& aInterpretedData ) override; virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL mergeInterpretedData( const css::chart2::InterpretedData& aInterpretedData ) override; + virtual css::uno::Any SAL_CALL getChartTypeSpecificData( + const OUString& sKey ) override; }; } // namespace chart diff --git a/chart2/source/model/template/StockDataInterpreter.cxx b/chart2/source/model/template/StockDataInterpreter.cxx index 15c2891975ad..dd42201c31c6 100644 --- a/chart2/source/model/template/StockDataInterpreter.cxx +++ b/chart2/source/model/template/StockDataInterpreter.cxx @@ -18,6 +18,7 @@ */ #include "StockDataInterpreter.hxx" +#include "StockChartTypeTemplate.hxx" #include <DataSeries.hxx> #include <com/sun/star/chart2/data/XDataSink.hpp> #include <tools/diagnose_ex.h> @@ -314,6 +315,23 @@ InterpretedData SAL_CALL StockDataInterpreter::reinterpretDataSeries( return aInterpretedData; } +uno::Any SAL_CALL StockDataInterpreter::getChartTypeSpecificData( + const OUString& sKey ) +{ + if( sKey == "stock variant" ) + { + StockChartTypeTemplate::StockVariant eStockVariant( GetStockVariant()); + std::map< StockChartTypeTemplate::StockVariant, sal_Int32 > aTranslation { + { StockChartTypeTemplate::StockVariant::NONE, 0 }, + { StockChartTypeTemplate::StockVariant::Open, 1 }, + { StockChartTypeTemplate::StockVariant::Volume, 2 }, + { StockChartTypeTemplate::StockVariant::VolumeOpen, 3 } + }; + return uno::Any( aTranslation[eStockVariant] ); + } + return uno::Any(); +} + } // namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/StockDataInterpreter.hxx b/chart2/source/model/template/StockDataInterpreter.hxx index 58fb88f970c8..ba2d5ee79111 100644 --- a/chart2/source/model/template/StockDataInterpreter.hxx +++ b/chart2/source/model/template/StockDataInterpreter.hxx @@ -42,6 +42,8 @@ protected: const css::chart2::InterpretedData& aInterpretedData ) override; virtual css::chart2::InterpretedData SAL_CALL reinterpretDataSeries( const css::chart2::InterpretedData& aInterpretedData ) override; + virtual css::uno::Any SAL_CALL getChartTypeSpecificData( + const OUString& sKey ) override; private: StockChartTypeTemplate::StockVariant m_eStockVariant; |