diff options
Diffstat (limited to 'chart2/source/model/template/ScatterChartTypeTemplate.cxx')
-rw-r--r-- | chart2/source/model/template/ScatterChartTypeTemplate.cxx | 229 |
1 files changed, 90 insertions, 139 deletions
diff --git a/chart2/source/model/template/ScatterChartTypeTemplate.cxx b/chart2/source/model/template/ScatterChartTypeTemplate.cxx index cf22e22c6d55..3457bfa00126 100644 --- a/chart2/source/model/template/ScatterChartTypeTemplate.cxx +++ b/chart2/source/model/template/ScatterChartTypeTemplate.cxx @@ -18,9 +18,11 @@ */ #include "ScatterChartTypeTemplate.hxx" +#include "ScatterChartType.hxx" #include "XYDataInterpreter.hxx" -#include <DiagramHelper.hxx> -#include <servicenames_charttypes.hxx> +#include <ChartType.hxx> +#include <Diagram.hxx> +#include <DataSeries.hxx> #include <DataSeriesHelper.hxx> #include <PropertyHelper.hxx> #include <unonames.hxx> @@ -31,8 +33,7 @@ #include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <algorithm> @@ -53,89 +54,58 @@ enum }; -void lcl_AddPropertiesToVector( - std::vector< Property > & rOutProperties ) +const ::chart::tPropertyValueMap& StaticScatterChartTypeTemplateDefaults() { - rOutProperties.emplace_back( CHART_UNONAME_CURVE_STYLE, - PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, - cppu::UnoType<chart2::CurveStyle>::get(), - beans::PropertyAttribute::BOUND - | beans::PropertyAttribute::MAYBEDEFAULT ); - rOutProperties.emplace_back( CHART_UNONAME_CURVE_RESOLUTION, - PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, - cppu::UnoType<sal_Int32>::get(), - beans::PropertyAttribute::BOUND - | beans::PropertyAttribute::MAYBEDEFAULT ); - rOutProperties.emplace_back( CHART_UNONAME_SPLINE_ORDER, - PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, - cppu::UnoType<sal_Int32>::get(), - beans::PropertyAttribute::BOUND - | beans::PropertyAttribute::MAYBEDEFAULT ); + static const ::chart::tPropertyValueMap aStaticDefaults = + []() + { + ::chart::tPropertyValueMap aOutMap; + ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 ); + + // todo: check whether order 3 means polygons of order 3 or 2. (see + // http://www.people.nnov.ru/fractal/Splines/Basis.htm ) + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 ); + return aOutMap; + }(); + return aStaticDefaults; } -struct StaticScatterChartTypeTemplateDefaults_Initializer -{ - ::chart::tPropertyValueMap* operator()() - { - static ::chart::tPropertyValueMap aStaticDefaults; - lcl_AddDefaultsToMap( aStaticDefaults ); - return &aStaticDefaults; - } -private: - static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ) - { - ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES ); - ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 ); - - // todo: check whether order 3 means polygons of order 3 or 2. (see - // http://www.people.nnov.ru/fractal/Splines/Basis.htm ) - ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 ); - } -}; - -struct StaticScatterChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticScatterChartTypeTemplateDefaults_Initializer > -{ -}; - -struct StaticScatterChartTypeTemplateInfoHelper_Initializer -{ - ::cppu::OPropertyArrayHelper* operator()() - { - static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() ); - return &aPropHelper; - } - -private: - static Sequence< Property > lcl_GetPropertySequence() - { - std::vector< css::beans::Property > aProperties; - lcl_AddPropertiesToVector( aProperties ); - - std::sort( aProperties.begin(), aProperties.end(), - ::chart::PropertyNameLess() ); - - return comphelper::containerToSequence( aProperties ); - } - -}; - -struct StaticScatterChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticScatterChartTypeTemplateInfoHelper_Initializer > -{ -}; -struct StaticScatterChartTypeTemplateInfo_Initializer +::cppu::OPropertyArrayHelper& StaticScatterChartTypeTemplateInfoHelper() { - uno::Reference< beans::XPropertySetInfo >* operator()() - { - static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( - ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeTemplateInfoHelper::get() ) ); - return &xPropertySetInfo; - } -}; + static ::cppu::OPropertyArrayHelper aPropHelper( + []() + { + std::vector< css::beans::Property > aProperties { + { CHART_UNONAME_CURVE_STYLE, + PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, + cppu::UnoType<chart2::CurveStyle>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT }, + { CHART_UNONAME_CURVE_RESOLUTION, + PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, + cppu::UnoType<sal_Int32>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT }, + { CHART_UNONAME_SPLINE_ORDER, + PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, + cppu::UnoType<sal_Int32>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT } }; + std::sort( aProperties.begin(), aProperties.end(), + ::chart::PropertyNameLess() ); + return comphelper::containerToSequence( aProperties ); + }() ); + return aPropHelper; +} -struct StaticScatterChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticScatterChartTypeTemplateInfo_Initializer > +const uno::Reference< beans::XPropertySetInfo >& StaticScatterChartTypeTemplateInfo() { -}; + static const uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( + ::cppu::OPropertySetHelper::createPropertySetInfo(StaticScatterChartTypeTemplateInfoHelper() ) ); + return xPropertySetInfo; +} } // anonymous namespace @@ -150,7 +120,6 @@ ScatterChartTypeTemplate::ScatterChartTypeTemplate( bool bHasLines /* = true */, sal_Int32 nDim /* = 2 */ ) : ChartTypeTemplate( xContext, rServiceName ), - ::property::OPropertySet( m_aMutex ), m_bHasSymbols( bSymbols ), m_bHasLines( bHasLines ), m_nDim( nDim ) @@ -165,7 +134,7 @@ ScatterChartTypeTemplate::~ScatterChartTypeTemplate() // ____ OPropertySet ____ void ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const { - const tPropertyValueMap& rStaticDefaults = *StaticScatterChartTypeTemplateDefaults::get(); + const tPropertyValueMap& rStaticDefaults = StaticScatterChartTypeTemplateDefaults(); tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) ); if( aFound == rStaticDefaults.end() ) rAny.clear(); @@ -175,13 +144,13 @@ void ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAn ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartTypeTemplate::getInfoHelper() { - return *StaticScatterChartTypeTemplateInfoHelper::get(); + return StaticScatterChartTypeTemplateInfoHelper(); } // ____ XPropertySet ____ uno::Reference< beans::XPropertySetInfo > SAL_CALL ScatterChartTypeTemplate::getPropertySetInfo() { - return *StaticScatterChartTypeTemplateInfo::get(); + return StaticScatterChartTypeTemplateInfo(); } sal_Int32 ScatterChartTypeTemplate::getDimension() const @@ -196,21 +165,19 @@ StackMode ScatterChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex * return StackMode::NONE; } -void SAL_CALL ScatterChartTypeTemplate::applyStyle( - const Reference< chart2::XDataSeries >& xSeries, +void ScatterChartTypeTemplate::applyStyle2( + const rtl::Reference< DataSeries >& xSeries, ::sal_Int32 nChartTypeIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount ) { - ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + ChartTypeTemplate::applyStyle2( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); try { - Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW ); - - DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex ); - DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines ); - DataSeriesHelper::makeLinesThickOrThin( xProp, m_nDim==2 ); + DataSeriesHelper::switchSymbolsOnOrOff( xSeries, m_bHasSymbols, nSeriesIndex ); + DataSeriesHelper::switchLinesOnOrOff( xSeries, m_bHasLines ); + DataSeriesHelper::makeLinesThickOrThin( xSeries, m_nDim==2 ); if( m_nDim==3 ) DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::Any( drawing::LineStyle_NONE ) ); } @@ -226,11 +193,11 @@ sal_Bool SAL_CALL ScatterChartTypeTemplate::supportsCategories() return false; } -sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( - const Reference< chart2::XDiagram >& xDiagram, - sal_Bool bAdaptProperties ) +bool ScatterChartTypeTemplate::matchesTemplate2( + const rtl::Reference< ::chart::Diagram >& xDiagram, + bool bAdaptProperties ) { - bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + bool bResult = ChartTypeTemplate::matchesTemplate2( xDiagram, bAdaptProperties ); // check symbol-style and line-style // for a template with symbols (or with lines) it is ok, if there is at least one series @@ -240,8 +207,8 @@ sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( bool bSymbolFound = false; bool bLineFound = false; - std::vector< Reference< chart2::XDataSeries > > aSeriesVec( - DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + std::vector< rtl::Reference< DataSeries > > aSeriesVec = + xDiagram->getDataSeries(); for (auto const& series : aSeriesVec) { @@ -249,9 +216,8 @@ sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( { chart2::Symbol aSymbProp; drawing::LineStyle eLineStyle; - Reference< beans::XPropertySet > xProp(series, uno::UNO_QUERY_THROW); - bool bCurrentHasSymbol = (xProp->getPropertyValue( "Symbol") >>= aSymbProp) && + bool bCurrentHasSymbol = (series->getPropertyValue( "Symbol") >>= aSymbProp) && (aSymbProp.Style != chart2::SymbolStyle_NONE); if( bCurrentHasSymbol ) @@ -263,7 +229,7 @@ sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( break; } - bool bCurrentHasLine = (xProp->getPropertyValue( "LineStyle") >>= eLineStyle) && + bool bCurrentHasLine = (series->getPropertyValue( "LineStyle") >>= eLineStyle) && ( eLineStyle != drawing::LineStyle_NONE ); if( bCurrentHasLine ) @@ -297,9 +263,8 @@ sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( { try { - uno::Reference< beans::XPropertySet > xChartTypeProp( - DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), - uno::UNO_QUERY_THROW ); + rtl::Reference< ChartType > xChartTypeProp = + xDiagram->getChartTypeByIndex(0); setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_STYLE) ); setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION) ); setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(CHART_UNONAME_SPLINE_ORDER) ); @@ -313,27 +278,20 @@ sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( return bResult; } -Reference< chart2::XChartType > ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +rtl::Reference< ChartType > ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) { - Reference< chart2::XChartType > xResult; + rtl::Reference< ChartType > xResult; try { - Reference< lang::XMultiServiceFactory > xFact( - GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); - xResult.set( xFact->createInstance( - CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW ); - - Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); - if( xCTProp.is()) - { - xCTProp->setPropertyValue( - CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE )); - xCTProp->setPropertyValue( - CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); - xCTProp->setPropertyValue( - CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER )); - } + xResult = new ScatterChartType(); + + xResult->setPropertyValue( + CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE )); + xResult->setPropertyValue( + CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); + xResult->setPropertyValue( + CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER )); } catch( const uno::Exception & ) { @@ -343,30 +301,23 @@ Reference< chart2::XChartType > ScatterChartTypeTemplate::getChartTypeForIndex( return xResult; } -Reference< chart2::XChartType > SAL_CALL ScatterChartTypeTemplate::getChartTypeForNewSeries( - const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) +rtl::Reference< ChartType > ScatterChartTypeTemplate::getChartTypeForNewSeries2( + const std::vector< rtl::Reference< ChartType > >& aFormerlyUsedChartTypes ) { - Reference< chart2::XChartType > xResult; + rtl::Reference< ChartType > xResult; try { - Reference< lang::XMultiServiceFactory > xFact( - GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); - xResult.set( xFact->createInstance( - CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW ); + xResult = new ScatterChartType(); ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult ); - Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); - if( xCTProp.is()) - { - xCTProp->setPropertyValue( - CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE )); - xCTProp->setPropertyValue( - CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); - xCTProp->setPropertyValue( - CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER )); - } + xResult->setPropertyValue( + CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE )); + xResult->setPropertyValue( + CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); + xResult->setPropertyValue( + CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER )); } catch( const uno::Exception & ) { @@ -376,7 +327,7 @@ Reference< chart2::XChartType > SAL_CALL ScatterChartTypeTemplate::getChartTypeF return xResult; } -Reference< chart2::XDataInterpreter > SAL_CALL ScatterChartTypeTemplate::getDataInterpreter() +rtl::Reference< DataInterpreter > ScatterChartTypeTemplate::getDataInterpreter2() { if( ! m_xDataInterpreter.is()) m_xDataInterpreter.set( new XYDataInterpreter ); |