fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / oox / excelchartconverter.cxx
blobc316cb7be381302a14a44d63748908100fa325b5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "excelchartconverter.hxx"
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/chart2/data/XDataProvider.hpp>
24 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
25 #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
27 #include <osl/diagnose.h>
28 #include <oox/core/filterbase.hxx>
29 #include <oox/drawingml/chart/datasourcemodel.hxx>
30 #include <oox/helper/containerhelper.hxx>
31 #include "formulaparser.hxx"
33 namespace oox {
34 namespace xls {
36 using namespace ::com::sun::star::chart2;
37 using namespace ::com::sun::star::chart2::data;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::table;
40 using namespace ::com::sun::star::uno;
42 using ::oox::drawingml::chart::DataSequenceModel;
44 ExcelChartConverter::ExcelChartConverter( const WorkbookHelper& rHelper ) :
45 WorkbookHelper( rHelper )
49 ExcelChartConverter::~ExcelChartConverter()
53 void ExcelChartConverter::createDataProvider( const Reference< XChartDocument >& rxChartDoc )
55 try
57 Reference< XDataReceiver > xDataRec( rxChartDoc, UNO_QUERY_THROW );
58 Reference< XDataProvider > xDataProv( getBaseFilter().getModelFactory()->createInstance(
59 "com.sun.star.chart2.data.DataProvider" ), UNO_QUERY_THROW );
60 xDataRec->attachDataProvider( xDataProv );
62 catch( Exception& )
67 Reference< XDataSequence > ExcelChartConverter::createDataSequence(
68 const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq,
69 const OUString& /*rRole*/ )
71 Reference< XDataSequence > xDataSeq;
72 if (!rxDataProvider.is())
73 return xDataSeq;
75 Reference<XSheetDataProvider> xSheetProvider(rxDataProvider, UNO_QUERY);
76 if (!xSheetProvider.is())
77 return xDataSeq;
79 if (!rDataSeq.maFormula.isEmpty())
81 // parse the formula string, create a token sequence
82 FormulaParser& rParser = getFormulaParser();
83 CellAddress aBaseAddr( getCurrentSheetIndex(), 0, 0 );
84 ApiTokenSequence aTokens = rParser.importFormula( aBaseAddr, rDataSeq.maFormula );
86 try
88 // create the data sequence
89 xDataSeq = xSheetProvider->createDataSequenceByFormulaTokens(aTokens);
91 catch (Exception&)
93 OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" );
96 else if (!rDataSeq.maData.empty())
98 // create a single-row array from constant source data
99 Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 );
100 Matrix< Any >::iterator aMIt = aMatrix.begin();
101 // TODO: how to handle missing values in the map?
102 for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt )
103 *aMIt = aDIt->second;
104 OUString aRangeRep = FormulaProcessorBase::generateApiArray( aMatrix );
106 if (!aRangeRep.isEmpty())
110 // create the data sequence
111 xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep );
113 catch (Exception&)
115 OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" );
119 return xDataSeq;
122 } // namespace xls
123 } // namespace oox
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */