LibreOffice Module oox (master) 1
chartconverter.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 * 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
21
22#include <com/sun/star/chart2/XChartDocument.hpp>
23#include <com/sun/star/chart2/data/XDataReceiver.hpp>
24#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
29#include <osl/diagnose.h>
30
31using ::oox::drawingml::chart::DataSequenceModel;
32using ::com::sun::star::uno::Any;
33namespace oox::drawingml::chart {
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::chart2;
37using namespace ::com::sun::star::chart2::data;
38using namespace ::com::sun::star::drawing;
39using namespace ::com::sun::star::uno;
40
41using ::oox::core::XmlFilterBase;
42
46
47static OUString lclGenerateApiArray(const std::vector<Any>& rRow, sal_Int32 nStart, sal_Int32 nCount)
48{
49 OSL_ENSURE( !rRow.empty(), "ChartConverter::lclGenerateApiArray - missing matrix values" );
50 OUStringBuffer aBuffer;
52 for (auto aBeg = rRow.begin() + nStart, aIt = aBeg, aEnd = aBeg + nCount; aIt != aEnd; ++aIt)
53 {
54 double fValue = 0.0;
55 OUString aString;
56 if( aIt != aBeg )
58 if( *aIt >>= fValue )
59 aBuffer.append( fValue );
60 else if( *aIt >>= aString )
61 {
62 // Code similar to sc/source/filter/oox/formulabase.cxx
63 aBuffer.append( "\"" + aString.replaceAll(u"\"", u"\"\"") + "\"" );
64 }
65 else
66 aBuffer.append( "\"\"" );
67 }
69 return aBuffer.makeStringAndClear();
70}
71
73{
74}
75
77{
78}
79
81 ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc,
82 const Reference< XShapes >& rxExternalPage, const awt::Point& rChartPos, const awt::Size& rChartSize )
83{
84 OSL_ENSURE( rxChartDoc.is(), "ChartConverter::convertFromModel - missing chart document" );
85 if( rxChartDoc.is() )
86 {
87 Reference< data::XDataReceiver > xDataReceiver( rxChartDoc, uno::UNO_QUERY_THROW );
88 Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( rFilter.getModel(), uno::UNO_QUERY );
89 if (xNumberFormatsSupplier.is())
90 xDataReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
91
92 ConverterRoot aConvBase( rFilter, *this, rChartModel, rxChartDoc, rChartSize );
93 ChartSpaceConverter aSpaceConv( aConvBase, rChartModel );
94 aSpaceConv.convertFromModel( rxExternalPage, rChartPos );
95 }
96}
97
99{
100 try
101 {
102 if( !rxChartDoc->hasInternalDataProvider() )
103 rxChartDoc->createInternalDataProvider( false );
104 }
105 catch( Exception& )
106 {
107 }
108}
109
111 const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq,
112 const OUString& rRole, const OUString& rRoleQualifier )
113{
115 if( rxDataProvider.is() )
116 {
117 OUString aRangeRep;
118 if( !rDataSeq.maData.empty() || (rRole == "values-y" && rDataSeq.mnPointCount > 0) ) try
119 {
120 // create a single-row array from constant source data
121 // (multiple levels in the case of complex categories)
122 std::vector<Any> aRow(rDataSeq.mnLevelCount * rDataSeq.mnPointCount);
123 for (auto const& elem : rDataSeq.maData)
124 aRow.at(elem.first) = elem.second;
125
126 for (sal_Int32 i = rDataSeq.mnLevelCount-1; i >= 0; i--)
127 {
128 aRangeRep = lclGenerateApiArray( aRow, i * rDataSeq.mnPointCount, rDataSeq.mnPointCount);
129
130 if (!aRangeRep.isEmpty())
131 {
132 // create or add a new level to the data sequence
133 xDataSeq = rxDataProvider->createDataSequenceByValueArray(rRole, aRangeRep, rRoleQualifier);
134 if (i == 0)
135 return xDataSeq;
136 }
137 }
138 }
139 catch( Exception& )
140 {
141 OSL_FAIL( "ChartConverter::createDataSequence - cannot create data sequence" );
142 }
143 }
144
145 return nullptr;
146}
147
148} // namespace oox::drawingml::chart
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
Definition: filterbase.cxx:220
void convertFromModel(::oox::core::XmlFilterBase &rFilter, ChartSpaceModel &rChartModel, const css::uno::Reference< css::chart2::XChartDocument > &rxChartDoc, const css::uno::Reference< css::drawing::XShapes > &rxExternalPage, const css::awt::Point &rChartPos, const css::awt::Size &rChartSize)
Converts the passed OOXML chart model to the passed chart2 document.
virtual void createDataProvider(const css::uno::Reference< css::chart2::XChartDocument > &rxChartDoc)
Creates an internal data provider.
virtual css::uno::Reference< css::chart2::data::XDataSequence > createDataSequence(const css::uno::Reference< css::chart2::data::XDataProvider > &rxDataProvider, const DataSequenceModel &rDataSeq, const OUString &rRole, const OUString &aRoleQualifier)
Creates a data sequence from a formula.
void convertFromModel(const css::uno::Reference< css::drawing::XShapes > &rxExternalPage, const css::awt::Point &rChartPos)
Converts the contained OOXML chart model to a chart2 document.
int nCount
float u
@ Exception
const sal_Unicode API_TOKEN_ARRAY_OPEN
const sal_Unicode API_TOKEN_ARRAY_CLOSE
const sal_Unicode API_TOKEN_ARRAY_COLSEP
static OUString lclGenerateApiArray(const std::vector< Any > &rRow, sal_Int32 nStart, sal_Int32 nCount)
sal_Int32 mnPointCount
Number format for double values.
sal_Int32 mnLevelCount
Number of points in this series source.
sal_uInt16 sal_Unicode
std::unique_ptr< char[]> aBuffer