summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-03-15 16:44:01 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-03-18 13:30:03 +0000
commit183c3d58fbaf20a61b589d8f8f29bffc07fbe7dd (patch)
tree0d1492868c8c0c2029e6905b34ed76fd85487b00
parenttdf#154242 Explanatory images of UI Chooser (.uno:ToolbarModeUI) (diff)
downloadcore-183c3d58fbaf20a61b589d8f8f29bffc07fbe7dd.tar.gz
core-183c3d58fbaf20a61b589d8f8f29bffc07fbe7dd.zip
move getCategories/setCategories inside chart2::Diagram
Change-Id: I7c6b4e92bb131cc3c6b5b4eedb3304128b8bd988 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149082 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--chart2/source/controller/dialogs/DialogModel.cxx4
-rw-r--r--chart2/source/inc/Diagram.hxx8
-rw-r--r--chart2/source/inc/DiagramHelper.hxx10
-rw-r--r--chart2/source/model/main/Diagram.cxx112
-rw-r--r--chart2/source/model/template/ChartTypeTemplate.cxx4
-rw-r--r--chart2/source/tools/AxisHelper.cxx2
-rw-r--r--chart2/source/tools/DataSourceHelper.cxx14
-rw-r--r--chart2/source/tools/DiagramHelper.cxx124
-rw-r--r--chart2/source/tools/InternalDataProvider.cxx8
9 files changed, 140 insertions, 146 deletions
diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx
index 501e68f201c1..6bd55142670c 100644
--- a/chart2/source/controller/dialogs/DialogModel.cxx
+++ b/chart2/source/controller/dialogs/DialogModel.cxx
@@ -598,7 +598,7 @@ uno::Reference< chart2::data::XLabeledDataSequence > DialogModel::getCategories(
if( m_xChartDocument.is())
{
rtl::Reference< Diagram > xDiagram( m_xChartDocument->getFirstChartDiagram());
- xResult = DiagramHelper::getCategoriesFromDiagram( xDiagram );
+ xResult = xDiagram->getCategories();
}
}
catch( const uno::Exception & )
@@ -626,7 +626,7 @@ void DialogModel::setCategories( const Reference< chart2::data::XLabeledDataSequ
sal_Int32 nAxisType = ChartTypeHelper::getAxisType( xFirstChartType, 0 ); // x-axis
bSupportsCategories = (nAxisType == AxisType::CATEGORY);
}
- DiagramHelper::setCategoriesToDiagram( xCategories, xDiagram, true, bSupportsCategories );
+ xDiagram->setCategories( xCategories, true, bSupportsCategories );
}
OUString DialogModel::getCategoriesRange() const
diff --git a/chart2/source/inc/Diagram.hxx b/chart2/source/inc/Diagram.hxx
index d28ad7bd0575..1d612902e568 100644
--- a/chart2/source/inc/Diagram.hxx
+++ b/chart2/source/inc/Diagram.hxx
@@ -226,6 +226,14 @@ public:
bool isSupportingDateAxis();
+ css::uno::Reference< css::chart2::data::XLabeledDataSequence >
+ getCategories();
+
+ void setCategories(
+ const css::uno::Reference< css::chart2::data::XLabeledDataSequence >& xCategories,
+ bool bSetAxisType = false, // when this flag is true ...
+ bool bCategoryAxis = true);// set the AxisType to CATEGORY or back to REALNUMBER
+
private:
// ____ XModifyListener ____
virtual void SAL_CALL modified(
diff --git a/chart2/source/inc/DiagramHelper.hxx b/chart2/source/inc/DiagramHelper.hxx
index 0e02db670287..4bba95a7b1af 100644
--- a/chart2/source/inc/DiagramHelper.hxx
+++ b/chart2/source/inc/DiagramHelper.hxx
@@ -181,16 +181,6 @@ public:
static bool isCategoryDiagram(
const rtl::Reference< ::chart::Diagram >& xDiagram );
- static void setCategoriesToDiagram(
- const css::uno::Reference< css::chart2::data::XLabeledDataSequence >& xCategories,
- const rtl::Reference< ::chart::Diagram >& xDiagram,
- bool bSetAxisType = false, // when this flag is true ...
- bool bCategoryAxis = true);// set the AxisType to CATEGORY or back to REALNUMBER
-
- static css::uno::Reference< css::chart2::data::XLabeledDataSequence >
- getCategoriesFromDiagram(
- const rtl::Reference< ::chart::Diagram > & xDiagram );
-
static css::uno::Sequence< OUString >
getExplicitSimpleCategories( ChartModel& rModel );
diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx
index daf1b91970d4..bd8d9c06d260 100644
--- a/chart2/source/model/main/Diagram.cxx
+++ b/chart2/source/model/main/Diagram.cxx
@@ -35,11 +35,13 @@
#include <unonames.hxx>
#include <BaseCoordinateSystem.hxx>
#include <Legend.hxx>
+#include <Axis.hxx>
#include <DataTable.hxx>
#include <servicenames_charttypes.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/chart2/AxisType.hpp>
#include <com/sun/star/chart2/DataPointGeometry3D.hpp>
#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/chart2/RelativeSize.hpp>
@@ -1065,7 +1067,117 @@ bool Diagram::isSupportingDateAxis()
return ::chart::ChartTypeHelper::isSupportingDateAxis( getChartTypeByIndex( 0 ), 0 );
}
+static std::vector< rtl::Reference< Axis > > lcl_getAxisHoldingCategoriesFromDiagram(
+ Diagram& rDiagram )
+{
+ std::vector< rtl::Reference< Axis > > aRet;
+
+ // return first x-axis as fall-back
+ rtl::Reference< Axis > xFallBack;
+ try
+ {
+ for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : rDiagram.getBaseCoordinateSystems() )
+ {
+ OSL_ASSERT( xCooSys.is());
+ for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
+ {
+ const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nN);
+ for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI)
+ {
+ rtl::Reference< Axis > xAxis = xCooSys->getAxisByDimension2( nN,nI );
+ OSL_ASSERT( xAxis.is());
+ if( xAxis.is())
+ {
+ chart2::ScaleData aScaleData = xAxis->getScaleData();
+ if( aScaleData.Categories.is() || (aScaleData.AxisType == chart2::AxisType::CATEGORY) )
+ {
+ aRet.push_back(xAxis);
+ }
+ if( (nN == 0) && !xFallBack.is())
+ xFallBack = xAxis;
+ }
+ }
+ }
+ }
+ }
+ catch( const uno::Exception & )
+ {
+ DBG_UNHANDLED_EXCEPTION("chart2" );
+ }
+
+ if( aRet.empty() )
+ aRet.push_back(xFallBack);
+
+ return aRet;
+}
+
+uno::Reference< chart2::data::XLabeledDataSequence > Diagram::getCategories()
+{
+ uno::Reference< chart2::data::XLabeledDataSequence > xResult;
+
+ try
+ {
+ std::vector< rtl::Reference< Axis > > aCatAxes(
+ lcl_getAxisHoldingCategoriesFromDiagram( *this ));
+ //search for first categories
+ if (aCatAxes.empty())
+ return xResult;
+
+ rtl::Reference< Axis > xCatAxis(aCatAxes[0]);
+ if( !xCatAxis.is())
+ return xResult;
+
+ chart2::ScaleData aScaleData( xCatAxis->getScaleData());
+ if( !aScaleData.Categories.is() )
+ return xResult;
+
+ xResult = aScaleData.Categories;
+ uno::Reference<beans::XPropertySet> xProp(xResult->getValues(), uno::UNO_QUERY );
+ if( xProp.is() )
+ {
+ try
+ {
+ xProp->setPropertyValue( "Role", uno::Any( OUString("categories") ) );
+ }
+ catch( const uno::Exception & )
+ {
+ DBG_UNHANDLED_EXCEPTION("chart2");
+ }
+ }
+ }
+ catch( const uno::Exception & )
+ {
+ DBG_UNHANDLED_EXCEPTION("chart2");
+ }
+
+ return xResult;
+}
+void Diagram::setCategories(
+ const uno::Reference< chart2::data::XLabeledDataSequence >& xCategories,
+ bool bSetAxisType /* = false */,
+ bool bCategoryAxis /* = true */ )
+{
+ std::vector< rtl::Reference< Axis > > aCatAxes(
+ lcl_getAxisHoldingCategoriesFromDiagram( *this ));
+
+ for (const rtl::Reference< Axis >& xCatAxis : aCatAxes)
+ {
+ if( xCatAxis.is())
+ {
+ chart2::ScaleData aScaleData( xCatAxis->getScaleData());
+ aScaleData.Categories = xCategories;
+ if( bSetAxisType )
+ {
+ if( bCategoryAxis )
+ aScaleData.AxisType = chart2::AxisType::CATEGORY;
+ else if( aScaleData.AxisType == chart2::AxisType::CATEGORY || aScaleData.AxisType == chart2::AxisType::DATE )
+ aScaleData.AxisType = chart2::AxisType::REALNUMBER;
+ }
+ xCatAxis->setScaleData( aScaleData );
+ }
+ }
+}
} // namespace chart
diff --git a/chart2/source/model/template/ChartTypeTemplate.cxx b/chart2/source/model/template/ChartTypeTemplate.cxx
index 17ae7dc215f9..a23b74af57e8 100644
--- a/chart2/source/model/template/ChartTypeTemplate.cxx
+++ b/chart2/source/model/template/ChartTypeTemplate.cxx
@@ -191,7 +191,7 @@ void ChartTypeTemplate::changeDiagram( const rtl::Reference< Diagram >& xDiagram
rtl::Reference< DataInterpreter > xInterpreter( getDataInterpreter2());
InterpretedData aData;
aData.Series = aSeriesSeq;
- aData.Categories = DiagramHelper::getCategoriesFromDiagram( xDiagram );
+ aData.Categories = xDiagram->getCategories();
if( xInterpreter->isDataCompatible( aData ) )
{
@@ -271,7 +271,7 @@ void ChartTypeTemplate::changeDiagramData(
}
// categories
- DiagramHelper::setCategoriesToDiagram( aData.Categories, xDiagram, true, supportsCategories() );
+ xDiagram->setCategories( aData.Categories, true, supportsCategories() );
std::vector< rtl::Reference< ChartType > > aChartTypes =
xDiagram->getChartTypes();
diff --git a/chart2/source/tools/AxisHelper.cxx b/chart2/source/tools/AxisHelper.cxx
index 5fd8de93dcf7..b56f7e9b0e57 100644
--- a/chart2/source/tools/AxisHelper.cxx
+++ b/chart2/source/tools/AxisHelper.cxx
@@ -207,7 +207,7 @@ sal_Int32 AxisHelper::getExplicitNumberFormatKeyForAxis(
DataSeriesHelper::getAllDataSequencesByRole( xSource->getDataSequences(), "values-x" ) );
if( aXValues.empty() )
{
- uno::Reference< chart2::data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
+ uno::Reference< chart2::data::XLabeledDataSequence > xCategories( xDiagram->getCategories() );
if( xCategories.is() )
{
Reference< data::XDataSequence > xSeq( xCategories->getValues());
diff --git a/chart2/source/tools/DataSourceHelper.cxx b/chart2/source/tools/DataSourceHelper.cxx
index 92889dbe22d4..57fef259b1f8 100644
--- a/chart2/source/tools/DataSourceHelper.cxx
+++ b/chart2/source/tools/DataSourceHelper.cxx
@@ -219,7 +219,9 @@ rtl::Reference< DataSource > DataSourceHelper::pressUsedDataIntoRectangularForma
//categories are always the first sequence
rtl::Reference< Diagram > xDiagram( xChartDoc->getFirstChartDiagram());
- Reference< chart2::data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
+ Reference< chart2::data::XLabeledDataSequence > xCategories;
+ if (xDiagram)
+ xCategories = xDiagram->getCategories();
if( xCategories.is() )
aResultVector.push_back( xCategories );
@@ -252,7 +254,7 @@ uno::Sequence< OUString > DataSourceHelper::getUsedDataRanges(
if( xDiagram.is())
{
- uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
+ uno::Reference< data::XLabeledDataSequence > xCategories( xDiagram->getCategories() );
if( xCategories.is() )
lcl_addRanges( aResult, xCategories );
@@ -279,7 +281,7 @@ rtl::Reference< DataSource > DataSourceHelper::getUsedData(
std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
rtl::Reference< Diagram > xDiagram = rModel.getFirstChartDiagram();
- uno::Reference< chart2::data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
+ uno::Reference< chart2::data::XLabeledDataSequence > xCategories( xDiagram->getCategories() );
if( xCategories.is() )
aResult.push_back( xCategories );
@@ -316,8 +318,10 @@ bool DataSourceHelper::detectRangeSegmentation(
rOutRangeString, rSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories );
bSomethingDetected = !rOutRangeString.isEmpty();
- uno::Reference< chart2::data::XLabeledDataSequence > xCategories(
- DiagramHelper::getCategoriesFromDiagram( xChartModel->getFirstChartDiagram() ));
+ rtl::Reference<Diagram> xDiagram = xChartModel->getFirstChartDiagram();
+ uno::Reference< chart2::data::XLabeledDataSequence > xCategories;
+ if (xDiagram)
+ xCategories = xDiagram->getCategories();
rOutHasCategories = xCategories.is();
}
catch( uno::Exception & )
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index cf27162c936c..8007a4f3a009 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -482,7 +482,7 @@ void DiagramHelper::replaceCoordinateSystem(
try
{
- uno::Reference< chart2::data::XLabeledDataSequence > xCategories = DiagramHelper::getCategoriesFromDiagram( xDiagram );
+ uno::Reference< chart2::data::XLabeledDataSequence > xCategories = xDiagram->getCategories();
// move chart types of xCooSysToReplace to xReplacement
xReplacement->setChartTypes( xCooSysToReplace->getChartTypes());
@@ -491,7 +491,7 @@ void DiagramHelper::replaceCoordinateSystem(
xDiagram->addCoordinateSystem( xReplacement );
if( xCategories.is() )
- DiagramHelper::setCategoriesToDiagram( xCategories, xDiagram );
+ xDiagram->setCategories( xCategories );
}
catch( const uno::Exception & )
{
@@ -643,55 +643,6 @@ std::vector< std::vector< rtl::Reference< DataSeries > > >
return aResult;
}
-namespace
-{
-
-std::vector< rtl::Reference< Axis > > lcl_getAxisHoldingCategoriesFromDiagram(
- const rtl::Reference< Diagram > & xDiagram )
-{
- std::vector< rtl::Reference< Axis > > aRet;
-
- // return first x-axis as fall-back
- rtl::Reference< Axis > xFallBack;
- if (xDiagram.is()) try
- {
- for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : xDiagram->getBaseCoordinateSystems() )
- {
- OSL_ASSERT( xCooSys.is());
- for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
- {
- const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nN);
- for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI)
- {
- rtl::Reference< Axis > xAxis = xCooSys->getAxisByDimension2( nN,nI );
- OSL_ASSERT( xAxis.is());
- if( xAxis.is())
- {
- ScaleData aScaleData = xAxis->getScaleData();
- if( aScaleData.Categories.is() || (aScaleData.AxisType == AxisType::CATEGORY) )
- {
- aRet.push_back(xAxis);
- }
- if( (nN == 0) && !xFallBack.is())
- xFallBack = xAxis;
- }
- }
- }
- }
- }
- catch( const uno::Exception & )
- {
- DBG_UNHANDLED_EXCEPTION("chart2" );
- }
-
- if( aRet.empty() )
- aRet.push_back(xFallBack);
-
- return aRet;
-}
-
-} // anonymous namespace
-
bool DiagramHelper::isCategoryDiagram(
const rtl::Reference< Diagram >& xDiagram )
{
@@ -724,77 +675,6 @@ bool DiagramHelper::isCategoryDiagram(
return false;
}
-void DiagramHelper::setCategoriesToDiagram(
- const uno::Reference< chart2::data::XLabeledDataSequence >& xCategories,
- const rtl::Reference< Diagram >& xDiagram,
- bool bSetAxisType /* = false */,
- bool bCategoryAxis /* = true */ )
-{
- std::vector< rtl::Reference< Axis > > aCatAxes(
- lcl_getAxisHoldingCategoriesFromDiagram( xDiagram ));
-
- for (const rtl::Reference< Axis >& xCatAxis : aCatAxes)
- {
- if( xCatAxis.is())
- {
- ScaleData aScaleData( xCatAxis->getScaleData());
- aScaleData.Categories = xCategories;
- if( bSetAxisType )
- {
- if( bCategoryAxis )
- aScaleData.AxisType = AxisType::CATEGORY;
- else if( aScaleData.AxisType == AxisType::CATEGORY || aScaleData.AxisType == AxisType::DATE )
- aScaleData.AxisType = AxisType::REALNUMBER;
- }
- xCatAxis->setScaleData( aScaleData );
- }
- }
-}
-
-uno::Reference< chart2::data::XLabeledDataSequence >
- DiagramHelper::getCategoriesFromDiagram(
- const rtl::Reference< Diagram > & xDiagram )
-{
- uno::Reference< chart2::data::XLabeledDataSequence > xResult;
-
- try
- {
- std::vector< rtl::Reference< Axis > > aCatAxes(
- lcl_getAxisHoldingCategoriesFromDiagram( xDiagram ));
- //search for first categories
- if (!aCatAxes.empty())
- {
- rtl::Reference< Axis > xCatAxis(aCatAxes[0]);
- if( xCatAxis.is())
- {
- ScaleData aScaleData( xCatAxis->getScaleData());
- if( aScaleData.Categories.is() )
- {
- xResult = aScaleData.Categories;
- uno::Reference<beans::XPropertySet> xProp(xResult->getValues(), uno::UNO_QUERY );
- if( xProp.is() )
- {
- try
- {
- xProp->setPropertyValue( "Role", uno::Any( OUString("categories") ) );
- }
- catch( const uno::Exception & )
- {
- DBG_UNHANDLED_EXCEPTION("chart2");
- }
- }
- }
- }
- }
- }
- catch( const uno::Exception & )
- {
- DBG_UNHANDLED_EXCEPTION("chart2");
- }
-
- return xResult;
-}
-
static void lcl_generateAutomaticCategoriesFromChartType(
Sequence< OUString >& rRet,
const rtl::Reference< ChartType >& xChartType )
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index 03d886cc9500..7983735b4485 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -376,10 +376,10 @@ InternalDataProvider::InternalDataProvider(
else
m_aInternalData.setComplexColumnLabels( std::move(aNewCategories) );
if( bConnectToModel )
- DiagramHelper::setCategoriesToDiagram(
- rtl::Reference< LabeledDataSequence >(new LabeledDataSequence(
- createDataSequenceByRangeRepresentation( lcl_aCategoriesRangeName ))),
- xDiagram );
+ xDiagram->setCategories(
+ new LabeledDataSequence(
+ createDataSequenceByRangeRepresentation( lcl_aCategoriesRangeName ))
+ );
}
// data series