Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/chartapiwrapper/WrappedGapwidthProperty.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 <sal/config.h>
21
22
#include <cstddef>
23
24
#include "WrappedGapwidthProperty.hxx"
25
#include "Chart2ModelContact.hxx"
26
#include <ChartType.hxx>
27
#include <tools/long.hxx>
28
#include <utility>
29
30
using namespace ::com::sun::star;
31
using ::com::sun::star::uno::Reference;
32
using ::com::sun::star::uno::Sequence;
33
using ::com::sun::star::uno::Any;
34
35
namespace chart::wrapper
36
{
37
38
const sal_Int32 DEFAULT_GAPWIDTH = 100;
39
const sal_Int32 DEFAULT_OVERLAP = 0;
40
41
WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
42
                  const OUString& rOuterName
43
                , OUString aInnerSequencePropertyName
44
                , sal_Int32 nDefaultValue
45
                , std::shared_ptr<Chart2ModelContact> spChart2ModelContact )
46
0
            : WrappedDefaultProperty( rOuterName, OUString(), uno::Any( nDefaultValue ) )
47
0
            , m_nDimensionIndex(0)
48
0
            , m_nAxisIndex(0)
49
0
            , m_spChart2ModelContact(std::move( spChart2ModelContact ))
50
0
            , m_nDefaultValue( nDefaultValue )
51
0
            , m_InnerSequencePropertyName(std::move( aInnerSequencePropertyName ))
52
0
{
53
0
}
54
55
void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
56
0
{
57
0
    m_nDimensionIndex = nDimensionIndex;
58
0
    m_nAxisIndex = nAxisIndex;
59
0
}
60
61
WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
62
0
{
63
0
}
64
65
void WrappedBarPositionProperty_Base::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
66
0
{
67
0
    sal_Int32 nNewValue = 0;
68
0
    if( ! (rOuterValue >>= nNewValue) )
69
0
        throw lang::IllegalArgumentException( u"GapWidth and Overlap property require value of type sal_Int32"_ustr, nullptr, 0 );
70
71
0
    m_aOuterValue = rOuterValue;
72
73
0
    rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
74
0
    if( !xDiagram.is() )
75
0
        return;
76
77
0
    if( m_nDimensionIndex!=1 )
78
0
        return;
79
80
0
    const std::vector< rtl::Reference< ChartType > > aChartTypeList( xDiagram->getChartTypes() );
81
0
    for( rtl::Reference< ChartType > const & chartType : aChartTypeList )
82
0
    {
83
0
        try
84
0
        {
85
0
            Sequence< sal_Int32 > aBarPositionSequence;
86
0
            chartType->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
87
88
0
            tools::Long nOldLength = aBarPositionSequence.getLength();
89
0
            if( nOldLength <= m_nAxisIndex  )
90
0
                aBarPositionSequence.realloc( m_nAxisIndex+1 );
91
0
            auto pBarPositionSequence = aBarPositionSequence.getArray();
92
0
            for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
93
0
            {
94
0
                pBarPositionSequence[i] = m_nDefaultValue;
95
0
            }
96
0
            pBarPositionSequence[m_nAxisIndex] = nNewValue;
97
98
0
            chartType->setPropertyValue( m_InnerSequencePropertyName, uno::Any( aBarPositionSequence ) );
99
0
        }
100
0
        catch( uno::Exception& e )
101
0
        {
102
            //the above properties are not supported by all charttypes (only by column and bar)
103
            //in that cases this exception is ok
104
0
            e.Context.is();//to have debug information without compilation warnings
105
0
        }
106
0
    }
107
0
}
108
109
Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
110
0
{
111
0
    rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
112
0
    if( xDiagram.is() )
113
0
    {
114
0
        bool bInnerValueDetected = false;
115
0
        sal_Int32 nInnerValue = m_nDefaultValue;
116
117
0
        if( m_nDimensionIndex==1 )
118
0
        {
119
0
            std::vector< rtl::Reference< ChartType > > aChartTypeList = xDiagram->getChartTypes();
120
0
            for( std::size_t nN = 0; nN < aChartTypeList.size() && !bInnerValueDetected; nN++ )
121
0
            {
122
0
                try
123
0
                {
124
0
                    Sequence< sal_Int32 > aBarPositionSequence;
125
0
                    aChartTypeList[nN]->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
126
0
                    if( m_nAxisIndex < aBarPositionSequence.getLength() )
127
0
                    {
128
0
                        nInnerValue = aBarPositionSequence[m_nAxisIndex];
129
0
                        bInnerValueDetected = true;
130
0
                    }
131
0
                }
132
0
                catch( uno::Exception& e )
133
0
                {
134
                    //the above properties are not supported by all charttypes (only by column and bar)
135
                    //in that cases this exception is ok
136
0
                    e.Context.is();//to have debug information without compilation warnings
137
0
                }
138
0
            }
139
0
        }
140
0
        if( bInnerValueDetected )
141
0
        {
142
0
            m_aOuterValue <<= nInnerValue;
143
0
        }
144
0
    }
145
0
    return m_aOuterValue;
146
0
}
147
148
WrappedGapwidthProperty::WrappedGapwidthProperty(
149
        const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
150
0
    : WrappedBarPositionProperty_Base( u"GapWidth"_ustr, u"GapwidthSequence"_ustr, DEFAULT_GAPWIDTH, spChart2ModelContact )
151
0
{
152
0
}
153
WrappedGapwidthProperty::~WrappedGapwidthProperty()
154
{
155
}
156
157
WrappedBarOverlapProperty::WrappedBarOverlapProperty(
158
        const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact )
159
0
    : WrappedBarPositionProperty_Base( u"Overlap"_ustr, u"OverlapSequence"_ustr, DEFAULT_OVERLAP, spChart2ModelContact )
160
0
{
161
0
}
162
WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
163
{
164
}
165
166
} //  namespace chart::wrapper
167
168
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */