chart2/source/controller/dialogs/DialogModel.cxx | 11 +-- chart2/source/controller/main/ChartController.cxx | 10 +-- chart2/source/controller/main/PositionAndSizeHelper.cxx | 3 - chart2/source/controller/sidebar/ChartElementsPanel.cxx | 9 +-- chart2/source/controller/sidebar/ChartSeriesPanel.cxx | 6 +- chart2/source/inc/ObjectIdentifier.hxx | 3 - chart2/source/inc/RangeHighlighter.hxx | 3 + chart2/source/tools/ObjectIdentifier.cxx | 46 ++++++---------- chart2/source/tools/RangeHighlighter.cxx | 18 +++++- chart2/source/view/charttypes/VSeriesPlotter.cxx | 5 + chart2/source/view/main/ChartView.cxx | 9 +-- 11 files changed, 64 insertions(+), 59 deletions(-)
New commits: commit c53181f3e91d9b8612abbc53307c2a39ca1446f1 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Thu Jan 20 21:57:00 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Jan 21 08:37:04 2022 +0100 use more concrete types in chart2, Diagram Change-Id: Ib78f327c8bf1b71c3bb038c029b10e6fe54edaa1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128708 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx index 9b270964ba6e..eed859f5d948 100644 --- a/chart2/source/controller/dialogs/DialogModel.cxx +++ b/chart2/source/controller/dialogs/DialogModel.cxx @@ -22,6 +22,7 @@ #include <DataSeriesHelper.hxx> #include <DataSourceHelper.hxx> #include <DiagramHelper.hxx> +#include <Diagram.hxx> #include <strings.hrc> #include <ResId.hxx> #include <ControllerLockGuard.hxx> @@ -466,15 +467,13 @@ std::vector< Reference< XDataSeriesContainer > > try { - Reference< XDiagram > xDiagram; - if( m_xChartDocument.is()) - xDiagram.set( m_xChartDocument->getFirstDiagram()); + if( !m_xChartDocument ) + return {}; + rtl::Reference< Diagram > xDiagram = m_xChartDocument->getFirstChartDiagram(); if( xDiagram.is()) { - Reference< XCoordinateSystemContainer > xCooSysCnt( - xDiagram, uno::UNO_QUERY_THROW ); const Sequence< Reference< XCoordinateSystem > > aCooSysSeq( - xCooSysCnt->getCoordinateSystems()); + xDiagram->getCoordinateSystems()); for( Reference< XCoordinateSystem > const & coords : aCooSysSeq ) { Reference< XChartTypeContainer > xCTCnt( coords, uno::UNO_QUERY_THROW ); diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index 440b7314d666..aaa8636e470e 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -231,16 +231,14 @@ bool ChartController::TheModelRef::is() const namespace { css::uno::Reference<css::chart2::XChartType> getChartType( - const css::uno::Reference<css::chart2::XChartDocument>& xChartDoc) + const rtl::Reference<ChartModel>& xChartDoc) { - Reference <chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram(); + rtl::Reference<Diagram > xDiagram = xChartDoc->getFirstChartDiagram(); if (!xDiagram.is()) { return css::uno::Reference<css::chart2::XChartType>(); } - Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY_THROW ); - - Sequence< Reference< chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems()); + Sequence< Reference< chart2::XCoordinateSystem > > xCooSysSequence( xDiagram->getCoordinateSystems()); if (!xCooSysSequence.hasElements()) { return css::uno::Reference<css::chart2::XChartType>(); } @@ -284,7 +282,7 @@ OUString ChartController::GetContextName() return "Grid"; case OBJECTTYPE_DIAGRAM: { - css::uno::Reference<css::chart2::XChartType> xChartType = getChartType(css::uno::Reference<css::chart2::XChartDocument>(getModel(), uno::UNO_QUERY)); + css::uno::Reference<css::chart2::XChartType> xChartType = getChartType(getChartModel()); if (xChartType.is() && xChartType->getChartType() == "com.sun.star.chart2.PieChartType") return "ChartElements"; break; diff --git a/chart2/source/controller/main/PositionAndSizeHelper.cxx b/chart2/source/controller/main/PositionAndSizeHelper.cxx index 63ddb818fd0d..badd2662d125 100644 --- a/chart2/source/controller/main/PositionAndSizeHelper.cxx +++ b/chart2/source/controller/main/PositionAndSizeHelper.cxx @@ -27,6 +27,7 @@ #include <tools/gen.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/awt/Rectangle.hpp> +#include <Diagram.hxx> namespace chart { @@ -167,7 +168,7 @@ bool PositionAndSizeHelper::moveObject( const OUString& rObjectCID ObjectType eObjectType( ObjectIdentifier::getObjectType( rObjectCID ) ); if(eObjectType==OBJECTTYPE_DIAGRAM || eObjectType==OBJECTTYPE_DIAGRAM_WALL || eObjectType==OBJECTTYPE_DIAGRAM_FLOOR) { - xObjectProp.set( ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ), uno::UNO_QUERY ); + xObjectProp = ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ); if(!xObjectProp.is()) return false; } diff --git a/chart2/source/controller/sidebar/ChartElementsPanel.cxx b/chart2/source/controller/sidebar/ChartElementsPanel.cxx index bae915ab2bb2..69931ff17303 100644 --- a/chart2/source/controller/sidebar/ChartElementsPanel.cxx +++ b/chart2/source/controller/sidebar/ChartElementsPanel.cxx @@ -406,17 +406,14 @@ void ChartElementsPanel::Initialize() namespace { -css::uno::Reference<css::chart2::XChartType> getChartType(const css::uno::Reference<css::frame::XModel>& xModel) +css::uno::Reference<css::chart2::XChartType> getChartType(const rtl::Reference<ChartModel>& xModel) { - css::uno::Reference<css::chart2::XChartDocument> xChartDoc(xModel, css::uno::UNO_QUERY_THROW); - css::uno::Reference<chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram(); + rtl::Reference<Diagram > xDiagram = xModel->getFirstChartDiagram(); if (!xDiagram.is()) { return css::uno::Reference<css::chart2::XChartType>(); } - css::uno::Reference<css::chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, css::uno::UNO_QUERY_THROW ); - - css::uno::Sequence<css::uno::Reference<css::chart2::XCoordinateSystem>> xCooSysSequence(xCooSysContainer->getCoordinateSystems()); + css::uno::Sequence<css::uno::Reference<css::chart2::XCoordinateSystem>> xCooSysSequence(xDiagram->getCoordinateSystems()); if (!xCooSysSequence.hasElements()) return css::uno::Reference<css::chart2::XChartType>(); diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx index a6fa9ea40fcb..dd3189350789 100644 --- a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx +++ b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx @@ -35,6 +35,7 @@ #include <ChartModel.hxx> #include <DataSeriesHelper.hxx> #include <DiagramHelper.hxx> +#include <Diagram.hxx> #include <RegressionCurveHelper.hxx> #include <StatisticsHelper.hxx> @@ -227,9 +228,8 @@ void setAttachedAxisType(const rtl::Reference<::chart::ChartModel>& css::uno::Reference<css::chart2::XChartType> getChartType( const rtl::Reference<::chart::ChartModel>& xModel) { - css::uno::Reference<css::chart2::XDiagram> xDiagram = xModel->getFirstDiagram(); - css::uno::Reference< css::chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, UNO_QUERY_THROW ); - css::uno::Sequence< css::uno::Reference< css::chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems()); + rtl::Reference<Diagram> xDiagram = xModel->getFirstChartDiagram(); + css::uno::Sequence< css::uno::Reference< css::chart2::XCoordinateSystem > > xCooSysSequence( xDiagram->getCoordinateSystems()); css::uno::Reference< css::chart2::XChartTypeContainer > xChartTypeContainer( xCooSysSequence[0], UNO_QUERY_THROW ); css::uno::Sequence< css::uno::Reference< css::chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() ); return xChartTypeSequence[0]; diff --git a/chart2/source/inc/ObjectIdentifier.hxx b/chart2/source/inc/ObjectIdentifier.hxx index a8a2f4f2da73..e429e3eb2105 100644 --- a/chart2/source/inc/ObjectIdentifier.hxx +++ b/chart2/source/inc/ObjectIdentifier.hxx @@ -42,6 +42,7 @@ namespace com::sun::star::uno { class XInterface; } namespace chart { +class Diagram; enum ObjectType { @@ -220,7 +221,7 @@ public: const OUString& rObjectCID , const css::uno::Reference< css::frame::XModel >& xChartModel ); - static css::uno::Reference< css::chart2::XDiagram > + static rtl::Reference< ::chart::Diagram > getDiagramForCID( const OUString& rObjectCID , const css::uno::Reference< css::frame::XModel >& xChartModel ); diff --git a/chart2/source/inc/RangeHighlighter.hxx b/chart2/source/inc/RangeHighlighter.hxx index 3c9278fc1328..8642d66f7e88 100644 --- a/chart2/source/inc/RangeHighlighter.hxx +++ b/chart2/source/inc/RangeHighlighter.hxx @@ -22,6 +22,7 @@ #include <comphelper/interfacecontainer4.hxx> #include <com/sun/star/chart2/data/XRangeHighlighter.hpp> #include <com/sun/star/view/XSelectionChangeListener.hpp> +#include <rtl/ref.hxx> namespace com::sun::star { namespace chart2 { @@ -35,6 +36,7 @@ namespace com::sun::star::view { class XSelectionSupplier; } namespace chart { +class Diagram; namespace impl { @@ -80,6 +82,7 @@ private: void determineRanges(); void fillRangesForDiagram( const css::uno::Reference< css::chart2::XDiagram > & xDiagram ); + void fillRangesForDiagram( const rtl::Reference< ::chart::Diagram > & xDiagram ); void fillRangesForDataSeries( const css::uno::Reference< css::chart2::XDataSeries > & xSeries ); void fillRangesForCategories( const css::uno::Reference< css::chart2::XAxis > & xAxis ); void fillRangesForDataPoint( const css::uno::Reference< css::uno::XInterface > & xDataSeries, sal_Int32 nIndex ); diff --git a/chart2/source/tools/ObjectIdentifier.cxx b/chart2/source/tools/ObjectIdentifier.cxx index 58fa0fc5c21b..fa538c81670d 100644 --- a/chart2/source/tools/ObjectIdentifier.cxx +++ b/chart2/source/tools/ObjectIdentifier.cxx @@ -130,16 +130,13 @@ OUString lcl_getTitleParentParticle( TitleHelper::eTitleType aTitleType ) Reference<XChartType> lcl_getFirstStockChartType( const Reference< frame::XModel >& xChartModel ) { - Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); + rtl::Reference< Diagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); if(!xDiagram.is()) return nullptr; //iterate through all coordinate systems - Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( !xCooSysContainer.is()) - return nullptr; - const uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); + const uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xDiagram->getCoordinateSystems() ); for( Reference< XCoordinateSystem > const & coords : aCooSysList ) { //iterate through all chart types in the current coordinate system @@ -219,7 +216,7 @@ void lcl_parseSeriesIndices( sal_Int32& rnChartTypeIndex, sal_Int32& rnSeriesInd void lcl_getDiagramAndCooSys( const OUString& rObjectCID , const Reference< frame::XModel >& xChartModel - , Reference< XDiagram >& xDiagram + , rtl::Reference< Diagram >& xDiagram , Reference< XCoordinateSystem >& xCooSys ) { sal_Int32 nDiagramIndex = -1; @@ -231,13 +228,9 @@ void lcl_getDiagramAndCooSys( const OUString& rObjectCID if( nCooSysIndex > -1 ) { - Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( xCooSysContainer.is() ) - { - uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); - if( nCooSysIndex < aCooSysList.getLength() ) - xCooSys = aCooSysList[nCooSysIndex]; - } + uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xDiagram->getCoordinateSystems() ); + if( nCooSysIndex < aCooSysList.getLength() ) + xCooSys = aCooSysList[nCooSysIndex]; } } @@ -511,12 +504,11 @@ OUString ObjectIdentifier::createParticleForCoordinateSystem( { OUString aRet; - Reference< XDiagram > xDiagram( rModel.getFirstDiagram() ); - Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( xCooSysContainer.is() ) + rtl::Reference< Diagram > xDiagram( rModel.getFirstChartDiagram() ); + if( xDiagram.is() ) { sal_Int32 nCooSysIndex = 0; - uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); + uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xDiagram->getCoordinateSystems() ); for( ; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex ) { Reference< XCoordinateSystem > xCurrentCooSys( aCooSysList[nCooSysIndex] ); @@ -537,12 +529,11 @@ OUString ObjectIdentifier::createParticleForCoordinateSystem( { OUString aRet; - Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); - Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( xCooSysContainer.is() ) + rtl::Reference< Diagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); + if( xDiagram.is() ) { sal_Int32 nCooSysIndex = 0; - uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); + uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xDiagram->getCoordinateSystems() ); for( ; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex ) { Reference< XCoordinateSystem > xCurrentCooSys( aCooSysList[nCooSysIndex] ); @@ -1181,7 +1172,7 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID ); OUString aParticleID = ObjectIdentifier::getParticleID( rObjectCID ); - Reference< XDiagram > xDiagram; + rtl::Reference< Diagram > xDiagram; Reference< XCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); @@ -1211,7 +1202,7 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( break; case OBJECTTYPE_DIAGRAM: { - xObjectProperties.set( xDiagram, uno::UNO_QUERY ); + xObjectProperties = xDiagram; } break; case OBJECTTYPE_DIAGRAM_WALL: @@ -1356,7 +1347,7 @@ Reference< XAxis > ObjectIdentifier::getAxisForCID( const OUString& rObjectCID , const Reference< frame::XModel >& xChartModel ) { - Reference< XDiagram > xDiagram; + rtl::Reference< Diagram > xDiagram; Reference< XCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); @@ -1373,7 +1364,7 @@ Reference< XDataSeries > ObjectIdentifier::getDataSeriesForCID( { Reference< XDataSeries > xSeries; - Reference< XDiagram > xDiagram; + rtl::Reference< Diagram > xDiagram; Reference< XCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); @@ -1393,12 +1384,11 @@ Reference< XDataSeries > ObjectIdentifier::getDataSeriesForCID( return xSeries; } -Reference< XDiagram > ObjectIdentifier::getDiagramForCID( +rtl::Reference< Diagram > ObjectIdentifier::getDiagramForCID( const OUString& rObjectCID , const uno::Reference< frame::XModel >& xChartModel ) { - Reference< XDiagram > xDiagram; - + rtl::Reference< Diagram > xDiagram; Reference< XCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); diff --git a/chart2/source/tools/RangeHighlighter.cxx b/chart2/source/tools/RangeHighlighter.cxx index 4a7e4be66ca0..2ea659f7b708 100644 --- a/chart2/source/tools/RangeHighlighter.cxx +++ b/chart2/source/tools/RangeHighlighter.cxx @@ -23,6 +23,7 @@ #include <DataSourceHelper.hxx> #include <ObjectIdentifier.hxx> #include <DataSeriesHelper.hxx> +#include <Diagram.hxx> #include <com/sun/star/chart2/ScaleData.hpp> #include <com/sun/star/chart2/XAxis.hpp> @@ -160,7 +161,7 @@ void RangeHighlighter::determineRanges() ) { // Diagram - Reference< chart2::XDiagram > xDia( ObjectIdentifier::getDiagramForCID( aCID, xChartModel ) ); + rtl::Reference< ::chart::Diagram > xDia( ObjectIdentifier::getDiagramForCID( aCID, xChartModel ) ); if( xDia.is()) { fillRangesForDiagram( xDia ); @@ -208,6 +209,21 @@ void RangeHighlighter::fillRangesForDiagram( const Reference< chart2::XDiagram > } } +void RangeHighlighter::fillRangesForDiagram( const rtl::Reference< Diagram > & xDiagram ) +{ + Sequence< OUString > aSelectedRanges( DataSourceHelper::getUsedDataRanges( xDiagram )); + m_aSelectedRanges.realloc( aSelectedRanges.getLength()); + auto pSelectedRanges = m_aSelectedRanges.getArray(); + // @todo: merge ranges + for( sal_Int32 i=0; i<aSelectedRanges.getLength(); ++i ) + { + pSelectedRanges[i].RangeRepresentation = aSelectedRanges[i]; + pSelectedRanges[i].Index = -1; + pSelectedRanges[i].PreferredColor = sal_Int32(defaultPreferredColor); + pSelectedRanges[i].AllowMerginigWithOtherRanges = true; + } +} + void RangeHighlighter::fillRangesForDataSeries( const uno::Reference< chart2::XDataSeries > & xSeries ) { Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index 76bb2d11f56a..5ffeb320478f 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -23,6 +23,7 @@ #include <BaseGFXHelper.hxx> #include <VLineProperties.hxx> #include <ShapeFactory.hxx> +#include <Diagram.hxx> #include <CommonConverters.hxx> #include <ExplicitCategoriesProvider.hxx> @@ -2360,8 +2361,8 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries( if( xTarget.is() ) { - uno::Reference< XCoordinateSystemContainer > xCooSysCnt( rModel.getFirstDiagram(), uno::UNO_QUERY ); - Reference< chart2::XCoordinateSystem > xCooSys(xCooSysCnt->getCoordinateSystems()[0]); + rtl::Reference< Diagram > xDiagram = rModel.getFirstChartDiagram(); + Reference< chart2::XCoordinateSystem > xCooSys(xDiagram->getCoordinateSystems()[0]); Reference< beans::XPropertySet > xProp( xCooSys, uno::UNO_QUERY ); bool bSwapXAndY = false; diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index e5a0bf17641a..fff8c6ea08d3 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -1790,14 +1790,13 @@ sal_Int32 lcl_getDiagramTitleSpace() { return 200; //=0,2 cm spacing } -bool lcl_getPropertySwapXAndYAxis( const uno::Reference< XDiagram >& xDiagram ) +bool lcl_getPropertySwapXAndYAxis( const rtl::Reference< Diagram >& xDiagram ) { bool bSwapXAndY = false; - uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( xCooSysContainer.is() ) + if( xDiagram.is() ) { - uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); + uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xDiagram->getCoordinateSystems() ); if( aCooSysList.hasElements() ) { uno::Reference<beans::XPropertySet> xProp(aCooSysList[0], uno::UNO_QUERY ); @@ -1876,7 +1875,7 @@ awt::Rectangle ExplicitValueProvider::AddSubtractAxisTitleSizes( if( pExplicitValueProvider ) { //detect whether x axis points into x direction or not - if( lcl_getPropertySwapXAndYAxis( rModel.getFirstDiagram() ) ) + if( lcl_getPropertySwapXAndYAxis( rModel.getFirstChartDiagram() ) ) { std::swap( xTitle_Height, xTitle_Width ); std::swap( xSecondTitle_Height, xSecondTitle_Width );