Line data Source code
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 :
20 : #include "SeriesOptionsItemConverter.hxx"
21 : #include "SchWhichPairs.hxx"
22 :
23 : #include "macros.hxx"
24 : #include "ItemPropertyMap.hxx"
25 : #include "GraphicPropertyItemConverter.hxx"
26 : #include "MultipleItemConverter.hxx"
27 : #include "ChartModelHelper.hxx"
28 : #include "AxisHelper.hxx"
29 : #include "DiagramHelper.hxx"
30 : #include "ChartTypeHelper.hxx"
31 : #include "DataSeriesHelper.hxx"
32 :
33 : #include <com/sun/star/chart/MissingValueTreatment.hpp>
34 : #include <com/sun/star/chart2/XDataSeries.hpp>
35 :
36 : // for SfxBoolItem
37 : #include <svl/eitem.hxx>
38 : #include <svl/intitem.hxx>
39 :
40 : //SfxIntegerListItem
41 : #include <svl/ilstitem.hxx>
42 :
43 : #include <rtl/math.hxx>
44 : #include <functional>
45 : #include <algorithm>
46 :
47 : using namespace ::com::sun::star;
48 : using namespace ::com::sun::star::chart2;
49 :
50 : namespace chart
51 : {
52 : namespace wrapper
53 : {
54 :
55 0 : SeriesOptionsItemConverter::SeriesOptionsItemConverter(
56 : const uno::Reference< frame::XModel >& xChartModel
57 : , const uno::Reference< uno::XComponentContext > & xContext
58 : , const uno::Reference< beans::XPropertySet >& xPropertySet
59 : , SfxItemPool& rItemPool )
60 : : ItemConverter( xPropertySet, rItemPool )
61 : , m_xChartModel(xChartModel)
62 : , m_xCC(xContext)
63 : , m_bAttachToMainAxis(true)
64 : , m_bSupportingOverlapAndGapWidthProperties(false)
65 : , m_bSupportingBarConnectors(false)
66 : , m_nBarOverlap(0)
67 : , m_nGapWidth(100)
68 : , m_bConnectBars(false)
69 : , m_bSupportingAxisSideBySide(false)
70 : , m_bGroupBarsPerAxis(true)
71 : , m_bAllSeriesAttachedToSameAxis(true)
72 : , m_nAllSeriesAxisIndex(-1)
73 : , m_bSupportingStartingAngle(false)
74 : , m_nStartingAngle(90)
75 : , m_bClockwise(false)
76 : , m_aSupportedMissingValueTreatments()
77 : , m_nMissingValueTreatment(0)
78 : , m_bSupportingPlottingOfHiddenCells(false)
79 0 : , m_bIncludeHiddenCells(true)
80 : {
81 : try
82 : {
83 0 : uno::Reference< XDataSeries > xDataSeries( xPropertySet, uno::UNO_QUERY );
84 :
85 0 : m_bAttachToMainAxis = DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries );
86 :
87 0 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram(xChartModel) );
88 0 : uno::Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY );
89 0 : uno::Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram , xDataSeries ) );
90 :
91 0 : m_xCooSys = DataSeriesHelper::getCoordinateSystemOfSeries( xDataSeries, xDiagram );
92 0 : if( m_xCooSys.is() )
93 : {
94 0 : uno::Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys ) );
95 0 : chart2::ScaleData aScale( xAxis->getScaleData() );
96 0 : m_bClockwise = (aScale.Orientation == chart2::AxisOrientation_REVERSE);
97 : }
98 :
99 0 : sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
100 0 : m_bSupportingOverlapAndGapWidthProperties = ChartTypeHelper::isSupportingOverlapAndGapWidthProperties( xChartType, nDimensionCount );
101 :
102 0 : if( m_bSupportingOverlapAndGapWidthProperties )
103 : {
104 :
105 0 : sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
106 :
107 0 : uno::Sequence< sal_Int32 > m_aBarPositionSequence;
108 0 : uno::Reference< beans::XPropertySet > xChartTypeProps( xChartType, uno::UNO_QUERY );
109 0 : if( xChartTypeProps.is() )
110 : {
111 0 : if( xChartTypeProps->getPropertyValue( "OverlapSequence" ) >>= m_aBarPositionSequence )
112 : {
113 0 : if( nAxisIndex >= 0 && nAxisIndex < m_aBarPositionSequence.getLength() )
114 0 : m_nBarOverlap = m_aBarPositionSequence[nAxisIndex];
115 : }
116 0 : if( xChartTypeProps->getPropertyValue( "GapwidthSequence" ) >>= m_aBarPositionSequence )
117 : {
118 0 : if( nAxisIndex >= 0 && nAxisIndex < m_aBarPositionSequence.getLength() )
119 0 : m_nGapWidth = m_aBarPositionSequence[nAxisIndex];
120 : }
121 0 : }
122 : }
123 :
124 0 : m_bSupportingBarConnectors = ChartTypeHelper::isSupportingBarConnectors( xChartType, nDimensionCount );
125 0 : if( m_bSupportingBarConnectors && xDiagramProperties.is() )
126 : {
127 0 : xDiagramProperties->getPropertyValue( "ConnectBars" ) >>= m_bConnectBars;
128 : }
129 :
130 0 : m_bSupportingAxisSideBySide = ChartTypeHelper::isSupportingAxisSideBySide( xChartType, nDimensionCount );
131 0 : if( m_bSupportingAxisSideBySide && xDiagramProperties.is() )
132 : {
133 0 : xDiagramProperties->getPropertyValue( "GroupBarsPerAxis" ) >>= m_bGroupBarsPerAxis;
134 0 : m_bAllSeriesAttachedToSameAxis = DataSeriesHelper::areAllSeriesAttachedToSameAxis( xChartType, m_nAllSeriesAxisIndex );
135 : }
136 :
137 0 : m_bSupportingStartingAngle = ChartTypeHelper::isSupportingStartingAngle( xChartType );
138 0 : if( m_bSupportingStartingAngle )
139 : {
140 0 : xDiagramProperties->getPropertyValue( "StartingAngle" ) >>= m_nStartingAngle;
141 : }
142 :
143 0 : m_aSupportedMissingValueTreatments = ChartTypeHelper::getSupportedMissingValueTreatments( xChartType );
144 : m_nMissingValueTreatment = DiagramHelper::getCorrectedMissingValueTreatment(
145 0 : ChartModelHelper::findDiagram(m_xChartModel), xChartType );
146 :
147 0 : uno::Reference< XChartDocument > xChartDoc( m_xChartModel, uno::UNO_QUERY );
148 0 : uno::Reference< beans::XPropertySet > xProp( xChartDoc->getDataProvider(), uno::UNO_QUERY );
149 0 : if( xProp.is() )
150 : {
151 : try
152 : {
153 : //test whether the data provider offers this property
154 0 : xProp->getPropertyValue( "IncludeHiddenCells" );
155 : //if not exception is thrown the property is offered
156 0 : m_bSupportingPlottingOfHiddenCells = true;
157 0 : xDiagramProperties->getPropertyValue( "IncludeHiddenCells" ) >>= m_bIncludeHiddenCells;
158 : }
159 0 : catch( const beans::UnknownPropertyException& )
160 : {
161 : }
162 0 : }
163 : }
164 0 : catch( const uno::Exception &ex )
165 : {
166 : ASSERT_EXCEPTION( ex );
167 : }
168 0 : }
169 :
170 0 : SeriesOptionsItemConverter::~SeriesOptionsItemConverter()
171 : {
172 0 : }
173 :
174 0 : const sal_uInt16 * SeriesOptionsItemConverter::GetWhichPairs() const
175 : {
176 : // must span all used items!
177 0 : return nSeriesOptionsWhichPairs;
178 : }
179 :
180 0 : bool SeriesOptionsItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
181 : {
182 0 : return false;
183 : }
184 :
185 0 : bool SeriesOptionsItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
186 : throw( uno::Exception )
187 : {
188 0 : bool bChanged = false;
189 0 : switch( nWhichId )
190 : {
191 : case SCHATTR_AXIS:
192 : {
193 : sal_Int32 nItemValue = static_cast< const SfxInt32Item & >(
194 0 : rItemSet.Get( nWhichId )).GetValue();
195 0 : bool bAttachToMainAxis = nItemValue == CHART_AXIS_PRIMARY_Y;
196 0 : if( bAttachToMainAxis != m_bAttachToMainAxis )
197 : {
198 : //change model:
199 : bChanged = DiagramHelper::attachSeriesToAxis( bAttachToMainAxis, uno::Reference< XDataSeries >::query( GetPropertySet() )
200 0 : , ChartModelHelper::findDiagram(m_xChartModel), m_xCC );
201 :
202 0 : if( bChanged )
203 0 : m_bAttachToMainAxis = bAttachToMainAxis;
204 : }
205 : }
206 0 : break;
207 :
208 : case SCHATTR_BAR_OVERLAP:
209 : case SCHATTR_BAR_GAPWIDTH:
210 : {
211 0 : if( m_bSupportingOverlapAndGapWidthProperties )
212 : {
213 0 : sal_Int32& rBarPosition = ( SCHATTR_BAR_OVERLAP == nWhichId ) ? m_nBarOverlap : m_nGapWidth;
214 0 : rBarPosition = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
215 :
216 0 : OUString aPropName("GapwidthSequence" );
217 0 : if( SCHATTR_BAR_OVERLAP == nWhichId )
218 0 : aPropName = "OverlapSequence";
219 :
220 0 : uno::Reference< XDataSeries > xDataSeries( GetPropertySet(), uno::UNO_QUERY );
221 0 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram(m_xChartModel) );
222 0 : uno::Reference< beans::XPropertySet > xChartTypeProps( DiagramHelper::getChartTypeOfSeries( xDiagram , xDataSeries ), uno::UNO_QUERY );
223 0 : if( xChartTypeProps.is() )
224 : {
225 0 : sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
226 0 : uno::Sequence< sal_Int32 > m_aBarPositionSequence;
227 0 : if( xChartTypeProps.is() )
228 : {
229 0 : if( xChartTypeProps->getPropertyValue( aPropName ) >>= m_aBarPositionSequence )
230 : {
231 0 : bool bGroupBarsPerAxis = static_cast< const SfxBoolItem & >(rItemSet.Get( SCHATTR_GROUP_BARS_PER_AXIS )).GetValue();
232 0 : if(!bGroupBarsPerAxis)
233 : {
234 : //set the same value for all axes
235 0 : for( sal_Int32 nN = 0; nN < m_aBarPositionSequence.getLength(); nN++ )
236 0 : m_aBarPositionSequence[nN] = rBarPosition;
237 : }
238 0 : else if( nAxisIndex >= 0 && nAxisIndex < m_aBarPositionSequence.getLength() )
239 0 : m_aBarPositionSequence[nAxisIndex] = rBarPosition;
240 :
241 0 : xChartTypeProps->setPropertyValue( aPropName, uno::makeAny(m_aBarPositionSequence) );
242 0 : bChanged = true;
243 : }
244 0 : }
245 0 : }
246 : }
247 : }
248 0 : break;
249 :
250 : case SCHATTR_BAR_CONNECT:
251 : {
252 0 : sal_Bool bOldConnectBars = sal_False;
253 : m_bConnectBars = static_cast< const SfxBoolItem & >(
254 0 : rItemSet.Get( nWhichId )).GetValue();
255 0 : if( m_bSupportingBarConnectors )
256 : {
257 0 : uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
258 0 : if( xDiagramProperties.is() &&
259 0 : (xDiagramProperties->getPropertyValue( "ConnectBars" ) >>= bOldConnectBars) &&
260 0 : bOldConnectBars != m_bConnectBars )
261 : {
262 0 : xDiagramProperties->setPropertyValue( "ConnectBars" , uno::makeAny(m_bConnectBars) );
263 0 : bChanged = true;
264 0 : }
265 : }
266 : }
267 0 : break;
268 :
269 : case SCHATTR_GROUP_BARS_PER_AXIS:
270 : {
271 0 : bool bOldGroupBarsPerAxis = true;
272 : m_bGroupBarsPerAxis = static_cast< const SfxBoolItem & >(
273 0 : rItemSet.Get( nWhichId )).GetValue();
274 0 : if( m_bSupportingAxisSideBySide )
275 : {
276 0 : uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
277 0 : if( xDiagramProperties.is() &&
278 0 : (xDiagramProperties->getPropertyValue( "GroupBarsPerAxis" ) >>= bOldGroupBarsPerAxis) &&
279 0 : bOldGroupBarsPerAxis != m_bGroupBarsPerAxis )
280 : {
281 0 : xDiagramProperties->setPropertyValue( "GroupBarsPerAxis" , uno::makeAny(m_bGroupBarsPerAxis) );
282 0 : bChanged = true;
283 0 : }
284 : }
285 : }
286 0 : break;
287 :
288 : case SCHATTR_STARTING_ANGLE:
289 : {
290 0 : if( m_bSupportingStartingAngle )
291 : {
292 0 : m_nStartingAngle = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
293 0 : uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
294 0 : if( xDiagramProperties.is() )
295 : {
296 0 : xDiagramProperties->setPropertyValue( "StartingAngle" , uno::makeAny(m_nStartingAngle) );
297 0 : bChanged = true;
298 0 : }
299 : }
300 : }
301 0 : break;
302 :
303 : case SCHATTR_CLOCKWISE:
304 : {
305 : bool bClockwise = (static_cast< const SfxBoolItem & >(
306 0 : rItemSet.Get( nWhichId )).GetValue() );
307 0 : if( m_xCooSys.is() )
308 : {
309 0 : uno::Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys ) );
310 0 : if( xAxis.is() )
311 : {
312 0 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
313 0 : aScaleData.Orientation = bClockwise ? chart2::AxisOrientation_REVERSE : chart2::AxisOrientation_MATHEMATICAL;
314 0 : xAxis->setScaleData( aScaleData );
315 0 : bChanged = true;
316 0 : }
317 : }
318 : }
319 0 : break;
320 :
321 : case SCHATTR_MISSING_VALUE_TREATMENT:
322 : {
323 0 : if( m_aSupportedMissingValueTreatments.getLength() )
324 : {
325 0 : sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
326 0 : if( m_nMissingValueTreatment != nNew )
327 : {
328 : try
329 : {
330 0 : uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
331 0 : if( xDiagramProperties.is() )
332 : {
333 0 : xDiagramProperties->setPropertyValue( "MissingValueTreatment" , uno::makeAny( nNew ));
334 0 : bChanged = true;
335 0 : }
336 : }
337 0 : catch( const uno::Exception& e )
338 : {
339 : ASSERT_EXCEPTION( e );
340 : }
341 : }
342 : }
343 : }
344 0 : break;
345 : case SCHATTR_INCLUDE_HIDDEN_CELLS:
346 : {
347 0 : if( m_bSupportingPlottingOfHiddenCells )
348 : {
349 0 : bool bIncludeHiddenCells = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
350 0 : if (bIncludeHiddenCells != m_bIncludeHiddenCells)
351 : {
352 0 : ChartModel* pModel = dynamic_cast<ChartModel*>(m_xChartModel.get());
353 0 : if (pModel)
354 0 : bChanged = ChartModelHelper::setIncludeHiddenCells( bIncludeHiddenCells, *pModel );
355 : }
356 : }
357 : }
358 0 : break;
359 : }
360 0 : return bChanged;
361 : }
362 :
363 0 : void SeriesOptionsItemConverter::FillSpecialItem(
364 : sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
365 : throw( uno::Exception )
366 : {
367 0 : switch( nWhichId )
368 : {
369 : case SCHATTR_AXIS:
370 : {
371 0 : sal_Int32 nItemValue = m_bAttachToMainAxis ? CHART_AXIS_PRIMARY_Y : CHART_AXIS_SECONDARY_Y;
372 0 : rOutItemSet.Put( SfxInt32Item(nWhichId,nItemValue ) );
373 0 : break;
374 : }
375 : case SCHATTR_BAR_OVERLAP:
376 : {
377 0 : if( m_bSupportingOverlapAndGapWidthProperties )
378 0 : rOutItemSet.Put( SfxInt32Item(nWhichId,m_nBarOverlap) );
379 0 : break;
380 : }
381 : case SCHATTR_BAR_GAPWIDTH:
382 : {
383 0 : if( m_bSupportingOverlapAndGapWidthProperties )
384 0 : rOutItemSet.Put( SfxInt32Item(nWhichId,m_nGapWidth) );
385 0 : break;
386 : }
387 : case SCHATTR_BAR_CONNECT:
388 : {
389 0 : if( m_bSupportingBarConnectors )
390 0 : rOutItemSet.Put( SfxBoolItem(nWhichId,m_bConnectBars));
391 0 : break;
392 : }
393 : case SCHATTR_GROUP_BARS_PER_AXIS:
394 : {
395 0 : if( m_bSupportingAxisSideBySide )
396 0 : rOutItemSet.Put( SfxBoolItem(nWhichId,m_bGroupBarsPerAxis) );
397 0 : break;
398 : }
399 : case SCHATTR_AXIS_FOR_ALL_SERIES:
400 : {
401 0 : if( m_nAllSeriesAxisIndex != - 1)
402 0 : rOutItemSet.Put( SfxInt32Item(nWhichId, m_nAllSeriesAxisIndex));
403 0 : break;
404 : }
405 : case SCHATTR_STARTING_ANGLE:
406 : {
407 0 : if( m_bSupportingStartingAngle )
408 0 : rOutItemSet.Put( SfxInt32Item(nWhichId,m_nStartingAngle));
409 0 : break;
410 : }
411 : case SCHATTR_CLOCKWISE:
412 : {
413 0 : rOutItemSet.Put( SfxBoolItem(nWhichId,m_bClockwise) );
414 0 : break;
415 : }
416 : case SCHATTR_MISSING_VALUE_TREATMENT:
417 : {
418 0 : if( m_aSupportedMissingValueTreatments.getLength() )
419 0 : rOutItemSet.Put( SfxInt32Item( nWhichId, m_nMissingValueTreatment ));
420 0 : break;
421 : }
422 : case SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS:
423 : {
424 0 : rOutItemSet.Put( SfxIntegerListItem( nWhichId, m_aSupportedMissingValueTreatments ) );
425 0 : break;
426 : }
427 : case SCHATTR_INCLUDE_HIDDEN_CELLS:
428 : {
429 0 : if( m_bSupportingPlottingOfHiddenCells )
430 0 : rOutItemSet.Put( SfxBoolItem(nWhichId, m_bIncludeHiddenCells) );
431 0 : break;
432 : }
433 : default:
434 0 : break;
435 : }
436 0 : }
437 :
438 : } // namespace wrapper
439 : } // namespace chart
440 :
441 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|