diff options
Diffstat (limited to 'chart2/source/tools/ObjectIdentifier.cxx')
-rw-r--r-- | chart2/source/tools/ObjectIdentifier.cxx | 843 |
1 files changed, 369 insertions, 474 deletions
diff --git a/chart2/source/tools/ObjectIdentifier.cxx b/chart2/source/tools/ObjectIdentifier.cxx index b5faa312d46b..d5b2f068c8a0 100644 --- a/chart2/source/tools/ObjectIdentifier.cxx +++ b/chart2/source/tools/ObjectIdentifier.cxx @@ -19,28 +19,31 @@ #include <sal/config.h> +#include <cstddef> #include <map> #include <ObjectIdentifier.hxx> #include <TitleHelper.hxx> #include <ChartModel.hxx> -#include <ChartModelHelper.hxx> +#include <ChartType.hxx> +#include <Axis.hxx> #include <AxisHelper.hxx> #include <servicenames_charttypes.hxx> -#include <DiagramHelper.hxx> +#include <Diagram.hxx> #include <unonames.hxx> +#include <BaseCoordinateSystem.hxx> +#include <DataSeries.hxx> +#include <RegressionCurveModel.hxx> -#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> -#include <com/sun/star/chart2/XChartDocument.hpp> -#include <com/sun/star/chart2/XChartTypeContainer.hpp> -#include <com/sun/star/chart2/XDataSeriesContainer.hpp> #include <com/sun/star/chart2/XAxis.hpp> -#include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/awt/Point.hpp> #include <com/sun/star/drawing/XShape.hpp> #include <rtl/ustrbuf.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> +#include <o3tl/safeint.hxx> +#include <o3tl/string_view.hxx> +#include <utility> namespace com::sun::star::drawing { class XShape; } @@ -52,18 +55,18 @@ using namespace ::com::sun::star::chart2; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Any; -const char m_aMultiClick[] = "MultiClick"; -const char m_aDragMethodEquals[] = "DragMethod="; -const char m_aDragParameterEquals[] = "DragParameter="; -const char m_aProtocol[] = "CID/"; -const OUString m_aPieSegmentDragMethodServiceName("PieSegmentDragging"); +constexpr OUString m_aMultiClick = u"MultiClick"_ustr; +constexpr OUString m_aDragMethodEquals = u"DragMethod="_ustr; +constexpr OUString m_aDragParameterEquals = u"DragParameter="_ustr; +constexpr OUString m_aProtocol = u"CID/"_ustr; +constexpr OUString m_aPieSegmentDragMethodServiceName(u"PieSegmentDragging"_ustr); namespace { OUString lcl_createClassificationStringForType( ObjectType eObjectType - , const OUString& rDragMethodServiceName - , const OUString& rDragParameterString + , std::u16string_view rDragMethodServiceName + , std::u16string_view rDragParameterString ) { OUStringBuffer aRet; @@ -81,19 +84,17 @@ OUString lcl_createClassificationStringForType( ObjectType eObjectType default: break;//empty string } - if( !rDragMethodServiceName.isEmpty() ) + if( !rDragMethodServiceName.empty() ) { if( !aRet.isEmpty() ) aRet.append(":"); - aRet.append( m_aDragMethodEquals ); - aRet.append( rDragMethodServiceName ); + aRet.append( OUString::Concat(m_aDragMethodEquals) + rDragMethodServiceName ); - if( !rDragParameterString.isEmpty() ) + if( !rDragParameterString.empty() ) { if( !aRet.isEmpty() ) aRet.append(":"); - aRet.append( m_aDragParameterEquals ); - aRet.append( rDragParameterString ); + aRet.append( OUString::Concat(m_aDragParameterEquals) + rDragParameterString ); } } return aRet.makeStringAndClear(); @@ -126,30 +127,20 @@ OUString lcl_getTitleParentParticle( TitleHelper::eTitleType aTitleType ) return aRet; } -Reference<XChartType> lcl_getFirstStockChartType( const Reference< frame::XModel >& xChartModel ) +rtl::Reference<ChartType> lcl_getFirstStockChartType( const rtl::Reference<::chart::ChartModel>& xChartModel ) { - Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); + rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() ); 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() ); - for( Reference< XCoordinateSystem > const & coords : aCooSysList ) + const std::vector< rtl::Reference< BaseCoordinateSystem > > & aCooSysList( xDiagram->getBaseCoordinateSystems() ); + for( rtl::Reference< BaseCoordinateSystem > const & coords : aCooSysList ) { //iterate through all chart types in the current coordinate system - Reference< XChartTypeContainer > xChartTypeContainer( coords, uno::UNO_QUERY ); - if( !xChartTypeContainer.is() ) - continue; - - const uno::Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() ); - for( Reference< XChartType > const & xChartType : aChartTypeList ) + for( rtl::Reference< ChartType > const & xChartType : coords->getChartTypes2() ) { - if(!xChartType.is()) - continue; OUString aChartType = xChartType->getChartType(); if( aChartType.equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) ) return xChartType; @@ -158,107 +149,95 @@ Reference<XChartType> lcl_getFirstStockChartType( const Reference< frame::XModel return nullptr; } -OUString lcl_getIndexStringAfterString( const OUString& rString, const OUString& rSearchString ) +std::u16string_view lcl_getIndexStringAfterString( std::u16string_view rString, std::u16string_view rSearchString ) { - OUStringBuffer aRet; - - sal_Int32 nIndexStart = rString.lastIndexOf( rSearchString ); - if( nIndexStart != -1 ) - { - nIndexStart += rSearchString.getLength(); - sal_Int32 nIndexEnd = rString.getLength(); - sal_Int32 nNextColon = rString.indexOf( ':', nIndexStart ); - if( nNextColon != -1 ) - nIndexEnd = nNextColon; - aRet = rString.copy(nIndexStart,nIndexEnd-nIndexStart); - } - - return aRet.makeStringAndClear(); + size_t nIndexStart = rString.rfind( rSearchString ); + if( nIndexStart == std::u16string_view::npos ) + return std::u16string_view(); + nIndexStart += rSearchString.size(); + size_t nIndexEnd = rString.size(); + size_t nNextColon = rString.find( ':', nIndexStart ); + if( nNextColon != std::u16string_view::npos ) + nIndexEnd = nNextColon; + return rString.substr(nIndexStart,nIndexEnd-nIndexStart); } -sal_Int32 lcl_StringToIndex( const OUString& rIndexString ) +sal_Int32 lcl_StringToIndex( std::u16string_view rIndexString ) { sal_Int32 nRet = -1; - if( !rIndexString.isEmpty() ) + if( !rIndexString.empty() ) { - nRet = rIndexString.toInt32(); + nRet = o3tl::toInt32(rIndexString); if( nRet < -1 ) nRet = -1; } return nRet; } -void lcl_parseCooSysIndices( sal_Int32& rnDiagram, sal_Int32& rnCooSys, const OUString& rString ) +void lcl_parseCooSysIndices( sal_Int32& rnDiagram, sal_Int32& rnCooSys, std::u16string_view rString ) { - rnDiagram = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, "D=" ) ); - rnCooSys = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, "CS=" ) ); + rnDiagram = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, u"D=" ) ); + rnCooSys = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, u"CS=" ) ); } -void lcl_parseAxisIndices( sal_Int32& rnDimensionIndex, sal_Int32& rnAxisIndex, const OUString& rString ) +void lcl_parseAxisIndices( sal_Int32& rnDimensionIndex, sal_Int32& rnAxisIndex, std::u16string_view rString ) { - OUString aAxisIndexString = lcl_getIndexStringAfterString( rString, ":Axis=" ); + std::u16string_view aAxisIndexString = lcl_getIndexStringAfterString( rString, u":Axis=" ); sal_Int32 nCharacterIndex=0; - rnDimensionIndex = lcl_StringToIndex( aAxisIndexString.getToken( 0, ',', nCharacterIndex ) ); - rnAxisIndex = lcl_StringToIndex( aAxisIndexString.getToken( 0, ',', nCharacterIndex ) ); + rnDimensionIndex = lcl_StringToIndex( o3tl::getToken(aAxisIndexString, 0, ',', nCharacterIndex ) ); + rnAxisIndex = lcl_StringToIndex( o3tl::getToken(aAxisIndexString, 0, ',', nCharacterIndex ) ); } -void lcl_parseGridIndices( sal_Int32& rnSubGridIndex, const OUString& rString ) +void lcl_parseGridIndices( sal_Int32& rnSubGridIndex, std::u16string_view rString ) { rnSubGridIndex = -1; - rnSubGridIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, ":SubGrid=" ) ); + rnSubGridIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, u":SubGrid=" ) ); } -void lcl_parseSeriesIndices( sal_Int32& rnChartTypeIndex, sal_Int32& rnSeriesIndex, sal_Int32& rnPointIndex, const OUString& rString ) +void lcl_parseSeriesIndices( sal_Int32& rnChartTypeIndex, sal_Int32& rnSeriesIndex, sal_Int32& rnPointIndex, std::u16string_view rString ) { - rnChartTypeIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, "CT=" ) ); - rnSeriesIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, "Series=" ) ); - rnPointIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, "Point=" ) ); + rnChartTypeIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, u"CT=" ) ); + rnSeriesIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, u"Series=" ) ); + rnPointIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rString, u"Point=" ) ); } -void lcl_getDiagramAndCooSys( const OUString& rObjectCID - , const Reference< frame::XModel >& xChartModel - , Reference< XDiagram >& xDiagram - , Reference< XCoordinateSystem >& xCooSys ) +void lcl_getDiagramAndCooSys( std::u16string_view rObjectCID + , const rtl::Reference<::chart::ChartModel>& xChartModel + , rtl::Reference< Diagram >& xDiagram + , rtl::Reference< BaseCoordinateSystem >& xCooSys ) { sal_Int32 nDiagramIndex = -1; sal_Int32 nCooSysIndex = -1; lcl_parseCooSysIndices( nDiagramIndex, nCooSysIndex, rObjectCID ); - xDiagram = ChartModelHelper::findDiagram( xChartModel );//todo use nDiagramIndex when more than one diagram is possible in future + xDiagram = xChartModel->getFirstChartDiagram();//todo use nDiagramIndex when more than one diagram is possible in future if( !xDiagram.is() ) return; 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]; - } + const std::vector< rtl::Reference< BaseCoordinateSystem > > aCooSysList( xDiagram->getBaseCoordinateSystems() ); + if( o3tl::make_unsigned(nCooSysIndex) < aCooSysList.size() ) + xCooSys = aCooSysList[nCooSysIndex]; } } } //anonymous namespace ObjectIdentifier::ObjectIdentifier() - :m_aObjectCID( OUString() ) { } -ObjectIdentifier::ObjectIdentifier( const OUString& rObjectCID ) - :m_aObjectCID( rObjectCID ) +ObjectIdentifier::ObjectIdentifier( OUString aObjectCID ) + :m_aObjectCID(std::move( aObjectCID )) { } ObjectIdentifier::ObjectIdentifier( const Reference< drawing::XShape >& rxShape ) - :m_aObjectCID( OUString() ) - ,m_xAdditionalShape( rxShape ) + : m_xAdditionalShape( rxShape ) { } ObjectIdentifier::ObjectIdentifier( const Any& rAny ) - :m_aObjectCID( OUString() ) { const uno::Type& rType = rAny.getValueType(); if ( rType == cppu::UnoType<OUString>::get() ) @@ -277,11 +256,6 @@ bool ObjectIdentifier::operator==( const ObjectIdentifier& rOID ) const ( m_xAdditionalShape == rOID.m_xAdditionalShape ); } -bool ObjectIdentifier::operator!=( const ObjectIdentifier& rOID ) const -{ - return !operator==( rOID ); -} - bool ObjectIdentifier::operator<( const ObjectIdentifier& rOID ) const { bool bReturn = false; @@ -305,41 +279,55 @@ bool ObjectIdentifier::operator<( const ObjectIdentifier& rOID ) const } OUString ObjectIdentifier::createClassifiedIdentifierForObject( + const rtl::Reference< ::chart::Title >& xTitle + , const rtl::Reference<::chart::ChartModel>& xChartModel ) +{ + TitleHelper::eTitleType aTitleType; + OUString aRet; + const std::u16string_view aObjectID; + const std::u16string_view aDragMethodServiceName; + const std::u16string_view aDragParameterString; + if( TitleHelper::getTitleType( aTitleType, xTitle, xChartModel ) ) + { + enum ObjectType eObjectType = OBJECTTYPE_TITLE; + OUString aParentParticle = lcl_getTitleParentParticle( aTitleType ); + aRet = ObjectIdentifier::createClassifiedIdentifierWithParent( + eObjectType, aObjectID, aParentParticle, aDragMethodServiceName, aDragParameterString ); + } + return aRet; +} + +OUString ObjectIdentifier::createClassifiedIdentifierForObject( const Reference< uno::XInterface >& xObject - , ChartModel& rModel) + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { OUString aRet; enum ObjectType eObjectType = OBJECTTYPE_UNKNOWN; - const OUString aObjectID; + const std::u16string_view aObjectID; OUString aParentParticle; - const OUString aDragMethodServiceName; - const OUString aDragParameterString; + const std::u16string_view aDragMethodServiceName; + const std::u16string_view aDragParameterString; try { //title - Reference< XTitle > xTitle( xObject, uno::UNO_QUERY ); - if( xTitle.is() ) - { - TitleHelper::eTitleType aTitleType; - if( TitleHelper::getTitleType( aTitleType, xTitle, rModel ) ) - { - eObjectType = OBJECTTYPE_TITLE; - aParentParticle = lcl_getTitleParentParticle( aTitleType ); - aRet = ObjectIdentifier::createClassifiedIdentifierWithParent( - eObjectType, aObjectID, aParentParticle, aDragMethodServiceName, aDragParameterString ); - } - return aRet; + if( ::chart::Title* pTitle = dynamic_cast<::chart::Title*>(xObject.get()) ) + return createClassifiedIdentifierForObject(rtl::Reference<Title>(pTitle), xChartModel); + uno::Reference<chart2::XDataTable> xDataTable(xObject, uno::UNO_QUERY); + if (xDataTable.is()) + { + return createClassifiedIdentifierForParticle(createParticleForDataTable(xChartModel)); } //axis - Reference< XAxis > xAxis( xObject, uno::UNO_QUERY ); + rtl::Reference< Axis > xAxis = dynamic_cast<Axis*>( xObject.get() ); if( xAxis.is() ) { - Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis( xAxis, rModel.getFirstDiagram() ) ); - OUString aCooSysParticle( createParticleForCoordinateSystem( xCooSys, rModel ) ); + rtl::Reference<Diagram> xDiagram = xChartModel->getFirstChartDiagram(); + rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis( xAxis, xDiagram ) ); + OUString aCooSysParticle( createParticleForCoordinateSystem( xCooSys, xChartModel ) ); sal_Int32 nDimensionIndex=-1; sal_Int32 nAxisIndex=-1; AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ); @@ -351,7 +339,7 @@ OUString ObjectIdentifier::createClassifiedIdentifierForObject( Reference< XLegend > xLegend( xObject, uno::UNO_QUERY ); if( xLegend.is() ) { - return createClassifiedIdentifierForParticle( createParticleForLegend( rModel ) ); + return createClassifiedIdentifierForParticle( createParticleForLegend( xChartModel ) ); } //diagram @@ -387,40 +375,37 @@ OUString ObjectIdentifier::createClassifiedIdentifierForObject( } OUString ObjectIdentifier::createClassifiedIdentifierForObject( - const Reference< uno::XInterface >& xObject - , const Reference< frame::XModel >& xChartModel ) + const rtl::Reference< Legend >& xLegend + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { - OUString aRet; - - enum ObjectType eObjectType = OBJECTTYPE_UNKNOWN; - const OUString aObjectID; - OUString aParentParticle; - const OUString aDragMethodServiceName; - const OUString aDragParameterString; - try { - //title - Reference< XTitle > xTitle( xObject, uno::UNO_QUERY ); - if( xTitle.is() ) + if( xLegend.is() ) { - TitleHelper::eTitleType aTitleType; - if( TitleHelper::getTitleType( aTitleType, xTitle, xChartModel ) ) - { - eObjectType = OBJECTTYPE_TITLE; - aParentParticle = lcl_getTitleParentParticle( aTitleType ); - aRet = ObjectIdentifier::createClassifiedIdentifierWithParent( - eObjectType, aObjectID, aParentParticle, aDragMethodServiceName, aDragParameterString ); - } - return aRet; - + return createClassifiedIdentifierForParticle( createParticleForLegend( xChartModel ) ); } + } + catch(const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } + + OSL_FAIL("give object could not be identified in createClassifiedIdentifierForObject"); + return OUString(); +} + +OUString ObjectIdentifier::createClassifiedIdentifierForObject( + const rtl::Reference<::chart::Axis>& xAxis + , const rtl::Reference<::chart::ChartModel>& xChartModel ) +{ + try + { //axis - Reference< XAxis > xAxis( xObject, uno::UNO_QUERY ); if( xAxis.is() ) { - Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ) ) ); + rtl::Reference<Diagram> xDiagram = xChartModel->getFirstChartDiagram(); + rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis( xAxis, xDiagram ) ); OUString aCooSysParticle( createParticleForCoordinateSystem( xCooSys, xChartModel ) ); sal_Int32 nDimensionIndex=-1; sal_Int32 nAxisIndex=-1; @@ -428,71 +413,42 @@ OUString ObjectIdentifier::createClassifiedIdentifierForObject( OUString aAxisParticle( createParticleForAxis( nDimensionIndex, nAxisIndex ) ); return createClassifiedIdentifierForParticles( aCooSysParticle, aAxisParticle ); } - - //legend - Reference< XLegend > xLegend( xObject, uno::UNO_QUERY ); - if( xLegend.is() ) - { - return createClassifiedIdentifierForParticle( createParticleForLegend( xChartModel ) ); - } - - //diagram - Reference< XDiagram > xDiagram( xObject, uno::UNO_QUERY ); - if( xDiagram.is() ) - { - return createClassifiedIdentifierForParticle( createParticleForDiagram() ); - } - - //todo - //XDataSeries - //CooSys - //charttype - //datapoint? - //Gridproperties } catch(const uno::Exception&) { DBG_UNHANDLED_EXCEPTION("chart2"); } - if( eObjectType != OBJECTTYPE_UNKNOWN ) - { - aRet = ObjectIdentifier::createClassifiedIdentifierWithParent( - eObjectType, aObjectID, aParentParticle, aDragMethodServiceName, aDragParameterString ); - } - else - { - OSL_FAIL("give object could not be identified in createClassifiedIdentifierForObject"); - } + OSL_FAIL("give object could not be identified in createClassifiedIdentifierForObject"); - return aRet; + return OUString(); } OUString ObjectIdentifier::createClassifiedIdentifierForParticle( - const OUString& rParticle ) + std::u16string_view rParticle ) { - return ObjectIdentifier::createClassifiedIdentifierForParticles( rParticle, OUString() ); + return ObjectIdentifier::createClassifiedIdentifierForParticles( rParticle, u"" ); } OUString ObjectIdentifier::createClassifiedIdentifierForParticles( - const OUString& rParentParticle - , const OUString& rChildParticle - , const OUString& rDragMethodServiceName - , const OUString& rDragParameterString ) + std::u16string_view rParentParticle + , std::u16string_view rChildParticle + , std::u16string_view rDragMethodServiceName + , std::u16string_view rDragParameterString ) { ObjectType eObjectType( ObjectIdentifier::getObjectType( rChildParticle ) ); if( eObjectType == OBJECTTYPE_UNKNOWN ) eObjectType = ObjectIdentifier::getObjectType( rParentParticle ); - OUStringBuffer aRet( m_aProtocol ); - aRet.append( lcl_createClassificationStringForType( eObjectType, rDragMethodServiceName, rDragParameterString )); - if(aRet.getLength() > static_cast<sal_Int32>(strlen(m_aProtocol))) + OUStringBuffer aRet( m_aProtocol + + lcl_createClassificationStringForType( eObjectType, rDragMethodServiceName, rDragParameterString )); + if(aRet.getLength() > m_aProtocol.getLength()) aRet.append("/"); - if(!rParentParticle.isEmpty()) + if(!rParentParticle.empty()) { aRet.append(rParentParticle); - if( !rChildParticle.isEmpty() ) + if( !rChildParticle.empty() ) aRet.append(":"); } aRet.append(rChildParticle); @@ -507,59 +463,27 @@ OUString ObjectIdentifier::createParticleForDiagram() } OUString ObjectIdentifier::createParticleForCoordinateSystem( - const Reference< XCoordinateSystem >& xCooSys - , ChartModel& rModel ) -{ - OUStringBuffer aRet; - - Reference< XDiagram > xDiagram( rModel.getFirstDiagram() ); - Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( xCooSysContainer.is() ) - { - sal_Int32 nCooSysIndex = 0; - uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); - for( ; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex ) - { - Reference< XCoordinateSystem > xCurrentCooSys( aCooSysList[nCooSysIndex] ); - if( xCooSys == xCurrentCooSys ) - { - aRet = ObjectIdentifier::createParticleForDiagram(); - aRet.append(":CS="); - aRet.append( OUString::number( nCooSysIndex ) ); - break; - } - } - } - - return aRet.makeStringAndClear(); -} - -OUString ObjectIdentifier::createParticleForCoordinateSystem( - const Reference< XCoordinateSystem >& xCooSys - , const Reference< frame::XModel >& xChartModel ) + const rtl::Reference< BaseCoordinateSystem >& xCooSys + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { - OUStringBuffer aRet; + OUString aRet; - Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); - Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); - if( xCooSysContainer.is() ) + rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() ); + if( xDiagram.is() ) { - sal_Int32 nCooSysIndex = 0; - uno::Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); - for( ; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex ) + std::size_t nCooSysIndex = 0; + const std::vector< rtl::Reference< BaseCoordinateSystem > > & aCooSysList( xDiagram->getBaseCoordinateSystems() ); + for( ; nCooSysIndex < aCooSysList.size(); ++nCooSysIndex ) { - Reference< XCoordinateSystem > xCurrentCooSys( aCooSysList[nCooSysIndex] ); - if( xCooSys == xCurrentCooSys ) + if( xCooSys == aCooSysList[nCooSysIndex] ) { - aRet = ObjectIdentifier::createParticleForDiagram(); - aRet.append(":CS="); - aRet.append( OUString::number( nCooSysIndex ) ); + aRet = ObjectIdentifier::createParticleForDiagram() + ":CS=" + OUString::number( nCooSysIndex ); break; } } } - return aRet.makeStringAndClear(); + return aRet; } OUString ObjectIdentifier::createParticleForAxis( @@ -584,7 +508,7 @@ OUString ObjectIdentifier::createParticleForGrid( OUString ObjectIdentifier::createClassifiedIdentifierForGrid( const Reference< XAxis >& xAxis - , const Reference< frame::XModel >& xChartModel + , const rtl::Reference<::chart::ChartModel>& xChartModel , sal_Int32 nSubGridIndex ) { //-1: main grid, 0: first subgrid etc @@ -604,81 +528,56 @@ OUString ObjectIdentifier::createParticleForSeries( sal_Int32 nDiagramIndex, sal_Int32 nCooSysIndex , sal_Int32 nChartTypeIndex, sal_Int32 nSeriesIndex ) { - OUStringBuffer aRet; - - aRet.append("D="); - aRet.append( OUString::number( nDiagramIndex ) ); - aRet.append(":CS="); - aRet.append( OUString::number( nCooSysIndex ) ); - aRet.append(":CT="); - aRet.append( OUString::number( nChartTypeIndex ) ); - aRet.append(":"); - aRet.append(getStringForType( OBJECTTYPE_DATA_SERIES )); - aRet.append("="); - aRet.append( OUString::number( nSeriesIndex ) ); - - return aRet.makeStringAndClear(); + return + "D=" + OUString::number( nDiagramIndex ) + + ":CS=" + OUString::number( nCooSysIndex ) + + ":CT=" + OUString::number( nChartTypeIndex ) + + ":" + getStringForType( OBJECTTYPE_DATA_SERIES ) + "=" + + OUString::number( nSeriesIndex ); } -OUString ObjectIdentifier::createParticleForLegend( ChartModel& ) -{ - OUStringBuffer aRet; - - //todo: if more than one diagram is implemented, find the correct diagram which is owner of the given legend - - aRet.append( ObjectIdentifier::createParticleForDiagram() ); - aRet.append(":"); - aRet.append(getStringForType( OBJECTTYPE_LEGEND )); - aRet.append("="); - - return aRet.makeStringAndClear(); -} OUString ObjectIdentifier::createParticleForLegend( - const Reference< frame::XModel >& ) + const rtl::Reference<::chart::ChartModel>& ) { - OUStringBuffer aRet; - //todo: if more than one diagram is implemented, find the correct diagram which is owner of the given legend - aRet.append( ObjectIdentifier::createParticleForDiagram() ); - aRet.append(":"); - aRet.append(getStringForType( OBJECTTYPE_LEGEND )); - aRet.append("="); + return ObjectIdentifier::createParticleForDiagram() + ":" + getStringForType( OBJECTTYPE_LEGEND ) + "="; +} - return aRet.makeStringAndClear(); +OUString ObjectIdentifier::createParticleForDataTable(const rtl::Reference<::chart::ChartModel>& /* xChartModel */) +{ + return ObjectIdentifier::createParticleForDiagram() + ":" + getStringForType(OBJECTTYPE_DATA_TABLE) + "="; } OUString ObjectIdentifier::createClassifiedIdentifier( enum ObjectType eObjectType //e.g. OBJECTTYPE_DATA_SERIES - , const OUString& rParticleID )//e.g. SeriesID + , std::u16string_view rParticleID )//e.g. SeriesID { return createClassifiedIdentifierWithParent( - eObjectType, rParticleID, OUString() ); + eObjectType, rParticleID, u"" ); } OUString ObjectIdentifier::createClassifiedIdentifierWithParent( enum ObjectType eObjectType //e.g. OBJECTTYPE_DATA_POINT or OBJECTTYPE_GRID - , const OUString& rParticleID //e.g. Point Index or SubGrid Index - , const OUString& rParentPartical //e.g. "Series=SeriesID" or "Grid=GridId" - , const OUString& rDragMethodServiceName - , const OUString& rDragParameterString + , std::u16string_view rParticleID //e.g. Point Index or SubGrid Index + , std::u16string_view rParentPartical //e.g. "Series=SeriesID" or "Grid=GridId" + , std::u16string_view rDragMethodServiceName + , std::u16string_view rDragParameterString ) //, bool bIsMultiClickObject ) //e.g. true { //e.g. "MultiClick/Series=2:Point=34" - OUStringBuffer aRet( m_aProtocol ); - aRet.append( lcl_createClassificationStringForType( eObjectType, rDragMethodServiceName, rDragParameterString )); - if(aRet.getLength() > static_cast<sal_Int32>(strlen(m_aProtocol))) + OUStringBuffer aRet( m_aProtocol + + lcl_createClassificationStringForType( eObjectType, rDragMethodServiceName, rDragParameterString )); + if(aRet.getLength() > m_aProtocol.getLength()) aRet.append("/"); aRet.append(rParentPartical); - if(!rParentPartical.isEmpty()) + if(!rParentPartical.empty()) aRet.append(":"); - aRet.append(getStringForType( eObjectType )); - aRet.append("="); - aRet.append(rParticleID); + aRet.append(getStringForType( eObjectType ) + "=" + rParticleID); return aRet.makeStringAndClear(); } @@ -702,89 +601,89 @@ OUString ObjectIdentifier::createPieSegmentDragParameterString( } bool ObjectIdentifier::parsePieSegmentDragParameterString( - const OUString& rDragParameterString + std::u16string_view rDragParameterString , sal_Int32& rOffsetPercent , awt::Point& rMinimumPosition , awt::Point& rMaximumPosition ) { sal_Int32 nCharacterIndex = 0; - OUString aValueString( rDragParameterString.getToken( 0, ',', nCharacterIndex ) ); - rOffsetPercent = aValueString.toInt32(); + std::u16string_view aValueString( o3tl::getToken(rDragParameterString, 0, ',', nCharacterIndex ) ); + rOffsetPercent = o3tl::toInt32(aValueString); if( nCharacterIndex < 0 ) return false; - aValueString = rDragParameterString.getToken( 0, ',', nCharacterIndex ); - rMinimumPosition.X = aValueString.toInt32(); + aValueString = o3tl::getToken(rDragParameterString, 0, ',', nCharacterIndex ); + rMinimumPosition.X = o3tl::toInt32(aValueString); if( nCharacterIndex < 0 ) return false; - aValueString = rDragParameterString.getToken( 0, ',', nCharacterIndex ); - rMinimumPosition.Y = aValueString.toInt32(); + aValueString = o3tl::getToken(rDragParameterString, 0, ',', nCharacterIndex ); + rMinimumPosition.Y = o3tl::toInt32(aValueString); if( nCharacterIndex < 0 ) return false; - aValueString = rDragParameterString.getToken( 0, ',', nCharacterIndex ); - rMaximumPosition.X = aValueString.toInt32(); + aValueString = o3tl::getToken(rDragParameterString, 0, ',', nCharacterIndex ); + rMaximumPosition.X = o3tl::toInt32(aValueString); if( nCharacterIndex < 0 ) return false; - aValueString = rDragParameterString.getToken( 0, ',', nCharacterIndex ); - rMaximumPosition.Y = aValueString.toInt32(); + aValueString = o3tl::getToken(rDragParameterString, 0, ',', nCharacterIndex ); + rMaximumPosition.Y = o3tl::toInt32(aValueString); return nCharacterIndex >= 0; } -OUString ObjectIdentifier::getDragMethodServiceName( const OUString& rCID ) +std::u16string_view ObjectIdentifier::getDragMethodServiceName( std::u16string_view rCID ) { - OUString aRet; + std::u16string_view aRet; - sal_Int32 nIndexStart = rCID.indexOf( m_aDragMethodEquals ); - if( nIndexStart != -1 ) + size_t nIndexStart = rCID.find( m_aDragMethodEquals ); + if( nIndexStart != std::u16string_view::npos ) { - nIndexStart = rCID.indexOf( '=', nIndexStart ); - if( nIndexStart != -1 ) + nIndexStart = rCID.find( '=', nIndexStart ); + if( nIndexStart != std::u16string_view::npos ) { nIndexStart++; - sal_Int32 nNextSlash = rCID.indexOf( '/', nIndexStart ); - if( nNextSlash != -1 ) + size_t nNextSlash = rCID.find( '/', nIndexStart ); + if( nNextSlash != std::u16string_view::npos ) { sal_Int32 nIndexEnd = nNextSlash; - sal_Int32 nNextColon = rCID.indexOf( ':', nIndexStart ); - if( nNextColon < nNextSlash ) + size_t nNextColon = rCID.find( ':', nIndexStart ); + if( nNextColon == std::u16string_view::npos || nNextColon < nNextSlash ) nIndexEnd = nNextColon; - aRet = rCID.copy(nIndexStart,nIndexEnd-nIndexStart); + aRet = rCID.substr(nIndexStart,nIndexEnd-nIndexStart); } } } return aRet; } -OUString ObjectIdentifier::getDragParameterString( const OUString& rCID ) +std::u16string_view ObjectIdentifier::getDragParameterString( std::u16string_view rCID ) { - OUString aRet; + std::u16string_view aRet; - sal_Int32 nIndexStart = rCID.indexOf( m_aDragParameterEquals ); - if( nIndexStart != -1 ) + size_t nIndexStart = rCID.find( m_aDragParameterEquals ); + if( nIndexStart != std::u16string_view::npos ) { - nIndexStart = rCID.indexOf( '=', nIndexStart ); - if( nIndexStart != -1 ) + nIndexStart = rCID.find( '=', nIndexStart ); + if( nIndexStart != std::u16string_view::npos ) { nIndexStart++; - sal_Int32 nNextSlash = rCID.indexOf( '/', nIndexStart ); - if( nNextSlash != -1 ) + size_t nNextSlash = rCID.find( '/', nIndexStart ); + if( nNextSlash != std::u16string_view::npos ) { sal_Int32 nIndexEnd = nNextSlash; - sal_Int32 nNextColon = rCID.indexOf( ':', nIndexStart ); - if( nNextColon < nNextSlash ) + size_t nNextColon = rCID.find( ':', nIndexStart ); + if( nNextColon == std::u16string_view::npos || nNextColon < nNextSlash ) nIndexEnd = nNextColon; - aRet = rCID.copy(nIndexStart,nIndexEnd-nIndexStart); + aRet = rCID.substr(nIndexStart,nIndexEnd-nIndexStart); } } } return aRet; } -bool ObjectIdentifier::isDragableObject( const OUString& rClassifiedIdentifier ) +bool ObjectIdentifier::isDragableObject( std::u16string_view rClassifiedIdentifier ) { bool bReturn = false; ObjectType eObjectType = ObjectIdentifier::getObjectType( rClassifiedIdentifier ); @@ -799,8 +698,8 @@ bool ObjectIdentifier::isDragableObject( const OUString& rClassifiedIdentifier ) bReturn = true; break; default: - OUString aDragMethodServiceName( ObjectIdentifier::getDragMethodServiceName( rClassifiedIdentifier ) ); - bReturn = !aDragMethodServiceName.isEmpty(); + std::u16string_view aDragMethodServiceName( ObjectIdentifier::getDragMethodServiceName( rClassifiedIdentifier ) ); + bReturn = !aDragMethodServiceName.empty(); break; } return bReturn; @@ -820,7 +719,7 @@ bool ObjectIdentifier::isDragableObject() const return bReturn; } -bool ObjectIdentifier::isRotateableObject( const OUString& rClassifiedIdentifier ) +bool ObjectIdentifier::isRotateableObject( std::u16string_view rClassifiedIdentifier ) { bool bReturn = false; ObjectType eObjectType = ObjectIdentifier::getObjectType( rClassifiedIdentifier ); @@ -837,7 +736,7 @@ bool ObjectIdentifier::isRotateableObject( const OUString& rClassifiedIdentifier return bReturn; } -bool ObjectIdentifier::isMultiClickObject( const OUString& rClassifiedIdentifier ) +bool ObjectIdentifier::isMultiClickObject( std::u16string_view rClassifiedIdentifier ) { //the name of a shape is it's ClassifiedIdentifier @@ -846,27 +745,27 @@ bool ObjectIdentifier::isMultiClickObject( const OUString& rClassifiedIdentifier //was selected before; //!!!!! by definition the name of a MultiClickObject starts with "CID/MultiClick:" - bool bRet = rClassifiedIdentifier.match( m_aMultiClick, strlen(m_aProtocol) ); + bool bRet = o3tl::starts_with(rClassifiedIdentifier.substr( m_aProtocol.getLength() ), m_aMultiClick); return bRet; } -bool ObjectIdentifier::areSiblings( const OUString& rCID1, const OUString& rCID2 ) +bool ObjectIdentifier::areSiblings( std::u16string_view rCID1, std::u16string_view rCID2 ) { bool bRet=false; - sal_Int32 nLastSign1 = rCID1.lastIndexOf( '=' ); - sal_Int32 nLastSign2 = rCID2.lastIndexOf( '=' ); - if( nLastSign1 == rCID1.indexOf( '=' ) )//CID cannot be sibling if only one "=" occurs + size_t nLastSign1 = rCID1.rfind( '=' ); + size_t nLastSign2 = rCID2.rfind( '=' ); + if( nLastSign1 == rCID1.find( '=' ) )//CID cannot be sibling if only one "=" occurs bRet=false; - else if( nLastSign2 == rCID2.indexOf( '=' ) )//CID cannot be sibling if only one "=" occurs + else if( nLastSign2 == rCID2.find( '=' ) )//CID cannot be sibling if only one "=" occurs bRet=false; else if( ObjectIdentifier::areIdenticalObjects( rCID1, rCID2 ) ) bRet=false; else { - OUString aParent1( ObjectIdentifier::getFullParentParticle( rCID1 ) ); - if( !aParent1.isEmpty() ) + std::u16string_view aParent1( ObjectIdentifier::getFullParentParticle( rCID1 ) ); + if( !aParent1.empty() ) { - OUString aParent2( ObjectIdentifier::getFullParentParticle( rCID2 ) ); + std::u16string_view aParent2( ObjectIdentifier::getFullParentParticle( rCID2 ) ); bRet=aParent1 == aParent2; } //legend entries are special: @@ -880,14 +779,14 @@ bool ObjectIdentifier::areSiblings( const OUString& rCID1, const OUString& rCID2 return bRet; } -bool ObjectIdentifier::areIdenticalObjects( const OUString& rCID1, const OUString& rCID2 ) +bool ObjectIdentifier::areIdenticalObjects( std::u16string_view rCID1, std::u16string_view rCID2 ) { if( rCID1 == rCID2 ) return true; //draggable pie or donut segments need special treatment, as their CIDs do change with offset { - if( rCID1.indexOf( m_aPieSegmentDragMethodServiceName ) < 0 - || rCID2.indexOf( m_aPieSegmentDragMethodServiceName ) < 0 ) + if( rCID1.find( m_aPieSegmentDragMethodServiceName ) == std::u16string_view::npos + || rCID2.find( m_aPieSegmentDragMethodServiceName ) == std::u16string_view::npos ) return false; OUString aID1( ObjectIdentifier::getObjectID( rCID1 ) ); @@ -975,76 +874,82 @@ OUString ObjectIdentifier::getStringForType( ObjectType eObjectType ) case OBJECTTYPE_DATA_STOCK_GAIN: aRet="StockGain"; break; + case OBJECTTYPE_DATA_TABLE: + aRet="DataTable"; + break; default: //OBJECTTYPE_UNKNOWN ; } return aRet; } -ObjectType ObjectIdentifier::getObjectType( const OUString& rCID ) +ObjectType ObjectIdentifier::getObjectType( std::u16string_view aCID ) { ObjectType eRet; - sal_Int32 nLastSign = rCID.lastIndexOf( ':' );//last sign before the type string - if(nLastSign==-1) - nLastSign = rCID.lastIndexOf( '/' ); - if(nLastSign==-1) + size_t nLastSign = aCID.rfind( ':' );//last sign before the type string + if(nLastSign == std::u16string_view::npos) + nLastSign = aCID.rfind( '/' ); + if(nLastSign == std::u16string_view::npos) { - sal_Int32 nEndIndex = rCID.lastIndexOf( '=' ); - if(nEndIndex==-1) + size_t nEndIndex = aCID.rfind( '=' ); + if(nEndIndex == std::u16string_view::npos) return OBJECTTYPE_UNKNOWN; nLastSign = 0; } if( nLastSign>0 ) nLastSign++; - if( rCID.match("Page",nLastSign) ) + aCID = aCID.substr(nLastSign); + if( o3tl::starts_with(aCID, u"Page") ) eRet = OBJECTTYPE_PAGE; - else if( rCID.match("Title",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Title") ) eRet = OBJECTTYPE_TITLE; - else if( rCID.match("LegendEntry",nLastSign) ) + else if( o3tl::starts_with(aCID, u"LegendEntry") ) eRet = OBJECTTYPE_LEGEND_ENTRY; - else if( rCID.match("Legend",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Legend") ) eRet = OBJECTTYPE_LEGEND; - else if( rCID.match("DiagramWall",nLastSign) ) + else if( o3tl::starts_with(aCID, u"DiagramWall") ) eRet = OBJECTTYPE_DIAGRAM_WALL; - else if( rCID.match("DiagramFloor",nLastSign) ) + else if( o3tl::starts_with(aCID, u"DiagramFloor") ) eRet = OBJECTTYPE_DIAGRAM_FLOOR; - else if( rCID.match("D=",nLastSign) ) + else if( o3tl::starts_with(aCID, u"D=") ) eRet = OBJECTTYPE_DIAGRAM; - else if( rCID.match("AxisUnitLabel",nLastSign) ) + else if( o3tl::starts_with(aCID, u"AxisUnitLabel") ) eRet = OBJECTTYPE_AXIS_UNITLABEL; - else if( rCID.match("Axis",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Axis") ) eRet = OBJECTTYPE_AXIS; - else if( rCID.match("Grid",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Grid") ) eRet = OBJECTTYPE_GRID; - else if( rCID.match("SubGrid",nLastSign) ) + else if( o3tl::starts_with(aCID, u"SubGrid") ) eRet = OBJECTTYPE_SUBGRID; - else if( rCID.match("Series",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Series") ) eRet = OBJECTTYPE_DATA_SERIES; - else if( rCID.match("Point",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Point") ) eRet = OBJECTTYPE_DATA_POINT; - else if( rCID.match("DataLabels",nLastSign) ) + else if( o3tl::starts_with(aCID, u"DataLabels") ) eRet = OBJECTTYPE_DATA_LABELS; - else if( rCID.match("DataLabel",nLastSign) ) + else if( o3tl::starts_with(aCID, u"DataLabel") ) eRet = OBJECTTYPE_DATA_LABEL; - else if( rCID.match("ErrorsX",nLastSign) ) + else if( o3tl::starts_with(aCID, u"ErrorsX") ) eRet = OBJECTTYPE_DATA_ERRORS_X; - else if( rCID.match("ErrorsY",nLastSign) ) + else if( o3tl::starts_with(aCID, u"ErrorsY") ) eRet = OBJECTTYPE_DATA_ERRORS_Y; - else if( rCID.match("ErrorsZ",nLastSign) ) + else if( o3tl::starts_with(aCID, u"ErrorsZ") ) eRet = OBJECTTYPE_DATA_ERRORS_Z; - else if( rCID.match("Curve",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Curve") ) eRet = OBJECTTYPE_DATA_CURVE; - else if( rCID.match("Equation",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Equation") ) eRet = OBJECTTYPE_DATA_CURVE_EQUATION; - else if( rCID.match("Average",nLastSign) ) + else if( o3tl::starts_with(aCID, u"Average") ) eRet = OBJECTTYPE_DATA_AVERAGE_LINE; - else if( rCID.match("StockRange",nLastSign) ) + else if( o3tl::starts_with(aCID, u"StockRange") ) eRet = OBJECTTYPE_DATA_STOCK_RANGE; - else if( rCID.match("StockLoss",nLastSign) ) + else if( o3tl::starts_with(aCID, u"StockLoss") ) eRet = OBJECTTYPE_DATA_STOCK_LOSS; - else if( rCID.match("StockGain",nLastSign) ) + else if( o3tl::starts_with(aCID, u"StockGain") ) eRet = OBJECTTYPE_DATA_STOCK_GAIN; + else if( o3tl::starts_with(aCID, u"DataTable") ) + eRet = OBJECTTYPE_DATA_TABLE; else eRet = OBJECTTYPE_UNKNOWN; @@ -1066,7 +971,7 @@ ObjectType ObjectIdentifier::getObjectType() const } OUString ObjectIdentifier::createDataCurveCID( - const OUString& rSeriesParticle + std::u16string_view rSeriesParticle , sal_Int32 nCurveIndex , bool bAverageLine ) { @@ -1076,20 +981,20 @@ OUString ObjectIdentifier::createDataCurveCID( } OUString ObjectIdentifier::createDataCurveEquationCID( - const OUString& rSeriesParticle + std::u16string_view rSeriesParticle , sal_Int32 nCurveIndex ) { OUString aParticleID( OUString::number( nCurveIndex ) ); return createClassifiedIdentifierWithParent( OBJECTTYPE_DATA_CURVE_EQUATION, aParticleID, rSeriesParticle ); } -OUString ObjectIdentifier::addChildParticle( const OUString& rParticle, const OUString& rChildParticle ) +OUString ObjectIdentifier::addChildParticle( std::u16string_view rParticle, std::u16string_view rChildParticle ) { OUStringBuffer aRet(rParticle); - if( !aRet.isEmpty() && !rChildParticle.isEmpty() ) + if( !aRet.isEmpty() && !rChildParticle.empty() ) aRet.append(":"); - if( !rChildParticle.isEmpty() ) + if( !rChildParticle.empty() ) aRet.append(rChildParticle); return aRet.makeStringAndClear(); @@ -1100,22 +1005,21 @@ OUString ObjectIdentifier::createChildParticleWithIndex( ObjectType eObjectType, OUStringBuffer aRet( getStringForType( eObjectType ) ); if( !aRet.isEmpty() ) { - aRet.append("="); - aRet.append(OUString::number(nIndex)); + aRet.append("=" + OUString::number(nIndex)); } return aRet.makeStringAndClear(); } -sal_Int32 ObjectIdentifier::getIndexFromParticleOrCID( const OUString& rParticleOrCID ) +sal_Int32 ObjectIdentifier::getIndexFromParticleOrCID( std::u16string_view rParticleOrCID ) { - const OUString aIndexString = lcl_getIndexStringAfterString( rParticleOrCID, "=" ); - return lcl_StringToIndex( aIndexString.getToken( 0, ',' ) ); + const std::u16string_view aIndexString = lcl_getIndexStringAfterString( rParticleOrCID, u"=" ); + return lcl_StringToIndex( o3tl::getToken(aIndexString, 0, ',' ) ); } OUString ObjectIdentifier::createSeriesSubObjectStub( ObjectType eSubObjectType - , const OUString& rSeriesParticle - , const OUString& rDragMethodServiceName - , const OUString& rDragParameterString ) + , std::u16string_view rSeriesParticle + , std::u16string_view rDragMethodServiceName + , std::u16string_view rDragParameterString ) { OUString aChildParticle = getStringForType( eSubObjectType ) + "="; @@ -1129,67 +1033,59 @@ OUString ObjectIdentifier::createPointCID( std::u16string_view rPointCID_Stub, s return rPointCID_Stub + OUString::number( nIndex ); } -OUString ObjectIdentifier::getParticleID( const OUString& rCID ) +std::u16string_view ObjectIdentifier::getParticleID( std::u16string_view rCID ) { - OUString aRet; - sal_Int32 nLast = rCID.lastIndexOf('='); - if(nLast>=0) - aRet = rCID.copy(++nLast); + std::u16string_view aRet; + size_t nLast = rCID.rfind('='); + if(nLast != std::u16string_view::npos) + aRet = rCID.substr(++nLast); return aRet; } -OUString ObjectIdentifier::getFullParentParticle( const OUString& rCID ) +std::u16string_view ObjectIdentifier::getFullParentParticle( std::u16string_view rCID ) { - OUString aRet; + std::u16string_view aRet; - sal_Int32 nStartPos = rCID.lastIndexOf('/'); - if( nStartPos>=0 ) + size_t nStartPos = rCID.rfind('/'); + if( nStartPos != std::u16string_view::npos ) { nStartPos++; - sal_Int32 nEndPos = rCID.lastIndexOf(':'); - if( nEndPos>=0 && nStartPos < nEndPos ) + size_t nEndPos = rCID.rfind(':'); + if( nEndPos != std::u16string_view::npos && nStartPos < nEndPos ) { - aRet = rCID.copy(nStartPos,nEndPos-nStartPos); + aRet = rCID.substr(nStartPos,nEndPos-nStartPos); } } return aRet; } -OUString ObjectIdentifier::getObjectID( const OUString& rCID ) +OUString ObjectIdentifier::getObjectID( std::u16string_view rCID ) { OUString aRet; - sal_Int32 nStartPos = rCID.lastIndexOf('/'); - if( nStartPos>=0 ) + size_t nStartPos = rCID.rfind('/'); + if( nStartPos != std::u16string_view::npos ) { nStartPos++; - sal_Int32 nEndPos = rCID.getLength(); - aRet = rCID.copy(nStartPos,nEndPos-nStartPos); + size_t nEndPos = rCID.size(); + aRet = rCID.substr(nStartPos,nEndPos-nStartPos); } return aRet; } -bool ObjectIdentifier::isCID( const OUString& rName ) +bool ObjectIdentifier::isCID( std::u16string_view rName ) { - return !rName.isEmpty() && rName.match( m_aProtocol ); + return !rName.empty() && o3tl::starts_with( rName, m_aProtocol ); } Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( - const OUString& rObjectCID, - const Reference< chart2::XChartDocument >& xChartDocument ) -{ - return ObjectIdentifier::getObjectPropertySet( - rObjectCID, Reference< frame::XModel >( xChartDocument )); -} - -Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( - const OUString& rObjectCID - , const Reference< frame::XModel >& xChartModel ) + std::u16string_view rObjectCID + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { //return the model object that is indicated by rObjectCID - if(rObjectCID.isEmpty()) + if(rObjectCID.empty()) return nullptr; if(!xChartModel.is()) return nullptr; @@ -1198,26 +1094,24 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( try { ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID ); - OUString aParticleID = ObjectIdentifier::getParticleID( rObjectCID ); + std::u16string_view aParticleID = ObjectIdentifier::getParticleID( rObjectCID ); - Reference< XDiagram > xDiagram; - Reference< XCoordinateSystem > xCooSys; + rtl::Reference< Diagram > xDiagram; + rtl::Reference< BaseCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); switch(eObjectType) { case OBJECTTYPE_PAGE: { - Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY ); - if( xChartDocument.is()) - xObjectProperties.set( xChartDocument->getPageBackground() ); + xObjectProperties.set( xChartModel->getPageBackground() ); } break; case OBJECTTYPE_TITLE: { TitleHelper::eTitleType aTitleType = getTitleTypeForCID( rObjectCID ); - Reference< XTitle > xTitle( TitleHelper::getTitle( aTitleType, xChartModel ) ); - xObjectProperties.set( xTitle, uno::UNO_QUERY ); + rtl::Reference< Title > xTitle( TitleHelper::getTitle( aTitleType, xChartModel ) ); + xObjectProperties = xTitle; } break; case OBJECTTYPE_LEGEND: @@ -1230,7 +1124,7 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( break; case OBJECTTYPE_DIAGRAM: { - xObjectProperties.set( xDiagram, uno::UNO_QUERY ); + xObjectProperties = xDiagram; } break; case OBJECTTYPE_DIAGRAM_WALL: @@ -1251,10 +1145,10 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( sal_Int32 nAxisIndex = -1; lcl_parseAxisIndices( nDimensionIndex, nAxisIndex, rObjectCID ); - Reference< chart2::XAxis > xAxis( - AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ) ); + rtl::Reference< Axis > xAxis = + AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ); if( xAxis.is() ) - xObjectProperties.set( xAxis, uno::UNO_QUERY ); + xObjectProperties = xAxis; } break; case OBJECTTYPE_AXIS_UNITLABEL: @@ -1269,27 +1163,27 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( sal_Int32 nSubGridIndex = -1; lcl_parseGridIndices( nSubGridIndex, rObjectCID ); - xObjectProperties.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, nAxisIndex, nSubGridIndex ) ); + xObjectProperties = AxisHelper::getGridProperties( xCooSys , nDimensionIndex, nAxisIndex, nSubGridIndex ); } break; case OBJECTTYPE_DATA_LABELS: case OBJECTTYPE_DATA_SERIES: { - Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( + rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID, xChartModel ) ); if( xSeries.is() ) - xObjectProperties.set( xSeries, uno::UNO_QUERY ); + xObjectProperties = xSeries; break; } case OBJECTTYPE_DATA_LABEL: case OBJECTTYPE_DATA_POINT: { - Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( - rObjectCID, xChartModel ) ); + rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( + rObjectCID, xChartModel ); if(xSeries.is()) { - sal_Int32 nIndex = aParticleID.toInt32(); + sal_Int32 nIndex = o3tl::toInt32(aParticleID); xObjectProperties = xSeries->getDataPointByIndex( nIndex ); } break; @@ -1298,26 +1192,22 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( case OBJECTTYPE_DATA_ERRORS_Y: case OBJECTTYPE_DATA_ERRORS_Z: { - Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( - rObjectCID, xChartModel ) ); + rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( + rObjectCID, xChartModel ); if(xSeries.is()) { - Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY ); Reference< beans::XPropertySet > xErrorBarProp; - if( xSeriesProp.is() ) - { - OUString errorBar; + OUString errorBar; - if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X) - errorBar = CHART_UNONAME_ERRORBAR_X; - else if (eObjectType == OBJECTTYPE_DATA_ERRORS_Y) - errorBar = CHART_UNONAME_ERRORBAR_Y; - else - errorBar = "ErrorBarZ"; + if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X) + errorBar = CHART_UNONAME_ERRORBAR_X; + else if (eObjectType == OBJECTTYPE_DATA_ERRORS_Y) + errorBar = CHART_UNONAME_ERRORBAR_Y; + else + errorBar = "ErrorBarZ"; - xSeriesProp->getPropertyValue( errorBar ) >>= xErrorBarProp; - xObjectProperties = xErrorBarProp; - } + xSeries->getPropertyValue( errorBar ) >>= xErrorBarProp; + xObjectProperties = xErrorBarProp; } break; } @@ -1325,19 +1215,19 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( case OBJECTTYPE_DATA_CURVE: case OBJECTTYPE_DATA_CURVE_EQUATION: { - Reference< XRegressionCurveContainer > xRegressionContainer( ObjectIdentifier::getDataSeriesForCID( - rObjectCID, xChartModel ), uno::UNO_QUERY ); + rtl::Reference< DataSeries > xRegressionContainer = ObjectIdentifier::getDataSeriesForCID( + rObjectCID, xChartModel ); if(xRegressionContainer.is()) { - sal_Int32 nIndex = aParticleID.toInt32(); - uno::Sequence< Reference< XRegressionCurve > > aCurveList = - xRegressionContainer->getRegressionCurves(); - if( nIndex >= 0 && nIndex <aCurveList.getLength() ) + sal_Int32 nIndex = o3tl::toInt32(aParticleID); + const std::vector< rtl::Reference< RegressionCurveModel > > & aCurveList = + xRegressionContainer->getRegressionCurves2(); + if( nIndex >= 0 && o3tl::make_unsigned(nIndex) < aCurveList.size() ) { if( eObjectType == OBJECTTYPE_DATA_CURVE_EQUATION ) - xObjectProperties.set( aCurveList[nIndex]->getEquationProperties()); + xObjectProperties = aCurveList[nIndex]->getEquationProperties(); else - xObjectProperties.set( aCurveList[nIndex], uno::UNO_QUERY ); + xObjectProperties = aCurveList[nIndex]; } } break; @@ -1346,20 +1236,25 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( break; case OBJECTTYPE_DATA_STOCK_LOSS: { - Reference<XChartType> xChartType( lcl_getFirstStockChartType( xChartModel ) ); - Reference< beans::XPropertySet > xChartTypeProps( xChartType, uno::UNO_QUERY ); - if(xChartTypeProps.is()) - xChartTypeProps->getPropertyValue( "BlackDay" ) >>= xObjectProperties; + rtl::Reference<ChartType> xChartType( lcl_getFirstStockChartType( xChartModel ) ); + if(xChartType.is()) + xChartType->getPropertyValue( "BlackDay" ) >>= xObjectProperties; } break; case OBJECTTYPE_DATA_STOCK_GAIN: { - Reference<XChartType> xChartType( lcl_getFirstStockChartType( xChartModel ) ); - Reference< beans::XPropertySet > xChartTypeProps( xChartType, uno::UNO_QUERY ); - if(xChartTypeProps.is()) - xChartTypeProps->getPropertyValue( "WhiteDay" ) >>= xObjectProperties; + rtl::Reference<ChartType> xChartType( lcl_getFirstStockChartType( xChartModel ) ); + if(xChartType.is()) + xChartType->getPropertyValue( "WhiteDay" ) >>= xObjectProperties; } break; + case OBJECTTYPE_DATA_TABLE: + { + if (xDiagram.is()) + xObjectProperties.set(xDiagram->getDataTable(), uno::UNO_QUERY); + } + break; + break; default: //OBJECTTYPE_UNKNOWN break; } @@ -1371,12 +1266,12 @@ Reference< beans::XPropertySet > ObjectIdentifier::getObjectPropertySet( return xObjectProperties; } -Reference< XAxis > ObjectIdentifier::getAxisForCID( - const OUString& rObjectCID - , const Reference< frame::XModel >& xChartModel ) +rtl::Reference< Axis > ObjectIdentifier::getAxisForCID( + std::u16string_view rObjectCID + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { - Reference< XDiagram > xDiagram; - Reference< XCoordinateSystem > xCooSys; + rtl::Reference< Diagram > xDiagram; + rtl::Reference< BaseCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); sal_Int32 nDimensionIndex = -1; @@ -1386,14 +1281,12 @@ Reference< XAxis > ObjectIdentifier::getAxisForCID( return AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ); } -Reference< XDataSeries > ObjectIdentifier::getDataSeriesForCID( - const OUString& rObjectCID - , const Reference< frame::XModel >& xChartModel ) +rtl::Reference< DataSeries > ObjectIdentifier::getDataSeriesForCID( + std::u16string_view rObjectCID + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { - Reference< XDataSeries > xSeries; - - Reference< XDiagram > xDiagram; - Reference< XCoordinateSystem > xCooSys; + rtl::Reference< Diagram > xDiagram; + rtl::Reference< BaseCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); sal_Int32 nChartTypeIndex = -1; @@ -1401,34 +1294,36 @@ Reference< XDataSeries > ObjectIdentifier::getDataSeriesForCID( sal_Int32 nPointIndex = -1; lcl_parseSeriesIndices( nChartTypeIndex, nSeriesIndex, nPointIndex, rObjectCID ); - Reference< XDataSeriesContainer > xDataSeriesContainer( DiagramHelper::getChartTypeByIndex( xDiagram, nChartTypeIndex ), uno::UNO_QUERY ); - if( xDataSeriesContainer.is() ) + rtl::Reference< DataSeries > xSeries; + if (xDiagram) { - uno::Sequence< uno::Reference< XDataSeries > > aDataSeriesSeq( xDataSeriesContainer->getDataSeries() ); - if( nSeriesIndex >= 0 && nSeriesIndex < aDataSeriesSeq.getLength() ) - xSeries.set( aDataSeriesSeq[nSeriesIndex] ); + rtl::Reference< ChartType > xDataSeriesContainer( xDiagram->getChartTypeByIndex( nChartTypeIndex ) ); + if( xDataSeriesContainer.is() ) + { + const std::vector< rtl::Reference< DataSeries > > & aDataSeriesSeq( xDataSeriesContainer->getDataSeries2() ); + if( nSeriesIndex >= 0 && o3tl::make_unsigned(nSeriesIndex) < aDataSeriesSeq.size() ) + xSeries = aDataSeriesSeq[nSeriesIndex]; + } } - return xSeries; } -Reference< XDiagram > ObjectIdentifier::getDiagramForCID( - const OUString& rObjectCID - , const uno::Reference< frame::XModel >& xChartModel ) +rtl::Reference< Diagram > ObjectIdentifier::getDiagramForCID( + std::u16string_view rObjectCID + , const rtl::Reference<::chart::ChartModel>& xChartModel ) { - Reference< XDiagram > xDiagram; - - Reference< XCoordinateSystem > xCooSys; + rtl::Reference< Diagram > xDiagram; + rtl::Reference< BaseCoordinateSystem > xCooSys; lcl_getDiagramAndCooSys( rObjectCID, xChartModel, xDiagram, xCooSys ); return xDiagram; } -TitleHelper::eTitleType ObjectIdentifier::getTitleTypeForCID( const OUString& rCID ) +TitleHelper::eTitleType ObjectIdentifier::getTitleTypeForCID( std::u16string_view rCID ) { TitleHelper::eTitleType eRet( TitleHelper::MAIN_TITLE ); - OUString aParentParticle = ObjectIdentifier::getFullParentParticle( rCID ); + std::u16string_view aParentParticle = ObjectIdentifier::getFullParentParticle( rCID ); const tTitleMap& rMap = lcl_getTitleMap(); tTitleMap::const_iterator aIt = std::find_if(rMap.begin(), rMap.end(), [&aParentParticle](tTitleMap::const_reference rEntry) { return aParentParticle == rEntry.second; }); @@ -1438,7 +1333,7 @@ TitleHelper::eTitleType ObjectIdentifier::getTitleTypeForCID( const OUString& rC return eRet; } -OUString ObjectIdentifier::getSeriesParticleFromCID( const OUString& rCID ) +OUString ObjectIdentifier::getSeriesParticleFromCID( std::u16string_view rCID ) { sal_Int32 nDiagramIndex = -1; sal_Int32 nCooSysIndex = -1; @@ -1452,12 +1347,12 @@ OUString ObjectIdentifier::getSeriesParticleFromCID( const OUString& rCID ) return ObjectIdentifier::createParticleForSeries( nDiagramIndex, nCooSysIndex, nChartTypeIndex, nSeriesIndex ); } -OUString ObjectIdentifier::getMovedSeriesCID( const OUString& rObjectCID, bool bForward ) +OUString ObjectIdentifier::getMovedSeriesCID( std::u16string_view rObjectCID, bool bForward ) { - sal_Int32 nDiagramIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, "CID/D=" ) ); - sal_Int32 nCooSysIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, "CS=" ) ); - sal_Int32 nChartTypeIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, "CT=" ) ); - sal_Int32 nSeriesIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, "Series=" ) ); + sal_Int32 nDiagramIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, u"CID/D=" ) ); + sal_Int32 nCooSysIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, u"CS=" ) ); + sal_Int32 nChartTypeIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, u"CT=" ) ); + sal_Int32 nSeriesIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, u"Series=" ) ); if( bForward ) nSeriesIndex--; |