chart2/source/controller/dialogs/DataBrowser.cxx       |    5 +
 chart2/source/controller/dialogs/DataBrowserModel.cxx  |    2 
 chart2/source/inc/DataSeriesHelper.hxx                 |    6 +-
 chart2/source/inc/StatisticsHelper.hxx                 |    4 +
 chart2/source/model/template/BubbleDataInterpreter.cxx |   17 +++---
 chart2/source/model/template/XYDataInterpreter.cxx     |   13 ++--
 chart2/source/tools/AxisHelper.cxx                     |    2 
 chart2/source/tools/DataSeriesHelper.cxx               |   48 +++++++++--------
 chart2/source/tools/StatisticsHelper.cxx               |   23 ++++----
 9 files changed, 67 insertions(+), 53 deletions(-)

New commits:
commit f7016b59dd21e3444d9e6802e2a9d254c4684b83
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Feb 4 20:14:09 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Feb 5 17:37:01 2022 +0100

    use more concrete types in chart2, LabeledDataSequence
    
    Change-Id: I50b23923c1aa946f2c448534719a6c18003592a1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129521
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx 
b/chart2/source/controller/dialogs/DataBrowser.cxx
index d8a69d1d6d35..0d78bdc53cf3 100644
--- a/chart2/source/controller/dialogs/DataBrowser.cxx
+++ b/chart2/source/controller/dialogs/DataBrowser.cxx
@@ -32,6 +32,7 @@
 #include <helpids.h>
 #include <ChartModel.hxx>
 #include <ChartType.hxx>
+#include <LabeledDataSequence.hxx>
 
 #include <vcl/weld.hxx>
 #include <vcl/settings.hxx>
