Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/chartapiwrapper/GridWrapper.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 "GridWrapper.hxx"
21
#include <AxisHelper.hxx>
22
#include "Chart2ModelContact.hxx"
23
#include <AxisIndexDefines.hxx>
24
#include <BaseCoordinateSystem.hxx>
25
26
#include <LinePropertiesHelper.hxx>
27
#include <UserDefinedProperties.hxx>
28
#include <WrappedDefaultProperty.hxx>
29
30
#include <comphelper/sequence.hxx>
31
#include <cppuhelper/supportsservice.hxx>
32
#include <algorithm>
33
#include <utility>
34
#include <comphelper/diagnose_ex.hxx>
35
36
using namespace ::com::sun::star;
37
38
using ::com::sun::star::beans::Property;
39
using ::com::sun::star::uno::Reference;
40
using ::com::sun::star::uno::Sequence;
41
42
namespace chart::wrapper
43
{
44
45
GridWrapper::GridWrapper(tGridType eType, std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
46
0
    : m_spChart2ModelContact(std::move(spChart2ModelContact))
47
0
    , m_eType(eType)
48
0
{
49
0
}
50
51
GridWrapper::~GridWrapper()
52
0
{}
53
54
void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
55
0
{
56
0
    rnDimensionIndex = 1;
57
0
    rbSubGrid = false;
58
59
0
    switch( eType )
60
0
    {
61
0
        case X_MAJOR_GRID:
62
0
            rnDimensionIndex = 0; rbSubGrid = false; break;
63
0
        case Y_MAJOR_GRID:
64
0
            rnDimensionIndex = 1; rbSubGrid = false; break;
65
0
        case Z_MAJOR_GRID:
66
0
            rnDimensionIndex = 2; rbSubGrid = false; break;
67
0
        case X_MINOR_GRID:
68
0
            rnDimensionIndex = 0; rbSubGrid = true;  break;
69
0
        case Y_MINOR_GRID:
70
0
            rnDimensionIndex = 1; rbSubGrid = true;  break;
71
0
        case Z_MINOR_GRID:
72
0
            rnDimensionIndex = 2; rbSubGrid = true;  break;
73
0
    }
74
0
}
75
76
// ____ XComponent ____
77
void SAL_CALL GridWrapper::dispose()
78
0
{
79
0
    std::unique_lock g(m_aMutex);
80
0
    Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
81
0
    m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) );
82
83
0
    clearWrappedPropertySet();
84
0
}
85
86
void SAL_CALL GridWrapper::addEventListener(
87
    const Reference< lang::XEventListener >& xListener )
88
0
{
89
0
    std::unique_lock g(m_aMutex);
90
0
    m_aEventListenerContainer.addInterface( g, xListener );
91
0
}
92
93
void SAL_CALL GridWrapper::removeEventListener(
94
    const Reference< lang::XEventListener >& aListener )
95
0
{
96
0
    std::unique_lock g(m_aMutex);
97
0
    m_aEventListenerContainer.removeInterface( g, aListener );
98
0
}
99
100
// WrappedPropertySet
101
102
Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
103
0
{
104
0
    rtl::Reference< GridProperties > xRet;
105
0
    try
106
0
    {
107
0
        rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
108
0
        rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
109
110
0
        sal_Int32 nDimensionIndex = 1;
111
0
        bool bSubGrid = false;
112
0
        getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
113
114
0
        sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
115
0
        xRet = AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex );
116
0
    }
117
0
    catch( const uno::Exception & )
118
0
    {
119
0
        DBG_UNHANDLED_EXCEPTION("chart2");
120
0
    }
121
0
    return xRet;
122
0
}
123
124
const Sequence< beans::Property >& GridWrapper::getPropertySequence()
125
0
{
126
0
    static Sequence< Property > aPropSeq = []()
127
0
        {
128
0
            std::vector< css::beans::Property > aProperties;
129
0
            ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
130
0
            ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
131
132
0
            std::sort( aProperties.begin(), aProperties.end(),
133
0
                         ::chart::PropertyNameLess() );
134
135
0
            return comphelper::containerToSequence( aProperties );
136
0
        }();
137
0
    return aPropSeq;
138
0
}
139
140
std::vector< std::unique_ptr<WrappedProperty> > GridWrapper::createWrappedProperties()
141
0
{
142
0
    std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
143
144
0
    aWrappedProperties.emplace_back( new WrappedDefaultProperty( u"LineColor"_ustr, u"LineColor"_ustr, uno::Any( sal_Int32( 0x000000) ) ) ); // black
145
146
0
    return aWrappedProperties;
147
0
}
148
149
OUString SAL_CALL GridWrapper::getImplementationName()
150
0
{
151
0
    return u"com.sun.star.comp.chart.Grid"_ustr;
152
0
}
153
154
sal_Bool SAL_CALL GridWrapper::supportsService( const OUString& rServiceName )
155
0
{
156
0
    return cppu::supportsService(this, rServiceName);
157
0
}
158
159
css::uno::Sequence< OUString > SAL_CALL GridWrapper::getSupportedServiceNames()
160
0
{
161
0
    return {
162
0
        u"com.sun.star.chart.ChartGrid"_ustr,
163
0
        u"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr,
164
0
        u"com.sun.star.drawing.LineProperties"_ustr,
165
0
        u"com.sun.star.beans.PropertySet"_ustr
166
0
    };
167
0
}
168
169
} //  namespace chart::wrapper
170
171
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */