LibreOffice Module chart2 (master) 1
SeriesOptionsItemConverter.cxx
Go to the documentation of this file.
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
21#include "SchWhichPairs.hxx"
22
23#include <ChartModelHelper.hxx>
24#include <ChartType.hxx>
25#include <Axis.hxx>
26#include <AxisHelper.hxx>
27#include <DiagramHelper.hxx>
28#include <Diagram.hxx>
29#include <ChartTypeHelper.hxx>
30#include <DataSeriesHelper.hxx>
31#include <ChartModel.hxx>
33
34#include <com/sun/star/chart2/XDataSeries.hpp>
35
36#include <svl/eitem.hxx>
37#include <svl/intitem.hxx>
38#include <svl/ilstitem.hxx>
39#include <svx/sdangitm.hxx>
40#include <utility>
42
43using namespace ::com::sun::star;
44using namespace ::com::sun::star::chart2;
45
46namespace chart::wrapper
47{
48
52 , const rtl::Reference< ::chart::DataSeries >& xDataSeries
53 , SfxItemPool& rItemPool )
54 : ItemConverter( xDataSeries, rItemPool )
55 , m_xChartModel(xChartModel)
56 , m_xCC(std::move(xContext))
57 , m_bAttachToMainAxis(true)
58 , m_bSupportingOverlapAndGapWidthProperties(false)
59 , m_bSupportingBarConnectors(false)
60 , m_nBarOverlap(0)
61 , m_nGapWidth(100)
62 , m_bConnectBars(false)
63 , m_bSupportingAxisSideBySide(false)
64 , m_bGroupBarsPerAxis(true)
65 , m_bSupportingStartingAngle(false)
66 , m_nStartingAngle(90)
67 , m_bClockwise(false)
68 , m_nMissingValueTreatment(0)
69 , m_bSupportingPlottingOfHiddenCells(false)
70 , m_bIncludeHiddenCells(true)
71 , m_bHideLegendEntry(false)
72{
73 try
74 {
76
77 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
78 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xDataSeries ) );
79
81 if( m_xCooSys.is() )
82 {
84 chart2::ScaleData aScale( xAxis->getScaleData() );
85 m_bClockwise = (aScale.Orientation == chart2::AxisOrientation_REVERSE);
86 }
87
88 sal_Int32 nDimensionCount = xDiagram->getDimension();
90
92 {
93
94 sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
95
96 uno::Sequence< sal_Int32 > aBarPositionSequence;
97 if( xChartType.is() )
98 {
99 if( xChartType->getPropertyValue( "OverlapSequence" ) >>= aBarPositionSequence )
100 {
101 if( nAxisIndex >= 0 && nAxisIndex < aBarPositionSequence.getLength() )
102 m_nBarOverlap = aBarPositionSequence[nAxisIndex];
103 }
104 if( xChartType->getPropertyValue( "GapwidthSequence" ) >>= aBarPositionSequence )
105 {
106 if( nAxisIndex >= 0 && nAxisIndex < aBarPositionSequence.getLength() )
107 m_nGapWidth = aBarPositionSequence[nAxisIndex];
108 }
109 }
110 }
111
113 if( m_bSupportingBarConnectors && xDiagram.is() )
114 {
115 xDiagram->getPropertyValue( "ConnectBars" ) >>= m_bConnectBars;
116 }
117
119 if( m_bSupportingAxisSideBySide && xDiagram.is() )
120 {
121 xDiagram->getPropertyValue( "GroupBarsPerAxis" ) >>= m_bGroupBarsPerAxis;
122 }
123
126 {
127 xDiagram->getPropertyValue( "StartingAngle" ) >>= m_nStartingAngle;
128 }
129
131 m_nMissingValueTreatment = xDiagram->getCorrectedMissingValueTreatment( xChartType );
132
133 uno::Reference< beans::XPropertySet > xProp( m_xChartModel->getDataProvider(), uno::UNO_QUERY );
134 if( xProp.is() )
135 {
136 try
137 {
138 //test whether the data provider offers this property
139 xProp->getPropertyValue( "IncludeHiddenCells" );
140 //if not exception is thrown the property is offered
142 xDiagram->getPropertyValue( "IncludeHiddenCells" ) >>= m_bIncludeHiddenCells;
143 }
144 catch( const beans::UnknownPropertyException& )
145 {
146 }
147 }
148
149 m_bHideLegendEntry = !xDataSeries->getPropertyValue("ShowLegendEntry").get<bool>();
150 }
151 catch( const uno::Exception & )
152 {
153 DBG_UNHANDLED_EXCEPTION("chart2");
154 }
155}
156
158{
159}
160
162{
163 // must span all used items!
165}
166
168{
169 return false;
170}
171
172bool SeriesOptionsItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
173{
174 bool bChanged = false;
175 switch( nWhichId )
176 {
177 case SCHATTR_AXIS:
178 {
179 sal_Int32 nItemValue = static_cast< const SfxInt32Item & >(
180 rItemSet.Get( nWhichId )).GetValue();
181 bool bAttachToMainAxis = nItemValue == CHART_AXIS_PRIMARY_Y;
182 if( bAttachToMainAxis != m_bAttachToMainAxis )
183 {
184 //change model:
185 rtl::Reference<DataSeries> xDataSeries = dynamic_cast<DataSeries*>( GetPropertySet().get() );
186 bChanged = m_xChartModel->getFirstChartDiagram()->attachSeriesToAxis( bAttachToMainAxis, xDataSeries
187 , m_xCC );
188
189 if( bChanged )
190 m_bAttachToMainAxis = bAttachToMainAxis;
191 }
192 }
193 break;
194
197 {
199 {
200 sal_Int32& rBarPosition = ( nWhichId == SCHATTR_BAR_OVERLAP ) ? m_nBarOverlap : m_nGapWidth;
201 rBarPosition = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
202
203 OUString aPropName("GapwidthSequence" );
204 if( nWhichId == SCHATTR_BAR_OVERLAP )
205 aPropName = "OverlapSequence";
206
207 rtl::Reference< DataSeries > xDataSeries( dynamic_cast<DataSeries*>(GetPropertySet().get()) );
208 rtl::Reference< Diagram > xDiagram( m_xChartModel->getFirstChartDiagram() );
209 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xDataSeries ) );
210 if( xChartType.is() )
211 {
212 sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
213 uno::Sequence< sal_Int32 > aBarPositionSequence;
214 if( xChartType->getPropertyValue( aPropName ) >>= aBarPositionSequence )
215 {
216 bool bGroupBarsPerAxis = rItemSet.Get( SCHATTR_GROUP_BARS_PER_AXIS ).GetValue();
217 if(!bGroupBarsPerAxis)
218 {
219 //set the same value for all axes
220 for( auto & pos : asNonConstRange(aBarPositionSequence) )
221 pos = rBarPosition;
222 }
223 else if( nAxisIndex >= 0 && nAxisIndex < aBarPositionSequence.getLength() )
224 aBarPositionSequence.getArray()[nAxisIndex] = rBarPosition;
225
226 xChartType->setPropertyValue( aPropName, uno::Any(aBarPositionSequence) );
227 bChanged = true;
228 }
229 }
230 }
231 }
232 break;
233
235 {
236 m_bConnectBars = static_cast< const SfxBoolItem & >(
237 rItemSet.Get( nWhichId )).GetValue();
239 {
240 bool bOldConnectBars = false;
241 rtl::Reference< Diagram > xDiagramProperties( m_xChartModel->getFirstChartDiagram() );
242 if( xDiagramProperties.is() &&
243 (xDiagramProperties->getPropertyValue( "ConnectBars" ) >>= bOldConnectBars) &&
244 bOldConnectBars != m_bConnectBars )
245 {
246 xDiagramProperties->setPropertyValue( "ConnectBars" , uno::Any(m_bConnectBars) );
247 bChanged = true;
248 }
249 }
250 }
251 break;
252
254 {
255 m_bGroupBarsPerAxis = static_cast< const SfxBoolItem & >(
256 rItemSet.Get( nWhichId )).GetValue();
258 {
259 bool bOldGroupBarsPerAxis = true;
260 rtl::Reference< Diagram > xDiagramProperties( m_xChartModel->getFirstChartDiagram() );
261 if( xDiagramProperties.is() &&
262 (xDiagramProperties->getPropertyValue( "GroupBarsPerAxis" ) >>= bOldGroupBarsPerAxis) &&
263 bOldGroupBarsPerAxis != m_bGroupBarsPerAxis )
264 {
265 xDiagramProperties->setPropertyValue( "GroupBarsPerAxis" , uno::Any(m_bGroupBarsPerAxis) );
266 bChanged = true;
267 }
268 }
269 }
270 break;
271
273 {
275 {
276 m_nStartingAngle = static_cast< const SdrAngleItem & >( rItemSet.Get( nWhichId )).GetValue().get() / 100;
277 rtl::Reference< Diagram > xDiagramProperties( m_xChartModel->getFirstChartDiagram() );
278 if( xDiagramProperties.is() )
279 {
280 xDiagramProperties->setPropertyValue( "StartingAngle" , uno::Any(m_nStartingAngle) );
281 bChanged = true;
282 }
283 }
284 }
285 break;
286
288 {
289 bool bClockwise = static_cast< const SfxBoolItem & >(
290 rItemSet.Get( nWhichId )).GetValue();
291 if( m_xCooSys.is() )
292 {
294 if( xAxis.is() )
295 {
296 chart2::ScaleData aScaleData( xAxis->getScaleData() );
297 aScaleData.Orientation = bClockwise ? chart2::AxisOrientation_REVERSE : chart2::AxisOrientation_MATHEMATICAL;
298 xAxis->setScaleData( aScaleData );
299 bChanged = true;
300 }
301 }
302 }
303 break;
304
306 {
307 if( m_aSupportedMissingValueTreatments.hasElements() )
308 {
309 sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
310 if( m_nMissingValueTreatment != nNew )
311 {
312 try
313 {
314 rtl::Reference< Diagram > xDiagramProperties( m_xChartModel->getFirstChartDiagram() );
315 if( xDiagramProperties.is() )
316 {
317 xDiagramProperties->setPropertyValue( "MissingValueTreatment" , uno::Any( nNew ));
318 bChanged = true;
319 }
320 }
321 catch( const uno::Exception& )
322 {
323 TOOLS_WARN_EXCEPTION("chart2", "" );
324 }
325 }
326 }
327 }
328 break;
330 {
332 {
333 bool bIncludeHiddenCells = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
334 if (bIncludeHiddenCells != m_bIncludeHiddenCells)
335 {
336 if (m_xChartModel)
337 bChanged = ChartModelHelper::setIncludeHiddenCells( bIncludeHiddenCells, *m_xChartModel );
338 }
339 }
340 }
341 break;
343 {
344 bool bHideLegendEntry = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
345 if (bHideLegendEntry != m_bHideLegendEntry)
346 {
347 GetPropertySet()->setPropertyValue("ShowLegendEntry", css::uno::Any(!bHideLegendEntry));
348 }
349 }
350 break;
351 }
352 return bChanged;
353}
354
356 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
357{
358 switch( nWhichId )
359 {
360 case SCHATTR_AXIS:
361 {
363 rOutItemSet.Put( SfxInt32Item(nWhichId,nItemValue ) );
364 break;
365 }
367 {
369 rOutItemSet.Put( SfxInt32Item(nWhichId,m_nBarOverlap) );
370 break;
371 }
373 {
375 rOutItemSet.Put( SfxInt32Item(nWhichId,m_nGapWidth) );
376 break;
377 }
379 {
381 rOutItemSet.Put( SfxBoolItem(nWhichId,m_bConnectBars));
382 break;
383 }
385 {
387 rOutItemSet.Put( SfxBoolItem(nWhichId,m_bGroupBarsPerAxis) );
388 break;
389 }
391 {
392 break;
393 }
395 {
398 break;
399 }
401 {
402 rOutItemSet.Put( SfxBoolItem(nWhichId,m_bClockwise) );
403 break;
404 }
406 {
407 if( m_aSupportedMissingValueTreatments.hasElements() )
408 rOutItemSet.Put( SfxInt32Item( nWhichId, m_nMissingValueTreatment ));
409 break;
410 }
412 {
414 break;
415 }
417 {
419 rOutItemSet.Put( SfxBoolItem(nWhichId, m_bIncludeHiddenCells) );
420 break;
421 }
423 {
424 rOutItemSet.Put(SfxBoolItem(nWhichId, m_bHideLegendEntry));
425 break;
426 }
427 default:
428 break;
429 }
430}
431
432} // namespace chart
433
434/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CHART_AXIS_PRIMARY_Y
constexpr TypedWhichId< SfxInt32Item > SCHATTR_MISSING_VALUE_TREATMENT(SCHATTR_CHARTTYPE_START+9)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS(SCHATTR_STYLE_END+1)
constexpr TypedWhichId< SfxIntegerListItem > SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS(SCHATTR_CHARTTYPE_START+10)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_HIDE_LEGEND_ENTRY(SCHATTR_CHARTTYPE_START+12)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_CLOCKWISE(SCHATTR_CHARTTYPE_START+8)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_BAR_GAPWIDTH(SCHATTR_CHARTTYPE_START+1)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_BAR_CONNECT(SCHATTR_CHARTTYPE_START+2)
#define CHART_AXIS_SECONDARY_Y
constexpr TypedWhichId< SdrAngleItem > SCHATTR_STARTING_ANGLE(SCHATTR_CHARTTYPE_START+7)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_GROUP_BARS_PER_AXIS(SCHATTR_CHARTTYPE_START+6)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_INCLUDE_HIDDEN_CELLS(SCHATTR_CHARTTYPE_START+11)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_FOR_ALL_SERIES(SCHATTR_MISC_START)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_BAR_OVERLAP(SCHATTR_CHARTTYPE_START)
const WhichRangesContainer nSeriesOptionsWhichPairs(svl::Items< SCHATTR_AXIS, SCHATTR_AXIS, SCHATTR_BAR_OVERLAP, SCHATTR_BAR_CONNECT, SCHATTR_GROUP_BARS_PER_AXIS, SCHATTR_AXIS_FOR_ALL_SERIES >)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static rtl::Reference< ::chart::Axis > getAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
static bool setIncludeHiddenCells(bool bIncludeHiddenCells, ChartModel &rModel)
static bool isSupportingAxisSideBySide(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionCount)
static css::uno::Sequence< sal_Int32 > getSupportedMissingValueTreatments(const rtl::Reference< ::chart::ChartType > &xChartType)
static bool isSupportingBarConnectors(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionCount)
static bool isSupportingOverlapAndGapWidthProperties(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionCount)
static bool isSupportingStartingAngle(const rtl::Reference< ::chart::ChartType > &xChartType)
static bool isSeriesAttachedToMainAxis(const rtl::Reference< ::chart::DataSeries > &xDataSeries)
This class serves for conversion between properties of an XPropertySet and SfxItems in SfxItemSets.
std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId
const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const
Returns the XPropertySet that was given in the CTOR and is used to apply items in ApplyItemSet().
rtl::Reference<::chart::ChartModel > m_xChartModel
css::uno::Sequence< sal_Int32 > m_aSupportedMissingValueTreatments
virtual bool GetItemProperty(tWhichIdType nWhichId, tPropertyNameWithMemberId &rOutProperty) const override
implement this method to return a Property object for a given which id.
SeriesOptionsItemConverter(const rtl::Reference<::chart::ChartModel > &xChartModel, css::uno::Reference< css::uno::XComponentContext > xContext, const rtl::Reference<::chart::DataSeries > &rPropertySet, SfxItemPool &rItemPool)
virtual void FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet &rOutItemSet) const override
for items that can not be mapped directly to a property.
css::uno::Reference< css::uno::XComponentContext > m_xCC
virtual bool ApplySpecialItem(sal_uInt16 nWhichId, const SfxItemSet &rItemSet) override
for items that can not be mapped directly to a property.
rtl::Reference< ::chart::BaseCoordinateSystem > m_xCooSys
virtual const WhichRangesContainer & GetWhichPairs() const override
implement this method to provide an array of which-ranges
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::BaseCoordinateSystem > getCoordinateSystemOfSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::Diagram > &xDiagram)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getAttachedAxisIndex(const rtl::Reference< ::chart::DataSeries > &xSeries)
OUString aPropName
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
const char GetValue[]
size_t pos