LibreOffice Module chart2 (master) 1
ErrorBar.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
20#include <ErrorBar.hxx>
22#include <CloneHelper.hxx>
24
27#include <svl/itemprop.hxx>
28#include <vcl/svapp.hxx>
29
30#include <com/sun/star/chart/ErrorBarStyle.hpp>
31
32#include <com/sun/star/drawing/LineStyle.hpp>
33#include <com/sun/star/util/Color.hpp>
34#include <com/sun/star/drawing/LineJoint.hpp>
35
37#include <sal/log.hxx>
38
39using namespace ::com::sun::star;
40
41namespace
42{
43
44constexpr OUStringLiteral lcl_aServiceName = u"com.sun.star.comp.chart2.ErrorBar";
45
46bool lcl_isInternalData( const uno::Reference< chart2::data::XLabeledDataSequence > & xLSeq )
47{
48 uno::Reference< lang::XServiceInfo > xServiceInfo( xLSeq, uno::UNO_QUERY );
49 return ( xServiceInfo.is() && xServiceInfo->getImplementationName() == "com.sun.star.comp.chart2.LabeledDataSequence" );
50}
51
52const SfxItemPropertySet* GetErrorBarPropertySet()
53{
54 static const SfxItemPropertyMapEntry aErrorBarPropertyMap_Impl[] =
55 {
56 {u"ShowPositiveError",0,cppu::UnoType<bool>::get(), 0, 0},
57 {u"ShowNegativeError",1,cppu::UnoType<bool>::get(), 0, 0},
58 {u"PositiveError",2,cppu::UnoType<double>::get(),0,0},
59 {u"NegativeError",3,cppu::UnoType<double>::get(), 0, 0},
60 {u"PercentageError",4,cppu::UnoType<double>::get(), 0, 0},
61 {u"ErrorBarStyle",5,cppu::UnoType<sal_Int32>::get(),0,0},
62 {u"ErrorBarRangePositive",6,cppu::UnoType<OUString>::get(),0,0}, // read-only for export
63 {u"ErrorBarRangeNegative",7,cppu::UnoType<OUString>::get(),0,0}, // read-only for export
64 {u"Weight",8,cppu::UnoType<double>::get(),0,0},
66 {u"LineDash",10,cppu::UnoType<drawing::LineDash>::get(),0,0},
67 {u"LineWidth",11,cppu::UnoType<sal_Int32>::get(),0,0},
68 {u"LineColor",12,cppu::UnoType<css::util::Color>::get(),0,0},
69 {u"LineTransparence",13,cppu::UnoType<sal_Int16>::get(),0,0},
71 };
72 static SfxItemPropertySet aPropSet( aErrorBarPropertyMap_Impl );
73 return &aPropSet;
74}
75
76} // anonymous namespace
77
78namespace chart
79{
80
82 mnLineWidth(0),
83 meLineStyle(drawing::LineStyle_SOLID),
84 maLineColor(0),
85 mnLineTransparence(0),
86 meLineJoint(drawing::LineJoint_ROUND),
87 mbShowPositiveError(true),
88 mbShowNegativeError(true),
89 mfPositiveError(0),
90 mfNegativeError(0),
91 mfWeight(1),
92 meStyle(css::chart::ErrorBarStyle::NONE),
93 m_xModifyEventForwarder( new ModifyEventForwarder() )
94{}
95
96ErrorBar::ErrorBar( const ErrorBar & rOther ) :
97 impl::ErrorBar_Base(rOther),
98 maDashName(rOther.maDashName),
99 maLineDash(rOther.maLineDash),
100 mnLineWidth(rOther.mnLineWidth),
101 meLineStyle(rOther.meLineStyle),
102 maLineColor(rOther.maLineColor),
103 mnLineTransparence(rOther.mnLineTransparence),
104 meLineJoint(rOther.meLineJoint),
105 mbShowPositiveError(rOther.mbShowPositiveError),
106 mbShowNegativeError(rOther.mbShowNegativeError),
107 mfPositiveError(rOther.mfPositiveError),
108 mfNegativeError(rOther.mfNegativeError),
109 mfWeight(rOther.mfWeight),
110 meStyle(rOther.meStyle),
111 m_xModifyEventForwarder( new ModifyEventForwarder() )
112{
113 if( ! rOther.m_aDataSequences.empty())
114 {
115 if( lcl_isInternalData( rOther.m_aDataSequences.front()))
116 CloneHelper::CloneRefVector< css::chart2::data::XLabeledDataSequence >(
118 else
121 }
122}
123
125{}
126
128{
129 return uno::Reference< util::XCloneable >( new ErrorBar( *this ));
130}
131
132// ____ XPropertySet ____
134{
136 new SfxItemPropertySetInfo( GetErrorBarPropertySet()->getPropertyMap() ) );
137 return aRef;
138}
139
140void ErrorBar::setPropertyValue( const OUString& rPropName, const uno::Any& rAny )
141{
142 SolarMutexGuard aGuard;
143
144 if(rPropName == "ErrorBarStyle")
145 rAny >>= meStyle;
146 else if(rPropName == "PositiveError")
147 rAny >>= mfPositiveError;
148 else if(rPropName == "PercentageError")
149 {
150 rAny >>= mfPositiveError;
151 rAny >>= mfNegativeError;
152 }
153 else if(rPropName == "Weight")
154 {
155 rAny >>= mfWeight;
156 }
157 else if(rPropName == "NegativeError")
158 rAny >>= mfNegativeError;
159 else if(rPropName == "ShowPositiveError")
160 rAny >>= mbShowPositiveError;
161 else if(rPropName == "ShowNegativeError")
162 rAny >>= mbShowNegativeError;
163 else if(rPropName == "ErrorBarRangePositive" || rPropName == "ErrorBarRangeNegative")
164 throw beans::UnknownPropertyException("read-only property", static_cast< uno::XWeak*>(this));
165 else if(rPropName == "LineDashName")
166 rAny >>= maDashName;
167 else if(rPropName == "LineDash")
168 rAny >>= maLineDash;
169 else if(rPropName == "LineWidth")
170 rAny >>= mnLineWidth;
171 else if(rPropName == "LineStyle")
172 rAny >>= meLineStyle;
173 else if(rPropName == "LineColor")
174 rAny >>= maLineColor;
175 else if(rPropName == "LineTransparence")
176 rAny >>= mnLineTransparence;
177 else if(rPropName == "LineJoint")
178 rAny >>= meLineJoint;
179
180 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
181}
182
183namespace {
184
185OUString getSourceRangeStrFromLabeledSequences( const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > >& aSequences, bool bPositive )
186{
187 OUString aDirection;
188 if(bPositive)
189 aDirection = "positive";
190 else
191 aDirection = "negative";
192
193 for( uno::Reference< chart2::data::XLabeledDataSequence > const & labeledData : aSequences )
194 {
195 try
196 {
197 if( labeledData.is())
198 {
199 uno::Reference< chart2::data::XDataSequence > xSequence( labeledData->getValues());
200 uno::Reference< beans::XPropertySet > xSeqProp( xSequence, uno::UNO_QUERY_THROW );
201 OUString aRole;
202 if( ( xSeqProp->getPropertyValue( "Role" ) >>= aRole ) &&
203 aRole.match( "error-bars" ) && aRole.indexOf(aDirection) >= 0 )
204 {
205 return xSequence->getSourceRangeRepresentation();
206 }
207 }
208 }
209 catch (uno::Exception const &)
210 {
211 // we can't be sure that this is 100% safe and we don't want to kill the export
212 // we should at least check why the exception is thrown
213 TOOLS_WARN_EXCEPTION("chart2", "unexpected exception");
214 }
215 catch (...)
216 {
217 // we can't be sure that this is 100% safe and we don't want to kill the export
218 // we should at least check why the exception is thrown
219 SAL_WARN("chart2", "unexpected exception! ");
220 }
221 }
222
223 return OUString();
224}
225
226}
227
228uno::Any ErrorBar::getPropertyValue(const OUString& rPropName)
229{
230 SolarMutexGuard aGuard;
231
232 uno::Any aRet;
233 if(rPropName == "ErrorBarStyle")
234 aRet <<= meStyle;
235 else if(rPropName == "PositiveError")
236 aRet <<= mfPositiveError;
237 else if(rPropName == "NegativeError")
238 aRet <<= mfNegativeError;
239 else if(rPropName == "PercentageError")
240 aRet <<= mfPositiveError;
241 else if(rPropName == "ShowPositiveError")
242 aRet <<= mbShowPositiveError;
243 else if(rPropName == "ShowNegativeError")
244 aRet <<= mbShowNegativeError;
245 else if(rPropName == "Weight")
246 aRet <<= mfWeight;
247 else if(rPropName == "ErrorBarRangePositive")
248 {
249 OUString aRange;
250 if(meStyle == css::chart::ErrorBarStyle::FROM_DATA)
251 {
254
255 aRange = getSourceRangeStrFromLabeledSequences( aSequences, true );
256 }
257
258 aRet <<= aRange;
259 }
260 else if(rPropName == "ErrorBarRangeNegative")
261 {
262 OUString aRange;
263 if(meStyle == css::chart::ErrorBarStyle::FROM_DATA)
264 {
267
268 aRange = getSourceRangeStrFromLabeledSequences( aSequences, false );
269 }
270
271 aRet <<= aRange;
272 }
273 else if(rPropName == "LineDashName")
274 aRet <<= maDashName;
275 else if(rPropName == "LineDash")
276 aRet <<= maLineDash;
277 else if(rPropName == "LineWidth")
278 aRet <<= mnLineWidth;
279 else if(rPropName == "LineStyle")
280 aRet <<= meLineStyle;
281 else if(rPropName == "LineColor")
282 aRet <<= maLineColor;
283 else if(rPropName == "LineTransparence")
284 aRet <<= mnLineTransparence;
285 else if(rPropName == "LineJoint")
286 aRet <<= meLineJoint;
287
288 SAL_WARN_IF(!aRet.hasValue(), "chart2", "asked for property value: " << rPropName);
289 return aRet;
290}
291
292beans::PropertyState ErrorBar::getPropertyState( const OUString& rPropName )
293{
294 if(rPropName == "ErrorBarStyle")
295 {
296 if(meStyle == css::chart::ErrorBarStyle::NONE)
297 return beans::PropertyState_DEFAULT_VALUE;
298 return beans::PropertyState_DIRECT_VALUE;
299 }
300 else if(rPropName == "PositiveError")
301 {
303 {
304 switch(meStyle)
305 {
306 case css::chart::ErrorBarStyle::ABSOLUTE:
307 case css::chart::ErrorBarStyle::ERROR_MARGIN:
308 return beans::PropertyState_DIRECT_VALUE;
309 default:
310 break;
311 }
312 }
313 return beans::PropertyState_DEFAULT_VALUE;
314 }
315 else if(rPropName == "NegativeError")
316 {
318 {
319 switch(meStyle)
320 {
321 case css::chart::ErrorBarStyle::ABSOLUTE:
322 case css::chart::ErrorBarStyle::ERROR_MARGIN:
323 return beans::PropertyState_DIRECT_VALUE;
324 default:
325 break;
326 }
327 }
328 return beans::PropertyState_DEFAULT_VALUE;
329 }
330 else if(rPropName == "PercentageError")
331 {
332 if(meStyle != css::chart::ErrorBarStyle::RELATIVE)
333 return beans::PropertyState_DEFAULT_VALUE;
334 return beans::PropertyState_DIRECT_VALUE;
335 }
336 else if(rPropName == "ShowPositiveError")
337 {
338 // this value should be never default
339 return beans::PropertyState_DIRECT_VALUE;
340 }
341 else if(rPropName == "ShowNegativeError")
342 {
343 // this value should be never default
344 return beans::PropertyState_DIRECT_VALUE;
345 }
346 else if(rPropName == "ErrorBarRangePositive")
347 {
348 if(meStyle == css::chart::ErrorBarStyle::FROM_DATA && mbShowPositiveError)
349 return beans::PropertyState_DIRECT_VALUE;
350 return beans::PropertyState_DEFAULT_VALUE;
351 }
352 else if(rPropName == "ErrorBarRangeNegative")
353 {
354 if(meStyle == css::chart::ErrorBarStyle::FROM_DATA && mbShowNegativeError)
355 return beans::PropertyState_DIRECT_VALUE;
356 return beans::PropertyState_DEFAULT_VALUE;
357 }
358 else
359 return beans::PropertyState_DIRECT_VALUE;
360}
361
363{
364 uno::Sequence< beans::PropertyState > aRet( rPropNames.getLength() );
365 auto aRetRange = asNonConstRange(aRet);
366 for(sal_Int32 i = 0; i < rPropNames.getLength(); ++i)
367 {
368 aRetRange[i] = getPropertyState(rPropNames[i]);
369 }
370 return aRet;
371}
372
373void ErrorBar::setPropertyToDefault( const OUString& )
374{
375 //keep them unimplemented for now
376}
377
379{
380 //keep them unimplemented for now
381 return uno::Any();
382}
383
384void ErrorBar::addPropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& )
385{
386}
387
388void ErrorBar::removePropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& )
389{
390}
391
392void ErrorBar::addVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& )
393{
394}
395
396void ErrorBar::removeVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& )
397{
398}
399
400// ____ XModifyBroadcaster ____
402{
403 m_xModifyEventForwarder->addModifyListener( aListener );
404}
405
407{
408 m_xModifyEventForwarder->removeModifyListener( aListener );
409}
410
411// ____ XModifyListener ____
412void SAL_CALL ErrorBar::modified( const lang::EventObject& aEvent )
413{
414 m_xModifyEventForwarder->modified( aEvent );
415}
416
417// ____ XEventListener (base of XModifyListener) ____
418void SAL_CALL ErrorBar::disposing( const lang::EventObject& /* Source */ )
419{
420 // nothing
421}
422
423// ____ XDataSink ____
425{
428 m_aDataSequences = comphelper::sequenceToContainer<tDataSequenceContainer>( aData );
431}
432
433// ____ XDataSource ____
435{
437}
438
440{
441 return lcl_aServiceName;
442}
443
444sal_Bool SAL_CALL ErrorBar::supportsService( const OUString& rServiceName )
445{
446 return cppu::supportsService(this, rServiceName);
447}
448
449css::uno::Sequence< OUString > SAL_CALL ErrorBar::getSupportedServiceNames()
450{
451 return {
452 lcl_aServiceName,
453 "com.sun.star.chart2.ErrorBar"
454 };
455}
456
457// needed by MSC compiler
459
460} // namespace chart
461
462extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
464 css::uno::Sequence<css::uno::Any> const &)
465{
466 return cppu::acquire(new ::chart::ErrorBar);
467}
468
469/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_ErrorBar_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: ErrorBar.cxx:463
AnyEventRef aEvent
tDataSequenceContainer m_aDataSequences
Definition: ErrorBar.hxx:130
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: ErrorBar.cxx:396
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: ErrorBar.cxx:127
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: ErrorBar.cxx:384
sal_Int16 mnLineTransparence
Definition: ErrorBar.hxx:67
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
Definition: ErrorBar.cxx:439
css::util::Color maLineColor
Definition: ErrorBar.hxx:66
double mfWeight
Definition: ErrorBar.hxx:73
bool mbShowPositiveError
Definition: ErrorBar.hxx:69
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ErrorBar.cxx:449
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: ErrorBar.cxx:140
virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override
Definition: ErrorBar.cxx:434
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &rPropName) override
Definition: ErrorBar.cxx:378
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
Definition: ErrorBar.cxx:418
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: ErrorBar.cxx:392
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: ErrorBar.cxx:228
virtual void SAL_CALL setData(const css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &aData) override
Definition: ErrorBar.cxx:424
double mfPositiveError
Definition: ErrorBar.hxx:71
double mfNegativeError
Definition: ErrorBar.hxx:72
virtual void SAL_CALL setPropertyToDefault(const OUString &rPropName) override
Definition: ErrorBar.cxx:373
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: ErrorBar.cxx:406
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: ErrorBar.cxx:401
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: ErrorBar.cxx:133
virtual ~ErrorBar() override
Definition: ErrorBar.cxx:124
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
Definition: ErrorBar.cxx:412
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: ErrorBar.cxx:388
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &rPropName) override
Definition: ErrorBar.cxx:292
sal_Int32 meStyle
Definition: ErrorBar.hxx:74
css::drawing::LineDash maLineDash
Definition: ErrorBar.hxx:63
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &rPropNames) override
Definition: ErrorBar.cxx:362
css::drawing::LineJoint meLineJoint
Definition: ErrorBar.hxx:68
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
Definition: ErrorBar.hxx:132
OOO_DLLPUBLIC_CHARTTOOLS ErrorBar()
Definition: ErrorBar.cxx:81
css::drawing::LineStyle meLineStyle
Definition: ErrorBar.hxx:65
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: ErrorBar.cxx:444
sal_Int32 mnLineWidth
Definition: ErrorBar.hxx:64
bool mbShowNegativeError
Definition: ErrorBar.hxx:70
OUString maDashName
Definition: ErrorBar.hxx:62
This helper class serves as forwarder of modify events.
css::uno::Type const & get()
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
constexpr OUStringLiteral aData
NONE
void addListenerToAllElements(const Container &rContainer, const css::uno::Reference< css::lang::XEventListener > &xListener)
void removeListenerFromAllElements(const Container &rContainer, const css::uno::Reference< css::lang::XEventListener > &xListener)
void removeListenerFromAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListenerToAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
::cppu::WeakImplHelper< css::lang::XServiceInfo, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener, css::chart2::data::XDataSource, css::chart2::data::XDataSink, css::beans::XPropertySet, css::beans::XPropertyState > ErrorBar_Base
Definition: ErrorBar.hxx:56
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
bool hasValue()
css::drawing::Direction3D aDirection
unsigned char sal_Bool