32#include <unonames.hxx>
34#include <com/sun/star/chart2/data/XDataSource.hpp>
35#include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
37#include <com/sun/star/chart/ChartDataRowSource.hpp>
38#include <com/sun/star/chart/ErrorBarStyle.hpp>
45using ::com::sun::star::uno::Reference;
46using ::com::sun::star::uno::Sequence;
50void lcl_addRanges( std::vector< OUString > & rOutResult,
51 const uno::Reference< data::XLabeledDataSequence > & xLabeledSeq )
53 if( ! xLabeledSeq.is())
55 uno::Reference< data::XDataSequence > xSeq( xLabeledSeq->getLabel());
57 rOutResult.push_back( xSeq->getSourceRangeRepresentation());
58 xSeq.set( xLabeledSeq->getValues());
60 rOutResult.push_back( xSeq->getSourceRangeRepresentation());
63void lcl_addDataSourceRanges(
64 std::vector< OUString > & rOutResult,
65 const uno::Reference< data::XDataSource > & xDataSource )
67 if( xDataSource.is() )
69 const auto aDataSequences(xDataSource->getDataSequences());
70 for (
const auto& rDataSequence : aDataSequences)
71 lcl_addRanges(rOutResult, rDataSequence);
75void lcl_addErrorBarRanges(
76 std::vector< OUString > & rOutResult,
79 if( !xDataSeries.is())
84 uno::Reference< beans::XPropertySet > xErrorBarProp;
88 sal_Int32 eStyle = css::chart::ErrorBarStyle::NONE;
89 if( ( xErrorBarProp->getPropertyValue(
"ErrorBarStyle") >>= eStyle ) &&
90 eStyle == css::chart::ErrorBarStyle::FROM_DATA )
92 uno::Reference< data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
93 if( xErrorBarDataSource.is() )
94 lcl_addDataSourceRanges( rOutResult, xErrorBarDataSource );
100 sal_Int32 eStyle = css::chart::ErrorBarStyle::NONE;
101 if( ( xErrorBarProp->getPropertyValue(
"ErrorBarStyle") >>= eStyle ) &&
102 eStyle == css::chart::ErrorBarStyle::FROM_DATA )
104 uno::Reference< data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
105 if( xErrorBarDataSource.is() )
106 lcl_addDataSourceRanges( rOutResult, xErrorBarDataSource );
110 catch(
const uno::Exception & )
120 return new ::chart::CachedDataSequence();
125 return new ::chart::CachedDataSequence( rSingleText );
132 return new ::chart::LabeledDataSequence( xValues, xLabels );
136 const Reference< chart2::data::XDataSequence >& xValues )
138 return new ::chart::LabeledDataSequence( xValues );
143 return new ::chart::LabeledDataSequence;
147 bool bUseColumns,
bool bFirstCellAsLabel,
bool bHasCategories )
149 css::chart::ChartDataRowSource eRowSource = css::chart::ChartDataRowSource_ROWS;
151 eRowSource = css::chart::ChartDataRowSource_COLUMNS;
155 {
"DataRowSource", -1,
uno::Any( eRowSource), beans::PropertyState_DIRECT_VALUE },
156 {
"FirstCellAsLabel", -1,
uno::Any( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE },
157 {
"HasCategories", -1,
uno::Any( bHasCategories ), beans::PropertyState_DIRECT_VALUE }
162 const OUString & rRangeRepresentation,
164 bool bUseColumns,
bool bFirstCellAsLabel,
bool bHasCategories )
169 beans::PropertyValue(
"CellRangeRepresentation"
170 , -1,
uno::Any( rRangeRepresentation )
171 , beans::PropertyState_DIRECT_VALUE );
172 if( rSequenceMapping.hasElements() )
176 beans::PropertyValue(
"SequenceMapping"
178 , beans::PropertyState_DIRECT_VALUE );
185 ,
bool& bUseColumns,
bool& bFirstCellAsLabel,
bool& bHasCategories )
187 for(
const beans::PropertyValue& rProperty : rArguments)
189 if ( rProperty.Name ==
"DataRowSource" )
191 css::chart::ChartDataRowSource eRowSource;
192 if( rProperty.Value >>= eRowSource )
193 bUseColumns = (eRowSource==css::chart::ChartDataRowSource_COLUMNS);
195 else if ( rProperty.Name ==
"FirstCellAsLabel" )
197 rProperty.Value >>= bFirstCellAsLabel;
199 else if ( rProperty.Name ==
"HasCategories" )
201 rProperty.Value >>= bHasCategories;
203 else if ( rProperty.Name ==
"CellRangeRepresentation" )
205 rProperty.Value >>= rRangeRepresentation;
207 else if ( rProperty.Name ==
"SequenceMapping" )
209 rProperty.Value >>= rSequenceMapping;
217 std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVector;
224 xCategories = xDiagram->getCategories();
225 if( xCategories.is() )
226 aResultVector.push_back( xCategories );
228 std::vector< rtl::Reference< DataSeries > > aSeriesVector;
230 aSeriesVector = xDiagram->getDataSeries();
239 aResultVector.push_back( xXValues );
245 if( aRole !=
"values-x" )
246 aResultVector.push_back( labeledData );
255 std::vector< OUString > aResult;
260 if( xCategories.is() )
261 lcl_addRanges( aResult, xCategories );
263 std::vector< rtl::Reference< DataSeries > > aSeriesVector( xDiagram->getDataSeries() );
264 for (
auto const& series : aSeriesVector)
266 lcl_addDataSourceRanges( aResult, series );
267 lcl_addErrorBarRanges( aResult, series );
283 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
287 if( xCategories.is() )
288 aResult.push_back( xCategories );
291 for (
auto const& series : aSeriesVector)
293 const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > & aDataSequences( series->getDataSequences2() );
294 aResult.insert( aResult.end(), aDataSequences.begin(), aDataSequences.end() );
302 , OUString& rOutRangeString
303 , css::uno::Sequence< sal_Int32 >& rSequenceMapping
304 ,
bool& rOutUseColumns
305 ,
bool& rOutFirstCellAsLabel
306 ,
bool& rOutHasCategories )
308 bool bSomethingDetected =
false;
310 if( !xChartModel.is() )
311 return bSomethingDetected;
313 if( !xDataProvider.is() )
314 return bSomethingDetected;
320 rOutRangeString, rSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories );
321 bSomethingDetected = !rOutRangeString.isEmpty();
326 xCategories = xDiagram->getCategories();
327 rOutHasCategories = xCategories.is();
329 catch( uno::Exception & )
333 return bSomethingDetected;
339 bool bHasDataRowSource =
false;
340 bool bHasFirstCellAsLabel =
false;
341 bool bHasCellRangeRepresentation =
false;
344 if( !xDataProvider.is() )
351 for(
const beans::PropertyValue& rProperty :
aArguments)
353 if ( rProperty.Name ==
"DataRowSource" )
356 (rProperty.Value.hasValue() && rProperty.Value.isExtractableTo(
359 else if ( rProperty.Name ==
"FirstCellAsLabel" )
361 bHasFirstCellAsLabel =
364 else if ( rProperty.Name ==
"CellRangeRepresentation" )
367 bHasCellRangeRepresentation =
368 (rProperty.Value.hasValue() && (rProperty.Value >>= aRange) && !aRange.isEmpty());
372 catch(
const uno::Exception & )
377 return (bHasCellRangeRepresentation && bHasDataRowSource && bHasFirstCellAsLabel);
382 ,
const css::uno::Sequence< sal_Int32 >& rSequenceMapping
383 ,
bool bUseColumns ,
bool bFirstCellAsLabel,
bool bUseCategories )
386 if( !xDataProvider.is() )
392 if( !xChartTypeManager.is() )
395 OUString aRangeString;
399 aRangeString, aDummy, bDummy, bDummy, bDummy );
402 createArguments( aRangeString, rSequenceMapping, bUseColumns, bFirstCellAsLabel, bUseCategories ) );
406 if( !xDataSource.is() )
410 xDiagram->setDiagramData( xDataSource,
aArguments );
426 aResult = { xLabel->getSourceRangeRepresentation(),
427 xValues->getSourceRangeRepresentation() };
431 aResult = { xLabel->getSourceRangeRepresentation() };
434 else if( xValues.is())
436 aResult = { xValues->getSourceRangeRepresentation() };
450 aResult = xValues->getSourceRangeRepresentation();
457 std::vector< OUString > aResult;
467 aResult.push_back( xLabel->getSourceRangeRepresentation());
469 aResult.push_back( xValues->getSourceRangeRepresentation());
static std::vector< rtl::Reference< ::chart::DataSeries > > getDataSeries(const rtl::Reference< ::chart::ChartModel > &xModel)
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static SAL_DLLPRIVATE css::uno::Sequence< OUString > getUsedDataRanges(const rtl::Reference< ::chart::Diagram > &xDiagram)
static bool detectRangeSegmentation(const rtl::Reference<::chart::ChartModel > &xChartModel, OUString &rOutRangeString, css::uno::Sequence< sal_Int32 > &rSequenceMapping, bool &rOutUseColumns, bool &rOutFirstCellAsLabel, bool &rOutHasCategories)
static SAL_DLLPRIVATE css::uno::Sequence< OUString > getRangesFromLabeledDataSequence(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xLSeq)
static void setRangeSegmentation(const rtl::Reference<::chart::ChartModel > &xChartModel, const css::uno::Sequence< sal_Int32 > &rSequenceMapping, bool bUseColumns, bool bFirstCellAsLabel, bool bUseCategories)
static SAL_DLLPRIVATE css::uno::Sequence< OUString > getRangesFromDataSource(const css::uno::Reference< css::chart2::data::XDataSource > &xSource)
static rtl::Reference< ::chart::DataSource > getUsedData(ChartModel &rModel)
static css::uno::Reference< css::chart2::data::XDataSequence > createCachedDataSequence()
static css::uno::Sequence< css::beans::PropertyValue > createArguments(bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories)
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 SAL_DLLPRIVATE OUString getRangeFromValues(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xLSeq)
static rtl::Reference< LabeledDataSequence > createLabeledDataSequence()
static rtl::Reference< ::chart::DataSource > pressUsedDataIntoRectangularFormat(const rtl::Reference< ::chart::ChartModel > &xChartDoc)
static SAL_DLLPRIVATE void readArguments(const css::uno::Sequence< css::beans::PropertyValue > &rArguments, OUString &rRangeRepresentation, css::uno::Sequence< sal_Int32 > &rSequenceMapping, bool &bUseColumns, bool &bFirstCellAsLabel, bool &bHasCategories)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< PropertyValue > aArguments
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::DataSource > getDataSource(const std::vector< rtl::Reference< ::chart::DataSeries > > &aSeries)
Retrieves all data sequences found in the given data series and puts them into a data source.
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< css::chart2::data::XLabeledDataSequence > getDataSequenceByRole(const css::uno::Reference< css::chart2::data::XDataSource > &xSource, const OUString &aRole, bool bMatchPrefix=false)
Retrieves the data sequence in the given data source that matches the given role.
OOO_DLLPUBLIC_CHARTTOOLS OUString getRole(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xLabeledDataSequence)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
constexpr OUStringLiteral CHART_UNONAME_ERRORBAR_Y
constexpr OUStringLiteral CHART_UNONAME_ERRORBAR_X