summaryrefslogtreecommitdiff
path: root/chart2/source/model
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-02-02 18:40:05 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-02-04 12:20:00 +0100
commitfc03ef1e02da261073994e7478b08fa57b3ea962 (patch)
treed87507a55da82763b88cd6844471a895d8bf9ea8 /chart2/source/model
parent957d5cf0d2acd10eee5b36f6cdf66117c059a4c0 (diff)
use more concrete types in chart2, LabeledDataSequence
Change-Id: I88d5b7e045814cbd40750ebe927e6a76d5a463d1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129456 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2/source/model')
-rw-r--r--chart2/source/model/template/BubbleDataInterpreter.cxx9
-rw-r--r--chart2/source/model/template/ChartTypeTemplate.cxx3
-rw-r--r--chart2/source/model/template/ColumnLineDataInterpreter.cxx1
-rw-r--r--chart2/source/model/template/DataInterpreter.cxx45
-rw-r--r--chart2/source/model/template/StockDataInterpreter.cxx9
-rw-r--r--chart2/source/model/template/XYDataInterpreter.cxx11
6 files changed, 56 insertions, 22 deletions
diff --git a/chart2/source/model/template/BubbleDataInterpreter.cxx b/chart2/source/model/template/BubbleDataInterpreter.cxx
index cac3ea68d343..8868fbb6ca89 100644
--- a/chart2/source/model/template/BubbleDataInterpreter.cxx
+++ b/chart2/source/model/template/BubbleDataInterpreter.cxx
@@ -21,6 +21,7 @@
#include <DataSeries.hxx>
#include <DataSeriesHelper.hxx>
#include <CommonConverters.hxx>
+#include <LabeledDataSequence.hxx>
#include <com/sun/star/chart2/data/XDataSink.hpp>
#include <com/sun/star/util/XCloneable.hpp>
#include <tools/diagnose_ex.h>
@@ -52,17 +53,17 @@ InterpretedData BubbleDataInterpreter::interpretDataSource(
if( ! xSource.is())
return InterpretedData();
- Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
+ std::vector< rtl::Reference< LabeledDataSequence > > aData = DataInterpreter::getDataSequences(xSource);
Reference< data::XLabeledDataSequence > xValuesX;
vector< Reference< data::XLabeledDataSequence > > aYValuesVector;
vector< Reference< data::XLabeledDataSequence > > aSizeValuesVector;
- Reference< data::XLabeledDataSequence > xCategories;
+ rtl::Reference< LabeledDataSequence > xCategories;
bool bHasCategories = HasCategories( aArguments, aData );
bool bUseCategoriesAsX = UseCategoriesAsX( aArguments );
- sal_Int32 nDataSeqCount = aData.getLength();
+ sal_Int32 nDataSeqCount = aData.size();
bool bSetXValues = bHasCategories ? ( (nDataSeqCount-1) > 2 && (nDataSeqCount-1) % 2 != 0 )
:( nDataSeqCount > 2 && nDataSeqCount % 2 != 0 );
@@ -75,7 +76,7 @@ InterpretedData BubbleDataInterpreter::interpretDataSource(
{
if( bHasCategories && !bCategoriesUsed )
{
- xCategories.set( aData[nDataIdx] );
+ xCategories = aData[nDataIdx];
if( xCategories.is())
{
SetRole( xCategories->getValues(), "categories");
diff --git a/chart2/source/model/template/ChartTypeTemplate.cxx b/chart2/source/model/template/ChartTypeTemplate.cxx
index 8c7ab1e7389a..0183907419ad 100644
--- a/chart2/source/model/template/ChartTypeTemplate.cxx
+++ b/chart2/source/model/template/ChartTypeTemplate.cxx
@@ -30,6 +30,7 @@
#include <AxisIndexDefines.hxx>
#include <BaseCoordinateSystem.hxx>
#include <unonames.hxx>
+#include <LabeledDataSequence.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/chart2/AxisType.hpp>
@@ -716,7 +717,7 @@ sal_Int32 ChartTypeTemplate::getAxisCountByDimension( sal_Int32 nDimension )
void ChartTypeTemplate::FillDiagram(
const rtl::Reference< ::chart::Diagram >& xDiagram,
const Sequence< Sequence< Reference< XDataSeries > > >& aSeriesSeq,
- const Reference< data::XLabeledDataSequence >& xCategories,
+ const rtl::Reference< LabeledDataSequence >& xCategories,
const std::vector< rtl::Reference< ChartType > >& aOldChartTypesSeq )
{
adaptDiagram( xDiagram );
diff --git a/chart2/source/model/template/ColumnLineDataInterpreter.cxx b/chart2/source/model/template/ColumnLineDataInterpreter.cxx
index c548b8c8eacb..c75c7818fd0b 100644
--- a/chart2/source/model/template/ColumnLineDataInterpreter.cxx
+++ b/chart2/source/model/template/ColumnLineDataInterpreter.cxx
@@ -18,6 +18,7 @@
*/
#include "ColumnLineDataInterpreter.hxx"
+#include <LabeledDataSequence.hxx>
#include <osl/diagnose.h>
#include <algorithm>
diff --git a/chart2/source/model/template/DataInterpreter.cxx b/chart2/source/model/template/DataInterpreter.cxx
index 3a619e3ec253..9461008c87ad 100644
--- a/chart2/source/model/template/DataInterpreter.cxx
+++ b/chart2/source/model/template/DataInterpreter.cxx
@@ -22,6 +22,7 @@
#include <DataSourceHelper.hxx>
#include <DataSeriesHelper.hxx>
#include <CommonConverters.hxx>
+#include <LabeledDataSequence.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/chart2/data/XDataSink.hpp>
#include <cppuhelper/supportsservice.hxx>
@@ -66,9 +67,9 @@ InterpretedData DataInterpreter::interpretDataSource(
lcl_ShowDataSource( xSource );
#endif
- const Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
+ std::vector< rtl::Reference< LabeledDataSequence > > aData = getDataSequences(xSource);
- Reference< data::XLabeledDataSequence > xCategories;
+ rtl::Reference< LabeledDataSequence > xCategories;
vector< Reference< data::XLabeledDataSequence > > aSequencesVec;
// check if we should use categories
@@ -77,13 +78,13 @@ InterpretedData DataInterpreter::interpretDataSource(
// parse data
bool bCategoriesUsed = false;
- for( Reference< data::XLabeledDataSequence > const & labeledData : aData )
+ for( rtl::Reference< LabeledDataSequence > const & labeledData : aData )
{
try
{
if( bHasCategories && ! bCategoriesUsed )
{
- xCategories.set( labeledData );
+ xCategories = labeledData;
if( xCategories.is())
SetRole( xCategories->getValues(), "categories");
bCategoriesUsed = true;
@@ -138,9 +139,9 @@ InterpretedData DataInterpreter::interpretDataSource(
lcl_ShowDataSource( xSource );
#endif
- const Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
+ std::vector< rtl::Reference< LabeledDataSequence > > aData = getDataSequences(xSource);
- Reference< data::XLabeledDataSequence > xCategories;
+ rtl::Reference< LabeledDataSequence > xCategories;
vector< Reference< data::XLabeledDataSequence > > aSequencesVec;
// check if we should use categories
@@ -149,13 +150,13 @@ InterpretedData DataInterpreter::interpretDataSource(
// parse data
bool bCategoriesUsed = false;
- for( Reference< data::XLabeledDataSequence > const & labeledData : aData )
+ for( rtl::Reference< LabeledDataSequence > const & labeledData : aData )
{
try
{
if( bHasCategories && ! bCategoriesUsed )
{
- xCategories.set( labeledData );
+ xCategories = labeledData;
if( xCategories.is())
SetRole( xCategories->getValues(), "categories");
bCategoriesUsed = true;
@@ -433,6 +434,21 @@ bool DataInterpreter::HasCategories(
return bHasCategories;
}
+bool DataInterpreter::HasCategories(
+ const Sequence< beans::PropertyValue > & rArguments,
+ const std::vector< rtl::Reference< LabeledDataSequence > > & rData )
+{
+ bool bHasCategories = false;
+
+ if( rArguments.hasElements() )
+ GetProperty( rArguments, u"HasCategories" ) >>= bHasCategories;
+
+ for( sal_Int32 nLSeqIdx=0; ! bHasCategories && nLSeqIdx<static_cast<sal_Int32>(rData.size()); ++nLSeqIdx )
+ bHasCategories = ( rData[nLSeqIdx].is() && GetRole( rData[nLSeqIdx]->getValues() ) == "categories");
+
+ return bHasCategories;
+}
+
bool DataInterpreter::UseCategoriesAsX( const Sequence< beans::PropertyValue > & rArguments )
{
bool bUseCategoriesAsX = true;
@@ -456,6 +472,19 @@ css::uno::Sequence< OUString > SAL_CALL DataInterpreter::getSupportedServiceName
return { "com.sun.star.chart2.DataInterpreter" };
}
+std::vector< rtl::Reference< LabeledDataSequence > > DataInterpreter::getDataSequences(
+ const css::uno::Reference< css::chart2::data::XDataSource >& xSource)
+{
+ std::vector< rtl::Reference< LabeledDataSequence > > aData;
+ for (const Reference< data::XLabeledDataSequence > & rLDS : xSource->getDataSequences() )
+ {
+ auto pLDS = dynamic_cast<LabeledDataSequence*>(rLDS.get());
+ assert(pLDS);
+ aData.push_back(pLDS);
+ }
+ return aData;
+}
+
} // namespace chart
#ifdef DEBUG_CHART2_TEMPLATE
diff --git a/chart2/source/model/template/StockDataInterpreter.cxx b/chart2/source/model/template/StockDataInterpreter.cxx
index 3b9315ee7a30..addf3f71e3f8 100644
--- a/chart2/source/model/template/StockDataInterpreter.cxx
+++ b/chart2/source/model/template/StockDataInterpreter.cxx
@@ -20,6 +20,7 @@
#include "StockDataInterpreter.hxx"
#include "StockChartTypeTemplate.hxx"
#include <DataSeries.hxx>
+#include <LabeledDataSequence.hxx>
#include <com/sun/star/chart2/data/XDataSink.hpp>
#include <tools/diagnose_ex.h>
@@ -51,9 +52,9 @@ InterpretedData StockDataInterpreter::interpretDataSource(
if( ! xSource.is())
return InterpretedData();
- Reference< data::XLabeledDataSequence > xCategories;
- Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
- const sal_Int32 nDataCount( aData.getLength());
+ rtl::Reference< LabeledDataSequence > xCategories;
+ std::vector< rtl::Reference< LabeledDataSequence > > aData = DataInterpreter::getDataSequences(xSource);
+ const sal_Int32 nDataCount( aData.size());
// sub-type properties
const StockChartTypeTemplate::StockVariant eVar( GetStockVariant());
@@ -114,7 +115,7 @@ InterpretedData StockDataInterpreter::interpretDataSource(
// 1. categories
if( bHasCategories )
{
- xCategories.set( aData[nSourceIndex] );
+ xCategories = aData[nSourceIndex];
++nSourceIndex;
}
diff --git a/chart2/source/model/template/XYDataInterpreter.cxx b/chart2/source/model/template/XYDataInterpreter.cxx
index c61088a268f0..090e77b609d5 100644
--- a/chart2/source/model/template/XYDataInterpreter.cxx
+++ b/chart2/source/model/template/XYDataInterpreter.cxx
@@ -21,6 +21,7 @@
#include <DataSeries.hxx>
#include <DataSeriesHelper.hxx>
#include <CommonConverters.hxx>
+#include <LabeledDataSequence.hxx>
#include <com/sun/star/chart2/data/XDataSink.hpp>
#include <com/sun/star/util/XCloneable.hpp>
#include <tools/diagnose_ex.h>
@@ -53,25 +54,25 @@ InterpretedData XYDataInterpreter::interpretDataSource(
if( ! xSource.is())
return InterpretedData();
- const Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
+ std::vector< rtl::Reference< LabeledDataSequence > > aData = DataInterpreter::getDataSequences(xSource);
Reference< data::XLabeledDataSequence > xValuesX;
vector< Reference< data::XLabeledDataSequence > > aSequencesVec;
- Reference< data::XLabeledDataSequence > xCategories;
+ rtl::Reference< LabeledDataSequence > xCategories;
bool bHasCategories = HasCategories( aArguments, aData );
bool bUseCategoriesAsX = UseCategoriesAsX( aArguments );
// parse data
bool bCategoriesUsed = false;
- bool bSetXValues = aData.getLength()>1;
- for( Reference< data::XLabeledDataSequence > const & labelData : aData )
+ bool bSetXValues = aData.size()>1;
+ for( rtl::Reference< LabeledDataSequence > const & labelData : aData )
{
try
{
if( bHasCategories && ! bCategoriesUsed )
{
- xCategories.set( labelData );
+ xCategories = labelData;
if( xCategories.is())
{
SetRole( xCategories->getValues(), "categories");