Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/chart/SchXMLPropertyMappingContext.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
10
#include "SchXMLPropertyMappingContext.hxx"
11
#include "SchXMLTools.hxx"
12
#include <utility>
13
#include <xmloff/xmlnamespace.hxx>
14
#include <xmloff/xmlimp.hxx>
15
#include <sal/log.hxx>
16
17
#include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
18
#include <com/sun/star/chart2/data/XDataSource.hpp>
19
#include <com/sun/star/chart2/data/XDataSink.hpp>
20
#include <com/sun/star/chart2/XChartDocument.hpp>
21
22
using namespace com::sun::star;
23
using namespace com::sun::star::uno;
24
using namespace ::xmloff::token;
25
26
namespace {
27
28
Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole
29
        , const OUString& rRange
30
        , const Reference< chart2::XChartDocument >& xChartDoc
31
        , const Reference< chart2::XDataSeries >& xSeries )
32
0
{
33
0
    Reference< chart2::data::XLabeledDataSequence2 > xLabeledSeq;
34
35
0
    Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
36
37
0
    if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) )
38
0
        return xLabeledSeq;
39
40
    // create a new sequence
41
0
    xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence();
42
43
    // set values at the new sequence
44
0
    Reference< chart2::data::XDataSequence > xSeq = SchXMLTools::CreateDataSequence( rRange, xChartDoc );
45
0
    Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
46
0
    if( xSeqProp.is())
47
0
        xSeqProp->setPropertyValue(u"Role"_ustr, uno::Any( rRole));
48
0
    xLabeledSeq->setValues( xSeq );
49
50
0
    Reference< chart2::data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY );
51
0
    if( xSink.is())
52
0
    {
53
0
        Sequence< Reference< chart2::data::XLabeledDataSequence > > aData( xSeriesSource->getDataSequences());
54
0
        aData.realloc( aData.getLength() + 1 );
55
0
        aData.getArray()[ aData.getLength() - 1 ] = xLabeledSeq;
56
0
        xSink->setData( aData );
57
0
    }
58
59
0
    return xLabeledSeq;
60
0
}
61
62
}
63
64
SchXMLPropertyMappingContext::SchXMLPropertyMappingContext(
65
        SvXMLImport& rImport,
66
        tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
67
        uno::Reference<
68
        chart2::XDataSeries > xSeries ):
69
0
    SvXMLImportContext( rImport ),
70
0
    mxDataSeries(std::move(xSeries)),
71
0
    mrLSequencesPerIndex(rLSequencesPerIndex)
72
0
{
73
74
0
}
75
76
SchXMLPropertyMappingContext::~SchXMLPropertyMappingContext()
77
0
{
78
0
}
79
80
void SchXMLPropertyMappingContext::startFastElement (sal_Int32 /*nElement*/,
81
        const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
82
0
{
83
0
    OUString aRange;
84
0
    OUString aRole;
85
    // parse attributes
86
0
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
87
0
    {
88
0
        OUString aValue = aIter.toString();
89
0
        switch( aIter.getToken() )
90
0
        {
91
0
            case XML_ELEMENT(LO_EXT, XML_PROPERTY):
92
0
                aRole = aValue;
93
0
                break;
94
0
            case XML_ELEMENT(LO_EXT, XML_CELL_RANGE_ADDRESS):
95
0
                aRange = aValue;
96
0
                break;
97
0
            default:
98
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
99
0
        }
100
0
    }
101
102
0
    if( !aRange.isEmpty() && !aRole.isEmpty() )
103
0
    {
104
0
        Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY );
105
0
        Reference< chart2::data::XLabeledDataSequence2 > xSeq =
106
0
            createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries);
107
0
        mrLSequencesPerIndex.emplace(
108
0
                    tSchXMLIndexWithPart( 0, SCH_XML_PART_VALUES),
109
0
                    xSeq);
110
0
    }
111
0
}
112
113
114
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */