Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/drawingml/chart/datasourceconverter.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 <drawingml/chart/datasourceconverter.hxx>
21
22
#include <com/sun/star/chart2/XChartDocument.hpp>
23
#include <oox/drawingml/chart/chartconverter.hxx>
24
#include <oox/drawingml/chart/datasourcemodel.hxx>
25
#include <oox/token/properties.hxx>
26
#include <svl/zforlist.hxx>
27
28
namespace oox::drawingml::chart {
29
30
using namespace ::com::sun::star::chart2::data;
31
using namespace ::com::sun::star::uno;
32
33
DataSequenceConverter::DataSequenceConverter( const ConverterRoot& rParent, DataSequenceModel& rModel ) :
34
0
    ConverterBase< DataSequenceModel >( rParent, rModel )
35
0
{
36
0
}
37
38
DataSequenceConverter::~DataSequenceConverter()
39
0
{
40
0
}
41
42
Reference< XDataSequence > DataSequenceConverter::createDataSequence( const OUString& rRole )
43
0
{
44
    // create data sequence from data source model (virtual call at chart converter)
45
0
    Reference< XDataSequence > xDataSeq;
46
    // the internal data table does not support complex labels
47
    // this is only supported in Calc!!!
48
    // merge the labels into a single one
49
0
    if(rRole == "label")
50
0
    {
51
0
        mrModel.mnPointCount = std::min<sal_Int32>(mrModel.mnPointCount, 1);
52
0
        OUStringBuffer aTitle;
53
0
        bool bFirst = true;
54
0
        for (auto const& elem : mrModel.maData)
55
0
        {
56
0
            Any aAny = elem.second;
57
0
            if(aAny.has<OUString>())
58
0
            {
59
0
                if(!bFirst)
60
0
                    aTitle.append(" ");
61
62
0
                aTitle.append(aAny.get<OUString>());
63
0
                bFirst = false;
64
0
            }
65
0
        }
66
67
0
        if(!bFirst)
68
0
        {
69
0
            mrModel.maData.clear();
70
0
            mrModel.maData.insert(std::make_pair<sal_Int32, Any>(0, Any(aTitle.makeStringAndClear())));
71
0
        }
72
0
    }
73
74
0
    bool bDateCategories = (mrModel.meFormatType == SvNumFormatType::DATE) && (rRole == "categories");
75
0
    xDataSeq = getChartConverter().createDataSequence(getChartDocument()->getDataProvider(), mrModel,
76
0
        rRole, bDateCategories ? u"date"_ustr : u""_ustr);
77
78
    // set sequence role
79
0
    PropertySet aSeqProp( xDataSeq );
80
0
    aSeqProp.setProperty( PROP_Role, rRole );
81
82
0
    const sal_Int32 nKey = getFormatter().getNumberFormatKey(mrModel.maFormatCode);
83
0
    if (nKey >= 0)
84
0
        aSeqProp.setProperty(PROP_NumberFormatKey, nKey);
85
86
0
    return xDataSeq;
87
0
}
88
89
DataSourceConverter::DataSourceConverter( const ConverterRoot& rParent, DataSourceModel& rModel ) :
90
0
    ConverterBase< DataSourceModel >( rParent, rModel )
91
0
{
92
0
}
93
94
DataSourceConverter::~DataSourceConverter()
95
0
{
96
0
}
97
98
Reference< XDataSequence > DataSourceConverter::createDataSequence( const OUString& rRole )
99
0
{
100
0
    Reference< XDataSequence > xDataSeq;
101
0
    if( mrModel.mxDataSeq.is() )
102
0
    {
103
0
        DataSequenceConverter aDataSeqConv( *this, *mrModel.mxDataSeq );
104
0
        xDataSeq = aDataSeqConv.createDataSequence( rRole );
105
0
    }
106
0
    return xDataSeq;
107
0
}
108
109
} // namespace oox::drawingml::chart
110
111
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */