1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <drawingml/chart/datasourcecontext.hxx>
22 #include <oox/drawingml/chart/datasourcemodel.hxx>
24 #include <oox/core/xmlfilterbase.hxx>
25 #include <oox/helper/attributelist.hxx>
26 #include <oox/token/namespaces.hxx>
27 #include <oox/token/tokens.hxx>
28 #include <svl/numformat.hxx>
29 #include <svl/zforlist.hxx>
30 #include <osl/diagnose.h>
32 namespace oox::drawingml::chart
{
34 using ::oox::core::ContextHandler2Helper
;
35 using ::oox::core::ContextHandlerRef
;
37 using namespace ::com::sun::star
;
39 DoubleSequenceContext::DoubleSequenceContext( ContextHandler2Helper
& rParent
, DataSequenceModel
& rModel
) :
40 DataSequenceContextBase( rParent
, rModel
),
45 DoubleSequenceContext::~DoubleSequenceContext()
49 ContextHandlerRef
DoubleSequenceContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
51 switch( getCurrentElement() )
53 case C_TOKEN( numRef
):
57 case C_TOKEN( numCache
):
62 case C_TOKEN( numCache
):
63 case C_TOKEN( numLit
):
66 case C_TOKEN( formatCode
):
68 case C_TOKEN( ptCount
):
69 mrModel
.mnPointCount
= rAttribs
.getInteger( XML_val
, -1 );
72 mnPtIndex
= rAttribs
.getInteger( XML_idx
, -1 );
88 void DoubleSequenceContext::onCharacters( const OUString
& rChars
)
90 switch( getCurrentElement() )
93 mrModel
.maFormula
= rChars
;
95 case C_TOKEN( formatCode
):
96 mrModel
.maFormatCode
= rChars
;
101 /* Import categories as String even though it could
102 * be values except when the format code indicates that they are dates.
103 * n#810508: xVal needs to be imported as double
104 * TODO: NumberFormat conversion, remove the check then.
106 if( isParentElement( C_TOKEN( cat
), 4 ) )
108 // workaround for bug n#889755
109 SvNumberFormatter
* pNumFrmt
= getNumberFormatter();
112 sal_uInt32 nKey
= pNumFrmt
->GetEntryKey( mrModel
.maFormatCode
);
113 bool bNoKey
= ( nKey
== NUMBERFORMAT_ENTRY_NOT_FOUND
);
116 OUString aFormatCode
= mrModel
.maFormatCode
;
117 sal_Int32 nCheckPos
= 0;
118 SvNumFormatType nType
;
119 pNumFrmt
->PutEntry( aFormatCode
, nCheckPos
, nType
, nKey
);
120 bNoKey
= (nCheckPos
!= 0);
122 mrModel
.meFormatType
= nType
;
126 mrModel
.maData
[ mnPtIndex
] <<= rChars
;
130 double fValue
= rChars
.toDouble();
131 if (mrModel
.meFormatType
== SvNumFormatType::DATE
)
132 mrModel
.maData
[ mnPtIndex
] <<= fValue
;
135 const ::Color
* pColor
= nullptr;
136 OUString aFormattedValue
;
137 // tdf#91250: use UNLIMITED_PRECISION in case of GENERAL Number Format of category axis labels
138 if( pNumFrmt
->GetStandardPrec() != SvNumberFormatter::UNLIMITED_PRECISION
)
139 pNumFrmt
->ChangeStandardPrec(SvNumberFormatter::UNLIMITED_PRECISION
);
140 pNumFrmt
->GetOutputString( fValue
, nKey
, aFormattedValue
, &pColor
);
141 mrModel
.maData
[ mnPtIndex
] <<= aFormattedValue
;
147 mrModel
.maData
[ mnPtIndex
] <<= rChars
;
152 mrModel
.maData
[ mnPtIndex
] <<= rChars
.toDouble();
160 SvNumberFormatter
* DoubleSequenceContext::getNumberFormatter()
162 if( mpNumberFormatter
== nullptr )
164 uno::Reference
<uno::XComponentContext
> rContext
=
165 getFilter().getComponentContext();
166 mpNumberFormatter
.reset(
167 new SvNumberFormatter(rContext
, LANGUAGE_SYSTEM
) );
169 return mpNumberFormatter
.get();
173 StringSequenceContext::StringSequenceContext( ContextHandler2Helper
& rParent
, DataSequenceModel
& rModel
)
174 : DataSequenceContextBase( rParent
, rModel
)
180 StringSequenceContext::~StringSequenceContext()
184 ContextHandlerRef
StringSequenceContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
186 switch( getCurrentElement() )
188 case C_TOKEN( multiLvlStrRef
):
192 case C_TOKEN( multiLvlStrCache
):
197 case C15_TOKEN( datalabelsRange
):
202 case C15_TOKEN( dlblRangeCache
):
207 case C_TOKEN( strRef
):
211 case C_TOKEN( strCache
):
216 case C_TOKEN( strCache
):
217 case C_TOKEN( strLit
):
218 case C15_TOKEN( dlblRangeCache
):
219 if (nElement
== C15_TOKEN( dlblRangeCache
) && !mbReadC15
)
224 case C_TOKEN( ptCount
):
225 mrModel
.mnPointCount
= rAttribs
.getInteger( XML_val
, -1 );
228 mnPtIndex
= rAttribs
.getInteger( XML_idx
, -1 );
233 case C_TOKEN( multiLvlStrCache
):
236 case C_TOKEN( ptCount
):
237 mrModel
.mnPointCount
= rAttribs
.getInteger(XML_val
, -1);
238 mrModel
.mnLevelCount
--; // normalize level count
241 mrModel
.mnLevelCount
++;
250 mnPtIndex
= rAttribs
.getInteger(XML_idx
, -1);
266 void StringSequenceContext::onCharacters( const OUString
& rChars
)
268 switch( getCurrentElement() )
271 mrModel
.maFormula
= rChars
;
275 mrModel
.maFormula
= rChars
;
279 mrModel
.maData
[ (mrModel
.mnLevelCount
-1) * mrModel
.mnPointCount
+ mnPtIndex
] <<= rChars
;
284 DataSourceContext::DataSourceContext( ContextHandler2Helper
& rParent
, DataSourceModel
& rModel
) :
285 ContextBase
< DataSourceModel
>( rParent
, rModel
)
289 DataSourceContext::~DataSourceContext()
293 ContextHandlerRef
DataSourceContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& )
295 switch( getCurrentElement() )
298 case C_TOKEN( xVal
):
302 case C_TOKEN( multiLvlStrRef
):
303 case C_TOKEN( strLit
):
304 case C_TOKEN( strRef
):
305 case C15_TOKEN( datalabelsRange
):
306 OSL_ENSURE( !mrModel
.mxDataSeq
, "DataSourceContext::onCreateContext - multiple data sequences" );
307 return new StringSequenceContext( *this, mrModel
.mxDataSeq
.create() );
309 case C_TOKEN( numLit
):
310 case C_TOKEN( numRef
):
311 OSL_ENSURE( !mrModel
.mxDataSeq
, "DataSourceContext::onCreateContext - multiple data sequences" );
312 return new DoubleSequenceContext( *this, mrModel
.mxDataSeq
.create() );
316 case C_TOKEN( plus
):
317 case C_TOKEN( minus
):
319 case C_TOKEN( yVal
):
320 case C_TOKEN( bubbleSize
):
323 case C_TOKEN( numLit
):
324 case C_TOKEN( numRef
):
325 OSL_ENSURE( !mrModel
.mxDataSeq
, "DataSourceContext::onCreateContext - multiple data sequences" );
326 return new DoubleSequenceContext( *this, mrModel
.mxDataSeq
.create() );
333 } // namespace oox::drawingml::chart
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */