39#include <com/sun/star/chart2/AxisType.hpp>
40#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
43#include <rtl/ustring.hxx>
54using ::com::sun::star::uno::Reference;
55using ::com::sun::star::uno::Sequence;
59constexpr OUStringLiteral lcl_aLabelRole( u
"label" );
62OUString lcl_ConvertRole(
const OUString & rRoleString )
64 OUString aResult( rRoleString );
66 typedef std::map< OUString, OUString > tTranslationMap;
67 static const tTranslationMap aTranslationMap =
88 tTranslationMap::const_iterator aIt( aTranslationMap.find( rRoleString ));
89 if( aIt != aTranslationMap.end())
91 aResult = (*aIt).second;
96typedef std::map< OUString, sal_Int32 > lcl_tRoleIndexMap;
98lcl_tRoleIndexMap lcl_createRoleIndexMap()
100 lcl_tRoleIndexMap
aMap;
123struct lcl_RolesWithRangeAppend
125 typedef Reference< data::XLabeledDataSequence > value_type;
128 explicit lcl_RolesWithRangeAppend( tContainerType * rCnt,
129 OUString aLabelRole )
130 : m_rDestCnt( rCnt ),
131 m_aRoleForLabelSeq(
std::move( aLabelRole ))
134 lcl_RolesWithRangeAppend & operator= (
const value_type & xVal )
141 Reference< data::XDataSequence > xSeq( xVal->getValues());
145 Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW );
146 if( xProp->getPropertyValue(
"Role" ) >>= aRole )
148 m_rDestCnt->emplace(aRole, xSeq->getSourceRangeRepresentation());
150 if( aRole == m_aRoleForLabelSeq )
152 Reference< data::XDataSequence > xLabelSeq( xVal->getLabel());
156 lcl_aLabelRole, xLabelSeq->getSourceRangeRepresentation());
163 catch(
const uno::Exception & )
174 lcl_RolesWithRangeAppend & operator* () {
return *
this; }
175 lcl_RolesWithRangeAppend & operator++ () {
return operator++(0); }
176 lcl_RolesWithRangeAppend & operator++ (
int) {
return *
this; }
179 tContainerType * m_rDestCnt;
180 OUString m_aRoleForLabelSeq;
187 template<>
struct iterator_traits<lcl_RolesWithRangeAppend>
197void lcl_SetSequenceRole(
198 const Reference< data::XDataSequence > & xSeq,
199 const OUString & rRole )
201 Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY );
203 xProp->setPropertyValue(
"Role" ,
uno::Any( rRole ));
206Sequence< OUString > lcl_CopyExcludingValuesFirst(
207 Sequence< OUString >
const & i_aInput )
209 Sequence< OUString > aOutput( i_aInput.getLength());
210 auto pOutput = aOutput.getArray();
211 int nSourceIndex, nDestIndex;
212 for( nSourceIndex = nDestIndex = 0; nSourceIndex < i_aInput.getLength(); nSourceIndex++ )
214 if( i_aInput[nSourceIndex] ==
"values-first" )
216 aOutput.realloc( aOutput.getLength() - 1 );
217 pOutput = aOutput.getArray();
221 pOutput[nDestIndex] = i_aInput[nSourceIndex];
230 sal_Int32 nNewSeriesIndex,
231 sal_Int32 nTotalNumberOfSeriesInCTGroup,
234 bool bCreateDataCachedSequences )
242 Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme());
243 if( xColorScheme.is())
244 xResult->setPropertyValue(
"Color" ,
uno::Any( xColorScheme->getColorByIndex( nNewSeriesIndex )));
245 std::size_t nGroupIndex=0;
248 std::vector< rtl::Reference< ::chart::ChartType > > aCTs =
249 xDiagram->getChartTypes();
250 for( ; nGroupIndex < aCTs.size(); ++nGroupIndex)
251 if( aCTs[nGroupIndex] == xChartType )
253 if( nGroupIndex == aCTs.size())
256 xTemplate->applyStyle2( xResult, nGroupIndex, nNewSeriesIndex, nTotalNumberOfSeriesInCTGroup );
259 if( bCreateDataCachedSequences )
262 if( xChartType.is() )
264 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aNewSequences;
265 const OUString aRoleOfSeqForSeriesLabel = xChartType->getRoleOfSequenceForSeriesLabel();
267 Sequence< OUString > aPossibleRoles( xChartType->getSupportedMandatoryRoles());
268 Sequence< OUString > aPossibleOptRoles( xChartType->getSupportedOptionalRoles());
274 if( xInterpreter.is())
276 sal_Int32 nStockVariant;
277 if( xInterpreter->getChartTypeSpecificData(
"stock variant") >>= nStockVariant )
279 if( nStockVariant == 0 || nStockVariant == 2) {
281 aPossibleRoles = lcl_CopyExcludingValuesFirst(aPossibleRoles);
282 aPossibleOptRoles = lcl_CopyExcludingValuesFirst(aPossibleOptRoles);
288 const Sequence< OUString > aRoles( aPossibleRoles );
289 const Sequence< OUString > aOptRoles( aPossibleOptRoles );
291 for(OUString
const & role : aRoles)
293 if( role == lcl_aLabelRole )
296 lcl_SetSequenceRole( xSeq, role );
298 if( role == aRoleOfSeqForSeriesLabel )
301 lcl_SetSequenceRole( xLabel, lcl_aLabelRole );
308 for(OUString
const & role : aOptRoles)
310 if( role == lcl_aLabelRole )
313 lcl_SetSequenceRole( xSeq, role );
317 xResult->setData( aNewSequences );
324struct lcl_addSeriesNumber
326 sal_Int32 operator() ( sal_Int32 nCurrentNumber,
const Reference< XDataSeriesContainer > & xCnt )
const
329 return nCurrentNumber + (xCnt->getDataSeries().getLength());
330 return nCurrentNumber;
348 m_xChartDocument(
std::move( xChartDocument )),
349 m_aTimerTriggeredControllerLock( m_xChartDocument )
367std::shared_ptr< RangeSelectionHelper >
const &
390std::vector< rtl::Reference< ChartType > >
393 std::vector< rtl::Reference< ChartType > > aResult;
402 const std::vector< rtl::Reference< BaseCoordinateSystem > > & aCooSysSeq(
403 xDiagram->getBaseCoordinateSystems());
407 for (
const auto & rxChartType : coords->getChartTypes2())
408 aResult.push_back(rxChartType);
412 catch(
const uno::Exception & )
420std::vector< DialogModel::tSeriesWithChartTypeByName >
423 std::vector< tSeriesWithChartTypeByName > aResult;
424 std::vector< rtl::Reference< ChartType > > aContainers(
427 for (
const auto & rxChartType : aContainers )
431 const std::vector< rtl::Reference< DataSeries > > &
aSeq = rxChartType->getDataSeries2();
432 OUString aRole = rxChartType->getRoleOfSequenceForSeriesLabel();
437 dataSeries->getLabelForRole( aRole ),
438 std::make_pair( dataSeries, rxChartType )));
441 catch(
const uno::Exception & )
454 for(OUString
const & role : rRoles)
456 if(rResult.find(role) == rResult.end())
457 rResult.emplace(role, OUString());
470void addNewSeriesToContainer(
475 auto aSeries = xChartType->getDataSeries2();
477 auto aIt = std::find( aSeries.begin(), aSeries.end(), xSeries);
479 if( aIt == aSeries.end())
481 aIt = aSeries.begin();
486 aSeries.insert(aIt, xNewSeries);
487 xChartType->setDataSeries(aSeries);
494 const OUString & aRoleOfSequenceForLabel,
502 std::copy(
aSeq.begin(),
aSeq.end(),
503 lcl_RolesWithRangeAppend( &aResult, aRoleOfSequenceForLabel ));
508 addMissingRoles(aResult, aRoles);
511 aRoles = xChartType->getSupportedOptionalRoles();
512 addMissingRoles(aResult, aRoles);
515 aRoles = xChartType->getSupportedPropertyRoles();
516 addMissingRoles(aResult, aRoles);
519 catch(
const uno::Exception & )
540 bool bCreateDataCachedSequences )
546 assert(xSeries || !xUnoSeries);
553 sal_Int32 nSeriesInChartType = 0;
557 nSeriesInChartType = xChartType->getDataSeries().getLength();
568 bCreateDataCachedSequences );
572 addNewSeriesToContainer(xChartType, xSeries, xNewSeries);
574 xDiagram->setScheme( e3DScheme );
576 catch(
const uno::Exception & )
602 xResult = xDiagram->getCategories();
605 catch(
const uno::Exception & )
622 bool bSupportsCategories =
true;
625 if( xFirstChartType.is() )
628 bSupportsCategories = (nAxisType == AxisType::CATEGORY);
630 xDiagram->setCategories( xCategories,
true, bSupportsCategories );
643 aRange = xSeq->getSourceRangeRepresentation();
646 catch (
const lang::DisposedException&)
662 OUString & rOutRangeString,
663 bool & rOutUseColumns,
664 bool & rOutFirstCellAsLabel,
665 bool & rOutHasCategories )
const
676 rOutRangeString, aSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories );
679 catch(
const uno::Exception & )
702 if( ! xDataProvider.is() ||
705 OSL_FAIL(
"Model objects missing" );
712 xDataProvider->createDataSource( rArguments ) );
716 if( xInterpreter.is())
721 std::vector< rtl::Reference< DataSeries > > aSeriesToReUse =
722 xDiagram->getDataSeries();
724 xInterpreter->interpretDataSource(
725 xDataSource, rArguments,
729 xDiagram->setScheme( e3DScheme );
732 catch(
const uno::Exception & )
747 return lcl_ConvertRole( rRoleString );
757 static lcl_tRoleIndexMap aRoleIndexMap = lcl_createRoleIndexMap();
759 lcl_tRoleIndexMap::const_iterator aIt( aRoleIndexMap.find( rInternalRoleString ));
760 if( aIt != aRoleIndexMap.end())
783 sal_Int32 nGroup = 0;
784 sal_Int32 nSeriesCounter = 0;
785 sal_Int32 nNewSeriesIndex =
static_cast< sal_Int32
>( rSeriesToReUse.size());
786 const sal_Int32 nOuterSize=rNewData.
Series.size();
788 for(; nGroup < nOuterSize; ++nGroup)
790 const std::vector< rtl::Reference< DataSeries > > & aSeries( rNewData.
Series[ nGroup ] );
791 const sal_Int32 nSeriesInGroup = aSeries.size();
792 for( sal_Int32 nSeries=0; nSeries<nSeriesInGroup; ++nSeries, ++nSeriesCounter )
794 if( std::find( rSeriesToReUse.begin(), rSeriesToReUse.end(), aSeries[nSeries] )
795 == rSeriesToReUse.end())
797 if( aSeries[nSeries].is())
802 if( xColorScheme.is())
803 aSeries[nSeries]->setPropertyValue(
"Color" ,
804 uno::Any( xColorScheme->getColorByIndex( nSeriesCounter )));
806 m_xTemplate->applyStyle2( aSeries[nSeries], nGroup, nNewSeriesIndex++, nSeriesInGroup );
815 OSL_ASSERT( aSeriesCnt.size() == rNewData.
Series.size());
817 auto aSrcIt = rNewData.
Series.begin();
818 auto aDestIt = aSeriesCnt.begin();
819 for(; aSrcIt != rNewData.
Series.end() && aDestIt != aSeriesCnt.end();
820 ++aSrcIt, ++aDestIt )
824 OSL_ASSERT( (*aDestIt).is());
825 (*aDestIt)->setDataSeries( *aSrcIt );
827 catch(
const uno::Exception & )
839 return std::accumulate( aCnt.begin(), aCnt.end(), 0, lcl_addSeriesNumber());
static sal_Int32 getAxisType(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionIndex)
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static bool detectRangeSegmentation(const rtl::Reference<::chart::ChartModel > &xChartModel, OUString &rOutRangeString, css::uno::Sequence< sal_Int32 > &rSequenceMapping, bool &rOutUseColumns, bool &rOutFirstCellAsLabel, bool &rOutHasCategories)
static css::uno::Reference< css::chart2::data::XDataSequence > createCachedDataSequence()
static bool allArgumentsForRectRangeDetected(const rtl::Reference<::chart::ChartModel > &xChartDocument)
Returns true, if all arguments necessary for getting all data by a rectangular region are returned by...
static rtl::Reference< LabeledDataSequence > createLabeledDataSequence()
std::vector< rtl::Reference< ::chart::ChartType > > getAllDataSeriesContainers() const
void setData(const css::uno::Sequence< css::beans::PropertyValue > &rArguments)
const rtl::Reference<::chart::ChartModel > & getChartModel() const
DialogModel(rtl::Reference<::chart::ChartModel > xChartDocument)
bool isCategoryDiagram() const
std::pair< OUString, std::pair< rtl::Reference< ::chart::DataSeries >, rtl::Reference< ::chart::ChartType > > > tSeriesWithChartTypeByName
std::shared_ptr< RangeSelectionHelper > m_spRangeSelectionHelper
void setCategories(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xCategories)
static OUString GetRoleDataLabel()
void detectArguments(OUString &rOutRangeString, bool &rOutUseColumns, bool &rOutFirstCellAsLabel, bool &rOutHasCategories) const
std::vector< tSeriesWithChartTypeByName > getAllDataSeriesWithLabel() const
void setTemplate(const rtl::Reference< ::chart::ChartTypeTemplate > &xTemplate)
void setTimeBasedRange(bool bTimeBased, sal_Int32 nStart, sal_Int32 nEnd) const
void deleteSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::ChartType > &xChartType)
rtl::Reference< ::chart::DataSeries > insertSeriesAfter(const css::uno::Reference< css::chart2::XDataSeries > &xSeries, const rtl::Reference< ::chart::ChartType > &xChartType, bool bCreateDataCachedSequences=false)
std::map< OUString, OUString > tRolesWithRanges
bool allArgumentsForRectRangeDetected() const
css::uno::Reference< css::chart2::data::XDataProvider > getDataProvider() const
static OUString ConvertRoleFromInternalToUI(const OUString &rRoleString)
ChartModel & getModel() const
void moveSeries(const rtl::Reference< DataSeries > &xSeries, MoveDirection eDirection)
sal_Int32 countSeries() const
std::shared_ptr< RangeSelectionHelper > const & getRangeSelectionHelper() const
void startControllerLockTimer()
rtl::Reference<::chart::ChartModel > m_xChartDocument
TimerTriggeredControllerLock m_aTimerTriggeredControllerLock
static sal_Int32 GetRoleIndexForSorting(const OUString &rInternalRoleString)
css::uno::Reference< css::chart2::data::XLabeledDataSequence > getCategories() const
DialogModelTimeBasedInfo maTimeBasedInfo
static tRolesWithRanges getRolesWithRanges(const css::uno::Reference< css::chart2::XDataSeries > &xSeries, const OUString &aRoleOfSequenceForLabel, const rtl::Reference< ::chart::ChartType > &xChartType)
rtl::Reference< ::chart::ChartTypeTemplate > m_xTemplate
OUString getCategoriesRange() const
void applyInterpretedData(const InterpretedData &rNewData, const std::vector< rtl::Reference< ::chart::DataSeries > > &rSeriesToReUse)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< sal_Int8 > aSeq
OOO_DLLPUBLIC_CHARTTOOLS void deleteSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::ChartType > &xChartType)
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
HashMap_OWString_Interface aMap
DialogModelTimeBasedInfo()
offers tooling to interpret different data sources in a structural and chart-type-dependent way.
std::vector< std::vector< rtl::Reference<::chart::DataSeries > > > Series
css::uno::Reference< css::chart2::data::XLabeledDataSequence > Categories
Reference< data::XLabeledDataSequence > value_type
std::output_iterator_tag iterator_category