LibreOffice Module chart2 (master) 1
MinMaxLineWrapper.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 "MinMaxLineWrapper.hxx"
22#include <ChartType.hxx>
23#include <DiagramHelper.hxx>
27#include <com/sun/star/drawing/LineJoint.hpp>
29#include <DataSeries.hxx>
32#include <utility>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::chart2;
37
38using ::com::sun::star::beans::Property;
39using ::com::sun::star::uno::Reference;
40using ::com::sun::star::uno::Sequence;
41using ::com::sun::star::uno::Any;
42
43namespace
44{
45
46Sequence< Property >& StaticMinMaxLineWrapperPropertyArray()
47{
48 static Sequence< Property > aPropSeq = []()
49 {
50 std::vector< css::beans::Property > aProperties;
51
54
55 std::sort( aProperties.begin(), aProperties.end(),
57
58 return comphelper::containerToSequence( aProperties );
59 }();
60 return aPropSeq;
61};
62
63::cppu::OPropertyArrayHelper& StaticMinMaxLineWrapperInfoHelper()
64{
65 static ::cppu::OPropertyArrayHelper aPropHelper( StaticMinMaxLineWrapperPropertyArray() );
66 return aPropHelper;
67};
68
69uno::Reference< beans::XPropertySetInfo >& StaticMinMaxLineWrapperInfo()
70{
71 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
72 ::cppu::OPropertySetHelper::createPropertySetInfo( StaticMinMaxLineWrapperInfoHelper() ) );
73 return xPropertySetInfo;
74};
75
76} // anonymous namespace
77
78namespace chart::wrapper
79{
80
81MinMaxLineWrapper::MinMaxLineWrapper(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
82 : m_spChart2ModelContact(std::move( spChart2ModelContact ))
83 , m_aWrappedLineJointProperty( "LineJoint", uno::Any( drawing::LineJoint_NONE ))
84{
85}
86
88{
89}
90
91// ____ XComponent ____
93{
94 std::unique_lock g(m_aMutex);
95 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
96 m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) );
97}
98
100 const Reference< lang::XEventListener >& xListener )
101{
102 std::unique_lock g(m_aMutex);
104}
105
107 const Reference< lang::XEventListener >& aListener )
108{
109 std::unique_lock g(m_aMutex);
111}
112
113//XPropertySet
115{
116 return StaticMinMaxLineWrapperInfo();
117}
118
119void SAL_CALL MinMaxLineWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue )
120{
122 const std::vector< rtl::Reference< ChartType > > & aTypes = xDiagram->getChartTypes();
123 for( rtl::Reference< ChartType > const & xType : aTypes )
124 {
125 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
126 {
127 const std::vector< rtl::Reference< DataSeries > > & aSeriesSeq( xType->getDataSeries2() );
128 if(!aSeriesSeq.empty())
129 {
130 if(aSeriesSeq[0].is())
131 {
132 if( rPropertyName == "LineColor" )
133 aSeriesSeq[0]->setPropertyValue( "Color", rValue );
134 else if( rPropertyName == "LineTransparence" )
135 aSeriesSeq[0]->setPropertyValue( "Transparency", rValue );
136 else if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
137 m_aWrappedLineJointProperty.setPropertyValue( rValue, aSeriesSeq[0] );
138 else
139 aSeriesSeq[0]->setPropertyValue( rPropertyName, rValue );
140 return;
141 }
142 }
143 }
144 }
145}
146uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const OUString& rPropertyName )
147{
148 Any aRet;
149
151
153 const std::vector< rtl::Reference< ChartType > > aTypes = xDiagram->getChartTypes();
154 for( rtl::Reference< ChartType > const & xType : aTypes )
155 {
156 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
157 {
158 const std::vector< rtl::Reference< DataSeries > > & aSeriesSeq( xType->getDataSeries2() );
159 if(!aSeriesSeq.empty())
160 {
161 xPropSet = aSeriesSeq[0];
162 break;
163 }
164 }
165 }
166 if(xPropSet.is())
167 {
168 if( rPropertyName == "LineColor" )
169 aRet = xPropSet->getPropertyValue( "Color" );
170 else if( rPropertyName == "LineTransparence" )
171 aRet = xPropSet->getPropertyValue( "Transparency" );
172 else if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
174 else
175 aRet = xPropSet->getPropertyValue( rPropertyName );
176
177 }
178 return aRet;
179}
180
181void SAL_CALL MinMaxLineWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
182{
183 OSL_FAIL("not implemented");
184}
185void SAL_CALL MinMaxLineWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
186{
187 OSL_FAIL("not implemented");
188}
189void SAL_CALL MinMaxLineWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
190{
191 OSL_FAIL("not implemented");
192}
193void SAL_CALL MinMaxLineWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
194{
195 OSL_FAIL("not implemented");
196}
197
198//XMultiPropertySet
199//getPropertySetInfo() already declared in XPropertySet
201{
202 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
203 for(sal_Int32 nN=0; nN<nMinCount; nN++)
204 {
205 OUString aPropertyName( rNameSeq[nN] );
206 try
207 {
208 setPropertyValue( aPropertyName, rValueSeq[nN] );
209 }
210 catch( const beans::UnknownPropertyException& )
211 {
212 DBG_UNHANDLED_EXCEPTION("chart2");
213 }
214 }
215 //todo: store unknown properties elsewhere
216}
218{
219 Sequence< Any > aRetSeq;
220 if( rNameSeq.hasElements() )
221 {
222 aRetSeq.realloc( rNameSeq.getLength() );
223 auto pRetSeq = aRetSeq.getArray();
224 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
225 {
226 OUString aPropertyName( rNameSeq[nN] );
227 pRetSeq[nN] = getPropertyValue( aPropertyName );
228 }
229 }
230 return aRetSeq;
231}
233 const uno::Sequence< OUString >& /* aPropertyNames */,
235{
236 OSL_FAIL("not implemented");
237}
240{
241 OSL_FAIL("not implemented");
242}
244 const uno::Sequence< OUString >& /* aPropertyNames */,
246{
247 OSL_FAIL("not implemented");
248}
249
250//XPropertyState
251beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const OUString& rPropertyName )
252{
253 if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
254 return beans::PropertyState_DEFAULT_VALUE;
255
256 uno::Any aDefault( getPropertyDefault( rPropertyName ) );
257 uno::Any aValue( getPropertyValue( rPropertyName ) );
258
259 if( aDefault == aValue )
260 return beans::PropertyState_DEFAULT_VALUE;
261
262 return beans::PropertyState_DIRECT_VALUE;
263}
265{
267 if( rNameSeq.hasElements() )
268 {
269 aRetSeq.realloc( rNameSeq.getLength() );
270 auto pRetSeq = aRetSeq.getArray();
271 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
272 {
273 OUString aPropertyName( rNameSeq[nN] );
274 pRetSeq[nN] = getPropertyState( aPropertyName );
275 }
276 }
277 return aRetSeq;
278}
279void SAL_CALL MinMaxLineWrapper::setPropertyToDefault( const OUString& rPropertyName )
280{
281 setPropertyValue( rPropertyName, getPropertyDefault(rPropertyName) );
282}
283
284uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const OUString& rPropertyName )
285{
286 static const ::chart::tPropertyValueMap aStaticDefaults = []
287 {
290 return aTmp;
291 }();
292 tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( StaticMinMaxLineWrapperInfoHelper().getHandleByName( rPropertyName ) ) );
293 if( aFound == aStaticDefaults.end() )
294 return uno::Any();
295 return (*aFound).second;
296}
297
298//XMultiPropertyStates
299//getPropertyStates() already declared in XPropertyState
301{
302 const Sequence< beans::Property >& rPropSeq = StaticMinMaxLineWrapperPropertyArray();
303 for(beans::Property const & prop : rPropSeq)
304 {
305 setPropertyToDefault( prop.Name );
306 }
307}
309{
310 for(OUString const & s : rNameSeq)
311 {
313 }
314}
316{
317 Sequence< Any > aRetSeq;
318 if( rNameSeq.hasElements() )
319 {
320 aRetSeq.realloc( rNameSeq.getLength() );
321 auto pRetSeq = aRetSeq.getArray();
322 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
323 {
324 OUString aPropertyName( rNameSeq[nN] );
325 pRetSeq[nN] = getPropertyDefault( aPropertyName );
326 }
327 }
328 return aRetSeq;
329}
330
332{
333 return "com.sun.star.comp.chart.ChartLine";
334}
335
336sal_Bool SAL_CALL MinMaxLineWrapper::supportsService( const OUString& rServiceName )
337{
338 return cppu::supportsService(this, rServiceName);
339}
340
341css::uno::Sequence< OUString > SAL_CALL MinMaxLineWrapper::getSupportedServiceNames()
342{
343 return {
344 "com.sun.star.chart.ChartLine",
345 "com.sun.star.xml.UserDefinedAttributesSupplier",
346 "com.sun.star.drawing.LineProperties"
347 };
348}
349
350} // namespace chart::wrapper
351
352/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
PropertiesInfo aProperties
virtual css::uno::Any getPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const override
virtual void setPropertyValue(const css::uno::Any &rOuterValue, const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const override
const OUString & getOuterName() const
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual void SAL_CALL setAllPropertiesToDefault() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Sequence< css::uno::Any > &aValues) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
WrappedIgnoreProperty m_aWrappedLineJointProperty
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL dispose() override
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aEventListenerContainer
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults(const css::uno::Sequence< OUString > &aPropertyNames) override
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
virtual void SAL_CALL setPropertiesToDefault(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
MinMaxLineWrapper(std::shared_ptr< Chart2ModelContact > spChart2ModelContact)
virtual void SAL_CALL firePropertiesChangeEvent(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]