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