LibreOffice Module xmloff (master)  1
SchXMLPropertyMappingContext.cxx
Go to the documentation of this file.
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 
11 #include "SchXMLTools.hxx"
12 #include <xmloff/xmlnamespace.hxx>
13 #include <xmloff/xmlimp.hxx>
14 #include <xmloff/namespacemap.hxx>
15 #include <SchXMLImport.hxx>
16 #include <sal/log.hxx>
17 
18 #include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
19 #include <com/sun/star/chart2/data/XDataSource.hpp>
20 #include <com/sun/star/chart2/data/XDataSink.hpp>
21 #include <com/sun/star/chart2/XChartDocument.hpp>
22 
23 using namespace com::sun::star;
24 using namespace com::sun::star::uno;
25 using namespace ::xmloff::token;
26 
27 namespace {
28 
29 Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole
30  , const OUString& rRange
31  , const Reference< chart2::XChartDocument >& xChartDoc
32  , const Reference< chart2::XDataSeries >& xSeries )
33 {
35 
36  Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
37 
38  if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) )
39  return xLabeledSeq;
40 
41  // create a new sequence
43 
44  // set values at the new sequence
46  Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
47  if( xSeqProp.is())
48  xSeqProp->setPropertyValue("Role", uno::makeAny( rRole));
49  xLabeledSeq->setValues( xSeq );
50 
51  Reference< chart2::data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY );
52  if( xSink.is())
53  {
54  Sequence< Reference< chart2::data::XLabeledDataSequence > > aData( xSeriesSource->getDataSequences());
55  aData.realloc( aData.getLength() + 1 );
56  aData[ aData.getLength() - 1 ] = xLabeledSeq;
57  xSink->setData( aData );
58  }
59 
60  return xLabeledSeq;
61 }
62 
63 }
64 
66  SvXMLImport& rImport,
67  tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
68  uno::Reference<
69  chart2::XDataSeries > const & xSeries ):
70  SvXMLImportContext( rImport ),
71  mxDataSeries(xSeries),
72  mrLSequencesPerIndex(rLSequencesPerIndex)
73 {
74 
75 }
76 
78 {
79 }
80 
82  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
83 {
84  OUString aRange;
85  OUString aRole;
86  // parse attributes
87  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
88  {
89  OUString aValue = aIter.toString();
90  switch( aIter.getToken() )
91  {
92  case XML_ELEMENT(LO_EXT, XML_PROPERTY):
93  aRole = aValue;
94  break;
95  case XML_ELEMENT(LO_EXT, XML_CELL_RANGE_ADDRESS):
96  aRange = aValue;
97  break;
98  default:
99  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
100  }
101  }
102 
103  if( !aRange.isEmpty() && !aRole.isEmpty() )
104  {
105  Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY );
107  createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries);
108  mrLSequencesPerIndex.emplace(
110  xSeq);
111  }
112 }
113 
114 
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::SvRef< SvBaseLink > xSink
SchXMLPropertyMappingContext(SvXMLImport &rImport, tSchXMLLSequencesPerIndex &rLSequencesPerIndex, css::uno::Reference< css::chart2::XDataSeries > const &xSeries)
css::uno::Reference< css::chart2::XDataSeries > mxDataSeries
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:56
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:110
::std::pair< tSchXMLIndex, SchXMLLabeledSequencePart > tSchXMLIndexWithPart
constexpr OUStringLiteral aData
Reference< chart2::data::XLabeledDataSequence2 > GetNewLabeledDataSequence()
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
Any makeAny(Color const &value)
Handling of tokens in XML:
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:96
Reference< chart2::data::XDataSequence > CreateDataSequence(const OUString &rRange, const Reference< chart2::XChartDocument > &xChartDoc)
::std::multimap< tSchXMLIndexWithPart, css::uno::Reference< css::chart2::data::XLabeledDataSequence > > tSchXMLLSequencesPerIndex
tSchXMLLSequencesPerIndex & mrLSequencesPerIndex