Coverage Report

Created: 2026-05-16 09:25

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