LibreOffice Module chart2 (master) 1
ChartType.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 <ChartType.hxx>
22#include <Axis.hxx>
23#include <AxisHelper.hxx>
24#include <CloneHelper.hxx>
25#include <AxisIndexDefines.hxx>
27#include <DataSeries.hxx>
28#include <vcl/svapp.hxx>
29#include <com/sun/star/chart2/AxisType.hpp>
30#include <com/sun/star/container/NoSuchElementException.hpp>
32
33using namespace ::com::sun::star;
34
35using ::com::sun::star::beans::Property;
36using ::com::sun::star::uno::Sequence;
37using ::com::sun::star::uno::Reference;
38
39namespace chart
40{
41
43 m_xModifyEventForwarder( new ModifyEventForwarder() ),
44 m_bNotifyChanges( true )
45{}
46
48 impl::ChartType_Base(rOther),
49 ::property::OPropertySet( rOther ),
50 m_xModifyEventForwarder( new ModifyEventForwarder() ),
51 m_bNotifyChanges( true )
52{
53 {
54 SolarMutexGuard g; // access to rOther.m_aDataSeries
57 }
59}
60
62{
64 m_aDataSeries.clear();
65}
66
67// ____ XChartType ____
69 ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
70{
71 return createCoordinateSystem2(DimensionCount);
72}
73
75 ChartType::createCoordinateSystem2( ::sal_Int32 DimensionCount )
76{
78 new CartesianCoordinateSystem( DimensionCount );
79
80 for( sal_Int32 i=0; i<DimensionCount; ++i )
81 {
82 rtl::Reference< Axis > xAxis = xResult->getAxisByDimension2( i, MAIN_AXIS_INDEX );
83 if( !xAxis.is() )
84 {
85 OSL_FAIL("a created coordinate system should have an axis for each dimension");
86 continue;
87 }
88
89 chart2::ScaleData aScaleData = xAxis->getScaleData();
90 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
91 aScaleData.Scaling = AxisHelper::createLinearScaling();
92
93 switch( i )
94 {
95 case 0: aScaleData.AxisType = chart2::AxisType::CATEGORY; break;
96 case 2: aScaleData.AxisType = chart2::AxisType::SERIES; break;
97 default: aScaleData.AxisType = chart2::AxisType::REALNUMBER; break;
98 }
99
100 xAxis->setScaleData( aScaleData );
101 }
102
103 return xResult;
104}
105
107{
108 return { "label", "values-y" };
109}
110
112{
113 return Sequence< OUString >();
114}
115
117{
118 return Sequence< OUString >();
119}
120
122{
123 return "values-y";
124}
125
127 const rtl::Reference< DataSeries >& xDataSeries )
128{
129 if( std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries )
130 != m_aDataSeries.end())
131 throw lang::IllegalArgumentException("dataseries not found", static_cast<cppu::OWeakObject*>(this), 1);
132
133 m_aDataSeries.push_back( xDataSeries );
135}
136
137// ____ XDataSeriesContainer ____
138void SAL_CALL ChartType::addDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
139{
140 rtl::Reference<DataSeries> xTmp = dynamic_cast<DataSeries*>(xDataSeries.get());
141 assert(xTmp);
142 addDataSeries(xTmp);
143}
144
146{
148
151}
152
153void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
154{
155 rtl::Reference<DataSeries> xTmp = dynamic_cast<DataSeries*>(xDataSeries.get());
156 assert(xTmp);
157 removeDataSeries(xTmp);
158}
159
161{
162 if( !xDataSeries.is())
163 throw container::NoSuchElementException();
164
166
167 auto aIt = std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries );
168
169 if( aIt == m_aDataSeries.end())
170 throw container::NoSuchElementException(
171 "The given series is no element of this charttype",
172 static_cast< uno::XWeak * >( this ));
173
175 m_aDataSeries.erase( aIt );
177}
178
180{
182
183 return comphelper::containerToSequence< Reference< chart2::XDataSeries > >( m_aDataSeries );
184}
185
186void SAL_CALL ChartType::setDataSeries( const Sequence< Reference< chart2::XDataSeries > >& aDataSeries )
187{
188 std::vector< rtl::Reference<DataSeries> > aTmp;
189 for (auto const & i : aDataSeries)
190 {
191 auto p = dynamic_cast<DataSeries*>(i.get());
192 assert(p);
193 aTmp.push_back(p);
194 }
195 setDataSeries(aTmp);
196}
197
198void ChartType::setDataSeries( const std::vector< rtl::Reference< DataSeries > >& aDataSeries )
199{
201
202 m_bNotifyChanges = false;
203 try
204 {
205 for( auto const & i : m_aDataSeries )
207 m_aDataSeries.clear();
208
209 for( auto const & i : aDataSeries )
211 }
212 catch( ... )
213 {
214 m_bNotifyChanges = true;
215 throw;
216 }
217 m_bNotifyChanges = true;
219}
220
221// ____ OPropertySet ____
222void ChartType::GetDefaultValue( sal_Int32 /* nHandle */, uno::Any& rAny ) const
223{
224 rAny.clear();
225}
226
227namespace
228{
229
230::cppu::OPropertyArrayHelper& StaticChartTypeInfoHelper()
231{
232 static ::cppu::OPropertyArrayHelper aPropHelper( Sequence< beans::Property >{} );
233 return aPropHelper;
234};
235
236}
237
238// ____ OPropertySet ____
240{
241 return StaticChartTypeInfoHelper();
242}
243
244// ____ XPropertySet ____
246{
247 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
248 ::cppu::OPropertySetHelper::createPropertySetInfo( StaticChartTypeInfoHelper() ) );
249 return xPropertySetInfo;
250}
251
252// ____ XModifyBroadcaster ____
254{
255 try
256 {
257 m_xModifyEventForwarder->addModifyListener( aListener );
258 }
259 catch( const uno::Exception & )
260 {
261 DBG_UNHANDLED_EXCEPTION("chart2");
262 }
263}
264
266{
267 try
268 {
269 m_xModifyEventForwarder->removeModifyListener( aListener );
270 }
271 catch( const uno::Exception & )
272 {
273 DBG_UNHANDLED_EXCEPTION("chart2");
274 }
275}
276
277// ____ XModifyListener ____
278void SAL_CALL ChartType::modified( const lang::EventObject& aEvent )
279{
280 m_xModifyEventForwarder->modified( aEvent );
281}
282
283// ____ XEventListener (base of XModifyListener) ____
284void SAL_CALL ChartType::disposing( const lang::EventObject& /* Source */ )
285{
286 // nothing
287}
288
289// ____ OPropertySet ____
291{
293}
294
296{
297 bool bNotifyChanges;
298
299 {
301 bNotifyChanges = m_bNotifyChanges;
302 }
303
304 if (bNotifyChanges)
305 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
306}
307
309
312
313} // namespace chart
314
315/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
static css::uno::Reference< css::chart2::XScaling > createLinearScaling()
Definition: AxisHelper.cxx:65
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedOptionalRoles() override
Definition: ChartType.cxx:111
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
merge XTypeProvider implementations
Definition: ChartType.hxx:142
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: ChartType.cxx:245
virtual void SAL_CALL setDataSeries(const css::uno::Sequence< css::uno::Reference< css::chart2::XDataSeries > > &aDataSeries) override
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
Definition: ChartType.cxx:278
void impl_addDataSeriesWithoutNotification(const rtl::Reference< ::chart::DataSeries > &aDataSeries)
Definition: ChartType.cxx:126
virtual void SAL_CALL removeDataSeries(const css::uno::Reference< css::chart2::XDataSeries > &aDataSeries) override
virtual css::uno::Sequence< css::uno::Reference< css::chart2::XDataSeries > > SAL_CALL getDataSeries() override
Definition: ChartType.cxx:179
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
Definition: ChartType.cxx:239
virtual rtl::Reference< ::chart::BaseCoordinateSystem > createCoordinateSystem2(sal_Int32 DimensionCount)
Definition: ChartType.cxx:75
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedPropertyRoles() override
Definition: ChartType.cxx:116
void fireModifyEvent()
Definition: ChartType.cxx:295
virtual void SAL_CALL addDataSeries(const css::uno::Reference< css::chart2::XDataSeries > &aDataSeries) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedMandatoryRoles() override
Definition: ChartType.cxx:106
virtual OUString SAL_CALL getRoleOfSequenceForSeriesLabel() override
Definition: ChartType.cxx:121
tDataSeriesContainerType m_aDataSeries
Definition: ChartType.hxx:154
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: ChartType.cxx:222
virtual ~ChartType() override
Definition: ChartType.cxx:61
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: ChartType.cxx:253
virtual css::uno::Reference< css::chart2::XCoordinateSystem > SAL_CALL createCoordinateSystem(::sal_Int32 DimensionCount) final override
Definition: ChartType.cxx:69
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
Definition: ChartType.cxx:290
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: ChartType.cxx:265
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()
#define DBG_UNHANDLED_EXCEPTION(...)
void * p
void CloneRefVector(const std::vector< css::uno::Reference< Interface > > &rSource, std::vector< css::uno::Reference< Interface > > &rDestination)
clones a vector of UNO-References
Definition: CloneHelper.hxx:48
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &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)
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
::cppu::WeakImplHelper< css::lang::XServiceInfo, css::chart2::XChartType, css::chart2::XDataSeriesContainer, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener > ChartType_Base
Definition: ChartType.hxx:58
const sal_Int32 MAIN_AXIS_INDEX
int i
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)