LibreOffice Module chart2 (master) 1
DataPoint.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 "DataPoint.hxx"
24#include <PropertyHelper.hxx>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/uno/Sequence.hxx>
30
31#include <algorithm>
32
33using namespace ::com::sun::star;
34
35using ::com::sun::star::uno::Reference;
36using ::com::sun::star::uno::Sequence;
37using ::com::sun::star::beans::Property;
38
39namespace
40{
41
42::cppu::OPropertyArrayHelper& StaticDataPointInfoHelper()
43{
44 static ::cppu::OPropertyArrayHelper aPropHelper = []()
45 {
46 std::vector< css::beans::Property > aProperties;
50
51 std::sort( aProperties.begin(), aProperties.end(),
53
54 return comphelper::containerToSequence( aProperties );
55 }();
56 return aPropHelper;
57};
58
59} // anonymous namespace
60
61namespace chart
62{
63
64DataPoint::DataPoint( const uno::Reference< beans::XPropertySet > & rParentProperties ) :
65 m_xParentProperties( rParentProperties ),
66 m_xModifyEventForwarder( new ModifyEventForwarder() ),
67 m_bNoParentPropAllowed( false )
68{
69 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
70}
71
72DataPoint::DataPoint( const DataPoint & rOther ) :
73 impl::DataPoint_Base(rOther),
74 ::property::OPropertySet( rOther ),
75 m_xModifyEventForwarder( new ModifyEventForwarder() ),
76 m_bNoParentPropAllowed( true )
77{
79
80 // m_xParentProperties has to be set from outside, like in the method
81 // DataSeries::createClone
82
83 // add as listener to XPropertySet properties
85 uno::Any aValue;
86
88 if( ( aValue >>= xPropertySet )
89 && xPropertySet.is())
91
93 if( ( aValue >>= xPropertySet )
94 && xPropertySet.is())
96
98}
99
101{
102 try
103 {
104 // remove listener from XPropertySet properties
106 uno::Any aValue;
107
109 if( ( aValue >>= xPropertySet )
110 && xPropertySet.is())
112
114 if( ( aValue >>= xPropertySet )
115 && xPropertySet.is())
117 }
118 catch( const uno::Exception & )
119 {
120 DBG_UNHANDLED_EXCEPTION("chart2");
121 }
122}
123
124// ____ XCloneable ____
126{
127 return uno::Reference< util::XCloneable >( new DataPoint( *this ));
128}
129
130// ____ XChild ____
132{
133 return Reference< uno::XInterface >( m_xParentProperties.get(), uno::UNO_QUERY );
134}
135
137 const Reference< uno::XInterface >& Parent )
138{
140}
141
142// ____ OPropertySet ____
143void DataPoint::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
144{
145 // the value set at the data series is the default
147 if( !xFast.is())
148 {
149 OSL_ENSURE( m_bNoParentPropAllowed, "data point needs a parent property set to provide values correctly" );
150 rAny.clear();
151 return;
152 }
153
154 rAny = xFast->getFastPropertyValue( nHandle );
155}
156
158 sal_Int32 nHandle, const uno::Any& rValue )
159{
162 {
163 uno::Any aOldValue;
165 getFastPropertyValue( aOldValue, nHandle );
166 if( aOldValue.hasValue() &&
167 (aOldValue >>= xBroadcaster) &&
168 xBroadcaster.is())
169 {
171 }
172
173 OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
174 if( rValue.hasValue() &&
175 (rValue >>= xBroadcaster) &&
176 xBroadcaster.is())
177 {
179 }
180 }
181
183}
184
186{
187 return StaticDataPointInfoHelper();
188}
189
190// ____ XPropertySet ____
192{
193 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
194 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticDataPointInfoHelper() ) );
195 return xPropertySetInfo;
196}
197
198// ____ XModifyBroadcaster ____
200{
201 m_xModifyEventForwarder->addModifyListener( aListener );
202}
203
205{
206 m_xModifyEventForwarder->removeModifyListener( aListener );
207}
208
209// ____ XModifyListener ____
210void SAL_CALL DataPoint::modified( const lang::EventObject& aEvent )
211{
212 m_xModifyEventForwarder->modified( aEvent );
213}
214
215// ____ XEventListener (base of XModifyListener) ____
216void SAL_CALL DataPoint::disposing( const lang::EventObject& )
217{
218 // nothing
219}
220
221// ____ OPropertySet ____
223{
224 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
225}
226
227// needed by MSC compiler
229
231
232// implement XServiceInfo methods basing upon getSupportedServiceNames_Static
233OUString SAL_CALL DataPoint::getImplementationName()
234{
235 return "com.sun.star.comp.chart.DataPoint" ;
236}
237
238sal_Bool SAL_CALL DataPoint::supportsService( const OUString& rServiceName )
239{
240 return cppu::supportsService(this, rServiceName);
241}
242
243css::uno::Sequence< OUString > SAL_CALL DataPoint::getSupportedServiceNames()
244{
245 return {
246 "com.sun.star.drawing.FillProperties",
247 "com.sun.star.chart2.DataPoint",
248 "com.sun.star.chart2.DataPointProperties",
249 "com.sun.star.beans.PropertySet"
250 };
251}
252
253} // namespace chart
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
AnyEventRef aEvent
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: DataPoint.cxx:243
bool m_bNoParentPropAllowed
Definition: DataPoint.hxx:104
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
Definition: DataPoint.cxx:131
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
Definition: DataPoint.cxx:222
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
Definition: DataPoint.cxx:157
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
Definition: DataPoint.cxx:143
DataPoint(const css::uno::Reference< css::beans::XPropertySet > &rParentProperties)
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
Definition: DataPoint.cxx:136
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
Definition: DataPoint.cxx:185
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
Definition: DataPoint.hxx:103
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: DataPoint.cxx:199
virtual ~DataPoint() override
Definition: DataPoint.cxx:100
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: DataPoint.cxx:191
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
Definition: DataPoint.cxx:210
css::uno::WeakReference< css::beans::XPropertySet > m_xParentProperties
Definition: DataPoint.hxx:101
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: DataPoint.cxx:125
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: DataPoint.cxx:238
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: DataPoint.cxx:204
This helper class serves as forwarder of modify events.
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL disposing()
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.
void SetNewValuesExplicitlyEvenIfTheyEqualDefault()
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 AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
::cppu::WeakImplHelper< css::container::XChild, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener, css::lang::XServiceInfo > DataPoint_Base
Definition: DataPoint.hxx:42
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
bool hasValue()
unsigned char sal_Bool