1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "LineChartTypeTemplate.hxx"
21 #include "LineChartType.hxx"
22 #include <Diagram.hxx>
23 #include <DataSeries.hxx>
24 #include <DataSeriesHelper.hxx>
25 #include <PropertyHelper.hxx>
26 #include <ChartType.hxx>
27 #include <unonames.hxx>
29 #include <com/sun/star/chart2/CurveStyle.hpp>
30 #include <com/sun/star/chart2/SymbolStyle.hpp>
31 #include <com/sun/star/chart2/Symbol.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <comphelper/diagnose_ex.hxx>
39 using namespace ::com::sun::star
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Sequence
;
43 using ::com::sun::star::beans::Property
;
50 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
51 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
52 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
56 ::chart::tPropertyValueMap
& StaticLineChartTypeTemplateDefaults()
58 static ::chart::tPropertyValueMap aStaticDefaults
=
61 ::chart::tPropertyValueMap aOutMap
;
62 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
63 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( aOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, 20 );
65 // todo: check whether order 3 means polygons of order 3 or 2. (see
66 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
67 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( aOutMap
, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, 3 );
70 return aStaticDefaults
;
73 ::cppu::OPropertyArrayHelper
& StaticLineChartTypeTemplateInfoHelper()
75 static ::cppu::OPropertyArrayHelper
aPropHelper(
78 std::vector
< css::beans::Property
> aProperties
{
79 { CHART_UNONAME_CURVE_STYLE
,
80 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
81 cppu::UnoType
<chart2::CurveStyle
>::get(),
82 beans::PropertyAttribute::BOUND
83 | beans::PropertyAttribute::MAYBEDEFAULT
},
84 { CHART_UNONAME_CURVE_RESOLUTION
,
85 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
86 cppu::UnoType
<sal_Int32
>::get(),
87 beans::PropertyAttribute::BOUND
88 | beans::PropertyAttribute::MAYBEDEFAULT
},
89 { CHART_UNONAME_SPLINE_ORDER
,
90 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
,
91 cppu::UnoType
<sal_Int32
>::get(),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEDEFAULT
} };
94 std::sort( aProperties
.begin(), aProperties
.end(),
95 ::chart::PropertyNameLess() );
97 return comphelper::containerToSequence( aProperties
);
102 uno::Reference
< beans::XPropertySetInfo
>& StaticLineChartTypeTemplateInfo()
104 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
105 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticLineChartTypeTemplateInfoHelper() ) );
106 return xPropertySetInfo
;
109 } // anonymous namespace
114 LineChartTypeTemplate::LineChartTypeTemplate(
116 uno::XComponentContext
> const & xContext
,
117 const OUString
& rServiceName
,
118 StackMode eStackMode
,
120 bool bHasLines
/* = true */,
121 sal_Int32 nDim
/* = 2 */ ) :
122 ChartTypeTemplate( xContext
, rServiceName
),
123 m_eStackMode( eStackMode
),
124 m_bHasSymbols( bSymbols
),
125 m_bHasLines( bHasLines
),
129 m_bHasSymbols
= false;
132 LineChartTypeTemplate::~LineChartTypeTemplate()
135 // ____ OPropertySet ____
136 void LineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
138 const tPropertyValueMap
& rStaticDefaults
= StaticLineChartTypeTemplateDefaults();
139 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
140 if( aFound
== rStaticDefaults
.end() )
143 rAny
= (*aFound
).second
;
146 ::cppu::IPropertyArrayHelper
& SAL_CALL
LineChartTypeTemplate::getInfoHelper()
148 return StaticLineChartTypeTemplateInfoHelper();
151 // ____ XPropertySet ____
152 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
LineChartTypeTemplate::getPropertySetInfo()
154 return StaticLineChartTypeTemplateInfo();
157 sal_Int32
LineChartTypeTemplate::getDimension() const
162 StackMode
LineChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
167 // ____ ChartTypeTemplate ____
168 bool LineChartTypeTemplate::matchesTemplate2(
169 const rtl::Reference
< ::chart::Diagram
>& xDiagram
,
170 bool bAdaptProperties
)
172 bool bResult
= ChartTypeTemplate::matchesTemplate2( xDiagram
, bAdaptProperties
);
174 // check symbol-style and line-style
175 // for a template with symbols (or with lines) it is ok, if there is at least one series
176 // with symbols (or with lines)
179 bool bSymbolFound
= false;
180 bool bLineFound
= false;
182 std::vector
< rtl::Reference
< DataSeries
> > aSeriesVec
=
183 xDiagram
->getDataSeries();
185 for (auto const& series
: aSeriesVec
)
189 chart2::Symbol aSymbProp
;
190 drawing::LineStyle eLineStyle
;
192 bool bCurrentHasSymbol
= (series
->getPropertyValue( u
"Symbol"_ustr
) >>= aSymbProp
) &&
193 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
195 if( bCurrentHasSymbol
)
198 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
204 bool bCurrentHasLine
= (series
->getPropertyValue( u
"LineStyle"_ustr
) >>= eLineStyle
) &&
205 ( eLineStyle
!= drawing::LineStyle_NONE
);
207 if( bCurrentHasLine
)
210 if( bCurrentHasLine
&& (!m_bHasLines
) )
216 catch( const uno::Exception
& )
218 DBG_UNHANDLED_EXCEPTION("chart2");
224 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
226 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
228 else if( !bLineFound
&& !bSymbolFound
)
229 return m_bHasLines
&& m_bHasSymbols
;
233 // adapt curve style, spline order and resolution
234 if( bResult
&& bAdaptProperties
)
238 rtl::Reference
< ChartType
> xChartType
= xDiagram
->getChartTypeByIndex( 0 );
239 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, xChartType
->getPropertyValue(CHART_UNONAME_CURVE_STYLE
) );
240 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, xChartType
->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION
) );
241 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, xChartType
->getPropertyValue(CHART_UNONAME_SPLINE_ORDER
) );
243 catch( const uno::Exception
& )
245 DBG_UNHANDLED_EXCEPTION("chart2");
252 rtl::Reference
< ChartType
> LineChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
254 rtl::Reference
< ChartType
> xResult
;
258 xResult
= new LineChartType();
260 xResult
->setPropertyValue(
261 CHART_UNONAME_CURVE_STYLE
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
262 xResult
->setPropertyValue(
263 CHART_UNONAME_CURVE_RESOLUTION
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
264 xResult
->setPropertyValue(
265 CHART_UNONAME_SPLINE_ORDER
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
267 catch( const uno::Exception
& )
269 DBG_UNHANDLED_EXCEPTION("chart2");
275 rtl::Reference
< ChartType
> LineChartTypeTemplate::getChartTypeForNewSeries2(
276 const std::vector
< rtl::Reference
< ChartType
> >& aFormerlyUsedChartTypes
)
278 rtl::Reference
< ChartType
> xResult
;
282 xResult
= new LineChartType();
284 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes
, xResult
);
286 xResult
->setPropertyValue(
287 CHART_UNONAME_CURVE_STYLE
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
288 xResult
->setPropertyValue(
289 CHART_UNONAME_CURVE_RESOLUTION
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
290 xResult
->setPropertyValue(
291 CHART_UNONAME_SPLINE_ORDER
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
293 catch( const uno::Exception
& )
295 DBG_UNHANDLED_EXCEPTION("chart2");
301 void LineChartTypeTemplate::applyStyle2(
302 const rtl::Reference
< DataSeries
>& xSeries
,
303 ::sal_Int32 nChartTypeIndex
,
304 ::sal_Int32 nSeriesIndex
,
305 ::sal_Int32 nSeriesCount
)
307 ChartTypeTemplate::applyStyle2( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
311 DataSeriesHelper::switchSymbolsOnOrOff( xSeries
, m_bHasSymbols
, nSeriesIndex
);
312 DataSeriesHelper::switchLinesOnOrOff( xSeries
, m_bHasLines
);
313 DataSeriesHelper::makeLinesThickOrThin( xSeries
, m_nDim
==2 );
315 catch( const uno::Exception
& )
317 DBG_UNHANDLED_EXCEPTION("chart2");
321 IMPLEMENT_FORWARD_XINTERFACE2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
322 IMPLEMENT_FORWARD_XTYPEPROVIDER2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */