LibreOffice Module chart2 (master) 1
ScatterChartTypeTemplate.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include "ScatterChartType.hxx"
22#include "XYDataInterpreter.hxx"
23#include <ChartType.hxx>
24#include <Diagram.hxx>
25#include <DiagramHelper.hxx>
26#include <DataSeries.hxx>
27#include <DataSeriesHelper.hxx>
28#include <PropertyHelper.hxx>
29#include <unonames.hxx>
30
31#include <com/sun/star/chart2/CurveStyle.hpp>
32#include <com/sun/star/chart2/SymbolStyle.hpp>
33#include <com/sun/star/chart2/Symbol.hpp>
34#include <com/sun/star/drawing/LineStyle.hpp>
35#include <com/sun/star/beans/PropertyAttribute.hpp>
36#include <com/sun/star/uno/XComponentContext.hpp>
38
39#include <algorithm>
40
41using namespace ::com::sun::star;
42
43using ::com::sun::star::uno::Reference;
44using ::com::sun::star::uno::Sequence;
45using ::com::sun::star::beans::Property;
46
47namespace
48{
49
50enum
51{
52 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE,
53 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
54 PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
55
56};
57
58const ::chart::tPropertyValueMap& StaticScatterChartTypeTemplateDefaults()
59{
60 static const ::chart::tPropertyValueMap aStaticDefaults =
61 []()
62 {
64 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES );
65 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 );
66
67 // todo: check whether order 3 means polygons of order 3 or 2. (see
68 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
69 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 );
70 return aOutMap;
71 }();
72 return aStaticDefaults;
73}
74
75
76::cppu::OPropertyArrayHelper& StaticScatterChartTypeTemplateInfoHelper()
77{
78 static ::cppu::OPropertyArrayHelper aPropHelper(
79 []()
80 {
81 std::vector< css::beans::Property > aProperties {
83 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE,
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT },
88 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
90 beans::PropertyAttribute::BOUND
91 | beans::PropertyAttribute::MAYBEDEFAULT },
93 PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER,
95 beans::PropertyAttribute::BOUND
96 | beans::PropertyAttribute::MAYBEDEFAULT } };
97 std::sort( aProperties.begin(), aProperties.end(),
99 return comphelper::containerToSequence( aProperties );
100 }() );
101 return aPropHelper;
102}
103
104const uno::Reference< beans::XPropertySetInfo >& StaticScatterChartTypeTemplateInfo()
105{
106 static const uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
107 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticScatterChartTypeTemplateInfoHelper() ) );
108 return xPropertySetInfo;
109}
110
111} // anonymous namespace
112
113namespace chart
114{
115
117 Reference<
118 uno::XComponentContext > const & xContext,
119 const OUString & rServiceName,
120 bool bSymbols,
121 bool bHasLines /* = true */,
122 sal_Int32 nDim /* = 2 */ ) :
123 ChartTypeTemplate( xContext, rServiceName ),
124 m_bHasSymbols( bSymbols ),
125 m_bHasLines( bHasLines ),
126 m_nDim( nDim )
127{
128 if( nDim == 3 )
129 m_bHasSymbols = false;
130}
131
133{}
134
135// ____ OPropertySet ____
136void ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
137{
138 const tPropertyValueMap& rStaticDefaults = StaticScatterChartTypeTemplateDefaults();
139 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
140 if( aFound == rStaticDefaults.end() )
141 rAny.clear();
142 else
143 rAny = (*aFound).second;
144}
145
147{
148 return StaticScatterChartTypeTemplateInfoHelper();
149}
150
151// ____ XPropertySet ____
153{
154 return StaticScatterChartTypeTemplateInfo();
155}
156
158{
159 return m_nDim;
160}
161
162StackMode ScatterChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
163{
164 if( m_nDim == 3 )
165 return StackMode::ZStacked;
166 return StackMode::NONE;
167}
168
170 const rtl::Reference< DataSeries >& xSeries,
171 ::sal_Int32 nChartTypeIndex,
172 ::sal_Int32 nSeriesIndex,
173 ::sal_Int32 nSeriesCount )
174{
175 ChartTypeTemplate::applyStyle2( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
176
177 try
178 {
182 if( m_nDim==3 )
183 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::Any( drawing::LineStyle_NONE ) );
184 }
185 catch( const uno::Exception & )
186 {
187 DBG_UNHANDLED_EXCEPTION("chart2");
188 }
189}
190
191// ____ XChartTypeTemplate ____
193{
194 return false;
195}
196
199 bool bAdaptProperties )
200{
201 bool bResult = ChartTypeTemplate::matchesTemplate2( xDiagram, bAdaptProperties );
202
203 // check symbol-style and line-style
204 // for a template with symbols (or with lines) it is ok, if there is at least one series
205 // with symbols (or with lines)
206 if( bResult )
207 {
208 bool bSymbolFound = false;
209 bool bLineFound = false;
210
211 std::vector< rtl::Reference< DataSeries > > aSeriesVec =
212 xDiagram->getDataSeries();
213
214 for (auto const& series : aSeriesVec)
215 {
216 try
217 {
218 chart2::Symbol aSymbProp;
219 drawing::LineStyle eLineStyle;
220
221 bool bCurrentHasSymbol = (series->getPropertyValue( "Symbol") >>= aSymbProp) &&
222 (aSymbProp.Style != chart2::SymbolStyle_NONE);
223
224 if( bCurrentHasSymbol )
225 bSymbolFound = true;
226
227 if( bCurrentHasSymbol && (!m_bHasSymbols) )
228 {
229 bResult = false;
230 break;
231 }
232
233 bool bCurrentHasLine = (series->getPropertyValue( "LineStyle") >>= eLineStyle) &&
234 ( eLineStyle != drawing::LineStyle_NONE );
235
236 if( bCurrentHasLine )
237 bLineFound = true;
238
239 if( bCurrentHasLine && (!m_bHasLines) )
240 {
241 bResult = false;
242 break;
243 }
244 }
245 catch( const uno::Exception & )
246 {
247 DBG_UNHANDLED_EXCEPTION("chart2");
248 }
249 }
250
251 if(bResult)
252 {
253 if( !bLineFound && m_bHasLines && bSymbolFound )
254 bResult = false;
255 else if( !bSymbolFound && m_bHasSymbols && bLineFound )
256 bResult = false;
257 else if( !bLineFound && !bSymbolFound )
258 return m_bHasLines && m_bHasSymbols;
259 }
260 }
261
262 // adapt curve style, spline order and resolution
263 if( bResult && bAdaptProperties )
264 {
265 try
266 {
267 rtl::Reference< ChartType > xChartTypeProp =
268 xDiagram->getChartTypeByIndex(0);
269 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_STYLE) );
270 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION) );
271 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(CHART_UNONAME_SPLINE_ORDER) );
272 }
273 catch( const uno::Exception & )
274 {
275 DBG_UNHANDLED_EXCEPTION("chart2");
276 }
277 }
278
279 return bResult;
280}
281
283{
285
286 try
287 {
288 xResult = new ScatterChartType();
289
290 xResult->setPropertyValue(
291 CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE ));
292 xResult->setPropertyValue(
293 CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
294 xResult->setPropertyValue(
295 CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER ));
296 }
297 catch( const uno::Exception & )
298 {
299 DBG_UNHANDLED_EXCEPTION("chart2");
300 }
301
302 return xResult;
303}
304
306 const std::vector< rtl::Reference< ChartType > >& aFormerlyUsedChartTypes )
307{
309
310 try
311 {
312 xResult = new ScatterChartType();
313
314 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult );
315
316 xResult->setPropertyValue(
317 CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE ));
318 xResult->setPropertyValue(
319 CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
320 xResult->setPropertyValue(
321 CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER ));
322 }
323 catch( const uno::Exception & )
324 {
325 DBG_UNHANDLED_EXCEPTION("chart2");
326 }
327
328 return xResult;
329}
330
332{
333 if( ! m_xDataInterpreter.is())
335
336 return m_xDataInterpreter;
337}
338
341
342} // namespace chart
343
344/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
For creating diagrams and modifying existing diagrams.
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties)
static void copyPropertiesFromOldToNewCoordinateSystem(const std::vector< rtl::Reference< ChartType > > &rOldChartTypesSeq, const rtl::Reference< ChartType > &xNewChartType)
rtl::Reference< ::chart::DataInterpreter > m_xDataInterpreter
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount)
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
merge XInterface implementations
virtual rtl::Reference< ::chart::ChartType > getChartTypeForIndex(sal_Int32 nChartTypeIndex) override
virtual rtl::Reference< ::chart::ChartType > getChartTypeForNewSeries2(const std::vector< rtl::Reference< ::chart::ChartType > > &aFormerlyUsedChartTypes) override
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties) override
virtual sal_Int32 getDimension() const override
returns 2 by default. Supported are 2 and 3
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeGroupIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount) override
virtual StackMode getStackMode(sal_Int32 nChartTypeIndex) const override
returns StackMode::NONE by default.
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual sal_Bool SAL_CALL supportsCategories() override
denotes if the chart needs categories at the first scale
ScatterChartTypeTemplate(css::uno::Reference< css::uno::XComponentContext > const &xContext, const OUString &rServiceName, bool bSymbols, bool bHasLines=true, sal_Int32 nDim=2)
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual rtl::Reference< ::chart::DataInterpreter > getDataInterpreter2() override
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
css::uno::Type const & get()
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
The same as getFastPropertyValue, but return the value through rValue and nHandle is always valid.
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS void switchLinesOnOrOff(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bLinesOn)
OOO_DLLPUBLIC_CHARTTOOLS void setPropertyAlsoToAllAttributedDataPoints(const rtl::Reference< ::chart::DataSeries > &xSeries, const OUString &rPropertyName, const css::uno::Any &rPropertyValue)
OOO_DLLPUBLIC_CHARTTOOLS void makeLinesThickOrThin(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bThick)
OOO_DLLPUBLIC_CHARTTOOLS void switchSymbolsOnOrOff(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bSymbolsOn, sal_Int32 nSeriesIndex)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
unsigned char sal_Bool
constexpr OUStringLiteral CHART_UNONAME_SPLINE_ORDER
Definition: unonames.hxx:16
constexpr OUStringLiteral CHART_UNONAME_CURVE_STYLE
Definition: unonames.hxx:18
constexpr OUStringLiteral CHART_UNONAME_CURVE_RESOLUTION
Definition: unonames.hxx:19