tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / DataPointItemConverter.cxx
blob1337ee3337e52de8a0c8139c4664c7f85843da8f
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 <Diagram.hxx>
32 #include <ChartModel.hxx>
33 #include <ChartType.hxx>
34 #include <ChartTypeHelper.hxx>
35 #include <unonames.hxx>
37 #include <com/sun/star/chart/DataLabelPlacement.hpp>
38 #include <com/sun/star/chart2/AxisType.hpp>
39 #include <com/sun/star/chart2/DataPointLabel.hpp>
40 #include <com/sun/star/chart2/Symbol.hpp>
41 #include <com/sun/star/chart2/RelativePosition.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <comphelper/sequence.hxx>
45 #include <svx/xflclit.hxx>
46 #include <svl/eitem.hxx>
47 #include <svl/intitem.hxx>
48 #include <editeng/sizeitem.hxx>
49 #include <svl/stritem.hxx>
50 #include <editeng/brushitem.hxx>
51 #include <svl/ilstitem.hxx>
52 #include <svx/sdangitm.hxx>
53 #include <comphelper/diagnose_ex.hxx>
54 #include <vcl/graph.hxx>
55 #include <rtl/math.hxx>
57 #include <svx/tabline.hxx>
59 #include <memory>
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::chart2;
63 using namespace ::chart::DataSeriesProperties;
64 using ::com::sun::star::uno::Reference;
66 namespace chart::wrapper {
68 namespace {
70 ItemPropertyMapType & lcl_GetDataPointPropertyMap()
72 static ItemPropertyMapType aDataPointPropertyMap{
73 {SCHATTR_STYLE_SHAPE, {"Geometry3D", 0}}};
74 return aDataPointPropertyMap;
77 sal_Int32 lcl_getSymbolStyleForSymbol( const chart2::Symbol & rSymbol )
79 sal_Int32 nStyle = SVX_SYMBOLTYPE_UNKNOWN;
80 switch( rSymbol.Style )
82 case chart2::SymbolStyle_NONE:
83 nStyle = SVX_SYMBOLTYPE_NONE;
84 break;
85 case chart2::SymbolStyle_AUTO:
86 nStyle = SVX_SYMBOLTYPE_AUTO;
87 break;
88 case chart2::SymbolStyle_GRAPHIC:
89 nStyle = SVX_SYMBOLTYPE_BRUSHITEM;
90 break;
91 case chart2::SymbolStyle_STANDARD:
92 nStyle = rSymbol.StandardSymbol;
93 break;
95 case chart2::SymbolStyle_POLYGON:
96 // to avoid warning
97 case chart2::SymbolStyle::SymbolStyle_MAKE_FIXED_SIZE:
98 // nothing
99 break;
101 return nStyle;
104 bool lcl_NumberFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso )
106 bool bChanged = false;
107 if( !xPropertySet.is() )
108 return bChanged;
109 OUString aPropertyName = (nWhichId==SID_ATTR_NUMBERFORMAT_VALUE) ? CHART_UNONAME_NUMFMT : u"PercentageNumberFormat"_ustr;
110 sal_uInt16 nSourceWhich = (nWhichId==SID_ATTR_NUMBERFORMAT_VALUE) ? SID_ATTR_NUMBERFORMAT_SOURCE : SCHATTR_PERCENT_NUMBERFORMAT_SOURCE;
112 if( rItemSet.GetItemState( nSourceWhich ) != SfxItemState::SET )
113 return bChanged;
115 uno::Any aValue;
116 bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
117 rItemSet.Get( nSourceWhich )).GetValue();
118 if( !bUseSourceFormat )
120 SfxItemState aState = rItemSet.GetItemState( nWhichId );
121 if( aState == SfxItemState::SET )
123 sal_Int32 nFmt = static_cast< sal_Int32 >(
124 static_cast< const SfxUInt32Item & >(
125 rItemSet.Get( nWhichId )).GetValue());
126 aValue <<= nFmt;
128 else
129 return bChanged;
132 uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
133 if( bOverwriteAttributedDataPointsAlso )
135 rtl::Reference< DataSeries > xSeries( dynamic_cast<DataSeries*>(xPropertySet.get()) );
136 if( aValue != aOldValue ||
137 ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, aPropertyName, aOldValue ) )
139 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, aPropertyName, aValue );
140 bChanged = true;
143 else if( aOldValue != aValue )
145 xPropertySet->setPropertyValue(aPropertyName, aValue );
146 bChanged = true;
148 return bChanged;
151 bool lcl_UseSourceFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso )
153 bool bChanged = false;
154 if( !xPropertySet.is() )
155 return bChanged;
156 OUString aPropertyName = (nWhichId==SID_ATTR_NUMBERFORMAT_SOURCE) ? CHART_UNONAME_NUMFMT : u"PercentageNumberFormat"_ustr;
157 sal_uInt16 nFormatWhich = (nWhichId==SID_ATTR_NUMBERFORMAT_SOURCE) ? SID_ATTR_NUMBERFORMAT_VALUE : SCHATTR_PERCENT_NUMBERFORMAT_VALUE;
159 if( rItemSet.GetItemState( nWhichId ) != SfxItemState::SET )
160 return bChanged;
162 uno::Any aNewValue;
163 bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
164 rItemSet.Get( nWhichId )).GetValue();
165 xPropertySet->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::Any(bUseSourceFormat));
166 if( !bUseSourceFormat )
168 SfxItemState aState = rItemSet.GetItemState( nFormatWhich );
169 if( aState == SfxItemState::SET )
171 sal_Int32 nFormatKey = static_cast< sal_Int32 >(
172 static_cast< const SfxUInt32Item & >(
173 rItemSet.Get( nFormatWhich )).GetValue());
174 aNewValue <<= nFormatKey;
176 else
177 return bChanged;
180 uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
181 if( bOverwriteAttributedDataPointsAlso )
183 rtl::Reference< DataSeries > xSeries( dynamic_cast<DataSeries*>(xPropertySet.get()) );
184 if( aNewValue != aOldValue ||
185 ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, aPropertyName, aOldValue ) )
187 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, aPropertyName, aNewValue );
188 bChanged = true;
191 else if( aOldValue != aNewValue )
193 xPropertySet->setPropertyValue( aPropertyName, aNewValue );
194 bChanged = true;
197 return bChanged;
200 } // anonymous namespace
202 DataPointItemConverter::DataPointItemConverter(
203 const rtl::Reference<::chart::ChartModel> & xChartModel,
204 const uno::Reference< uno::XComponentContext > & xContext,
205 const uno::Reference< beans::XPropertySet > & rPropertySet,
206 const rtl::Reference< DataSeries > & xSeries,
207 SfxItemPool& rItemPool,
208 SdrModel& rDrawModel,
209 const uno::Reference<lang::XMultiServiceFactory>& xNamedPropertyContainerFactory,
210 GraphicObjectType eMapTo,
211 const std::optional<awt::Size>& pRefSize,
212 bool bDataSeries,
213 bool bUseSpecialFillColor,
214 sal_Int32 nSpecialFillColor,
215 bool bOverwriteLabelsForAttributedDataPointsAlso,
216 sal_Int32 nNumberFormat,
217 sal_Int32 nPercentNumberFormat,
218 sal_Int32 nPointIndex ) :
219 ItemConverter( rPropertySet, rItemPool ),
220 m_bDataSeries( bDataSeries ),
221 m_bOverwriteLabelsForAttributedDataPointsAlso(m_bDataSeries && bOverwriteLabelsForAttributedDataPointsAlso),
222 m_bUseSpecialFillColor(bUseSpecialFillColor),
223 m_nSpecialFillColor(ColorTransparency, nSpecialFillColor),
224 m_nNumberFormat(nNumberFormat),
225 m_nPercentNumberFormat(nPercentNumberFormat),
226 m_bForbidPercentValue(true),
227 m_bHideLegendEntry(false),
228 m_nPointIndex(nPointIndex),
229 m_xSeries(xSeries)
231 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
232 rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory, eMapTo ));
233 m_aConverters.emplace_back( new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, u"ReferencePageSize"_ustr));
234 if( bDataSeries )
236 assert(dynamic_cast<DataSeries*>(rPropertySet.get()));
237 m_aConverters.emplace_back( new StatisticsItemConverter( xChartModel, rPropertySet, rItemPool ));
238 m_aConverters.emplace_back( new SeriesOptionsItemConverter( xChartModel, xContext,
239 dynamic_cast<DataSeries*>(rPropertySet.get()), rItemPool ));
242 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
243 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) );
244 bool bFound = false;
245 bool bAmbiguous = false;
246 bool bSwapXAndY = xDiagram->getVertical( bFound, bAmbiguous );
247 m_aAvailableLabelPlacements = ChartTypeHelper::getSupportedLabelPlacements( xChartType, bSwapXAndY, xSeries );
249 m_bForbidPercentValue = ChartTypeHelper::getAxisType( xChartType, 0 ) != AxisType::CATEGORY;
251 if (bDataSeries)
252 return;
254 uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
255 // "DeletedLegendEntries"
256 xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
257 for (const auto& deletedLegendEntry : deletedLegendEntriesSeq)
259 if (nPointIndex == deletedLegendEntry)
261 m_bHideLegendEntry = true;
262 break;
267 DataPointItemConverter::~DataPointItemConverter()
271 void DataPointItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
273 for( const auto& pConv : m_aConverters )
274 pConv->FillItemSet( rOutItemSet );
276 // own items
277 ItemConverter::FillItemSet( rOutItemSet );
279 if( m_bUseSpecialFillColor )
281 Color aColor(m_nSpecialFillColor);
282 rOutItemSet.Put( XFillColorItem( OUString(), aColor ) );
286 bool DataPointItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
288 bool bResult = false;
290 for( const auto& pConv : m_aConverters )
291 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
293 // own items
294 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
297 const WhichRangesContainer& DataPointItemConverter::GetWhichPairs() const
299 // must span all used items!
300 if( m_bDataSeries )
301 return nRowWhichPairs;
302 return nDataPointWhichPairs;
305 bool DataPointItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
307 ItemPropertyMapType & rMap( lcl_GetDataPointPropertyMap());
308 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
310 if( aIt == rMap.end())
311 return false;
313 rOutProperty =(*aIt).second;
314 return true;
317 bool DataPointItemConverter::ApplySpecialItem(
318 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
320 bool bChanged = false;
322 switch( nWhichId )
324 case SCHATTR_DATADESCR_SHOW_NUMBER:
325 case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
326 case SCHATTR_DATADESCR_SHOW_CATEGORY:
327 case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
328 case SCHATTR_DATADESCR_SHOW_SYMBOL:
330 const SfxBoolItem & rItem = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId ));
332 uno::Any aOldValue = GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL);
333 chart2::DataPointLabel aLabel;
334 if( aOldValue >>= aLabel )
336 sal_Bool& rValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
337 (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
338 (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
339 (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
340 bool bOldValue = rValue;
341 rValue = rItem.GetValue();
342 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
344 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
345 if( bOldValue != bool(rValue) ||
346 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, CHART_UNONAME_LABEL , aOldValue ) )
348 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_LABEL , uno::Any( aLabel ) );
349 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() );
350 bChanged = true;
353 else if( bOldValue != bool(rValue) )
355 GetPropertySet()->setPropertyValue(CHART_UNONAME_LABEL , uno::Any(aLabel));
356 bChanged = true;
360 break;
362 case SID_ATTR_NUMBERFORMAT_VALUE:
363 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE: //fall through intended
365 bChanged = lcl_NumberFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
367 break;
369 case SID_ATTR_NUMBERFORMAT_SOURCE:
370 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE: //fall through intended
372 bChanged = lcl_UseSourceFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
374 break;
376 case SCHATTR_DATADESCR_SEPARATOR:
378 OUString aNewValue = static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue();
381 OUString aOldValue;
382 GetPropertySet()->getPropertyValue( u"LabelSeparator"_ustr ) >>= aOldValue;
383 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
385 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
386 if( aOldValue != aNewValue ||
387 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, u"LabelSeparator"_ustr , uno::Any( aOldValue ) ) )
389 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, u"LabelSeparator"_ustr , uno::Any( aNewValue ) );
390 bChanged = true;
393 else if( aOldValue != aNewValue )
395 GetPropertySet()->setPropertyValue( u"LabelSeparator"_ustr , uno::Any( aNewValue ));
396 bChanged = true;
399 catch( const uno::Exception& )
401 TOOLS_WARN_EXCEPTION("chart2", "" );
404 break;
406 case SCHATTR_DATADESCR_WRAP_TEXT:
411 bool bNew = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
412 bool bOld = false;
413 GetPropertySet()->getPropertyValue( u"TextWordWrap"_ustr ) >>= bOld;
414 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
416 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
417 if( bOld!=bNew ||
418 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, u"TextWordWrap"_ustr, uno::Any( bOld ) ) )
420 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, u"TextWordWrap"_ustr, uno::Any( bNew ) );
421 bChanged = true;
424 else if( bOld!=bNew )
426 GetPropertySet()->setPropertyValue( u"TextWordWrap"_ustr, uno::Any( bNew ));
427 bChanged = true;
430 catch( const uno::Exception& )
432 TOOLS_WARN_EXCEPTION("chart2", "" );
435 break;
437 case SCHATTR_DATADESCR_PLACEMENT:
442 sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
443 sal_Int32 nOld = -1;
444 RelativePosition aCustomLabelPosition;
445 GetPropertySet()->getPropertyValue(u"LabelPlacement"_ustr) >>= nOld;
446 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
448 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
449 if( nOld!=nNew ||
450 DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, u"LabelPlacement"_ustr , uno::Any( nOld ) ) )
452 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, u"LabelPlacement"_ustr , uno::Any( nNew ) );
453 bChanged = true;
456 else if( nOld!=nNew || (GetPropertySet()->getPropertyValue(u"CustomLabelPosition"_ustr) >>= aCustomLabelPosition) )
458 GetPropertySet()->setPropertyValue(u"LabelPlacement"_ustr, uno::Any(nNew));
459 GetPropertySet()->setPropertyValue(u"CustomLabelPosition"_ustr, uno::Any());
460 GetPropertySet()->setPropertyValue(u"CustomLabelSize"_ustr, uno::Any());
461 bChanged = true;
464 catch( const uno::Exception& )
466 TOOLS_WARN_EXCEPTION("chart2", "" );
469 break;
471 case SCHATTR_STYLE_SYMBOL:
473 sal_Int32 nStyle =
474 static_cast< const SfxInt32Item & >(
475 rItemSet.Get( nWhichId )).GetValue();
476 chart2::Symbol aSymbol;
478 GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
479 sal_Int32 nOldStyle = lcl_getSymbolStyleForSymbol( aSymbol );
481 if( nStyle != nOldStyle )
483 bool bDeleteSymbol = false;
484 switch( nStyle )
486 case SVX_SYMBOLTYPE_NONE:
487 aSymbol.Style = chart2::SymbolStyle_NONE;
488 break;
489 case SVX_SYMBOLTYPE_AUTO:
490 aSymbol.Style = chart2::SymbolStyle_AUTO;
491 break;
492 case SVX_SYMBOLTYPE_BRUSHITEM:
493 aSymbol.Style = chart2::SymbolStyle_GRAPHIC;
494 break;
495 case SVX_SYMBOLTYPE_UNKNOWN:
496 bDeleteSymbol = true;
497 break;
499 default:
500 aSymbol.Style = chart2::SymbolStyle_STANDARD;
501 aSymbol.StandardSymbol = nStyle;
504 if( bDeleteSymbol )
505 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any());
506 else
507 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
508 bChanged = true;
511 break;
513 case SCHATTR_SYMBOL_SIZE:
515 Size aSize = static_cast< const SvxSizeItem & >(
516 rItemSet.Get( nWhichId )).GetSize();
517 chart2::Symbol aSymbol;
519 GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
520 if( aSize.getWidth() != aSymbol.Size.Width ||
521 aSize.getHeight() != aSymbol.Size.Height )
523 aSymbol.Size.Width = aSize.getWidth();
524 aSymbol.Size.Height = aSize.getHeight();
526 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
527 bChanged = true;
530 break;
532 case SCHATTR_SYMBOL_BRUSH:
534 const SvxBrushItem & rBrshItem( static_cast< const SvxBrushItem & >(
535 rItemSet.Get( nWhichId )));
536 uno::Any aXGraphicAny;
537 const Graphic *pGraphic( rBrshItem.GetGraphic());
538 if( pGraphic )
540 uno::Reference< graphic::XGraphic > xGraphic( pGraphic->GetXGraphic());
541 if( xGraphic.is())
543 aXGraphicAny <<= xGraphic;
544 chart2::Symbol aSymbol;
545 GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
546 if( aSymbol.Graphic != xGraphic )
548 aSymbol.Graphic = std::move(xGraphic);
549 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
550 bChanged = true;
555 break;
557 case SCHATTR_TEXT_DEGREES:
559 double fValue = toDegrees(rItemSet.Get(SCHATTR_TEXT_DEGREES).GetValue());
560 double fOldValue = 0.0;
561 bool bPropExisted =
562 ( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fOldValue );
564 if( ! bPropExisted || fOldValue != fValue )
566 GetPropertySet()->setPropertyValue( u"TextRotation"_ustr , uno::Any( fValue ));
567 bChanged = true;
570 break;
572 case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
574 bool bHideLegendEntry = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
575 if (bHideLegendEntry != m_bHideLegendEntry)
577 uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
578 // "DeletedLegendEntries"
579 m_xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
580 std::vector<sal_Int32> deletedLegendEntries;
581 for (const auto& deletedLegendEntry : deletedLegendEntriesSeq)
583 if (bHideLegendEntry || m_nPointIndex != deletedLegendEntry)
584 deletedLegendEntries.push_back(deletedLegendEntry);
586 if (bHideLegendEntry)
587 deletedLegendEntries.push_back(m_nPointIndex);
588 // "DeletedLegendEntries"
589 m_xSeries->setFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES, uno::Any(comphelper::containerToSequence(deletedLegendEntries)));
592 break;
594 case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
598 bool bNew = static_cast<const SfxBoolItem&>(rItemSet.Get(nWhichId)).GetValue();
599 bool bOld = true;
600 if( (m_xSeries->getFastPropertyValue(PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES) >>= bOld) && bOld != bNew )
602 m_xSeries->setFastPropertyValue(PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES, uno::Any(bNew));
603 bChanged = true;
606 catch (const uno::Exception&)
608 TOOLS_WARN_EXCEPTION("chart2", "");
611 break;
614 return bChanged;
617 void DataPointItemConverter::FillSpecialItem(
618 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
620 switch( nWhichId )
622 case SCHATTR_DATADESCR_SHOW_NUMBER:
623 case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
624 case SCHATTR_DATADESCR_SHOW_CATEGORY:
625 case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
626 case SCHATTR_DATADESCR_SHOW_SYMBOL:
628 chart2::DataPointLabel aLabel;
629 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel)
631 bool bValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
632 (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
633 (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
634 (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
636 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
638 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
640 if( DataSeriesHelper::hasAttributedDataPointDifferentValue(
641 dynamic_cast<DataSeries*>(GetPropertySet().get()), CHART_UNONAME_LABEL , uno::Any(aLabel) ) )
643 rOutItemSet.InvalidateItem(nWhichId);
648 break;
650 case SID_ATTR_NUMBERFORMAT_VALUE:
652 sal_Int32 nKey = 0;
653 if (!(GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nKey))
654 nKey = m_nNumberFormat;
655 rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
657 break;
659 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE:
661 sal_Int32 nKey = 0;
662 if( !(GetPropertySet()->getPropertyValue( u"PercentageNumberFormat"_ustr ) >>= nKey) )
663 nKey = m_nPercentNumberFormat;
664 rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
666 break;
668 case SID_ATTR_NUMBERFORMAT_SOURCE:
670 bool bUseSourceFormat = false;
673 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
675 catch (const uno::Exception&)
677 TOOLS_WARN_EXCEPTION("chart2", "");
679 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue() && !bUseSourceFormat;
680 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
682 break;
683 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
685 bool bUseSourceFormat = false;
688 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
690 catch (const uno::Exception&)
692 TOOLS_WARN_EXCEPTION("chart2", "");
694 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue( u"PercentageNumberFormat"_ustr ).hasValue() && !bUseSourceFormat;
695 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
697 break;
699 case SCHATTR_DATADESCR_SEPARATOR:
703 OUString aValue;
704 GetPropertySet()->getPropertyValue( u"LabelSeparator"_ustr ) >>= aValue;
705 rOutItemSet.Put( SfxStringItem( nWhichId, aValue ));
707 catch( const uno::Exception& )
709 TOOLS_WARN_EXCEPTION("chart2", "" );
712 break;
714 case SCHATTR_DATADESCR_WRAP_TEXT:
718 bool bValue = false;
719 GetPropertySet()->getPropertyValue( u"TextWordWrap"_ustr ) >>= bValue;
720 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
722 catch( const uno::Exception& )
724 TOOLS_WARN_EXCEPTION("chart2", "" );
727 break;
729 case SCHATTR_DATADESCR_PLACEMENT:
733 sal_Int32 nPlacement=0;
734 RelativePosition aCustomLabelPosition;
735 if( !m_bOverwriteLabelsForAttributedDataPointsAlso && (GetPropertySet()->getPropertyValue(u"CustomLabelPosition"_ustr) >>= aCustomLabelPosition) )
736 rOutItemSet.Put(SfxInt32Item(nWhichId, css::chart::DataLabelPlacement::CUSTOM));
737 else if( GetPropertySet()->getPropertyValue( u"LabelPlacement"_ustr ) >>= nPlacement )
738 rOutItemSet.Put( SfxInt32Item( nWhichId, nPlacement ));
739 else if( m_aAvailableLabelPlacements.hasElements() )
740 rOutItemSet.Put( SfxInt32Item( nWhichId, m_aAvailableLabelPlacements[0] ));
742 catch( const uno::Exception& )
744 TOOLS_WARN_EXCEPTION("chart2", "" );
747 break;
749 case SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS:
751 rOutItemSet.Put( SfxIntegerListItem( nWhichId, m_aAvailableLabelPlacements ) );
753 break;
755 case SCHATTR_DATADESCR_NO_PERCENTVALUE:
757 rOutItemSet.Put( SfxBoolItem( nWhichId, m_bForbidPercentValue ));
759 break;
761 case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
765 bool bValue = true;
766 if( m_xSeries->getFastPropertyValue( PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES ) >>= bValue )
767 rOutItemSet.Put(SfxBoolItem(nWhichId, bValue));
769 catch (const uno::Exception&)
771 TOOLS_WARN_EXCEPTION("chart2", "");
774 break;
776 case SCHATTR_STYLE_SYMBOL:
778 chart2::Symbol aSymbol;
779 if( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
780 rOutItemSet.Put( SfxInt32Item( nWhichId, lcl_getSymbolStyleForSymbol( aSymbol ) ));
782 break;
784 case SCHATTR_SYMBOL_SIZE:
786 chart2::Symbol aSymbol;
787 if( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
788 rOutItemSet.Put(
789 SvxSizeItem( nWhichId, Size( aSymbol.Size.Width, aSymbol.Size.Height ) ));
791 break;
793 case SCHATTR_SYMBOL_BRUSH:
795 chart2::Symbol aSymbol;
796 if(( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
797 && aSymbol.Graphic.is() )
799 rOutItemSet.Put( SvxBrushItem( Graphic( aSymbol.Graphic ), GPOS_MM, SCHATTR_SYMBOL_BRUSH ));
802 break;
804 case SCHATTR_TEXT_DEGREES:
806 double fValue = 0;
808 if( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fValue )
810 rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
811 ::rtl::math::round( fValue * 100.0 ) ) )));
814 break;
816 case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
818 rOutItemSet.Put(SfxBoolItem(nWhichId, m_bHideLegendEntry));
819 break;
821 break;
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */