diff options
Diffstat (limited to 'chart2/source/tools/DiagramHelper.cxx')
-rw-r--r-- | chart2/source/tools/DiagramHelper.cxx | 1185 |
1 files changed, 39 insertions, 1146 deletions
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx index 7d9136e7291a..38aa97265396 100644 --- a/chart2/source/tools/DiagramHelper.cxx +++ b/chart2/source/tools/DiagramHelper.cxx @@ -19,54 +19,42 @@ #include <DiagramHelper.hxx> #include <Diagram.hxx> +#include <DataSeries.hxx> #include <DataSeriesHelper.hxx> +#include <Axis.hxx> #include <AxisHelper.hxx> -#include <ChartTypeHelper.hxx> -#include <ChartTypeManager.hxx> -#include <ChartTypeTemplate.hxx> +#include <ChartType.hxx> #include <ChartModel.hxx> #include <ChartModelHelper.hxx> #include <ExplicitCategoriesProvider.hxx> -#include <servicenames_charttypes.hxx> #include <RelativePositionHelper.hxx> #include <ControllerLockGuard.hxx> #include <NumberFormatterWrapper.hxx> #include <unonames.hxx> #include <BaseCoordinateSystem.hxx> -#include <com/sun/star/chart/MissingValueTreatment.hpp> #include <com/sun/star/chart/XDiagramPositioning.hpp> #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp> -#include <com/sun/star/chart2/XTitled.hpp> -#include <com/sun/star/chart2/XChartTypeContainer.hpp> -#include <com/sun/star/chart2/XChartTypeTemplate.hpp> -#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> -#include <com/sun/star/chart2/XDataSeriesContainer.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> #include <com/sun/star/chart2/StackingDirection.hpp> -#include <com/sun/star/util/CloseVetoException.hpp> #include <com/sun/star/util/NumberFormat.hpp> -#include <com/sun/star/util/XNumberFormatsSupplier.hpp> #include <unotools/saveopt.hxx> -#include <rtl/math.hxx> #include <svl/numformat.hxx> #include <svl/zforlist.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> #include <comphelper/sequence.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <sal/log.hxx> #include <limits> using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; -using namespace ::std; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; @@ -76,266 +64,10 @@ using ::com::sun::star::chart2::XAnyDescriptionAccess; namespace chart { -DiagramHelper::tTemplateWithServiceName - DiagramHelper::getTemplateForDiagram( - const Reference< XDiagram > & xDiagram, - const rtl::Reference< ::chart::ChartTypeManager > & xChartTypeManager ) -{ - DiagramHelper::tTemplateWithServiceName aResult; - - if( ! (xChartTypeManager.is() && xDiagram.is())) - return aResult; - - Sequence< OUString > aServiceNames( xChartTypeManager->getAvailableServiceNames()); - const sal_Int32 nLength = aServiceNames.getLength(); - - bool bTemplateFound = false; - - for( sal_Int32 i = 0; ! bTemplateFound && i < nLength; ++i ) - { - try - { - rtl::Reference< ::chart::ChartTypeTemplate > xTempl = - xChartTypeManager->createTemplate( aServiceNames[ i ] ); - - if (xTempl.is() && xTempl->matchesTemplate(xDiagram, true)) - { - aResult.xChartTypeTemplate = xTempl; - aResult.sServiceName = aServiceNames[ i ]; - bTemplateFound = true; - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - } - - return aResult; -} - -void DiagramHelper::setVertical( - const Reference< XDiagram > & xDiagram, - bool bVertical /* = true */ ) -{ - try - { - if (!xDiagram.is()) - return; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - uno::Any aValue; - aValue <<= bVertical; - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : pDiagram->getBaseCoordinateSystems() ) - { - bool bChanged = false; - bool bOldSwap = false; - if( !(xCooSys->getPropertyValue("SwapXAndYAxis") >>= bOldSwap) - || bVertical != bOldSwap ) - bChanged = true; - - if( bChanged ) - xCooSys->setPropertyValue("SwapXAndYAxis", aValue); - - const sal_Int32 nDimensionCount = xCooSys->getDimension(); - sal_Int32 nDimIndex = 0; - for (nDimIndex=0; nDimIndex < nDimensionCount; ++nDimIndex) - { - const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nDimIndex); - for (sal_Int32 nI = 0; nI <= nMaximumScaleIndex; ++nI) - { - Reference<chart2::XAxis> xAxis = xCooSys->getAxisByDimension(nDimIndex,nI); - if (!xAxis.is()) - continue; - - //adapt title rotation only when axis swapping has changed - if (!bChanged) - continue; - - Reference< XTitled > xTitled( xAxis, uno::UNO_QUERY ); - if (!xTitled.is()) - continue; - - Reference< beans::XPropertySet > xTitleProps( xTitled->getTitleObject(), uno::UNO_QUERY ); - if (!xTitleProps.is()) - continue; - - double fAngleDegree = 0.0; - xTitleProps->getPropertyValue("TextRotation") >>= fAngleDegree; - if (fAngleDegree != 0.0 && - !rtl::math::approxEqual(fAngleDegree, 90.0)) - continue; - - double fNewAngleDegree = 0.0; - if( !bVertical && nDimIndex == 1 ) - fNewAngleDegree = 90.0; - else if( bVertical && nDimIndex == 0 ) - fNewAngleDegree = 90.0; - - xTitleProps->setPropertyValue("TextRotation", uno::Any(fNewAngleDegree)); - } - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } -} - -bool DiagramHelper::getVertical( const uno::Reference< chart2::XDiagram > & xDiagram, - bool& rbFound, bool& rbAmbiguous ) -{ - bool bValue = false; - rbFound = false; - rbAmbiguous = false; - - if (!xDiagram.is()) - return false; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - for (rtl::Reference<BaseCoordinateSystem> const & coords : pDiagram->getBaseCoordinateSystems()) - { - bool bCurrent = false; - if (coords->getPropertyValue("SwapXAndYAxis") >>= bCurrent) - { - if (!rbFound) - { - bValue = bCurrent; - rbFound = true; - } - else if (bCurrent != bValue) - { - // ambiguous -> choose always first found - rbAmbiguous = true; - } - } - } - return bValue; -} - -void DiagramHelper::setStackMode( - const Reference< XDiagram > & xDiagram, - StackMode eStackMode -) -{ - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - try - { - bool bValueFound = false; - bool bIsAmbiguous = false; - StackMode eOldStackMode = DiagramHelper::getStackMode( xDiagram, bValueFound, bIsAmbiguous ); - - if( eStackMode == eOldStackMode && !bIsAmbiguous ) - return; - - StackingDirection eNewDirection = StackingDirection_NO_STACKING; - if( eStackMode == StackMode::YStacked || eStackMode == StackMode::YStackedPercent ) - eNewDirection = StackingDirection_Y_STACKING; - else if( eStackMode == StackMode::ZStacked ) - eNewDirection = StackingDirection_Z_STACKING; - - uno::Any aNewDirection( eNewDirection ); - - bool bPercent = false; - if( eStackMode == StackMode::YStackedPercent ) - bPercent = true; - - //iterate through all coordinate systems - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : pDiagram->getBaseCoordinateSystems() ) - { - //set correct percent stacking - const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(1); - for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI) - { - Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( 1,nI )); - if( xAxis.is()) - { - chart2::ScaleData aScaleData = xAxis->getScaleData(); - if( (aScaleData.AxisType==AxisType::PERCENT) != bPercent ) - { - if( bPercent ) - aScaleData.AxisType = AxisType::PERCENT; - else - aScaleData.AxisType = AxisType::REALNUMBER; - xAxis->setScaleData( aScaleData ); - } - } - } - //iterate through all chart types in the current coordinate system - uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xCooSys->getChartTypes() ); - if (!aChartTypeList.hasElements()) - continue; - - uno::Reference< XChartType > xChartType( aChartTypeList[0] ); - - //iterate through all series in this chart type - uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY ); - OSL_ASSERT( xDataSeriesContainer.is()); - if( !xDataSeriesContainer.is() ) - continue; - - const uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() ); - for( uno::Reference< XDataSeries > const & dataSeries : aSeriesList ) - { - Reference< beans::XPropertySet > xProp( dataSeries, uno::UNO_QUERY ); - if(xProp.is()) - xProp->setPropertyValue( "StackingDirection", aNewDirection ); - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } -} - -StackMode DiagramHelper::getStackMode( const Reference< XDiagram > & xDiagram, bool& rbFound, bool& rbAmbiguous ) -{ - rbFound=false; - rbAmbiguous=false; - - StackMode eGlobalStackMode = StackMode::NONE; - - if( !xDiagram.is() ) - return eGlobalStackMode; - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - //iterate through all coordinate systems - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : pDiagram->getBaseCoordinateSystems() ) - { - //iterate through all chart types in the current coordinate system - uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xCooSys->getChartTypes() ); - for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT ) - { - uno::Reference< XChartType > xChartType( aChartTypeList[nT] ); - - StackMode eLocalStackMode = DiagramHelper::getStackModeFromChartType( - xChartType, rbFound, rbAmbiguous, xCooSys ); - - if( rbFound && eLocalStackMode != eGlobalStackMode && nT>0 ) - { - rbAmbiguous = true; - return eGlobalStackMode; - } - - eGlobalStackMode = eLocalStackMode; - } - } - - return eGlobalStackMode; -} - StackMode DiagramHelper::getStackModeFromChartType( - const Reference< XChartType > & xChartType, + const rtl::Reference< ChartType > & xChartType, bool& rbFound, bool& rbAmbiguous, - const Reference< XCoordinateSystem > & xCorrespondingCoordinateSystem ) + const rtl::Reference< BaseCoordinateSystem > & xCorrespondingCoordinateSystem ) { StackMode eStackMode = StackMode::NONE; rbFound = false; @@ -343,23 +75,21 @@ StackMode DiagramHelper::getStackModeFromChartType( try { - Reference< XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY_THROW ); - Sequence< Reference< chart2::XDataSeries > > aSeries( xDSCnt->getDataSeries()); + const std::vector< rtl::Reference< DataSeries > > & aSeries = xChartType->getDataSeries2(); chart2::StackingDirection eCommonDirection = chart2::StackingDirection_NO_STACKING; bool bDirectionInitialized = false; // first series is irrelevant for stacking, start with second, unless // there is only one series - const sal_Int32 nSeriesCount = aSeries.getLength(); + const sal_Int32 nSeriesCount = aSeries.size(); sal_Int32 i = (nSeriesCount == 1) ? 0: 1; for( ; i<nSeriesCount; ++i ) { rbFound = true; - Reference< beans::XPropertySet > xProp( aSeries[i], uno::UNO_QUERY_THROW ); chart2::StackingDirection eCurrentDirection = eCommonDirection; // property is not MAYBEVOID - bool bSuccess = ( xProp->getPropertyValue( "StackingDirection" ) >>= eCurrentDirection ); + bool bSuccess = ( aSeries[i]->getPropertyValue( "StackingDirection" ) >>= eCurrentDirection ); OSL_ASSERT( bSuccess ); if( ! bDirectionInitialized ) { @@ -393,8 +123,8 @@ StackMode DiagramHelper::getStackModeFromChartType( if( nSeriesCount ) nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(aSeries[0]); - Reference< chart2::XAxis > xAxis( - xCorrespondingCoordinateSystem->getAxisByDimension( 1,nAxisIndex )); + rtl::Reference< Axis > xAxis = + xCorrespondingCoordinateSystem->getAxisByDimension2( 1,nAxisIndex ); if( xAxis.is()) { chart2::ScaleData aScaleData = xAxis->getScaleData(); @@ -414,483 +144,26 @@ StackMode DiagramHelper::getStackModeFromChartType( return eStackMode; } -sal_Int32 DiagramHelper::getDimension( const Reference< XDiagram > & xDiagram ) -{ - // -1: not yet set - sal_Int32 nResult = -1; - if (!xDiagram) - return nResult; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - try - { - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : pDiagram->getBaseCoordinateSystems() ) - { - if(xCooSys.is()) - { - nResult = xCooSys->getDimension(); - break; - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - - return nResult; -} - -void DiagramHelper::setDimension( - const Reference< XDiagram > & xDiagram, - sal_Int32 nNewDimensionCount ) -{ - if( ! xDiagram.is()) - return; - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - if( DiagramHelper::getDimension( xDiagram ) == nNewDimensionCount ) - return; - - try - { - bool rbFound = false; - bool rbAmbiguous = true; - StackMode eStackMode = DiagramHelper::getStackMode( xDiagram, rbFound, rbAmbiguous ); - bool bIsSupportingOnlyDeepStackingFor3D=false; - - //change all coordinate systems: - auto aCoordSystems = pDiagram->getBaseCoordinateSystems(); - for( rtl::Reference<BaseCoordinateSystem> const & xOldCooSys : aCoordSystems ) - { - rtl::Reference< BaseCoordinateSystem > xNewCooSys; - - const Sequence< Reference< XChartType > > aChartTypeList( xOldCooSys->getChartTypes() ); - for( Reference< XChartType > const & xChartType : aChartTypeList ) - { - bIsSupportingOnlyDeepStackingFor3D = ChartTypeHelper::isSupportingOnlyDeepStackingFor3D( xChartType ); - if(!xNewCooSys.is()) - { - xNewCooSys = dynamic_cast<BaseCoordinateSystem*>(xChartType->createCoordinateSystem( nNewDimensionCount ).get()); - assert(xNewCooSys); - break; - } - //@todo make sure that all following charttypes are also capable of the new dimension - //otherwise separate them in a different group - //BM: might be done in replaceCoordinateSystem() - } - - // replace the old coordinate system at all places where it was used - DiagramHelper::replaceCoordinateSystem( xDiagram, xOldCooSys, xNewCooSys ); - } - - //correct stack mode if necessary - if( nNewDimensionCount==3 && eStackMode != StackMode::ZStacked && bIsSupportingOnlyDeepStackingFor3D ) - DiagramHelper::setStackMode( xDiagram, StackMode::ZStacked ); - else if( nNewDimensionCount==2 && eStackMode == StackMode::ZStacked ) - DiagramHelper::setStackMode( xDiagram, StackMode::NONE ); - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } -} - -void DiagramHelper::replaceCoordinateSystem( - const Reference< XDiagram > & xDiagram, - const Reference< XCoordinateSystem > & xCooSysToReplace, - const Reference< XCoordinateSystem > & xReplacement ) -{ - OSL_ASSERT( xDiagram.is()); - if( ! xDiagram.is()) - return; - - // update the coordinate-system container - Reference< XCoordinateSystemContainer > xCont( xDiagram, uno::UNO_QUERY ); - if( !xCont.is()) - return; - - try - { - Reference< chart2::data::XLabeledDataSequence > xCategories = DiagramHelper::getCategoriesFromDiagram( xDiagram ); - - // move chart types of xCooSysToReplace to xReplacement - Reference< XChartTypeContainer > xCTCntCooSys( xCooSysToReplace, uno::UNO_QUERY_THROW ); - Reference< XChartTypeContainer > xCTCntReplacement( xReplacement, uno::UNO_QUERY_THROW ); - xCTCntReplacement->setChartTypes( xCTCntCooSys->getChartTypes()); - - xCont->removeCoordinateSystem( xCooSysToReplace ); - xCont->addCoordinateSystem( xReplacement ); - - if( xCategories.is() ) - DiagramHelper::setCategoriesToDiagram( xCategories, xDiagram ); - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } -} - bool DiagramHelper::isSeriesAttachedToMainAxis( - const uno::Reference< chart2::XDataSeries >& xDataSeries ) + const rtl::Reference< ::chart::DataSeries >& xDataSeries ) { sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries); return (nAxisIndex==0); } -bool DiagramHelper::attachSeriesToAxis( bool bAttachToMainAxis - , const uno::Reference< chart2::XDataSeries >& xDataSeries - , const uno::Reference< chart2::XDiagram >& xDiagram - , const uno::Reference< uno::XComponentContext > & xContext - , bool bAdaptAxes ) -{ - bool bChanged = false; - - //set property at axis - Reference< beans::XPropertySet > xProp( xDataSeries, uno::UNO_QUERY_THROW ); - - sal_Int32 nNewAxisIndex = bAttachToMainAxis ? 0 : 1; - sal_Int32 nOldAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries); - uno::Reference< chart2::XAxis > xOldAxis( DiagramHelper::getAttachedAxis( xDataSeries, xDiagram ) ); - - if( nOldAxisIndex != nNewAxisIndex ) - { - try - { - xProp->setPropertyValue( "AttachedAxisIndex", uno::Any( nNewAxisIndex ) ); - bChanged = true; - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - } - - if( bChanged && xDiagram.is() ) - { - uno::Reference< XAxis > xAxis( AxisHelper::getAxis( 1, bAttachToMainAxis, xDiagram ) ); - if(!xAxis.is()) //create an axis if necessary - xAxis = AxisHelper::createAxis( 1, bAttachToMainAxis, xDiagram, xContext ); - if( bAdaptAxes ) - { - AxisHelper::makeAxisVisible( xAxis ); - AxisHelper::hideAxisIfNoDataIsAttached( xOldAxis, xDiagram ); - } - } - - return bChanged; -} - -uno::Reference< XAxis > DiagramHelper::getAttachedAxis( - const uno::Reference< XDataSeries >& xSeries, - const uno::Reference< XDiagram >& xDiagram ) -{ - return AxisHelper::getAxis( 1, DiagramHelper::isSeriesAttachedToMainAxis( xSeries ), xDiagram ); -} - -uno::Reference< XChartType > DiagramHelper::getChartTypeOfSeries( - const uno::Reference< chart2::XDiagram >& xDiagram - , const uno::Reference< XDataSeries >& xGivenDataSeries ) -{ - if( !xGivenDataSeries.is() ) - return nullptr; - if(!xDiagram.is()) - return nullptr; - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - //iterate through the model to find the given xSeries - //the found parent indicates the charttype - - //iterate through all coordinate systems - - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : pDiagram->getBaseCoordinateSystems() ) - { - //iterate through all chart types in the current coordinate system - const uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xCooSys->getChartTypes() ); - for( uno::Reference< XChartType > const & xChartType : aChartTypeList ) - { - //iterate through all series in this chart type - uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY ); - OSL_ASSERT( xDataSeriesContainer.is()); - if( !xDataSeriesContainer.is() ) - continue; - - const uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() ); - for( uno::Reference< XDataSeries > const & dataSeries : aSeriesList ) - { - if( xGivenDataSeries==dataSeries ) - return xChartType; - } - } - } - return nullptr; -} - -std::vector< Reference< XDataSeries > > - DiagramHelper::getDataSeriesFromDiagram( - const Reference< XDiagram > & xDiagram ) -{ - std::vector< Reference< XDataSeries > > aResult; - if (!xDiagram) - return aResult; - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - try - { - for( rtl::Reference< BaseCoordinateSystem > const & coords : pDiagram->getBaseCoordinateSystems() ) - { - const Sequence< Reference< XChartType > > aChartTypeSeq( coords->getChartTypes()); - for( Reference< XChartType> const & chartType : aChartTypeSeq ) - { - Reference< XDataSeriesContainer > xDSCnt( chartType, uno::UNO_QUERY_THROW ); - const Sequence< Reference< XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() ); - aResult.insert( aResult.end(), aSeriesSeq.begin(), aSeriesSeq.end() ); - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - - return aResult; -} - -Sequence< Sequence< Reference< XDataSeries > > > - DiagramHelper::getDataSeriesGroups( const Reference< XDiagram > & xDiagram ) -{ - if (!xDiagram) - return {}; - - vector< Sequence< Reference< XDataSeries > > > aResult; - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - //iterate through all coordinate systems - for( rtl::Reference< BaseCoordinateSystem > const & coords : pDiagram->getBaseCoordinateSystems() ) - { - //iterate through all chart types in the current coordinate system - const Sequence< Reference< XChartType > > aChartTypeList( coords->getChartTypes() ); - for( Reference< XChartType > const & chartType : aChartTypeList ) - { - Reference< XDataSeriesContainer > xDataSeriesContainer( chartType, uno::UNO_QUERY ); - if( !xDataSeriesContainer.is() ) - continue; - aResult.push_back( xDataSeriesContainer->getDataSeries() ); - } - } - return comphelper::containerToSequence( aResult ); -} - -Reference< XChartType > - DiagramHelper::getChartTypeByIndex( const Reference< XDiagram >& xDiagram, sal_Int32 nIndex ) -{ - if (!xDiagram) - return nullptr; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - Reference< XChartType > xChartType; - - //iterate through all coordinate systems - sal_Int32 nTypesSoFar = 0; - for( rtl::Reference< BaseCoordinateSystem > const & coords : pDiagram->getBaseCoordinateSystems() ) - { - Sequence< Reference< XChartType > > aChartTypeList( coords->getChartTypes() ); - if( nIndex >= 0 && nIndex < (nTypesSoFar + aChartTypeList.getLength()) ) - { - xChartType.set( aChartTypeList[nIndex - nTypesSoFar] ); - break; - } - nTypesSoFar += aChartTypeList.getLength(); - } - - return xChartType; -} - -namespace -{ - -std::vector< Reference< XAxis > > lcl_getAxisHoldingCategoriesFromDiagram( - const rtl::Reference< Diagram > & xDiagram ) -{ - std::vector< Reference< XAxis > > aRet; - - // return first x-axis as fall-back - Reference< XAxis > xFallBack; - 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) - { - Reference< XAxis > xAxis = xCooSys->getAxisByDimension( 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.set( xAxis ); - } - } - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2" ); - } - - if( aRet.empty() ) - aRet.push_back(xFallBack); - - return aRet; -} - -} // anonymous namespace - -bool DiagramHelper::isCategoryDiagram( - const Reference< XDiagram >& xDiagram ) -{ - try - { - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : pDiagram->getBaseCoordinateSystems() ) - { - for( sal_Int32 nN = xCooSys->getDimension(); nN--; ) - { - const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nN); - for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI) - { - Reference< XAxis > xAxis = xCooSys->getAxisByDimension( nN,nI ); - OSL_ASSERT( xAxis.is()); - if( xAxis.is()) - { - ScaleData aScaleData = xAxis->getScaleData(); - if( aScaleData.AxisType == AxisType::CATEGORY || aScaleData.AxisType == AxisType::DATE ) - return true; - } - } - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - - return false; -} - -void DiagramHelper::setCategoriesToDiagram( - const Reference< chart2::data::XLabeledDataSequence >& xCategories, - const Reference< XDiagram >& xDiagram, - bool bSetAxisType /* = false */, - bool bCategoryAxis /* = true */ ) -{ - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - std::vector< Reference< chart2::XAxis > > aCatAxes( - lcl_getAxisHoldingCategoriesFromDiagram( pDiagram )); - - for (const Reference< chart2::XAxis >& 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 ); - } - } -} - -Reference< data::XLabeledDataSequence > - DiagramHelper::getCategoriesFromDiagram( - const Reference< XDiagram > & xDiagram ) -{ - Reference< data::XLabeledDataSequence > xResult; - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - - try - { - std::vector< Reference< chart2::XAxis > > aCatAxes( - lcl_getAxisHoldingCategoriesFromDiagram( pDiagram )); - //search for first categories - if (!aCatAxes.empty()) - { - Reference< chart2::XAxis > xCatAxis(aCatAxes[0]); - if( xCatAxis.is()) - { - ScaleData aScaleData( xCatAxis->getScaleData()); - if( aScaleData.Categories.is() ) - { - xResult.set( aScaleData.Categories ); - uno::Reference<beans::XPropertySet> xProp(aScaleData.Categories->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 Reference< XChartType >& xChartType ) + const rtl::Reference< ChartType >& xChartType ) { if(!xChartType.is()) return; OUString aMainSeq( xChartType->getRoleOfSequenceForSeriesLabel() ); - Reference< XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY ); - if( !xSeriesCnt.is() ) - return; - const Sequence< Reference< XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries() ); - for( Reference< XDataSeries > const & dataSeries : aSeriesSeq ) + const std::vector< rtl::Reference< DataSeries > > & aSeriesSeq = xChartType->getDataSeries2(); + for( rtl::Reference< DataSeries > const & dataSeries : aSeriesSeq ) { - Reference< data::XDataSource > xDataSource( dataSeries, uno::UNO_QUERY ); - if( !xDataSource.is() ) - continue; - Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( - ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aMainSeq )); + uno::Reference< data::XLabeledDataSequence > xLabeledSeq = + ::chart::DataSeriesHelper::getDataSequenceByRole( dataSeries, aMainSeq ); if( !xLabeledSeq.is() ) continue; Reference< chart2::data::XDataSequence > xValueSeq( xLabeledSeq->getValues() ); @@ -902,15 +175,14 @@ static void lcl_generateAutomaticCategoriesFromChartType( } } -Sequence< OUString > DiagramHelper::generateAutomaticCategoriesFromCooSys( const Reference< XCoordinateSystem > & xCooSys ) +Sequence< OUString > DiagramHelper::generateAutomaticCategoriesFromCooSys( const rtl::Reference< BaseCoordinateSystem > & xCooSys ) { Sequence< OUString > aRet; - Reference< XChartTypeContainer > xTypeCntr( xCooSys, uno::UNO_QUERY ); - if( xTypeCntr.is() ) + if( xCooSys.is() ) { - const Sequence< Reference< XChartType > > aChartTypes( xTypeCntr->getChartTypes() ); - for( Reference< XChartType > const & chartType : aChartTypes ) + const std::vector< rtl::Reference< ChartType > > & aChartTypes( xCooSys->getChartTypes2() ); + for( rtl::Reference< ChartType > const & chartType : aChartTypes ) { lcl_generateAutomaticCategoriesFromChartType( aRet, chartType ); if( aRet.hasElements() ) @@ -923,14 +195,14 @@ Sequence< OUString > DiagramHelper::generateAutomaticCategoriesFromCooSys( const Sequence< OUString > DiagramHelper::getExplicitSimpleCategories( ChartModel& rModel ) { - rtl::Reference< BaseCoordinateSystem > xCooSys = ChartModelHelper::getFirstCoordinateSystem( rModel ); + rtl::Reference< BaseCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( &rModel ) ); ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSys, rModel ); return aExplicitCategoriesProvider.getSimpleCategories(); } namespace { -void lcl_switchToDateCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis ) +void lcl_switchToDateCategories( const rtl::Reference< ChartModel >& xChartDoc, const Reference< XAxis >& xAxis ) { if( !xAxis.is() ) return; @@ -966,13 +238,12 @@ void lcl_switchToDateCategories( const Reference< XChartDocument >& xChartDoc, c } //check the numberformat at the axis Reference< beans::XPropertySet > xAxisProps( xAxis, uno::UNO_QUERY ); - Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartDoc, uno::UNO_QUERY ); - if( xAxisProps.is() && xNumberFormatsSupplier.is() ) + if( xAxisProps.is() ) { sal_Int32 nNumberFormat = -1; xAxisProps->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat; - Reference< util::XNumberFormats > xNumberFormats( xNumberFormatsSupplier->getNumberFormats() ); + Reference< util::XNumberFormats > xNumberFormats( xChartDoc->getNumberFormats() ); if( xNumberFormats.is() ) { Reference< beans::XPropertySet > xKeyProps; @@ -1006,7 +277,7 @@ void lcl_switchToDateCategories( const Reference< XChartDocument >& xChartDoc, c xAxis->setScaleData( aScale ); } -void lcl_switchToTextCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis ) +void lcl_switchToTextCategories( const rtl::Reference< ChartModel >& xChartDoc, const Reference< XAxis >& xAxis ) { if( !xAxis.is() ) return; @@ -1023,42 +294,36 @@ void lcl_switchToTextCategories( const Reference< XChartDocument >& xChartDoc, c } -void DiagramHelper::switchToDateCategories( const Reference< XChartDocument >& xChartDoc ) +void DiagramHelper::switchToDateCategories( const rtl::Reference<::chart::ChartModel>& xChartDoc ) { if(xChartDoc.is()) { ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); - Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartDoc ) ); + rtl::Reference< BaseCoordinateSystem > xCooSys = ChartModelHelper::getFirstCoordinateSystem( xChartDoc ); if( xCooSys.is() ) { - Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) ); + rtl::Reference< Axis > xAxis = xCooSys->getAxisByDimension2(0,0); lcl_switchToDateCategories( xChartDoc, xAxis ); } } } -void DiagramHelper::switchToTextCategories( const Reference< XChartDocument >& xChartDoc ) +void DiagramHelper::switchToTextCategories( const rtl::Reference<::chart::ChartModel>& xChartDoc ) { if(xChartDoc.is()) { ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); - Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartDoc ) ); + rtl::Reference< BaseCoordinateSystem > xCooSys = ChartModelHelper::getFirstCoordinateSystem( xChartDoc ); if( xCooSys.is() ) { - Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) ); + rtl::Reference< Axis > xAxis = xCooSys->getAxisByDimension2(0,0); lcl_switchToTextCategories( xChartDoc, xAxis ); } } } -bool DiagramHelper::isSupportingDateAxis( const Reference< chart2::XDiagram >& xDiagram ) -{ - return ::chart::ChartTypeHelper::isSupportingDateAxis( - DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), 0 ); -} - bool DiagramHelper::isDateNumberFormat( sal_Int32 nNumberFormat, const Reference< util::XNumberFormats >& xNumberFormats ) { bool bIsDate = false; @@ -1118,7 +383,7 @@ sal_Int32 DiagramHelper::getDateTimeInputNumberFormat( const Reference< util::XN // Obtain best matching date, time or datetime format. nRet = pNumFormatter->GuessDateTimeFormat( nType, fNumber, LANGUAGE_SYSTEM); // Obtain the corresponding edit format. - nRet = pNumFormatter->GetEditFormat( fNumber, nRet, nType, LANGUAGE_SYSTEM, nullptr); + nRet = pNumFormatter->GetEditFormat( fNumber, nRet, nType, nullptr); } return nRet; } @@ -1153,34 +418,8 @@ sal_Int32 DiagramHelper::getPercentNumberFormat( const Reference< util::XNumberF return nRet; } -Sequence< Reference< XChartType > > - DiagramHelper::getChartTypesFromDiagram( - const Reference< XDiagram > & xDiagram ) -{ - if(!xDiagram) - return {}; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(pDiagram); - std::vector< Reference< XChartType > > aResult; - try - { - for( rtl::Reference< BaseCoordinateSystem > const & coords : pDiagram->getBaseCoordinateSystems() ) - { - const Sequence< Reference< XChartType > > aChartTypeSeq( coords->getChartTypes()); - aResult.insert( aResult.end(), aChartTypeSeq.begin(), aChartTypeSeq.end() ); - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - - return comphelper::containerToSequence( aResult ); -} - -bool DiagramHelper::areChartTypesCompatible( const Reference< ::chart2::XChartType >& xFirstType, - const Reference< ::chart2::XChartType >& xSecondType ) +bool DiagramHelper::areChartTypesCompatible( const rtl::Reference< ChartType >& xFirstType, + const rtl::Reference< ChartType >& xSecondType ) { if( !xFirstType.is() || !xSecondType.is() ) return false; @@ -1192,352 +431,6 @@ bool DiagramHelper::areChartTypesCompatible( const Reference< ::chart2::XChartTy return ( aFirstRoles == aSecondRoles ); } -namespace -{ - /** - * This method implements the logic of checking if a series can be moved - * forward/backward. Depending on the "bDoMove" parameter the series will - * be moved (bDoMove = true) or the function just will test if the - * series can be moved without doing the move (bDoMove = false). - * - * @param xDiagram - * Reference to the diagram that contains the series. - * - * @param xGivenDataSeries - * Reference to the series that should moved or tested for moving. - * - * @param bForward - * Direction in which the series should be moved or tested for moving. - * - * @param bDoMove - * Should this function really move the series (true) or just test if it is - * possible (false). - * - * - * @returns - * in case of bDoMove == true - * - True : if the move was done - * - False : the move failed - * in case of bDoMove == false - * - True : the series can be moved - * - False : the series can not be moved - * - */ - -bool lcl_moveSeriesOrCheckIfMoveIsAllowed( - const rtl::Reference< Diagram >& xDiagram, - const Reference< XDataSeries >& xGivenDataSeries, - bool bForward, - bool bDoMove ) -{ - bool bMovedOrMoveAllowed = false; - - try - { - if( xGivenDataSeries.is() && xDiagram.is() ) - { - //find position of series. - bool bFound = false; - const std::vector< rtl::Reference< BaseCoordinateSystem > > & aCooSysList( xDiagram->getBaseCoordinateSystems() ); - - for( sal_Int32 nCS = 0; !bFound && nCS < static_cast<sal_Int32>(aCooSysList.size()); ++nCS ) - { - const rtl::Reference< BaseCoordinateSystem > & xCooSys( aCooSysList[nCS] ); - - //iterate through all chart types in the current coordinate system - uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xCooSys->getChartTypes() ); - uno::Reference< XChartType > xFormerChartType; - - for( sal_Int32 nT = 0; !bFound && nT < aChartTypeList.getLength(); ++nT ) - { - uno::Reference< XChartType > xCurrentChartType( aChartTypeList[nT] ); - - //iterate through all series in this chart type - uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xCurrentChartType, uno::UNO_QUERY ); - OSL_ASSERT( xDataSeriesContainer.is()); - if( !xDataSeriesContainer.is() ) - continue; - - uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() ); - auto aSeriesListRange = asNonConstRange(aSeriesList); - - for( sal_Int32 nS = 0; !bFound && nS < aSeriesList.getLength(); ++nS ) - { - - // We found the series we are interested in! - if( xGivenDataSeries==aSeriesList[nS] ) - { - sal_Int32 nOldSeriesIndex = nS; - bFound = true; - - try - { - sal_Int32 nNewSeriesIndex = nS; - - // tdf#34517 Bringing forward means increasing, backwards means decreasing series position - if( !bForward ) - nNewSeriesIndex--; - else - nNewSeriesIndex++; - - if( nNewSeriesIndex >= 0 && nNewSeriesIndex < aSeriesList.getLength() ) - { - //move series in the same charttype - bMovedOrMoveAllowed = true; - if( bDoMove ) - { - aSeriesListRange[ nOldSeriesIndex ] = aSeriesList[ nNewSeriesIndex ]; - aSeriesListRange[ nNewSeriesIndex ] = xGivenDataSeries; - xDataSeriesContainer->setDataSeries( aSeriesList ); - } - } - else if( nNewSeriesIndex<0 ) - { - //exchange series with former charttype - if( xFormerChartType.is() && DiagramHelper::areChartTypesCompatible( xFormerChartType, xCurrentChartType ) ) - { - bMovedOrMoveAllowed = true; - if( bDoMove ) - { - uno::Reference< XDataSeriesContainer > xOtherDataSeriesContainer( xFormerChartType, uno::UNO_QUERY ); - if( xOtherDataSeriesContainer.is() ) - { - uno::Sequence< uno::Reference< XDataSeries > > aOtherSeriesList( xOtherDataSeriesContainer->getDataSeries() ); - sal_Int32 nOtherSeriesIndex = aOtherSeriesList.getLength()-1; - if( nOtherSeriesIndex >= 0 && nOtherSeriesIndex < aOtherSeriesList.getLength() ) - { - uno::Reference< XDataSeries > xExchangeSeries( aOtherSeriesList[nOtherSeriesIndex] ); - aOtherSeriesList.getArray()[nOtherSeriesIndex] = xGivenDataSeries; - xOtherDataSeriesContainer->setDataSeries(aOtherSeriesList); - - aSeriesListRange[nOldSeriesIndex]=xExchangeSeries; - xDataSeriesContainer->setDataSeries(aSeriesList); - } - } - } - } - } - else if( nT+1 < aChartTypeList.getLength() ) - { - //exchange series with next charttype - uno::Reference< XChartType > xOtherChartType( aChartTypeList[nT+1] ); - if( xOtherChartType.is() && DiagramHelper::areChartTypesCompatible( xOtherChartType, xCurrentChartType ) ) - { - bMovedOrMoveAllowed = true; - if( bDoMove ) - { - uno::Reference< XDataSeriesContainer > xOtherDataSeriesContainer( xOtherChartType, uno::UNO_QUERY ); - if( xOtherDataSeriesContainer.is() ) - { - uno::Sequence< uno::Reference< XDataSeries > > aOtherSeriesList( xOtherDataSeriesContainer->getDataSeries() ); - if( aOtherSeriesList.hasElements() ) - { - uno::Reference< XDataSeries > xExchangeSeries( aOtherSeriesList[0] ); - aOtherSeriesList.getArray()[0] = xGivenDataSeries; - xOtherDataSeriesContainer->setDataSeries(aOtherSeriesList); - - aSeriesListRange[nOldSeriesIndex]=xExchangeSeries; - xDataSeriesContainer->setDataSeries(aSeriesList); - } - } - } - } - } - } - catch( const util::CloseVetoException& ) - { - } - catch( const uno::RuntimeException& ) - { - } - } - } - xFormerChartType = xCurrentChartType; - } - } - } - } - catch( const util::CloseVetoException& ) - { - } - catch( const uno::RuntimeException& ) - { - } - return bMovedOrMoveAllowed; -} -} // anonymous namespace - -bool DiagramHelper::isSeriesMoveable( - const Reference< XDiagram >& xDiagram, - const Reference< XDataSeries >& xGivenDataSeries, - bool bForward ) -{ - const bool bDoMove = false; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(!xDiagram || pDiagram); - bool bIsMoveable = lcl_moveSeriesOrCheckIfMoveIsAllowed( - pDiagram, xGivenDataSeries, bForward, bDoMove ); - - return bIsMoveable; -} - -bool DiagramHelper::moveSeries( const Reference< XDiagram >& xDiagram, const Reference< XDataSeries >& xGivenDataSeries, bool bForward ) -{ - const bool bDoMove = true; - - Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get()); - assert(!xDiagram || pDiagram); - bool bMoved = lcl_moveSeriesOrCheckIfMoveIsAllowed( - pDiagram, xGivenDataSeries, bForward, bDoMove ); - - return bMoved; -} - -bool DiagramHelper::isSupportingFloorAndWall( const Reference< - chart2::XDiagram >& xDiagram ) -{ - //pies and donuts currently do not support this because of wrong files from older versions - //todo: allow this in future again, if fileversion is available for OLE objects (metastream) - //thus the wrong bottom can be removed on import - - const Sequence< Reference< chart2::XChartType > > aTypes( - ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) ); - for( Reference< chart2::XChartType > const & xType : aTypes ) - { - if( xType.is() && xType->getChartType().match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) ) - return false; - if( xType.is() && xType->getChartType().match(CHART2_SERVICE_NAME_CHARTTYPE_NET) ) - return false; - if( xType.is() && xType->getChartType().match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) ) - return false; - } - return true; -} - -bool DiagramHelper::isPieOrDonutChart( const css::uno::Reference< css::chart2::XDiagram >& xDiagram ) -{ - uno::Reference< chart2::XChartType > xChartType( DiagramHelper::getChartTypeByIndex( - xDiagram, 0 ) ); - - if( xChartType .is() ) - { - OUString aChartType = xChartType->getChartType(); - if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE ) - return true; - } - return false; -} - -sal_Int32 DiagramHelper::getGeometry3D( - const uno::Reference< chart2::XDiagram > & xDiagram, - bool& rbFound, bool& rbAmbiguous ) -{ - sal_Int32 nCommonGeom( DataPointGeometry3D::CUBOID ); - rbFound = false; - rbAmbiguous = false; - - std::vector< Reference< chart2::XDataSeries > > aSeriesVec( - DiagramHelper::getDataSeriesFromDiagram( xDiagram )); - - if( aSeriesVec.empty()) - rbAmbiguous = true; - - for (auto const& series : aSeriesVec) - { - try - { - sal_Int32 nGeom = 0; - Reference< beans::XPropertySet > xProp(series, uno::UNO_QUERY_THROW); - if( xProp->getPropertyValue( "Geometry3D") >>= nGeom ) - { - if( ! rbFound ) - { - // first series - nCommonGeom = nGeom; - rbFound = true; - } - // further series: compare for uniqueness - else if( nCommonGeom != nGeom ) - { - rbAmbiguous = true; - break; - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - } - - return nCommonGeom; -} - -void DiagramHelper::setGeometry3D( - const Reference< chart2::XDiagram > & xDiagram, - sal_Int32 nNewGeometry ) -{ - std::vector< Reference< chart2::XDataSeries > > aSeriesVec( - DiagramHelper::getDataSeriesFromDiagram( xDiagram )); - - for (auto const& series : aSeriesVec) - { - DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( - series, "Geometry3D", uno::Any( nNewGeometry )); - } -} - -sal_Int32 DiagramHelper::getCorrectedMissingValueTreatment( - const Reference< chart2::XDiagram > & xDiagram, - const Reference< chart2::XChartType >& xChartType ) -{ - sal_Int32 nResult = css::chart::MissingValueTreatment::LEAVE_GAP; - const uno::Sequence < sal_Int32 > aAvailableMissingValueTreatments( - ChartTypeHelper::getSupportedMissingValueTreatments( xChartType ) ); - - uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY ); - if( xDiaProp.is() && (xDiaProp->getPropertyValue( "MissingValueTreatment" ) >>= nResult) ) - { - //ensure that the set value is supported by this charttype - for( sal_Int32 n : aAvailableMissingValueTreatments ) - if( n == nResult ) - return nResult; //ok - } - - //otherwise use the first supported one - if( aAvailableMissingValueTreatments.hasElements() ) - { - nResult = aAvailableMissingValueTreatments[0]; - return nResult; - } - - return nResult; -} - -DiagramPositioningMode DiagramHelper::getDiagramPositioningMode( const uno::Reference< - chart2::XDiagram > & xDiagram ) -{ - DiagramPositioningMode eMode = DiagramPositioningMode_AUTO; - uno::Reference< beans::XPropertySet > xDiaProps( xDiagram, uno::UNO_QUERY ); - if( xDiaProps.is() ) - { - RelativePosition aRelPos; - RelativeSize aRelSize; - if( (xDiaProps->getPropertyValue("RelativePosition") >>= aRelPos ) && - (xDiaProps->getPropertyValue("RelativeSize") >>= aRelSize ) ) - { - bool bPosSizeExcludeAxes=false; - xDiaProps->getPropertyValue("PosSizeExcludeAxes") >>= bPosSizeExcludeAxes; - if( bPosSizeExcludeAxes ) - eMode = DiagramPositioningMode_EXCLUDING; - else - eMode = DiagramPositioningMode_INCLUDING; - } - } - return eMode; -} - static void lcl_ensureRange0to1( double& rValue ) { if(rValue<0.0) @@ -1546,14 +439,14 @@ static void lcl_ensureRange0to1( double& rValue ) rValue=1.0; } -bool DiagramHelper::setDiagramPositioning( const uno::Reference< frame::XModel >& xChartModel, +bool DiagramHelper::setDiagramPositioning( const rtl::Reference<::chart::ChartModel>& xChartModel, const awt::Rectangle& rPosRect /*100th mm*/ ) { ControllerLockGuardUNO aCtrlLockGuard( xChartModel ); bool bChanged = false; awt::Size aPageSize( ChartModelHelper::getPageSize(xChartModel) ); - rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( xChartModel ); + rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram(); if( !xDiagram.is() ) return bChanged; @@ -1591,11 +484,11 @@ bool DiagramHelper::setDiagramPositioning( const uno::Reference< frame::XModel > return bChanged; } -awt::Rectangle DiagramHelper::getDiagramRectangleFromModel( const uno::Reference< frame::XModel >& xChartModel ) +awt::Rectangle DiagramHelper::getDiagramRectangleFromModel( const rtl::Reference<::chart::ChartModel>& xChartModel ) { awt::Rectangle aRet(-1,-1,-1,-1); - rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( xChartModel ); + rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram(); if( !xDiagram.is() ) return aRet; |