@@ -1372,8 +1373,8 @@ IMPL_LINK( DataBrowser, SeriesHeaderChanged, 
impl::SeriesHeaderEdit&, rEdit, voi
         m_apDataBrowserModel->getHeaderForSeries( xSeries ).m_xChartType );
     if( xChartType.is())
     {
-        Reference< chart2::data::XLabeledDataSequence > xLabeledSeq(
-            DataSeriesHelper::getDataSequenceByRole( xSource, 
xChartType->getRoleOfSequenceForSeriesLabel()));
+        rtl::Reference< LabeledDataSequence > xLabeledSeq =
+            DataSeriesHelper::getDataSequenceByRole( xSource, 
xChartType->getRoleOfSequenceForSeriesLabel());
         if( xLabeledSeq.is())
         {
             Reference< container::XIndexReplace > xIndexReplace( 
xLabeledSeq->getLabel(), uno::UNO_QUERY );
diff --git a/chart2/source/controller/dialogs/DataBrowserModel.cxx 
b/chart2/source/controller/dialogs/DataBrowserModel.cxx
index e0b1fe6c9edf..d6df1c4789aa 100644
--- a/chart2/source/controller/dialogs/DataBrowserModel.cxx
+++ b/chart2/source/controller/dialogs/DataBrowserModel.cxx
@@ -469,7 +469,7 @@ void 
DataBrowserModel::removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColu
 
     // Collect all the remaining data sequences in the same chart type. The
     // deleted data series is already gone by this point.
-    std::vector<Reference<chart2::data::XLabeledDataSequence> > aAllDataSeqs =
+    std::vector<rtl::Reference<LabeledDataSequence> > aAllDataSeqs =
         DataSeriesHelper::getAllDataSequences(xSeriesCnt->getDataSeries());
 
     // Check if the sequences to be deleted are still referenced by any of
diff --git a/chart2/source/inc/DataSeriesHelper.hxx 
b/chart2/source/inc/DataSeriesHelper.hxx
index 90c5e0f40c0e..93b1cffe30fb 100644
--- a/chart2/source/inc/DataSeriesHelper.hxx
+++ b/chart2/source/inc/DataSeriesHelper.hxx
@@ -61,7 +61,7 @@ OOO_DLLPUBLIC_CHARTTOOLS OUString
     @param aRole
         The role that is to be filtered out.
 */
-OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< 
css::chart2::data::XLabeledDataSequence >
+OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::LabeledDataSequence >
     getDataSequenceByRole( const css::uno::Reference< 
css::chart2::data::XDataSource > & xSource,
                            const OUString& aRole,
                            bool bMatchPrefix = false );
@@ -76,7 +76,7 @@ OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< 
css::chart2::data::XLabeledDataSeq
         The role that is to be filtered out.
 */
 OOO_DLLPUBLIC_CHARTTOOLS std::vector<
-  css::uno::Reference< css::chart2::data::XLabeledDataSequence > >
+  rtl::Reference< ::chart::LabeledDataSequence > >
     getAllDataSequencesByRole( const css::uno::Sequence< css::uno::Reference< 
css::chart2::data::XLabeledDataSequence > > & aDataSequences,
                                const OUString& aRole );
 OOO_DLLPUBLIC_CHARTTOOLS std::vector<
@@ -85,7 +85,7 @@ OOO_DLLPUBLIC_CHARTTOOLS std::vector<
                                const OUString& aRole );
 
 OOO_DLLPUBLIC_CHARTTOOLS
-std::vector<css::uno::Reference<css::chart2::data::XLabeledDataSequence> >
+std::vector<rtl::Reference< ::chart::LabeledDataSequence > >
 getAllDataSequences(
     const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries> >& 
aSeries );
 OOO_DLLPUBLIC_CHARTTOOLS
diff --git a/chart2/source/inc/StatisticsHelper.hxx 
b/chart2/source/inc/StatisticsHelper.hxx
index 7a6a96c5e5bd..34127923e36f 100644
--- a/chart2/source/inc/StatisticsHelper.hxx
+++ b/chart2/source/inc/StatisticsHelper.hxx
@@ -20,6 +20,7 @@
 
 #include <com/sun/star/uno/Reference.h>
 #include <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
 #include "charttoolsdllapi.hxx"
 
 namespace com::sun::star::beans { class XPropertySet; }
@@ -29,6 +30,7 @@ namespace com::sun::star::chart2::data { class XDataSequence; 
}
 namespace com::sun::star::chart2::data { class XDataSource; }
 namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
 namespace com::sun::star::uno { template <typename > class Sequence; }
+namespace chart { class LabeledDataSequence; }
 
 namespace chart::StatisticsHelper
 {
@@ -44,7 +46,7 @@ namespace chart::StatisticsHelper
     // also called "Standard deviation of the mean (SDOM)"
     OOO_DLLPUBLIC_CHARTTOOLS double getStandardError( const 
css::uno::Sequence< double > & rData );
 
-    OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< 
css::chart2::data::XLabeledDataSequence >
+    OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::LabeledDataSequence >
         getErrorLabeledDataSequenceFromDataSource(
             const css::uno::Reference< css::chart2::data::XDataSource > & 
xDataSource,
             bool bPositiveValue,
diff --git a/chart2/source/model/template/BubbleDataInterpreter.cxx 
b/chart2/source/model/template/BubbleDataInterpreter.cxx
index 1ebf56056712..84b51b4dcd74 100644
--- a/chart2/source/model/template/BubbleDataInterpreter.cxx
+++ b/chart2/source/model/template/BubbleDataInterpreter.cxx
@@ -164,18 +164,18 @@ InterpretedData 
BubbleDataInterpreter::reinterpretDataSeries(
             Reference< data::XDataSource > xSeriesSource( aSeries[i], 
uno::UNO_QUERY_THROW );
             Sequence< Reference< data::XLabeledDataSequence > > aNewSequences;
 
-            Reference< data::XLabeledDataSequence > xValuesSize(
+            rtl::Reference< LabeledDataSequence > xValuesSize(
                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, 
"values-size" ));
-            Reference< data::XLabeledDataSequence > xValuesY(
+            rtl::Reference< LabeledDataSequence > xValuesY(
                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, 
"values-y" ));
-            Reference< data::XLabeledDataSequence > xValuesX(
+            rtl::Reference< LabeledDataSequence > xValuesX(
                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, 
"values-x" ));
 
             if( ! xValuesX.is() ||
                 ! xValuesY.is() ||
                 ! xValuesSize.is() )
             {
-                vector< Reference< data::XLabeledDataSequence > > aValueSeqVec(
+                vector< rtl::Reference< LabeledDataSequence > > aValueSeqVec(
                     DataSeriesHelper::getAllDataSequencesByRole(
                         xSeriesSource->getDataSequences(), "values" ));
                 if( xValuesX.is())
@@ -190,7 +190,7 @@ InterpretedData 
BubbleDataInterpreter::reinterpretDataSeries(
                 if( ! xValuesSize.is() &&
                     aValueSeqVec.size() > nIndex )
                 {
-                    xValuesSize.set( aValueSeqVec[nIndex++] );
+                    xValuesSize = aValueSeqVec[nIndex++];
                     if( xValuesSize.is())
                         SetRole( xValuesSize->getValues(), "values-size");
                 }
@@ -198,7 +198,7 @@ InterpretedData 
BubbleDataInterpreter::reinterpretDataSeries(
                 if( ! xValuesY.is() &&
                     aValueSeqVec.size() > nIndex )
                 {
-                    xValuesY.set( aValueSeqVec[nIndex++] );
+                    xValuesY = aValueSeqVec[nIndex++];
                     if( xValuesY.is())
                         SetRole( xValuesY->getValues(), "values-y");
                 }
@@ -206,7 +206,7 @@ InterpretedData 
BubbleDataInterpreter::reinterpretDataSeries(
                 if( ! xValuesX.is() &&
                     aValueSeqVec.size() > nIndex )
                 {
-                    xValuesX.set( aValueSeqVec[nIndex++] );
+                    xValuesX = aValueSeqVec[nIndex++];
                     if( xValuesX.is())
                         SetRole( xValuesY->getValues(), "values-x");
                 }
@@ -236,7 +236,8 @@ InterpretedData 
BubbleDataInterpreter::reinterpretDataSeries(
 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
                 for( auto const & j : aSeqs )
                 {
-                    assert( (j == xValuesY || j == xValuesX || j == 
xValuesSize) && "All sequences should be used" );
+                    rtl::Reference< ::chart::LabeledDataSequence > j2 = 
dynamic_cast<LabeledDataSequence*>(j.get());
+                    assert( (j2 == xValuesY || j2 == xValuesX || j2 == 
xValuesSize) && "All sequences should be used" );
                 }
 #endif
                 Reference< data::XDataSink > xSink( xSeriesSource, 
uno::UNO_QUERY_THROW );
diff --git a/chart2/source/model/template/XYDataInterpreter.cxx 
b/chart2/source/model/template/XYDataInterpreter.cxx
index 59ab45451fdb..772963b7e29e 100644
--- a/chart2/source/model/template/XYDataInterpreter.cxx
+++ b/chart2/source/model/template/XYDataInterpreter.cxx
@@ -149,15 +149,15 @@ InterpretedData XYDataInterpreter::reinterpretDataSeries(
             Sequence< Reference< data::XLabeledDataSequence > > aNewSequences;
 
             // values-y
-            Reference< data::XLabeledDataSequence > xValuesY(
+            rtl::Reference< LabeledDataSequence > xValuesY(
                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, 
"values-y" ));
-            Reference< data::XLabeledDataSequence > xValuesX(
+            rtl::Reference< LabeledDataSequence > xValuesX(
                 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, 
"values-x" ));
             // re-use values-... as values-x/values-y
             if( ! xValuesX.is() ||
                 ! xValuesY.is())
             {
-                vector< Reference< data::XLabeledDataSequence > > aValueSeqVec(
+                vector< rtl::Reference< LabeledDataSequence > > aValueSeqVec(
                     DataSeriesHelper::getAllDataSequencesByRole(
                         xSeriesSource->getDataSequences(), "values" ));
                 if( xValuesX.is())
@@ -169,7 +169,7 @@ InterpretedData XYDataInterpreter::reinterpretDataSeries(
                 if( ! xValuesY.is() &&
                     aValueSeqVec.size() > nIndex )
                 {
-                    xValuesY.set( aValueSeqVec[nIndex++] );
+                    xValuesY = aValueSeqVec[nIndex++];
                     if( xValuesY.is())
                         SetRole( xValuesY->getValues(), "values-y");
                 }
@@ -177,7 +177,7 @@ InterpretedData XYDataInterpreter::reinterpretDataSeries(
                 if( ! xValuesX.is() &&
                     aValueSeqVec.size() > nIndex )
                 {
-                    xValuesX.set( aValueSeqVec[nIndex++] );
+                    xValuesX = aValueSeqVec[nIndex++];
                     if( xValuesX.is())
                         SetRole( xValuesY->getValues(), "values-x");
                 }
@@ -200,7 +200,8 @@ InterpretedData XYDataInterpreter::reinterpretDataSeries(
 #ifdef DBG_UTIL
                 for( auto const & j : aSeqs )
                 {
-                    SAL_WARN_IF((j == xValuesY || j == xValuesX), 
"chart2.template", "All sequences should be used" );
+                    rtl::Reference< ::chart::LabeledDataSequence > j2 = 
dynamic_cast<LabeledDataSequence*>(j.get());
+                    SAL_WARN_IF((j2 == xValuesY || j2 == xValuesX), 
"chart2.template", "All sequences should be used" );
                 }
 #endif
                 Reference< data::XDataSink > xSink( xSeriesSource, 
uno::UNO_QUERY_THROW );
diff --git a/chart2/source/tools/AxisHelper.cxx 
b/chart2/source/tools/AxisHelper.cxx
index c15b6f18a5f8..8f9b93cf8873 100644
--- a/chart2/source/tools/AxisHelper.cxx
+++ b/chart2/source/tools/AxisHelper.cxx
@@ -194,7 +194,7 @@ sal_Int32 AxisHelper::getExplicitNumberFormatKeyForAxis(
                     Reference< data::XDataSource > xSource( 
DataSourceHelper::getUsedData( *xChartDoc ) );
                     if( xSource.is() )
                     {
-                        std::vector< Reference< 
chart2::data::XLabeledDataSequence > > aXValues(
+                        std::vector< rtl::Reference< LabeledDataSequence > > 
aXValues(
                             DataSeriesHelper::getAllDataSequencesByRole( 
xSource->getDataSequences(), "values-x" ) );
                         if( aXValues.empty() )
                         {
diff --git a/chart2/source/tools/DataSeriesHelper.cxx 
b/chart2/source/tools/DataSeriesHelper.cxx
index 9f449e92d66f..964f2f05a436 100644
--- a/chart2/source/tools/DataSeriesHelper.cxx
+++ b/chart2/source/tools/DataSeriesHelper.cxx
@@ -213,36 +213,39 @@ OUString getRole( const rtl::Reference< 
::chart::LabeledDataSequence >& xLabeled
     return aRet;
 }
 
-Reference< chart2::data::XLabeledDataSequence >
+rtl::Reference< ::chart::LabeledDataSequence >
     getDataSequenceByRole(
         const Reference< chart2::data::XDataSource > & xSource,
         const OUString& aRole,
         bool bMatchPrefix /* = false */ )
 {
-    Reference< chart2::data::XLabeledDataSequence > aNoResult;
+    rtl::Reference< LabeledDataSequence > 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());
+    for (auto const & i : aLabeledSeq)
+    {
+        auto p = dynamic_cast<LabeledDataSequence*>(i.get());
+        assert(p);
+        if (lcl_MatchesRole(aRole, bMatchPrefix)(p))
+            return p;
+    }
 
     return aNoResult;
 }
 
-std::vector< Reference< chart2::data::XLabeledDataSequence > >
+std::vector< rtl::Reference< LabeledDataSequence > >
     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) );
+    std::vector< rtl::Reference< LabeledDataSequence > > aResultVec;
+    for (const auto & i : aDataSequences)
+    {
+        auto p = dynamic_cast<LabeledDataSequence*>(i.get());
+        assert(p);
+        if (lcl_MatchesRole(aRole, /*bMatchPrefix*/true)(p))
+            aResultVec.push_back(p);
+    }
     return aResultVec;
 }
 
@@ -257,10 +260,10 @@ std::vector< rtl::Reference< LabeledDataSequence > >
     return aResultVec;
 }
 
-std::vector<Reference<css::chart2::data::XLabeledDataSequence> >
+std::vector<rtl::Reference<LabeledDataSequence> >
 getAllDataSequences( const uno::Sequence<uno::Reference<chart2::XDataSeries> 
>& aSeries )
 {
-    std::vector< Reference< chart2::data::XLabeledDataSequence > > aSeqVec;
+    std::vector< rtl::Reference< LabeledDataSequence > > aSeqVec;
 
     for( uno::Reference<chart2::XDataSeries> const & dataSeries : aSeries )
     {
@@ -268,7 +271,12 @@ getAllDataSequences( const 
uno::Sequence<uno::Reference<chart2::XDataSeries> >&
         if( xSource.is())
         {
             const Sequence< Reference< chart2::data::XLabeledDataSequence > > 
aSeq( xSource->getDataSequences());
-            aSeqVec.insert( aSeqVec.end(), aSeq.begin(), aSeq.end() );
+            for (const auto & i : aSeq)
+            {
+                auto p = dynamic_cast<LabeledDataSequence*>(i.get());
+                assert(p);
+                aSeqVec.push_back(p);
+            }
         }
     }
 
@@ -292,7 +300,7 @@ getAllDataSequences( const 
std::vector<rtl::Reference<DataSeries> >& aSeries )
 rtl::Reference< ::chart::DataSource >
     getDataSource( const Sequence< Reference< chart2::XDataSeries > > & 
aSeries )
 {
-    return new 
DataSource(comphelper::containerToSequence(getAllDataSequences(aSeries)));
+    return new DataSource(getAllDataSequences(aSeries));
 }
 
 rtl::Reference< DataSource >
diff --git a/chart2/source/tools/StatisticsHelper.cxx 
b/chart2/source/tools/StatisticsHelper.cxx
index c8fad963deab..ac748c1901c4 100644
--- a/chart2/source/tools/StatisticsHelper.cxx
+++ b/chart2/source/tools/StatisticsHelper.cxx
@@ -21,6 +21,7 @@
 #include <DataSeriesHelper.hxx>
 #include <ErrorBar.hxx>
 #include <unonames.hxx>
+#include <LabeledDataSequence.hxx>
 
 #include <rtl/ustrbuf.hxx>
 #include <comphelper/processfactory.hxx>
@@ -69,7 +70,7 @@ double lcl_getVariance( const Sequence< double > & rData, 
sal_Int32 & rOutValidC
     return (fQuadSum - fSum*fSum/fN) / fN;
 }
 
-Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence(
+rtl::Reference< ::chart::LabeledDataSequence > lcl_getErrorBarLabeledSequence(
     const Reference< chart2::data::XDataSource > & xDataSource,
     bool bPositiveValue, bool bYError,
     OUString & rOutRoleNameUsed )
@@ -90,14 +91,14 @@ Reference< chart2::data::XLabeledDataSequence > 
lcl_getErrorBarLabeledSequence(
         aRole.append( "negative" );
 
     OUString aLongRole = aRole.makeStringAndClear();
-    Reference< chart2::data::XLabeledDataSequence > xLSeq(
-        ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, 
aLongRole ));
+    rtl::Reference< ::chart::LabeledDataSequence > xLSeq =
+        ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, 
aLongRole );
     // try role without "-negative" or "-positive" postfix
     if( xLSeq.is())
         rOutRoleNameUsed = aLongRole;
     else
     {
-        xLSeq.set( ::chart::DataSeriesHelper::getDataSequenceByRole( 
xDataSource, aPlainRole ));
+        xLSeq = ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, 
aPlainRole );
         if( xLSeq.is())
             rOutRoleNameUsed = aPlainRole;
         else
@@ -188,20 +189,20 @@ double StatisticsHelper::getStandardError( const 
Sequence< double > & rData )
     return sqrt( fVar ) / sqrt( double(nValCount) );
 }
 
-Reference< chart2::data::XLabeledDataSequence > 
StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
+rtl::Reference< LabeledDataSequence > 
StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
     const Reference< chart2::data::XDataSource > & xDataSource,
     bool bPositiveValue,
     bool bYError /* = true */ )
 {
-    Reference< chart2::data::XLabeledDataSequence > xResult;
+    rtl::Reference< LabeledDataSequence > xResult;
     if( !xDataSource.is())
         return xResult;
 
     OUString aRole;
-    Reference< chart2::data::XLabeledDataSequence > xLSeq(
-        lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, 
aRole ));
+    rtl::Reference< LabeledDataSequence > xLSeq =
+        lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, 
aRole );
     if( xLSeq.is())
-        xResult.set( xLSeq );
+        xResult = xLSeq;
 
     return xResult;
 }
@@ -211,10 +212,10 @@ Reference< chart2::data::XDataSequence > 
StatisticsHelper::getErrorDataSequenceF
     bool bPositiveValue,
     bool bYError /* = true */ )
 {
-    Reference< chart2::data::XLabeledDataSequence > xLSeq(
+    rtl::Reference< LabeledDataSequence > xLSeq =
         StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
             xDataSource, bPositiveValue,
-            bYError ));
+            bYError );
     if( !xLSeq.is())
         return Reference< chart2::data::XDataSequence >();
 

Reply via email to