LibreOffice Module chart2 (master) 1
LineChartTypeTemplate.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 "LineChartType.hxx"
22#include <Diagram.hxx>
23#include <DiagramHelper.hxx>
24#include <DataSeries.hxx>
25#include <DataSeriesHelper.hxx>
26#include <PropertyHelper.hxx>
27#include <ChartType.hxx>
28#include <unonames.hxx>
29
30#include <com/sun/star/chart2/CurveStyle.hpp>
31#include <com/sun/star/chart2/SymbolStyle.hpp>
32#include <com/sun/star/chart2/Symbol.hpp>
33#include <com/sun/star/drawing/LineStyle.hpp>
34#include <com/sun/star/beans/PropertyAttribute.hpp>
35#include <com/sun/star/uno/XComponentContext.hpp>
37
38#include <algorithm>
39
40using namespace ::com::sun::star;
41
42using ::com::sun::star::uno::Reference;
43using ::com::sun::star::uno::Sequence;
44using ::com::sun::star::beans::Property;
45
46namespace
47{
48
49enum
50{
51 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE,
52 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
53 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
54
55};
56
57::chart::tPropertyValueMap& StaticLineChartTypeTemplateDefaults()
58{
59 static ::chart::tPropertyValueMap aStaticDefaults =
60 []()
61 {
63 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES );
64 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 );
65
66 // todo: check whether order 3 means polygons of order 3 or 2. (see
67 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
68 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 );
69 return aOutMap;
70 }();
71 return aStaticDefaults;
72}
73
74::cppu::OPropertyArrayHelper& StaticLineChartTypeTemplateInfoHelper()
75{
76 static ::cppu::OPropertyArrayHelper aPropHelper(
77 []()
78 {
79 std::vector< css::beans::Property > aProperties {
81 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE,
83 beans::PropertyAttribute::BOUND
84 | beans::PropertyAttribute::MAYBEDEFAULT },
86 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
88 beans::PropertyAttribute::BOUND
89 | beans::PropertyAttribute::MAYBEDEFAULT },
91 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER,
93 beans::PropertyAttribute::BOUND
94 | beans::PropertyAttribute::MAYBEDEFAULT } };
95 std::sort( aProperties.begin(), aProperties.end(),
97
98 return comphelper::containerToSequence( aProperties );
99 }());
100 return aPropHelper;
101}
102
103uno::Reference< beans::XPropertySetInfo >& StaticLineChartTypeTemplateInfo()
104{
105 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
106 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticLineChartTypeTemplateInfoHelper() ) );
107 return xPropertySetInfo;
108}
109
110} // anonymous namespace
111
112namespace chart
113{
114
117 uno::XComponentContext > const & xContext,
118 const OUString & rServiceName,
119 StackMode eStackMode,
120 bool bSymbols,
121 bool bHasLines /* = true */,
122 sal_Int32 nDim /* = 2 */ ) :
123 ChartTypeTemplate( xContext, rServiceName ),
124 m_eStackMode( eStackMode ),
125 m_bHasSymbols( bSymbols ),
126 m_bHasLines( bHasLines ),
127 m_nDim( nDim )
128{
129 if( nDim == 3 )
130 m_bHasSymbols = false;
131}
132
134{}
135
136// ____ OPropertySet ____
137void LineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
138{
139 const tPropertyValueMap& rStaticDefaults = StaticLineChartTypeTemplateDefaults();
140 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
141 if( aFound == rStaticDefaults.end() )
142 rAny.clear();
143 else
144 rAny = (*aFound).second;
145}
146
148{
149 return StaticLineChartTypeTemplateInfoHelper();
150}
151
152// ____ XPropertySet ____
154{
155 return StaticLineChartTypeTemplateInfo();
156}
157
159{
160 return m_nDim;
161}
162
163StackMode LineChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
164{
165 return m_eStackMode;
166}
167
168// ____ ChartTypeTemplate ____
171 bool bAdaptProperties )
172{
173 bool bResult = ChartTypeTemplate::matchesTemplate2( xDiagram, bAdaptProperties );
174
175 // check symbol-style and line-style
176 // for a template with symbols (or with lines) it is ok, if there is at least one series
177 // with symbols (or with lines)
178 if( bResult )
179 {
180 bool bSymbolFound = false;
181 bool bLineFound = false;
182
183 std::vector< rtl::Reference< DataSeries > > aSeriesVec =
184 xDiagram->getDataSeries();
185
186 for (auto const& series : aSeriesVec)
187 {
188 try
189 {
190 chart2::Symbol aSymbProp;
191 drawing::LineStyle eLineStyle;
192
193 bool bCurrentHasSymbol = (series->getPropertyValue( "Symbol") >>= aSymbProp) &&
194 (aSymbProp.Style != chart2::SymbolStyle_NONE);
195
196 if( bCurrentHasSymbol )
197 bSymbolFound = true;
198
199 if( bCurrentHasSymbol && (!m_bHasSymbols) )
200 {
201 bResult = false;
202 break;
203 }
204
205 bool bCurrentHasLine = (series->getPropertyValue( "LineStyle") >>= eLineStyle) &&
206 ( eLineStyle != drawing::LineStyle_NONE );
207
208 if( bCurrentHasLine )
209 bLineFound = true;
210
211 if( bCurrentHasLine && (!m_bHasLines) )
212 {
213 bResult = false;
214 break;
215 }
216 }
217 catch( const uno::Exception & )
218 {
219 DBG_UNHANDLED_EXCEPTION("chart2");
220 }
221 }
222
223 if(bResult)
224 {
225 if( !bLineFound && m_bHasLines && bSymbolFound )
226 bResult = false;
227 else if( !bSymbolFound && m_bHasSymbols && bLineFound )
228 bResult = false;
229 else if( !bLineFound && !bSymbolFound )
230 return m_bHasLines && m_bHasSymbols;
231 }
232 }
233
234 // adapt curve style, spline order and resolution
235 if( bResult && bAdaptProperties )
236 {
237 try
238 {
239 rtl::Reference< ChartType > xChartType = xDiagram->getChartTypeByIndex( 0 );
240 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, xChartType->getPropertyValue(CHART_UNONAME_CURVE_STYLE) );
241 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartType->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION) );
242 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartType->getPropertyValue(CHART_UNONAME_SPLINE_ORDER) );
243 }
244 catch( const uno::Exception & )
245 {
246 DBG_UNHANDLED_EXCEPTION("chart2");
247 }
248 }
249
250 return bResult;
251}
252
254{
256
257 try
258 {
259 xResult = new LineChartType();
260
261 xResult->setPropertyValue(
262 CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE ));
263 xResult->setPropertyValue(
264 CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
265 xResult->setPropertyValue(
266 CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER ));
267 }
268 catch( const uno::Exception & )
269 {
270 DBG_UNHANDLED_EXCEPTION("chart2");
271 }
272
273 return xResult;
274}
275
277 const std::vector< rtl::Reference< ChartType > >& aFormerlyUsedChartTypes )
278{
280
281 try
282 {
283 xResult = new LineChartType();
284
285 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult );
286
287 xResult->setPropertyValue(
288 CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE ));
289 xResult->setPropertyValue(
290 CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
291 xResult->setPropertyValue(
292 CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER ));
293 }
294 catch( const uno::Exception & )
295 {
296 DBG_UNHANDLED_EXCEPTION("chart2");
297 }
298
299 return xResult;
300}
301
303 const rtl::Reference< DataSeries >& xSeries,
304 ::sal_Int32 nChartTypeIndex,
305 ::sal_Int32 nSeriesIndex,
306 ::sal_Int32 nSeriesCount )
307{
308 ChartTypeTemplate::applyStyle2( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
309
310 try
311 {
315 }
316 catch( const uno::Exception & )
317 {
318 DBG_UNHANDLED_EXCEPTION("chart2");
319 }
320}
321
324
325} // namespace chart
326
327/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StackMode m_eStackMode
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)
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount)
virtual sal_Int32 getDimension() const override
returns 2 by default. Supported are 2 and 3
LineChartTypeTemplate(css::uno::Reference< css::uno::XComponentContext > const &xContext, const OUString &rServiceName, StackMode eStackMode, bool bSymbols, bool bHasLines=true, sal_Int32 nDim=2)
virtual rtl::Reference< ::chart::ChartType > getChartTypeForIndex(sal_Int32 nChartTypeIndex) override
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
merge XInterface implementations
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeGroupIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual StackMode getStackMode(sal_Int32 nChartTypeIndex) const override
returns StackMode::NONE by default.
virtual rtl::Reference< ::chart::ChartType > getChartTypeForNewSeries2(const std::vector< rtl::Reference< ::chart::ChartType > > &aFormerlyUsedChartTypes) 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 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
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