1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SeriesOptionsItemConverter.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "SeriesOptionsItemConverter.hxx"
35 #include "SchWhichPairs.hxx"
38 #include "ItemPropertyMap.hxx"
39 #include "GraphicPropertyItemConverter.hxx"
40 #include "MultipleItemConverter.hxx"
41 #include "ChartModelHelper.hxx"
42 #include "AxisHelper.hxx"
43 #include "DiagramHelper.hxx"
44 #include "ChartTypeHelper.hxx"
45 #include "DataSeriesHelper.hxx"
47 #include <com/sun/star/chart/MissingValueTreatment.hpp>
48 #include <com/sun/star/chart2/XDataSeries.hpp>
51 #include <svtools/eitem.hxx>
52 #include <svtools/intitem.hxx>
55 #include <svtools/ilstitem.hxx>
56 #define _SVSTDARR_ULONGS
57 #include <svtools/svstdarr.hxx>
59 #include <rtl/math.hxx>
63 using namespace ::com::sun::star
;
64 using namespace ::com::sun::star::chart2
;
71 // ========================================
73 SeriesOptionsItemConverter::SeriesOptionsItemConverter(
74 const uno::Reference
< frame::XModel
>& xChartModel
75 , const uno::Reference
< uno::XComponentContext
> & xContext
76 , const uno::Reference
< beans::XPropertySet
>& xPropertySet
77 , SfxItemPool
& rItemPool
)
78 : ItemConverter( xPropertySet
, rItemPool
)
79 , m_xChartModel(xChartModel
)
81 , m_bAttachToMainAxis(true)
82 , m_bSupportingOverlapAndGapWidthProperties(false)
83 , m_bSupportingBarConnectors(false)
86 , m_bConnectBars(false)
87 , m_bSupportingAxisSideBySide(false)
88 , m_bGroupBarsPerAxis(true)
89 , m_bAllSeriesAttachedToSameAxis(true)
90 , m_nAllSeriesAxisIndex(-1)
91 , m_bSupportingStartingAngle(false)
92 , m_nStartingAngle(90)
94 , m_aSupportedMissingValueTreatments()
95 , m_nMissingValueTreatment(0)
96 , m_bSupportingPlottingOfHiddenCells(false)
97 , m_bIncludeHiddenCells(true)
101 uno::Reference
< XDataSeries
> xDataSeries( xPropertySet
, uno::UNO_QUERY
);
103 m_bAttachToMainAxis
= DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries
);
105 uno::Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram(xChartModel
) );
106 uno::Reference
< beans::XPropertySet
> xDiagramProperties( xDiagram
, uno::UNO_QUERY
);
107 uno::Reference
< XChartType
> xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram
, xDataSeries
) );
109 m_xCooSys
= DataSeriesHelper::getCoordinateSystemOfSeries( xDataSeries
, xDiagram
);
112 uno::Reference
< chart2::XAxis
> xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys
) );
113 chart2::ScaleData
aScale( xAxis
->getScaleData() );
114 m_bClockwise
= (aScale
.Orientation
== chart2::AxisOrientation_REVERSE
);
117 sal_Int32 nDimensionCount
= DiagramHelper::getDimension( xDiagram
);
118 m_bSupportingOverlapAndGapWidthProperties
= ChartTypeHelper::isSupportingOverlapAndGapWidthProperties( xChartType
, nDimensionCount
);
120 if( m_bSupportingOverlapAndGapWidthProperties
)
123 sal_Int32 nAxisIndex
= DataSeriesHelper::getAttachedAxisIndex(xDataSeries
);
125 uno::Sequence
< sal_Int32
> m_aBarPositionSequence
;
126 uno::Reference
< beans::XPropertySet
> xChartTypeProps( xChartType
, uno::UNO_QUERY
);
127 if( xChartTypeProps
.is() )
129 if( xChartTypeProps
->getPropertyValue( C2U( "OverlapSequence" ) ) >>= m_aBarPositionSequence
)
131 if( nAxisIndex
>= 0 && nAxisIndex
< m_aBarPositionSequence
.getLength() )
132 m_nBarOverlap
= m_aBarPositionSequence
[nAxisIndex
];
134 if( xChartTypeProps
->getPropertyValue( C2U( "GapwidthSequence" ) ) >>= m_aBarPositionSequence
)
136 if( nAxisIndex
>= 0 && nAxisIndex
< m_aBarPositionSequence
.getLength() )
137 m_nGapWidth
= m_aBarPositionSequence
[nAxisIndex
];
142 m_bSupportingBarConnectors
= ChartTypeHelper::isSupportingBarConnectors( xChartType
, nDimensionCount
);
143 if( m_bSupportingBarConnectors
&& xDiagramProperties
.is() )
145 xDiagramProperties
->getPropertyValue( C2U("ConnectBars")) >>= m_bConnectBars
;
148 m_bSupportingAxisSideBySide
= ChartTypeHelper::isSupportingAxisSideBySide( xChartType
, nDimensionCount
);
149 if( m_bSupportingAxisSideBySide
&& xDiagramProperties
.is() )
151 xDiagramProperties
->getPropertyValue( C2U("GroupBarsPerAxis")) >>= m_bGroupBarsPerAxis
;
152 m_bAllSeriesAttachedToSameAxis
= DataSeriesHelper::areAllSeriesAttachedToSameAxis( xChartType
, m_nAllSeriesAxisIndex
);
155 m_bSupportingStartingAngle
= ChartTypeHelper::isSupportingStartingAngle( xChartType
);
156 if( m_bSupportingStartingAngle
)
158 xDiagramProperties
->getPropertyValue( C2U( "StartingAngle" ) ) >>= m_nStartingAngle
;
161 m_aSupportedMissingValueTreatments
= ChartTypeHelper::getSupportedMissingValueTreatments( xChartType
);
162 m_nMissingValueTreatment
= DiagramHelper::getCorrectedMissingValueTreatment(
163 ChartModelHelper::findDiagram(m_xChartModel
), xChartType
);
165 uno::Reference
< XChartDocument
> xChartDoc( m_xChartModel
, uno::UNO_QUERY
);
166 uno::Reference
< beans::XPropertySet
> xProp( xChartDoc
->getDataProvider(), uno::UNO_QUERY
);
171 //test whether the data provider offers this property
172 xProp
->getPropertyValue(C2U("IncludeHiddenCells"));
173 //if not exception is thrown the property is offered
174 m_bSupportingPlottingOfHiddenCells
= true;
175 xDiagramProperties
->getPropertyValue( C2U("IncludeHiddenCells") ) >>= m_bIncludeHiddenCells
;
177 catch( const beans::UnknownPropertyException
& )
182 catch( uno::Exception ex
)
184 ASSERT_EXCEPTION( ex
);
188 SeriesOptionsItemConverter::~SeriesOptionsItemConverter()
192 const USHORT
* SeriesOptionsItemConverter::GetWhichPairs() const
194 // must span all used items!
195 return nSeriesOptionsWhichPairs
;
198 bool SeriesOptionsItemConverter::GetItemProperty( tWhichIdType
/*nWhichId*/, tPropertyNameWithMemberId
& /*rOutProperty*/ ) const
203 bool SeriesOptionsItemConverter::ApplySpecialItem( USHORT nWhichId
, const SfxItemSet
& rItemSet
)
204 throw( uno::Exception
)
206 bool bChanged
= false;
211 sal_Int32 nItemValue
= static_cast< const SfxInt32Item
& >(
212 rItemSet
.Get( nWhichId
)).GetValue();
213 bool bAttachToMainAxis
= nItemValue
== CHART_AXIS_PRIMARY_Y
;
214 if( bAttachToMainAxis
!= m_bAttachToMainAxis
)
217 bChanged
= DiagramHelper::attachSeriesToAxis( bAttachToMainAxis
, uno::Reference
< XDataSeries
>::query( GetPropertySet() )
218 , ChartModelHelper::findDiagram(m_xChartModel
), m_xCC
);
221 m_bAttachToMainAxis
= bAttachToMainAxis
;
226 case SCHATTR_BAR_OVERLAP
:
227 case SCHATTR_BAR_GAPWIDTH
:
229 if( m_bSupportingOverlapAndGapWidthProperties
)
231 sal_Int32
& rBarPosition
= ( SCHATTR_BAR_OVERLAP
== nWhichId
) ? m_nBarOverlap
: m_nGapWidth
;
232 rBarPosition
= static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue();
234 rtl::OUString
aPropName( C2U( "GapwidthSequence" ) );
235 if( SCHATTR_BAR_OVERLAP
== nWhichId
)
236 aPropName
= C2U( "OverlapSequence" );
238 uno::Reference
< XDataSeries
> xDataSeries( GetPropertySet(), uno::UNO_QUERY
);
239 uno::Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram(m_xChartModel
) );
240 uno::Reference
< beans::XPropertySet
> xChartTypeProps( DiagramHelper::getChartTypeOfSeries( xDiagram
, xDataSeries
), uno::UNO_QUERY
);
241 if( xChartTypeProps
.is() )
243 sal_Int32 nAxisIndex
= DataSeriesHelper::getAttachedAxisIndex(xDataSeries
);
244 uno::Sequence
< sal_Int32
> m_aBarPositionSequence
;
245 if( xChartTypeProps
.is() )
247 if( xChartTypeProps
->getPropertyValue( aPropName
) >>= m_aBarPositionSequence
)
249 bool bGroupBarsPerAxis
= static_cast< const SfxBoolItem
& >(rItemSet
.Get( SCHATTR_GROUP_BARS_PER_AXIS
)).GetValue();
250 if(!bGroupBarsPerAxis
)
252 //set the same value for all axes
253 for( sal_Int32 nN
= 0; nN
< m_aBarPositionSequence
.getLength(); nN
++ )
254 m_aBarPositionSequence
[nN
] = rBarPosition
;
256 else if( nAxisIndex
>= 0 && nAxisIndex
< m_aBarPositionSequence
.getLength() )
257 m_aBarPositionSequence
[nAxisIndex
] = rBarPosition
;
259 xChartTypeProps
->setPropertyValue( aPropName
, uno::makeAny(m_aBarPositionSequence
) );
268 case SCHATTR_BAR_CONNECT
:
270 sal_Bool bOldConnectBars
= sal_False
;
271 m_bConnectBars
= static_cast< const SfxBoolItem
& >(
272 rItemSet
.Get( nWhichId
)).GetValue();
273 if( m_bSupportingBarConnectors
)
275 uno::Reference
< beans::XPropertySet
> xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel
), uno::UNO_QUERY
);
276 if( xDiagramProperties
.is() &&
277 (xDiagramProperties
->getPropertyValue( C2U("ConnectBars")) >>= bOldConnectBars
) &&
278 bOldConnectBars
!= m_bConnectBars
)
280 xDiagramProperties
->setPropertyValue( C2U("ConnectBars"), uno::makeAny(m_bConnectBars
) );
287 case SCHATTR_GROUP_BARS_PER_AXIS
:
289 bool bOldGroupBarsPerAxis
= true;
290 m_bGroupBarsPerAxis
= static_cast< const SfxBoolItem
& >(
291 rItemSet
.Get( nWhichId
)).GetValue();
292 if( m_bSupportingAxisSideBySide
)
294 uno::Reference
< beans::XPropertySet
> xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel
), uno::UNO_QUERY
);
295 if( xDiagramProperties
.is() &&
296 (xDiagramProperties
->getPropertyValue( C2U("GroupBarsPerAxis")) >>= bOldGroupBarsPerAxis
) &&
297 bOldGroupBarsPerAxis
!= m_bGroupBarsPerAxis
)
299 xDiagramProperties
->setPropertyValue( C2U("GroupBarsPerAxis"), uno::makeAny(m_bGroupBarsPerAxis
) );
306 case SCHATTR_STARTING_ANGLE
:
308 if( m_bSupportingStartingAngle
)
310 m_nStartingAngle
= static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue();
311 uno::Reference
< beans::XPropertySet
> xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel
), uno::UNO_QUERY
);
312 if( xDiagramProperties
.is() )
314 xDiagramProperties
->setPropertyValue( C2U("StartingAngle"), uno::makeAny(m_nStartingAngle
) );
321 case SCHATTR_CLOCKWISE
:
323 bool bClockwise
= (static_cast< const SfxBoolItem
& >(
324 rItemSet
.Get( nWhichId
)).GetValue() );
327 uno::Reference
< chart2::XAxis
> xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys
) );
330 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
331 aScaleData
.Orientation
= bClockwise
? chart2::AxisOrientation_REVERSE
: chart2::AxisOrientation_MATHEMATICAL
;
332 xAxis
->setScaleData( aScaleData
);
339 case SCHATTR_MISSING_VALUE_TREATMENT
:
341 if( m_aSupportedMissingValueTreatments
.getLength() )
343 sal_Int32 nNew
= static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue();
344 if( m_nMissingValueTreatment
!= nNew
)
348 uno::Reference
< beans::XPropertySet
> xDiagramProperties( ChartModelHelper::findDiagram(m_xChartModel
), uno::UNO_QUERY
);
349 if( xDiagramProperties
.is() )
351 xDiagramProperties
->setPropertyValue( C2U( "MissingValueTreatment" ), uno::makeAny( nNew
));
355 catch( uno::Exception
& e
)
357 ASSERT_EXCEPTION( e
);
363 case SCHATTR_INCLUDE_HIDDEN_CELLS
:
365 if( m_bSupportingPlottingOfHiddenCells
)
367 bool bIncludeHiddenCells
= static_cast<const SfxBoolItem
&>(rItemSet
.Get(nWhichId
)).GetValue();
368 if (bIncludeHiddenCells
!= m_bIncludeHiddenCells
)
369 bChanged
= ChartModelHelper::setIncludeHiddenCells( bIncludeHiddenCells
, m_xChartModel
);
377 void SeriesOptionsItemConverter::FillSpecialItem(
378 USHORT nWhichId
, SfxItemSet
& rOutItemSet
) const
379 throw( uno::Exception
)
385 sal_Int32 nItemValue
= m_bAttachToMainAxis
? CHART_AXIS_PRIMARY_Y
: CHART_AXIS_SECONDARY_Y
;
386 rOutItemSet
.Put( SfxInt32Item(nWhichId
,nItemValue
) );
389 case SCHATTR_BAR_OVERLAP
:
391 if( m_bSupportingOverlapAndGapWidthProperties
)
392 rOutItemSet
.Put( SfxInt32Item(nWhichId
,m_nBarOverlap
) );
395 case SCHATTR_BAR_GAPWIDTH
:
397 if( m_bSupportingOverlapAndGapWidthProperties
)
398 rOutItemSet
.Put( SfxInt32Item(nWhichId
,m_nGapWidth
) );
401 case SCHATTR_BAR_CONNECT
:
403 if( m_bSupportingBarConnectors
)
404 rOutItemSet
.Put( SfxBoolItem(nWhichId
,m_bConnectBars
));
407 case SCHATTR_GROUP_BARS_PER_AXIS
:
409 if( m_bSupportingAxisSideBySide
)
410 rOutItemSet
.Put( SfxBoolItem(nWhichId
,m_bGroupBarsPerAxis
) );
413 case SCHATTR_AXIS_FOR_ALL_SERIES
:
415 if( m_nAllSeriesAxisIndex
!= - 1)
416 rOutItemSet
.Put( SfxInt32Item(nWhichId
, m_nAllSeriesAxisIndex
));
419 case SCHATTR_STARTING_ANGLE
:
421 if( m_bSupportingStartingAngle
)
422 rOutItemSet
.Put( SfxInt32Item(nWhichId
,m_nStartingAngle
));
425 case SCHATTR_CLOCKWISE
:
427 rOutItemSet
.Put( SfxBoolItem(nWhichId
,m_bClockwise
) );
430 case SCHATTR_MISSING_VALUE_TREATMENT
:
432 if( m_aSupportedMissingValueTreatments
.getLength() )
433 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_nMissingValueTreatment
));
436 case SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS
:
439 for ( sal_Int32 nN
=0; nN
<m_aSupportedMissingValueTreatments
.getLength(); nN
++ )
440 aList
.Insert( m_aSupportedMissingValueTreatments
[nN
], sal::static_int_cast
< USHORT
>(nN
) );
441 rOutItemSet
.Put( SfxIntegerListItem( nWhichId
, aList
) );
444 case SCHATTR_INCLUDE_HIDDEN_CELLS
:
446 if( m_bSupportingPlottingOfHiddenCells
)
447 rOutItemSet
.Put( SfxBoolItem(nWhichId
, m_bIncludeHiddenCells
) );
455 } // namespace wrapper