Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / DataPointItemConverter.cxx
blob8ac9b33cdb0875e33bf06937c14b2743f12efc00
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 <DataPointItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
24 #include <GraphicPropertyItemConverter.hxx>
25 #include <CharacterPropertyItemConverter.hxx>
26 #include <StatisticsItemConverter.hxx>
27 #include <SeriesOptionsItemConverter.hxx>
28 #include <DataSeries.hxx>
29 #include <DataSeriesHelper.hxx>
30 #include <DataSeriesProperties.hxx>
31 #include <DiagramHelper.hxx>
32 #include <Diagram.hxx>
33 #include <ChartModel.hxx>
34 #include <ChartModelHelper.hxx>
35 #include <ChartType.hxx>
36 #include <ChartTypeHelper.hxx>
37 #include <unonames.hxx>
39 #include <com/sun/star/chart/DataLabelPlacement.hpp>
40 #include <com/sun/star/chart2/AxisType.hpp>
41 #include <com/sun/star/chart2/DataPointLabel.hpp>
42 #include <com/sun/star/chart2/Symbol.hpp>
43 #include <com/sun/star/chart2/RelativePosition.hpp>
44 #include <com/sun/star/chart2/XDataSeries.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <comphelper/sequence.hxx>
48 #include <svx/xflclit.hxx>
49 #include <svl/eitem.hxx>
50 #include <svl/intitem.hxx>
51 #include <editeng/sizeitem.hxx>
52 #include <svl/stritem.hxx>
53 #include <editeng/brushitem.hxx>
54 #include <svl/ilstitem.hxx>
55 #include <svx/sdangitm.hxx>
56 #include <comphelper/diagnose_ex.hxx>
57 #include <vcl/graph.hxx>
58 #include <rtl/math.hxx>
60 #include <svx/tabline.hxx>
62 #include <memory>
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::chart2;
66 using namespace ::chart::DataSeriesProperties;
67 using ::com::sun::star::uno::Reference;
69 namespace chart::wrapper {
71 namespace {
73 ItemPropertyMapType & lcl_GetDataPointPropertyMap()
75 static ItemPropertyMapType aDataPointPropertyMap{
76 {SCHATTR_STYLE_SHAPE, {"Geometry3D", 0}}};
77 return aDataPointPropertyMap;
80 sal_Int32 lcl_getSymbolStyleForSymbol( const chart2::Symbol & rSymbol )
82 sal_Int32 nStyle = SVX_SYMBOLTYPE_UNKNOWN;
83 switch( rSymbol.Style )
85 case chart2::SymbolStyle_NONE:
86 nStyle = SVX_SYMBOLTYPE_NONE;
87 break;
88 case chart2::SymbolStyle_AUTO:
89 nStyle = SVX_SYMBOLTYPE_AUTO;
90 break;
91 case chart2::SymbolStyle_GRAPHIC:
92 nStyle = SVX_SYMBOLTYPE_BRUSHITEM;
93 break;
94 case chart2::SymbolStyle_STANDARD:
95 nStyle = rSymbol.StandardSymbol;
96 break;
98 case chart2::SymbolStyle_POLYGON:
99 // to avoid warning
100 case chart2::SymbolStyle::SymbolStyle_MAKE_FIXED_SIZE:
101 // nothing
102 break;
104 return nStyle;
107 bool lcl_NumberFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso )
109 bool bChanged = false;
110 if( !xPropertySet.is() )
111 return bChanged;
112 OUString aPropertyName = (nWhichId==SID_ATTR_NUMBERFORMAT_VALUE) ? CHART_UNONAME_NUMFMT : OUString( "PercentageNumberFormat" );
113 sal_uInt16 nSourceWhich = (nWhichId==SID_ATTR_NUMBERFORMAT_VALUE) ? SID_ATTR_NUMBERFORMAT_SOURCE : SCHATTR_PERCENT_NUMBERFORMAT_SOURCE;
115 if( rItemSet.GetItemState( nSourceWhich ) != SfxItemState::SET )
116 return bChanged;
118 uno::Any aValue;
119 bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
120 rItemSet.Get( nSourceWhich )).GetValue();
121 if( !bUseSourceFormat )
123 SfxItemState aState = rItemSet.GetItemState( nWhichId );
124 if( aState == SfxItemState::SET )
126 sal_Int32 nFmt = static_cast< sal_Int32 >(
127 static_cast< const SfxUInt32Item & >(
128 rItemSet.Get( nWhichId )).GetValue());
129 aValue <<= nFmt;
131 else
132 return bChanged;
135 uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
136 if( bOverwriteAttributedDataPointsAlso )
138 rtl::Reference< DataSeries > xSeries( dynamic_cast<DataSeries*>(xPropertySet.get()) );
139 if( aValue != aOldValue ||
140 ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, aPropertyName, aOldValue ) )
142 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, aPropertyName, aValue );
143 bChanged = true;
146 else if( aOldValue != aValue )
148 xPropertySet->setPropertyValue(aPropertyName, aValue );
149 bChanged = true;
151 return bChanged;
154 bool lcl_UseSourceFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso )
156 bool bChanged = false;
157 if( !xPropertySet.is() )
158 return bChanged;
159 OUString aPropertyName = (nWhichId==SID_ATTR_NUMBERFORMAT_SOURCE) ? CHART_UNONAME_NUMFMT : OUString( "PercentageNumberFormat" );
160 sal_uInt16 nFormatWhich = (nWhichId==SID_ATTR_NUMBERFORMAT_SOURCE) ? SID_ATTR_NUMBERFORMAT_VALUE : SCHATTR_PERCENT_NUMBERFORMAT_VALUE;
162 if( rItemSet.GetItemState( nWhichId ) != SfxItemState::SET )
163 return bChanged;
165 uno::Any aNewValue;
166 bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
167 rItemSet.Get( nWhichId )).GetValue();
168 xPropertySet->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::Any(bUseSourceFormat));
169 if( !bUseSourceFormat )
171 SfxItemState aState = rItemSet.GetItemState( nFormatWhich );
172 if( aState == SfxItemState::SET )
174 sal_Int32 nFormatKey = static_cast< sal_Int32 >(
175 static_cast< const SfxUInt32Item & >(
176 rItemSet.Get( nFormatWhich )).GetValue());
177 aNewValue <<= nFormatKey;
179 else
180 return bChanged;
183 uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
184 if( bOverwriteAttributedDataPointsAlso )
186 rtl::Reference< DataSeries > xSeries( dynamic_cast<DataSeries*>(xPropertySet.get()) );
187 if( aNewValue != aOldValue ||
188 ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, aPropertyName, aOldValue ) )
190 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, aPropertyName, aNewValue );
191 bChanged = true;
194 else if( aOldValue != aNewValue )
196 xPropertySet->setPropertyValue( aPropertyName, aNewValue );
197 bChanged = true;
200 return bChanged;
203 } // anonymous namespace
205 DataPointItemConverter::DataPointItemConverter(
206 const rtl::Reference<::chart::ChartModel> & xChartModel,
207 const uno::Reference< uno::XComponentContext > & xContext,
208 const uno::Reference< beans::XPropertySet > & rPropertySet,
209 const rtl::Reference< DataSeries > & xSeries,
210 SfxItemPool& rItemPool,
211 SdrModel& rDrawModel,
212 const uno::Reference<lang::XMultiServiceFactory>& xNamedPropertyContainerFactory,
213 GraphicObjectType eMapTo,
214 const awt::Size* pRefSize,
215 bool bDataSeries,
216 bool bUseSpecialFillColor,
217 sal_Int32 nSpecialFillColor,
218 bool bOverwriteLabelsForAttributedDataPointsAlso,
219 sal_Int32 nNumberFormat,
220 sal_Int32 nPercentNumberFormat,
221 sal_Int32 nPointIndex ) :
222 ItemConverter( rPropertySet, rItemPool ),
223 m_bDataSeries( bDataSeries ),
224 m_bOverwriteLabelsForAttributedDataPointsAlso(m_bDataSeries && bOverwriteLabelsForAttributedDataPointsAlso),
225 m_bUseSpecialFillColor(bUseSpecialFillColor),
226 m_nSpecialFillColor(ColorTransparency, nSpecialFillColor),
227 m_nNumberFormat(nNumberFormat),
228 m_nPercentNumberFormat(nPercentNumberFormat),
229 m_bForbidPercentValue(true),
230 m_bHideLegendEntry(false),
231 m_nPointIndex(nPointIndex),
232 m_xSeries(xSeries)
234 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
235 rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory, eMapTo ));
236 m_aConverters.emplace_back( new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, "ReferencePageSize"));
237 if( bDataSeries )
239 assert(dynamic_cast<DataSeries*>(rPropertySet.get()));
240 m_aConverters.emplace_back( new StatisticsItemConverter( xChartModel, rPropertySet, rItemPool ));
241 m_aConverters.emplace_back( new SeriesOptionsItemConverter( xChartModel, xContext,
242 dynamic_cast<DataSeries*>(rPropertySet.get()), rItemPool ));
245 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
246 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) );
247 bool bFound = false;
248 bool bAmbiguous = false;
249 bool bSwapXAndY = xDiagram->getVertical( bFound, bAmbiguous );
250 m_aAvailableLabelPlacements = ChartTypeHelper::getSupportedLabelPlacements( xChartType, bSwapXAndY, xSeries );
252 m_bForbidPercentValue = ChartTypeHelper::getAxisType( xChartType, 0 ) != AxisType::CATEGORY;
254 if (bDataSeries)
255 return;
257 uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
258 // "DeletedLegendEntries"
259 xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
260 for (const auto& deletedLegendEntry : std::as_const(deletedLegendEntriesSeq))
262 if (nPointIndex == deletedLegendEntry)
264 m_bHideLegendEntry = true;
265 break;
270 DataPointItemConverter::~DataPointItemConverter()
274 void DataPointItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
276 for( const auto& pConv : m_aConverters )
277 pConv->FillItemSet( rOutItemSet );
279 // own items
280 ItemConverter::FillItemSet( rOutItemSet );
282 if( m_bUseSpecialFillColor )
284 Color aColor(m_nSpecialFillColor);
285 rOutItemSet.Put( XFillColorItem( OUString(), aColor ) );
289 bool DataPointItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
291 bool bResult = false;
293 for( const auto& pConv : m_aConverters )
294 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
296 // own items
297 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
300 const WhichRangesContainer& DataPointItemConverter::GetWhichPairs() const
302 // must span all used items!
303 if( m_bDataSeries )
304 return nRowWhichPairs;
305 return nDataPointWhichPairs;
308 bool DataPointItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
310 ItemPropertyMapType & rMap( lcl_GetDataPointPropertyMap());
311 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
313 if( aIt == rMap.end())
314 return false;
316 rOutProperty =(*aIt).second;
317 return true;
320 bool DataPointItemConverter::ApplySpecialItem(
321 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
323 bool bChanged = false;
325 switch( nWhichId )
327 case SCHATTR_DATADESCR_SHOW_NUMBER:
328 case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
329 case SCHATTR_DATADESCR_SHOW_CATEGORY:
330 case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
331 case SCHATTR_DATADESCR_SHOW_SYMBOL:
333 const SfxBoolItem & rItem = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId ));
335 uno::Any aOldValue = GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL);
336 chart2::DataPointLabel aLabel;
337 if( aOldValue >>= aLabel )
339 sal_Bool& rValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
340 (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
341 (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
342 (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
343 bool bOldValue = rValue;
344 rValue = rItem.GetValue();
345 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
347 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
348 if( bOldValue != bool(rValue) ||
349 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, CHART_UNONAME_LABEL , aOldValue ) )
351 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_LABEL , uno::Any( aLabel ) );
352 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() );
353 bChanged = true;
356 else if( bOldValue != bool(rValue) )
358 GetPropertySet()->setPropertyValue(CHART_UNONAME_LABEL , uno::Any(aLabel));
359 bChanged = true;
363 break;
365 case SID_ATTR_NUMBERFORMAT_VALUE:
366 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE: //fall through intended
368 bChanged = lcl_NumberFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
370 break;
372 case SID_ATTR_NUMBERFORMAT_SOURCE:
373 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE: //fall through intended
375 bChanged = lcl_UseSourceFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
377 break;
379 case SCHATTR_DATADESCR_SEPARATOR:
381 OUString aNewValue = static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue();
384 OUString aOldValue;
385 GetPropertySet()->getPropertyValue( "LabelSeparator" ) >>= aOldValue;
386 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
388 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
389 if( aOldValue != aNewValue ||
390 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, "LabelSeparator" , uno::Any( aOldValue ) ) )
392 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "LabelSeparator" , uno::Any( aNewValue ) );
393 bChanged = true;
396 else if( aOldValue != aNewValue )
398 GetPropertySet()->setPropertyValue( "LabelSeparator" , uno::Any( aNewValue ));
399 bChanged = true;
402 catch( const uno::Exception& )
404 TOOLS_WARN_EXCEPTION("chart2", "" );
407 break;
409 case SCHATTR_DATADESCR_WRAP_TEXT:
414 bool bNew = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
415 bool bOld = false;
416 GetPropertySet()->getPropertyValue( "TextWordWrap" ) >>= bOld;
417 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
419 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
420 if( bOld!=bNew ||
421 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, "TextWordWrap", uno::Any( bOld ) ) )
423 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "TextWordWrap", uno::Any( bNew ) );
424 bChanged = true;
427 else if( bOld!=bNew )
429 GetPropertySet()->setPropertyValue( "TextWordWrap", uno::Any( bNew ));
430 bChanged = true;
433 catch( const uno::Exception& )
435 TOOLS_WARN_EXCEPTION("chart2", "" );
438 break;
440 case SCHATTR_DATADESCR_PLACEMENT:
445 sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
446 sal_Int32 nOld = -1;
447 RelativePosition aCustomLabelPosition;
448 GetPropertySet()->getPropertyValue("LabelPlacement") >>= nOld;
449 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
451 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
452 if( nOld!=nNew ||
453 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, "LabelPlacement" , uno::Any( nOld ) ) )
455 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "LabelPlacement" , uno::Any( nNew ) );
456 bChanged = true;
459 else if( nOld!=nNew || (GetPropertySet()->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition) )
461 GetPropertySet()->setPropertyValue("LabelPlacement", uno::Any(nNew));
462 GetPropertySet()->setPropertyValue("CustomLabelPosition", uno::Any());
463 bChanged = true;
466 catch( const uno::Exception& )
468 TOOLS_WARN_EXCEPTION("chart2", "" );
471 break;
473 case SCHATTR_STYLE_SYMBOL:
475 sal_Int32 nStyle =
476 static_cast< const SfxInt32Item & >(
477 rItemSet.Get( nWhichId )).GetValue();
478 chart2::Symbol aSymbol;
480 GetPropertySet()->getPropertyValue( "Symbol" ) >>= aSymbol;
481 sal_Int32 nOldStyle = lcl_getSymbolStyleForSymbol( aSymbol );
483 if( nStyle != nOldStyle )
485 bool bDeleteSymbol = false;
486 switch( nStyle )
488 case SVX_SYMBOLTYPE_NONE:
489 aSymbol.Style = chart2::SymbolStyle_NONE;
490 break;
491 case SVX_SYMBOLTYPE_AUTO:
492 aSymbol.Style = chart2::SymbolStyle_AUTO;
493 break;
494 case SVX_SYMBOLTYPE_BRUSHITEM:
495 aSymbol.Style = chart2::SymbolStyle_GRAPHIC;
496 break;
497 case SVX_SYMBOLTYPE_UNKNOWN:
498 bDeleteSymbol = true;
499 break;
501 default:
502 aSymbol.Style = chart2::SymbolStyle_STANDARD;
503 aSymbol.StandardSymbol = nStyle;
506 if( bDeleteSymbol )
507 GetPropertySet()->setPropertyValue( "Symbol" , uno::Any());
508 else
509 GetPropertySet()->setPropertyValue( "Symbol" , uno::Any( aSymbol ));
510 bChanged = true;
513 break;
515 case SCHATTR_SYMBOL_SIZE:
517 Size aSize = static_cast< const SvxSizeItem & >(
518 rItemSet.Get( nWhichId )).GetSize();
519 chart2::Symbol aSymbol;
521 GetPropertySet()->getPropertyValue( "Symbol" ) >>= aSymbol;
522 if( aSize.getWidth() != aSymbol.Size.Width ||
523 aSize.getHeight() != aSymbol.Size.Height )
525 aSymbol.Size.Width = aSize.getWidth();
526 aSymbol.Size.Height = aSize.getHeight();
528 GetPropertySet()->setPropertyValue( "Symbol" , uno::Any( aSymbol ));
529 bChanged = true;
532 break;
534 case SCHATTR_SYMBOL_BRUSH:
536 const SvxBrushItem & rBrshItem( static_cast< const SvxBrushItem & >(
537 rItemSet.Get( nWhichId )));
538 uno::Any aXGraphicAny;
539 const Graphic *pGraphic( rBrshItem.GetGraphic());
540 if( pGraphic )
542 uno::Reference< graphic::XGraphic > xGraphic( pGraphic->GetXGraphic());
543 if( xGraphic.is())
545 aXGraphicAny <<= xGraphic;
546 chart2::Symbol aSymbol;
547 GetPropertySet()->getPropertyValue( "Symbol" ) >>= aSymbol;
548 if( aSymbol.Graphic != xGraphic )
550 aSymbol.Graphic = xGraphic;
551 GetPropertySet()->setPropertyValue( "Symbol" , uno::Any( aSymbol ));
552 bChanged = true;
557 break;
559 case SCHATTR_TEXT_DEGREES:
561 double fValue = toDegrees(rItemSet.Get(SCHATTR_TEXT_DEGREES).GetValue());
562 double fOldValue = 0.0;
563 bool bPropExisted =
564 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldValue );
566 if( ! bPropExisted || fOldValue != fValue )
568 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fValue ));
569 bChanged = true;
572 break;
574 case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
576 bool bHideLegendEntry = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
577 if (bHideLegendEntry != m_bHideLegendEntry)
579 uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
580 // "DeletedLegendEntries"
581 m_xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
582 std::vector<sal_Int32> deletedLegendEntries;
583 for (const auto& deletedLegendEntry : std::as_const(deletedLegendEntriesSeq))
585 if (bHideLegendEntry || m_nPointIndex != deletedLegendEntry)
586 deletedLegendEntries.push_back(deletedLegendEntry);
588 if (bHideLegendEntry)
589 deletedLegendEntries.push_back(m_nPointIndex);
590 // "DeletedLegendEntries"
591 m_xSeries->setFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES, uno::Any(comphelper::containerToSequence(deletedLegendEntries)));
594 break;
596 case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
600 bool bNew = static_cast<const SfxBoolItem&>(rItemSet.Get(nWhichId)).GetValue();
601 bool bOld = true;
602 if( (m_xSeries->getPropertyValue("ShowCustomLeaderLines") >>= bOld) && bOld != bNew )
604 m_xSeries->setPropertyValue("ShowCustomLeaderLines", uno::Any(bNew));
605 bChanged = true;
608 catch (const uno::Exception&)
610 TOOLS_WARN_EXCEPTION("chart2", "");
613 break;
616 return bChanged;
619 void DataPointItemConverter::FillSpecialItem(
620 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
622 switch( nWhichId )
624 case SCHATTR_DATADESCR_SHOW_NUMBER:
625 case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
626 case SCHATTR_DATADESCR_SHOW_CATEGORY:
627 case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
628 case SCHATTR_DATADESCR_SHOW_SYMBOL:
630 chart2::DataPointLabel aLabel;
631 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel)
633 bool bValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
634 (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
635 (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
636 (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
638 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
640 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
642 if( DataSeriesHelper::hasAttributedDataPointDifferentValue(
643 dynamic_cast<DataSeries*>(GetPropertySet().get()), CHART_UNONAME_LABEL , uno::Any(aLabel) ) )
645 rOutItemSet.InvalidateItem(nWhichId);
650 break;
652 case SID_ATTR_NUMBERFORMAT_VALUE:
654 sal_Int32 nKey = 0;
655 if (!(GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nKey))
656 nKey = m_nNumberFormat;
657 rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
659 break;
661 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE:
663 sal_Int32 nKey = 0;
664 if( !(GetPropertySet()->getPropertyValue( "PercentageNumberFormat" ) >>= nKey) )
665 nKey = m_nPercentNumberFormat;
666 rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
668 break;
670 case SID_ATTR_NUMBERFORMAT_SOURCE:
672 bool bUseSourceFormat = false;
675 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
677 catch (const uno::Exception&)
679 TOOLS_WARN_EXCEPTION("chart2", "");
681 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue() && !bUseSourceFormat;
682 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
684 break;
685 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
687 bool bUseSourceFormat = false;
690 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
692 catch (const uno::Exception&)
694 TOOLS_WARN_EXCEPTION("chart2", "");
696 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue( "PercentageNumberFormat" ).hasValue() && !bUseSourceFormat;
697 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
699 break;
701 case SCHATTR_DATADESCR_SEPARATOR:
705 OUString aValue;
706 GetPropertySet()->getPropertyValue( "LabelSeparator" ) >>= aValue;
707 rOutItemSet.Put( SfxStringItem( nWhichId, aValue ));
709 catch( const uno::Exception& )
711 TOOLS_WARN_EXCEPTION("chart2", "" );
714 break;
716 case SCHATTR_DATADESCR_WRAP_TEXT:
720 bool bValue = false;
721 GetPropertySet()->getPropertyValue( "TextWordWrap" ) >>= bValue;
722 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
724 catch( const uno::Exception& )
726 TOOLS_WARN_EXCEPTION("chart2", "" );
729 break;
731 case SCHATTR_DATADESCR_PLACEMENT:
735 sal_Int32 nPlacement=0;
736 RelativePosition aCustomLabelPosition;
737 if( !m_bOverwriteLabelsForAttributedDataPointsAlso && (GetPropertySet()->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition) )
738 rOutItemSet.Put(SfxInt32Item(nWhichId, css::chart::DataLabelPlacement::CUSTOM));
739 else if( GetPropertySet()->getPropertyValue( "LabelPlacement" ) >>= nPlacement )
740 rOutItemSet.Put( SfxInt32Item( nWhichId, nPlacement ));
741 else if( m_aAvailableLabelPlacements.hasElements() )
742 rOutItemSet.Put( SfxInt32Item( nWhichId, m_aAvailableLabelPlacements[0] ));
744 catch( const uno::Exception& )
746 TOOLS_WARN_EXCEPTION("chart2", "" );
749 break;
751 case SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS:
753 rOutItemSet.Put( SfxIntegerListItem( nWhichId, m_aAvailableLabelPlacements ) );
755 break;
757 case SCHATTR_DATADESCR_NO_PERCENTVALUE:
759 rOutItemSet.Put( SfxBoolItem( nWhichId, m_bForbidPercentValue ));
761 break;
763 case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
767 bool bValue = true;
768 if( m_xSeries->getPropertyValue( "ShowCustomLeaderLines" ) >>= bValue )
769 rOutItemSet.Put(SfxBoolItem(nWhichId, bValue));
771 catch (const uno::Exception&)
773 TOOLS_WARN_EXCEPTION("chart2", "");
776 break;
778 case SCHATTR_STYLE_SYMBOL:
780 chart2::Symbol aSymbol;
781 if( GetPropertySet()->getPropertyValue( "Symbol" ) >>= aSymbol )
782 rOutItemSet.Put( SfxInt32Item( nWhichId, lcl_getSymbolStyleForSymbol( aSymbol ) ));
784 break;
786 case SCHATTR_SYMBOL_SIZE:
788 chart2::Symbol aSymbol;
789 if( GetPropertySet()->getPropertyValue( "Symbol" ) >>= aSymbol )
790 rOutItemSet.Put(
791 SvxSizeItem( nWhichId, Size( aSymbol.Size.Width, aSymbol.Size.Height ) ));
793 break;
795 case SCHATTR_SYMBOL_BRUSH:
797 chart2::Symbol aSymbol;
798 if(( GetPropertySet()->getPropertyValue( "Symbol" ) >>= aSymbol )
799 && aSymbol.Graphic.is() )
801 rOutItemSet.Put( SvxBrushItem( Graphic( aSymbol.Graphic ), GPOS_MM, SCHATTR_SYMBOL_BRUSH ));
804 break;
806 case SCHATTR_TEXT_DEGREES:
808 double fValue = 0;
810 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fValue )
812 rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
813 ::rtl::math::round( fValue * 100.0 ) ) )));
816 break;
818 case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
820 rOutItemSet.Put(SfxBoolItem(nWhichId, m_bHideLegendEntry));
821 break;
823 break;
829 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */