LibreOffice Module chart2 (master) 1
BaseCoordinateSystem.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 <PropertyHelper.hxx>
23#include <CloneHelper.hxx>
25#include <Axis.hxx>
26#include <ChartType.hxx>
27#include <com/sun/star/chart2/AxisType.hpp>
28#include <com/sun/star/container/NoSuchElementException.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30#include <o3tl/safeint.hxx>
32
33#include <algorithm>
34
35#include <com/sun/star/beans/PropertyAttribute.hpp>
36
37using namespace ::com::sun::star;
38using ::com::sun::star::uno::Reference;
39using ::com::sun::star::uno::Sequence;
40using ::com::sun::star::beans::Property;
41
42namespace
43{
44enum
45{
46 PROP_COORDINATESYSTEM_SWAPXANDYAXIS
47};
48
49void lcl_AddPropertiesToVector(
50 std::vector< Property > & rOutProperties )
51{
52 rOutProperties.emplace_back( "SwapXAndYAxis",
53 PROP_COORDINATESYSTEM_SWAPXANDYAXIS,
55 beans::PropertyAttribute::BOUND
56 | beans::PropertyAttribute::MAYBEVOID );
57}
58
59const ::chart::tPropertyValueMap & StaticCooSysDefaults()
60{
61 static ::chart::tPropertyValueMap aStaticDefaults = []()
62 {
64 ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_COORDINATESYSTEM_SWAPXANDYAXIS, false );
65 return aMap;
66 }();
67 return aStaticDefaults;
68};
69
70::cppu::OPropertyArrayHelper& StaticCooSysInfoHelper()
71{
72 static ::cppu::OPropertyArrayHelper aPropHelper = []()
73 {
74 std::vector< css::beans::Property > aProperties;
75 lcl_AddPropertiesToVector( aProperties );
77
78 std::sort( aProperties.begin(), aProperties.end(),
80
81 return comphelper::containerToSequence( aProperties );
82 }();
83 return aPropHelper;
84};
85
86} // anonymous namespace
87
88namespace chart
89{
90
92 sal_Int32 nDimensionCount /* = 2 */ ) :
93 m_xModifyEventForwarder( new ModifyEventForwarder() ),
94 m_nDimensionCount( nDimensionCount )
95 {
97 for( sal_Int32 nN=0; nN<m_nDimensionCount; nN++ )
98 {
99 m_aAllAxis[nN].resize( 1 );
100 rtl::Reference< Axis > xAxis( new Axis );
101 m_aAllAxis[nN][0] = xAxis;
102
104 chart2::ScaleData aScaleData( xAxis->getScaleData() );
105 if(nN==0)
106 {
107 aScaleData.AxisType = chart2::AxisType::CATEGORY;
108 }
109 else if( nN==1)
110 {
111 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
112 }
113 else if( nN==2)
114 {
115 aScaleData.AxisType = chart2::AxisType::SERIES;
116 }
117 xAxis->setScaleData( aScaleData );
118 }
119
120 setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS, uno::Any( false ));
121}
122
123// explicit
125 const BaseCoordinateSystem & rSource ) :
127 ::property::OPropertySet( rSource ),
128 m_xModifyEventForwarder( new ModifyEventForwarder() ),
129 m_nDimensionCount( rSource.m_nDimensionCount )
130{
131 m_aAllAxis.resize(rSource.m_aAllAxis.size());
132 tAxisVecVecType::size_type nN=0;
133 for( nN=0; nN<m_aAllAxis.size(); nN++ )
135 for (const auto & rxChartType : rSource.m_aChartTypes)
136 m_aChartTypes.push_back(rxChartType->cloneChartType());
137
138 for( nN=0; nN<m_aAllAxis.size(); nN++ )
140 for (const auto & rxChartType : m_aChartTypes)
141 rxChartType->addModifyListener( m_xModifyEventForwarder );
142}
143
145{
146 try
147 {
148 for(const tAxisVecVecType::value_type & i : m_aAllAxis)
150 for (const auto & rxChartType : m_aChartTypes)
151 rxChartType->removeModifyListener( m_xModifyEventForwarder );
152 }
153 catch( const uno::Exception & )
154 {
155 DBG_UNHANDLED_EXCEPTION("chart2" );
156 }
157}
158
159// ____ XCoordinateSystem ____
161{
162 return m_nDimensionCount;
163}
164
166 sal_Int32 nDimensionIndex,
167 const Reference< chart2::XAxis >& xAxis,
168 sal_Int32 nIndex )
169{
170 if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
171 throw lang::IndexOutOfBoundsException();
172
173 if( nIndex < 0 )
174 throw lang::IndexOutOfBoundsException();
175
176 assert(!xAxis || dynamic_cast<Axis*>(xAxis.get()));
177
178 if( m_aAllAxis[ nDimensionIndex ].size() < o3tl::make_unsigned( nIndex+1 ))
179 {
180 m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 );
181 m_aAllAxis[ nDimensionIndex ][nIndex] = nullptr;
182 }
183
184 rtl::Reference< Axis > xOldAxis( m_aAllAxis[ nDimensionIndex ][nIndex] );
185 if( xOldAxis.is())
187 m_aAllAxis[ nDimensionIndex ][nIndex] = dynamic_cast<Axis*>(xAxis.get());
188 if( xAxis.is())
191}
192
194 sal_Int32 nDimensionIndex,
195 const rtl::Reference< Axis >& xAxis,
196 sal_Int32 nIndex )
197{
198 if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
199 throw lang::IndexOutOfBoundsException();
200
201 if( nIndex < 0 )
202 throw lang::IndexOutOfBoundsException();
203
204 if( m_aAllAxis[ nDimensionIndex ].size() < o3tl::make_unsigned( nIndex+1 ))
205 {
206 m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 );
207 m_aAllAxis[ nDimensionIndex ][nIndex] = nullptr;
208 }
209
210 rtl::Reference< Axis > xOldAxis( m_aAllAxis[ nDimensionIndex ][nIndex] );
211 if( xOldAxis.is())
213 m_aAllAxis[ nDimensionIndex ][nIndex] = xAxis;
214 if( xAxis.is())
217}
218
220 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
221{
222 if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
223 throw lang::IndexOutOfBoundsException();
224
225 OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
226
227 if( nAxisIndex < 0 || nAxisIndex > getMaximumAxisIndexByDimension(nDimensionIndex) )
228 throw lang::IndexOutOfBoundsException();
229
230 return m_aAllAxis[ nDimensionIndex ][nAxisIndex];
231}
232
234 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const
235{
236 if( nDimensionIndex < 0 || nDimensionIndex >= m_nDimensionCount )
237 throw lang::IndexOutOfBoundsException();
238
239 OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( m_nDimensionCount));
240
241 if( nAxisIndex < 0 || o3tl::make_unsigned(nAxisIndex) > m_aAllAxis[ nDimensionIndex ].size() )
242 throw lang::IndexOutOfBoundsException();
243
244 return m_aAllAxis[ nDimensionIndex ][nAxisIndex];
245}
246
247sal_Int32 SAL_CALL BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex )
248{
249 if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
250 throw lang::IndexOutOfBoundsException();
251
252 OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
253
254 sal_Int32 nRet = m_aAllAxis[ nDimensionIndex ].size();
255 if(nRet)
256 nRet-=1;
257
258 return nRet;
259}
260
261// ____ XChartTypeContainer ____
263{
264 auto pChartType = dynamic_cast<ChartType*>(aChartType.get());
265 assert(pChartType);
266
267 if( std::find( m_aChartTypes.begin(), m_aChartTypes.end(), pChartType )
268 != m_aChartTypes.end())
269 throw lang::IllegalArgumentException("type not found", static_cast<cppu::OWeakObject*>(this), 1);
270
271 m_aChartTypes.push_back( pChartType );
274}
275
277{
278 auto pChartType = dynamic_cast<ChartType*>(aChartType.get());
279 assert(pChartType);
280 auto aIt( std::find( m_aChartTypes.begin(), m_aChartTypes.end(), pChartType ));
281 if( aIt == m_aChartTypes.end())
282 throw container::NoSuchElementException(
283 "The given chart type is no element of the container",
284 static_cast< uno::XWeak * >( this ));
285
286 m_aChartTypes.erase( aIt );
289}
290
292{
293 return comphelper::containerToSequence< Reference< chart2::XChartType > >( m_aChartTypes );
294}
295
297{
298 for (auto const & aChartType : m_aChartTypes)
299 aChartType->removeModifyListener( m_xModifyEventForwarder );
300 m_aChartTypes.clear();
301 for (auto const & aChartType : aChartTypes)
302 {
303 auto pChartType = dynamic_cast<ChartType*>(aChartType.get());
304 assert(pChartType);
305 m_aChartTypes.push_back(pChartType);
306 pChartType->addModifyListener( m_xModifyEventForwarder );
307 }
309}
310
311void BaseCoordinateSystem::setChartTypes( const std::vector< rtl::Reference< ChartType > >& aChartTypes )
312{
313 for (auto const & aChartType : m_aChartTypes)
314 aChartType->removeModifyListener( m_xModifyEventForwarder );
315 m_aChartTypes = aChartTypes;
316 for (auto const & aChartType : m_aChartTypes)
317 aChartType->addModifyListener( m_xModifyEventForwarder );
319}
320
321// ____ XModifyBroadcaster ____
323{
324 m_xModifyEventForwarder->addModifyListener( aListener );
325}
326
328{
329 m_xModifyEventForwarder->removeModifyListener( aListener );
330}
331
332// ____ XModifyListener ____
333void SAL_CALL BaseCoordinateSystem::modified( const lang::EventObject& aEvent )
334{
335 m_xModifyEventForwarder->modified( aEvent );
336}
337
338// ____ XEventListener (base of XModifyListener) ____
339void SAL_CALL BaseCoordinateSystem::disposing( const lang::EventObject& /* Source */ )
340{
341 // nothing
342}
343
344// ____ OPropertySet ____
346{
348}
349
351{
352 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
353}
354
355// ____ OPropertySet ____
356void BaseCoordinateSystem::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
357{
358 const tPropertyValueMap& rStaticDefaults = StaticCooSysDefaults();
359 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
360 if( aFound == rStaticDefaults.end() )
361 rAny.clear();
362 else
363 rAny = (*aFound).second;
364}
365
366// ____ OPropertySet ____
368{
369 return StaticCooSysInfoHelper();
370}
371
372// ____ XPropertySet ____
374{
375 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
376 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticCooSysInfoHelper() ) );
377 return xPropertySetInfo;
378}
379
381
384
385} // namespace chart
386
387/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
AnyEventRef aEvent
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual void SAL_CALL setChartTypes(const css::uno::Sequence< css::uno::Reference< css::chart2::XChartType > > &aChartTypes) final override
virtual void SAL_CALL addChartType(const css::uno::Reference< css::chart2::XChartType > &aChartType) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
std::vector< rtl::Reference<::chart::ChartType > > m_aChartTypes
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL setAxisByDimension(::sal_Int32 nDimension, const css::uno::Reference< css::chart2::XAxis > &xAxis, ::sal_Int32 nIndex) override
virtual void SAL_CALL removeChartType(const css::uno::Reference< css::chart2::XChartType > &aChartType) override
virtual ~BaseCoordinateSystem() override
const rtl::Reference< ::chart::Axis > & getAxisByDimension2(sal_Int32 nDimension, sal_Int32 nIndex) const
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
virtual ::sal_Int32 SAL_CALL getDimension() override
merge XInterface implementations
BaseCoordinateSystem(sal_Int32 nDimensionCount)
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual ::sal_Int32 SAL_CALL getMaximumAxisIndexByDimension(::sal_Int32 nDimension) override
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
virtual css::uno::Reference< css::chart2::XAxis > SAL_CALL getAxisByDimension(::sal_Int32 nDimension, ::sal_Int32 nIndex) override
virtual css::uno::Sequence< css::uno::Reference< css::chart2::XChartType > > SAL_CALL getChartTypes() override
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 setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
#define DBG_UNHANDLED_EXCEPTION(...)
sal_Int32 nIndex
size
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
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)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
::cppu::WeakImplHelper< css::lang::XServiceInfo, css::chart2::XCoordinateSystem, css::chart2::XChartTypeContainer, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener > BaseCoordinateSystem_Base
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
HashMap_OWString_Interface aMap
sal_Int32 nHandle