fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / SeriesOptionsItemConverter.cxx
blob52451c938d2ba7a6af42a4be093e30a966d980c9
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 "SeriesOptionsItemConverter.hxx"
21 #include "SchWhichPairs.hxx"
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"
33 #include <com/sun/star/chart/MissingValueTreatment.hpp>
34 #include <com/sun/star/chart2/XDataSeries.hpp>
36 #include <svl/eitem.hxx>
37 #include <svl/intitem.hxx>
38 #include <svl/ilstitem.hxx>
39 #include <rtl/math.hxx>
41 #include <functional>
42 #include <algorithm>
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::chart2;
47 namespace chart
49 namespace wrapper
52 SeriesOptionsItemConverter::SeriesOptionsItemConverter(
53 const uno::Reference< frame::XModel >& xChartModel
54 , const uno::Reference< uno::XComponentContext > & xContext
55 , const uno::Reference< beans::XPropertySet >& xPropertySet
56 , SfxItemPool& rItemPool )
57 : ItemConverter( xPropertySet, rItemPool )
58 , m_xChartModel(xChartModel)
59 , m_xCC(xContext)
60 , m_bAttachToMainAxis(true)
61 , m_bSupportingOverlapAndGapWidthProperties(false)
62 , m_bSupportingBarConnectors(false)
63 , m_nBarOverlap(0)
64 , m_nGapWidth(100)
65 , m_bConnectBars(false)
66 , m_bSupportingAxisSideBySide(false)
67 , m_bGroupBarsPerAxis(true)
68 , m_bAllSeriesAttachedToSameAxis(true)
69 , m_nAllSeriesAxisIndex(-1)
70 , m_bSupportingStartingAngle(false)
71 , m_nStartingAngle(90)
72 , m_bClockwise(false)
73 , m_aSupportedMissingValueTreatments()
74 , m_nMissingValueTreatment(0)
75 , m_bSupportingPlottingOfHiddenCells(false)
76 , m_bIncludeHiddenCells(true)
78 try
80 uno::Reference< XDataSeries > xDataSeries( xPropertySet, uno::UNO_QUERY );
82 m_bAttachToMainAxis = DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries );
84 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram(xChartModel) );
85 uno::Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY );
86 uno::Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram , xDataSeries ) );
88 m_xCooSys = DataSeriesHelper::getCoordinateSystemOfSeries( xDataSeries, xDiagram );
89 if( m_xCooSys.is() )
91 uno::Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys ) );
92 chart2::ScaleData aScale( xAxis->getScaleData() );
93 m_bClockwise = (aScale.Orientation == chart2::AxisOrientation_REVERSE);
96 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
97 m_bSupportingOverlapAndGapWidthProperties = ChartTypeHelper::isSupportingOverlapAndGapWidthProperties( xChartType, nDimensionCount );
99 if( m_bSupportingOverlapAndGapWidthProperties )
102 sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
104 uno::Sequence< sal_Int32 > m_aBarPositionSequence;
105 uno::Reference< beans::XPropertySet > xChartTypeProps( xChartType, uno::UNO_QUERY );
106 if( xChartTypeProps.is() )
108 if( xChartTypeProps->getPropertyValue( "OverlapSequence" ) >>= m_aBarPositionSequence )
110 if( nAxisIndex >= 0 && nAxisIndex < m_aBarPositionSequence.getLength() )
111 m_nBarOverlap = m_aBarPositionSequence[nAxisIndex];
113 if( xChartTypeProps->getPropertyValue( "GapwidthSequence" ) >>= m_aBarPositionSequence )
115 if( nAxisIndex >= 0 && nAxisIndex < m_aBarPositionSequence.getLength() )
116 m_nGapWidth = m_aBarPositionSequence[nAxisIndex];
121 m_bSupportingBarConnectors = ChartTypeHelper::isSupportingBarConnectors( xChartType, nDimensionCount );
122 if( m_bSupportingBarConnectors && xDiagramProperties.is() )
124 xDiagramProperties->getPropertyValue( "ConnectBars" ) >>= m_bConnectBars;
127 m_bSupportingAxisSideBySide = ChartTypeHelper::isSupportingAxisSideBySide( xChartType, nDimensionCount );
128 if( m_bSupportingAxisSideBySide && xDiagramProperties.is() )
130 xDiagramProperties->getPropertyValue( "GroupBarsPerAxis" ) >>= m_bGroupBarsPerAxis;
131 m_bAllSeriesAttachedToSameAxis = DataSeriesHelper::areAllSeriesAttachedToSameAxis( xChartType, m_nAllSeriesAxisIndex );
134 m_bSupportingStartingAngle = ChartTypeHelper::isSupportingStartingAngle( xChartType );
135 if( m_bSupportingStartingAngle )
137 xDiagramProperties->getPropertyValue( "StartingAngle" ) >>= m_nStartingAngle;
140 m_aSupportedMissingValueTreatments = ChartTypeHelper::getSupportedMissingValueTreatments( xChartType );
141 m_nMissingValueTreatment = DiagramHelper::getCorrectedMissingValueTreatment(
142 ChartModelHelper::findDiagram(m_xChartModel), xChartType );
144 uno::Reference< XChartDocument > xChartDoc( m_xChartModel, uno::UNO_QUERY );
145 uno::Reference< beans::XPropertySet > xProp( xChartDoc->getDataProvider(), uno::UNO_QUERY );
146 if( xProp.is() )
150 //test whether the data provider offers this property
151 xProp->getPropertyValue( "IncludeHiddenCells" );
152 //if not exception is thrown the property is offered
153 m_bSupportingPlottingOfHiddenCells = true;
154 xDiagramProperties->getPropertyValue( "IncludeHiddenCells" ) >>= m_bIncludeHiddenCells;
156 catch( const beans::UnknownPropertyException& )
161 catch( const uno::Exception &ex )
163 ASSERT_EXCEPTION( ex );
167 SeriesOptionsItemConverter::~SeriesOptionsItemConverter()
171 const sal_uInt16 * SeriesOptionsItemConverter::GetWhichPairs() const
173 // must span all used items!
174 return nSeriesOptionsWhichPairs;
177 bool SeriesOptionsItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
179 return false;
182 bool SeriesOptionsItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
183 throw( uno::Exception )
185 bool bChanged = false;
186 switch( nWhichId )
188 case SCHATTR_AXIS:
190 sal_Int32 nItemValue = static_cast< const SfxInt32Item & >(
191 rItemSet.Get( nWhichId )).GetValue();
192 bool bAttachToMainAxis = nItemValue == CHART_AXIS_PRIMARY_Y;
193 if( bAttachToMainAxis != m_bAttachToMainAxis )
195 //change model:
196 bChanged = DiagramHelper::attachSeriesToAxis( bAttachToMainAxis, uno::Reference< XDataSeries >::query( GetPropertySet() )
197 , ChartModelHelper::findDiagram(m_xChartModel), m_xCC );
199 if( bChanged )
200 m_bAttachToMainAxis = bAttachToMainAxis;
203 break;
205 case SCHATTR_BAR_OVERLAP:
206 case SCHATTR_BAR_GAPWIDTH:
208 if( m_bSupportingOverlapAndGapWidthProperties )
210 sal_Int32& rBarPosition = ( SCHATTR_BAR_OVERLAP == nWhichId ) ? m_nBarOverlap : m_nGapWidth;
211 rBarPosition = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
213 OUString aPropName("GapwidthSequence" );
214 if( SCHATTR_BAR_OVERLAP == nWhichId )
215 aPropName = "OverlapSequence";
217 uno::Reference< XDataSeries > xDataSeries( GetPropertySet(), uno::UNO_QUERY );
218 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram(m_xChartModel) );
219 uno::Reference< beans::XPropertySet > xChartTypeProps( DiagramHelper::getChartTypeOfSeries( xDiagram , xDataSeries ), uno::UNO_QUERY );
220 if( xChartTypeProps.is() )
222 sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
223 uno::Sequence< sal_Int32 > m_aBarPositionSequence;
224 if( xChartTypeProps.is() )
226 if( xChartTypeProps->getPropertyValue( aPropName ) >>= m_aBarPositionSequence )
228 bool bGroupBarsPerAxis = static_cast< const SfxBoolItem & >(rItemSet.Get( SCHATTR_GROUP_BARS_PER_AXIS )).GetValue();
229 if(!bGroupBarsPerAxis)
231 //set the same value for all axes
232 for( sal_Int32 nN = 0; nN < m_aBarPositionSequence.getLength(); nN++ )
233 m_aBarPositionSequence[nN] = rBarPosition;
235 else if( nAxisIndex >= 0 && nAxisIndex < m_aBarPositionSequence.getLength() )
236 m_aBarPositionSequence[nAxisIndex] = rBarPosition;
238 xChartTypeProps->setPropertyValue( aPropName, uno::makeAny(m_aBarPositionSequence) );
239 bChanged = true;
245 break;
247 case SCHATTR_BAR_CONNECT:
249 m_bConnectBars = static_cast< const SfxBoolItem & >(
250 rItemSet.Get( nWhichId )).GetValue();
251 if( m_bSupportingBarConnectors )
253 bool bOldConnectBars = false;
254 uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
255 if( xDiagramProperties.is() &&
256 (xDiagramProperties->getPropertyValue( "ConnectBars" ) >>= bOldConnectBars) &&
257 bOldConnectBars != m_bConnectBars )
259 xDiagramProperties->setPropertyValue( "ConnectBars" , uno::makeAny(m_bConnectBars) );
260 bChanged = true;
264 break;
266 case SCHATTR_GROUP_BARS_PER_AXIS:
268 m_bGroupBarsPerAxis = static_cast< const SfxBoolItem & >(
269 rItemSet.Get( nWhichId )).GetValue();
270 if( m_bSupportingAxisSideBySide )
272 bool bOldGroupBarsPerAxis = true;
273 uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
274 if( xDiagramProperties.is() &&
275 (xDiagramProperties->getPropertyValue( "GroupBarsPerAxis" ) >>= bOldGroupBarsPerAxis) &&
276 bOldGroupBarsPerAxis != m_bGroupBarsPerAxis )
278 xDiagramProperties->setPropertyValue( "GroupBarsPerAxis" , uno::makeAny(m_bGroupBarsPerAxis) );
279 bChanged = true;
283 break;
285 case SCHATTR_STARTING_ANGLE:
287 if( m_bSupportingStartingAngle )
289 m_nStartingAngle = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
290 uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
291 if( xDiagramProperties.is() )
293 xDiagramProperties->setPropertyValue( "StartingAngle" , uno::makeAny(m_nStartingAngle) );
294 bChanged = true;
298 break;
300 case SCHATTR_CLOCKWISE:
302 bool bClockwise = (static_cast< const SfxBoolItem & >(
303 rItemSet.Get( nWhichId )).GetValue() );
304 if( m_xCooSys.is() )
306 uno::Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys ) );
307 if( xAxis.is() )
309 chart2::ScaleData aScaleData( xAxis->getScaleData() );
310 aScaleData.Orientation = bClockwise ? chart2::AxisOrientation_REVERSE : chart2::AxisOrientation_MATHEMATICAL;
311 xAxis->setScaleData( aScaleData );
312 bChanged = true;
316 break;
318 case SCHATTR_MISSING_VALUE_TREATMENT:
320 if( m_aSupportedMissingValueTreatments.getLength() )
322 sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
323 if( m_nMissingValueTreatment != nNew )
327 uno::Reference< beans::XPropertySet > xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel), uno::UNO_QUERY );
328 if( xDiagramProperties.is() )
330 xDiagramProperties->setPropertyValue( "MissingValueTreatment" , uno::makeAny( nNew ));
331 bChanged = true;
334 catch( const uno::Exception& e )
336 ASSERT_EXCEPTION( e );
341 break;
342 case SCHATTR_INCLUDE_HIDDEN_CELLS:
344 if( m_bSupportingPlottingOfHiddenCells )
346 bool bIncludeHiddenCells = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
347 if (bIncludeHiddenCells != m_bIncludeHiddenCells)
349 ChartModel* pModel = dynamic_cast<ChartModel*>(m_xChartModel.get());
350 if (pModel)
351 bChanged = ChartModelHelper::setIncludeHiddenCells( bIncludeHiddenCells, *pModel );
355 break;
357 return bChanged;
360 void SeriesOptionsItemConverter::FillSpecialItem(
361 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
362 throw( uno::Exception )
364 switch( nWhichId )
366 case SCHATTR_AXIS:
368 sal_Int32 nItemValue = m_bAttachToMainAxis ? CHART_AXIS_PRIMARY_Y : CHART_AXIS_SECONDARY_Y;
369 rOutItemSet.Put( SfxInt32Item(nWhichId,nItemValue ) );
370 break;
372 case SCHATTR_BAR_OVERLAP:
374 if( m_bSupportingOverlapAndGapWidthProperties )
375 rOutItemSet.Put( SfxInt32Item(nWhichId,m_nBarOverlap) );
376 break;
378 case SCHATTR_BAR_GAPWIDTH:
380 if( m_bSupportingOverlapAndGapWidthProperties )
381 rOutItemSet.Put( SfxInt32Item(nWhichId,m_nGapWidth) );
382 break;
384 case SCHATTR_BAR_CONNECT:
386 if( m_bSupportingBarConnectors )
387 rOutItemSet.Put( SfxBoolItem(nWhichId,m_bConnectBars));
388 break;
390 case SCHATTR_GROUP_BARS_PER_AXIS:
392 if( m_bSupportingAxisSideBySide )
393 rOutItemSet.Put( SfxBoolItem(nWhichId,m_bGroupBarsPerAxis) );
394 break;
396 case SCHATTR_AXIS_FOR_ALL_SERIES:
398 if( m_nAllSeriesAxisIndex != - 1)
399 rOutItemSet.Put( SfxInt32Item(nWhichId, m_nAllSeriesAxisIndex));
400 break;
402 case SCHATTR_STARTING_ANGLE:
404 if( m_bSupportingStartingAngle )
405 rOutItemSet.Put( SfxInt32Item(nWhichId,m_nStartingAngle));
406 break;
408 case SCHATTR_CLOCKWISE:
410 rOutItemSet.Put( SfxBoolItem(nWhichId,m_bClockwise) );
411 break;
413 case SCHATTR_MISSING_VALUE_TREATMENT:
415 if( m_aSupportedMissingValueTreatments.getLength() )
416 rOutItemSet.Put( SfxInt32Item( nWhichId, m_nMissingValueTreatment ));
417 break;
419 case SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS:
421 rOutItemSet.Put( SfxIntegerListItem( nWhichId, m_aSupportedMissingValueTreatments ) );
422 break;
424 case SCHATTR_INCLUDE_HIDDEN_CELLS:
426 if( m_bSupportingPlottingOfHiddenCells )
427 rOutItemSet.Put( SfxBoolItem(nWhichId, m_bIncludeHiddenCells) );
428 break;
430 default:
431 break;
435 } // namespace wrapper
436 } // namespace chart
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */