Debian Codegraph @

chart2/source/controller/itemsetwrapper/DataPointItemConverter.cxx

raw
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
20 #include <DataPointItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23
24 #include <GraphicPropertyItemConverter.hxx>
25 #include <CharacterPropertyItemConverter.hxx>
26 #include <StatisticsItemConverter.hxx>
27 #include <SeriesOptionsItemConverter.hxx>
28 #include <DataSeries.hxx>
29 #include <DataSeriesProperties.hxx>
30 #include <Diagram.hxx>
31 #include <ChartModel.hxx>
32 #include <ChartType.hxx>
33 #include <ChartTypeHelper.hxx>
34 #include <unonames.hxx>
35
36 #include <com/sun/star/chart/DataLabelPlacement.hpp>
37 #include <com/sun/star/chart2/AxisType.hpp>
38 #include <com/sun/star/chart2/DataPointLabel.hpp>
39 #include <com/sun/star/chart2/Symbol.hpp>
40 #include <com/sun/star/chart2/RelativePosition.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42
43 #include <comphelper/sequence.hxx>
44 #include <svx/xflclit.hxx>
45 #include <svl/eitem.hxx>
46 #include <svl/intitem.hxx>
47 #include <editeng/sizeitem.hxx>
48 #include <svl/stritem.hxx>
49 #include <editeng/brushitem.hxx>
50 #include <svl/ilstitem.hxx>
51 #include <svx/sdangitm.hxx>
52 #include <comphelper/diagnose_ex.hxx>
53 #include <vcl/graph.hxx>
54 #include <rtl/math.hxx>
55
56 #include <svx/tabline.hxx>
57
58 #include <memory>
59
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::chart2;
62 using namespace ::chart::DataSeriesProperties;
63 using ::com::sun::star::uno::Reference;
64
65 namespace chart::wrapper {
66
67 namespace {
68
69 ItemPropertyMapType & lcl_GetDataPointPropertyMap()
70 {
71 static ItemPropertyMapType aDataPointPropertyMap{
72 {SCHATTR_STYLE_SHAPE, {"Geometry3D", 0}}};
73 return aDataPointPropertyMap;
74 };
75
76 sal_Int32 lcl_getSymbolStyleForSymbol( const chart2::Symbol & rSymbol )
77 {
78 sal_Int32 nStyle = SVX_SYMBOLTYPE_UNKNOWN;
79 switch( rSymbol.Style )
80 {
81 case chart2::SymbolStyle_NONE:
82 nStyle = SVX_SYMBOLTYPE_NONE;
83 break;
84 case chart2::SymbolStyle_AUTO:
85 nStyle = SVX_SYMBOLTYPE_AUTO;
86 break;
87 case chart2::SymbolStyle_GRAPHIC:
88 nStyle = SVX_SYMBOLTYPE_BRUSHITEM;
89 break;
90 case chart2::SymbolStyle_STANDARD:
91 nStyle = rSymbol.StandardSymbol;
92 break;
93
94 case chart2::SymbolStyle_POLYGON:
95 // to avoid warning
96 case chart2::SymbolStyle::SymbolStyle_MAKE_FIXED_SIZE:
97 // nothing
98 break;
99 }
100 return nStyle;
101 }
102
103 bool lcl_NumberFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso )
104 {
105 bool bChanged = false;
106 if( !xPropertySet.is() )
107 return bChanged;
108 OUString aPropertyName = (nWhichId==SID_ATTR_NUMBERFORMAT_VALUE) ? CHART_UNONAME_NUMFMT : u"PercentageNumberFormat"_ustr;
109 sal_uInt16 nSourceWhich = (nWhichId==SID_ATTR_NUMBERFORMAT_VALUE) ? SID_ATTR_NUMBERFORMAT_SOURCE : SCHATTR_PERCENT_NUMBERFORMAT_SOURCE;
110
111 if( rItemSet.GetItemState( nSourceWhich ) != SfxItemState::SET )
112 return bChanged;
113
114 uno::Any aValue;
115 bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
116 rItemSet.Get( nSourceWhich )).GetValue();
117 if( !bUseSourceFormat )
118 {
119 SfxItemState aState = rItemSet.GetItemState( nWhichId );
120 if( aState == SfxItemState::SET )
121 {
122 sal_Int32 nFmt = static_cast< sal_Int32 >(
123 static_cast< const SfxUInt32Item & >(
124 rItemSet.Get( nWhichId )).GetValue());
125 aValue <<= nFmt;
126 }
127 else
128 return bChanged;
129 }
130
131 uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
132 if( bOverwriteAttributedDataPointsAlso )
133 {
134 rtl::Reference< DataSeries > xSeries( dynamic_cast<DataSeries*>(xPropertySet.get()) );
135 if( aValue != aOldValue ||
136 xSeries->hasAttributedDataPointDifferentValue( aPropertyName, aOldValue ) )
137 {
138 xSeries->setPropertyAlsoToAllAttributedDataPoints( aPropertyName, aValue );
139 bChanged = true;
140 }
141 }
142 else if( aOldValue != aValue )
143 {
144 xPropertySet->setPropertyValue(aPropertyName, aValue );
145 bChanged = true;
146 }
147 return bChanged;
148 }
149
150 bool lcl_UseSourceFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso )
151 {
152 bool bChanged = false;
153 if( !xPropertySet.is() )
154 return bChanged;
155 OUString aPropertyName = (nWhichId==SID_ATTR_NUMBERFORMAT_SOURCE) ? CHART_UNONAME_NUMFMT : u"PercentageNumberFormat"_ustr;
156 sal_uInt16 nFormatWhich = (nWhichId==SID_ATTR_NUMBERFORMAT_SOURCE) ? SID_ATTR_NUMBERFORMAT_VALUE : SCHATTR_PERCENT_NUMBERFORMAT_VALUE;
157
158 if( rItemSet.GetItemState( nWhichId ) != SfxItemState::SET )
159 return bChanged;
160
161 uno::Any aNewValue;
162 bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
163 rItemSet.Get( nWhichId )).GetValue();
164 xPropertySet->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::Any(bUseSourceFormat));
165 if( !bUseSourceFormat )
166 {
167 SfxItemState aState = rItemSet.GetItemState( nFormatWhich );
168 if( aState == SfxItemState::SET )
169 {
170 sal_Int32 nFormatKey = static_cast< sal_Int32 >(
171 static_cast< const SfxUInt32Item & >(
172 rItemSet.Get( nFormatWhich )).GetValue());
173 aNewValue <<= nFormatKey;
174 }
175 else
176 return bChanged;
177 }
178
179 uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
180 if( bOverwriteAttributedDataPointsAlso )
181 {
182 rtl::Reference< DataSeries > xSeries( dynamic_cast<DataSeries*>(xPropertySet.get()) );
183 if( aNewValue != aOldValue ||
184 xSeries->hasAttributedDataPointDifferentValue( aPropertyName, aOldValue ) )
185 {
186 xSeries->setPropertyAlsoToAllAttributedDataPoints( aPropertyName, aNewValue );
187 bChanged = true;
188 }
189 }
190 else if( aOldValue != aNewValue )
191 {
192 xPropertySet->setPropertyValue( aPropertyName, aNewValue );
193 bChanged = true;
194 }
195
196 return bChanged;
197 }
198
199 } // anonymous namespace
200
201 DataPointItemConverter::DataPointItemConverter(
202 const rtl::Reference<::chart::ChartModel> & xChartModel,
203 const uno::Reference< uno::XComponentContext > & xContext,
204 const uno::Reference< beans::XPropertySet > & rPropertySet,
205 const rtl::Reference< DataSeries > & xSeries,
206 SfxItemPool& rItemPool,
207 SdrModel& rDrawModel,
208 GraphicObjectType eMapTo,
209 const std::optional<awt::Size>& pRefSize,
210 bool bDataSeries,
211 bool bUseSpecialFillColor,
212 sal_Int32 nSpecialFillColor,
213 bool bOverwriteLabelsForAttributedDataPointsAlso,
214 sal_Int32 nNumberFormat,
215 sal_Int32 nPercentNumberFormat,
216 sal_Int32 nPointIndex ) :
217 ItemConverter( rPropertySet, rItemPool ),
218 m_bDataSeries( bDataSeries ),
219 m_bOverwriteLabelsForAttributedDataPointsAlso(m_bDataSeries && bOverwriteLabelsForAttributedDataPointsAlso),
220 m_bUseSpecialFillColor(bUseSpecialFillColor),
221 m_nSpecialFillColor(ColorTransparency, nSpecialFillColor),
222 m_nNumberFormat(nNumberFormat),
223 m_nPercentNumberFormat(nPercentNumberFormat),
224 m_bForbidPercentValue(true),
225 m_bHideLegendEntry(false),
226 m_nPointIndex(nPointIndex),
227 m_xSeries(xSeries)
228 {
229 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
230 rPropertySet, rItemPool, rDrawModel, xChartModel, eMapTo ));
231 m_aConverters.emplace_back( new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, u"ReferencePageSize"_ustr));
232 if( bDataSeries )
233 {
234 assert(dynamic_cast<DataSeries*>(rPropertySet.get()));
235 m_aConverters.emplace_back( new StatisticsItemConverter( xChartModel, rPropertySet, rItemPool ));
236 m_aConverters.emplace_back( new SeriesOptionsItemConverter( xChartModel, xContext,
237 dynamic_cast<DataSeries*>(rPropertySet.get()), rItemPool ));
238 }
239
240 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
241 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) );
242 bool bFound = false;
243 bool bAmbiguous = false;
244 bool bSwapXAndY = xDiagram->getVertical( bFound, bAmbiguous );
245 m_aAvailableLabelPlacements = ChartTypeHelper::getSupportedLabelPlacements( xChartType, bSwapXAndY, xSeries );
246
247 m_bForbidPercentValue = xChartType.is() ? xChartType->getAxisType(0) != AxisType::CATEGORY : false;
248
249 if (bDataSeries)
250 return;
251
252 uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
253 // "DeletedLegendEntries"
254 xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
255 for (const auto& deletedLegendEntry : deletedLegendEntriesSeq)
256 {
257 if (nPointIndex == deletedLegendEntry)
258 {
259 m_bHideLegendEntry = true;
260 break;
261 }
262 }
263 }
264
265 DataPointItemConverter::~DataPointItemConverter()
266 {
267 }
268
269 void DataPointItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
270 {
271 for( const auto& pConv : m_aConverters )
272 pConv->FillItemSet( rOutItemSet );
273
274 // own items
275 ItemConverter::FillItemSet( rOutItemSet );
276
277 if( m_bUseSpecialFillColor )
278 {
279 Color aColor(m_nSpecialFillColor);
280 rOutItemSet.Put( XFillColorItem( OUString(), aColor ) );
281 }
282 }
283
284 bool DataPointItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
285 {
286 bool bResult = false;
287
288 for( const auto& pConv : m_aConverters )
289 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
290
291 // own items
292 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
293 }
294
295 const WhichRangesContainer& DataPointItemConverter::GetWhichPairs() const
296 {
297 // must span all used items!
298 if( m_bDataSeries )
299 return nRowWhichPairs;
300 return nDataPointWhichPairs;
301 }
302
303 bool DataPointItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
304 {
305 ItemPropertyMapType & rMap( lcl_GetDataPointPropertyMap());
306 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
307
308 if( aIt == rMap.end())
309 return false;
310
311 rOutProperty =(*aIt).second;
312 return true;
313 }
314
315 bool DataPointItemConverter::ApplySpecialItem(
316 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
317 {
318 bool bChanged = false;
319
320 switch( nWhichId )
321 {
322 case SCHATTR_DATADESCR_SHOW_NUMBER:
323 case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
324 case SCHATTR_DATADESCR_SHOW_CATEGORY:
325 case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
326 case SCHATTR_DATADESCR_SHOW_SYMBOL:
327 {
328 const SfxBoolItem & rItem = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId ));
329
330 uno::Any aOldValue = GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL);
331 chart2::DataPointLabel aLabel;
332 if( aOldValue >>= aLabel )
333 {
334 sal_Bool& rValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
335 (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
336 (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
337 (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
338 bool bOldValue = rValue;
339 rValue = rItem.GetValue();
340 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
341 {
342 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
343 if( bOldValue != bool(rValue) ||
344 xSeries->hasAttributedDataPointDifferentValue( CHART_UNONAME_LABEL , aOldValue ) )
345 {
346 xSeries->setPropertyAlsoToAllAttributedDataPoints( CHART_UNONAME_LABEL , uno::Any( aLabel ) );
347 xSeries->setPropertyAlsoToAllAttributedDataPoints( CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() );
348 bChanged = true;
349 }
350 }
351 else if( bOldValue != bool(rValue) )
352 {
353 GetPropertySet()->setPropertyValue(CHART_UNONAME_LABEL , uno::Any(aLabel));
354 bChanged = true;
355 }
356 }
357 }
358 break;
359
360 case SID_ATTR_NUMBERFORMAT_VALUE:
361 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE: //fall through intended
362 {
363 bChanged = lcl_NumberFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
364 }
365 break;
366
367 case SID_ATTR_NUMBERFORMAT_SOURCE:
368 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE: //fall through intended
369 {
370 bChanged = lcl_UseSourceFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
371 }
372 break;
373
374 case SCHATTR_DATADESCR_SEPARATOR:
375 {
376 OUString aNewValue = static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue();
377 try
378 {
379 OUString aOldValue;
380 GetPropertySet()->getPropertyValue( u"LabelSeparator"_ustr ) >>= aOldValue;
381 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
382 {
383 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
384 if( aOldValue != aNewValue ||
385 xSeries->hasAttributedDataPointDifferentValue( u"LabelSeparator"_ustr , uno::Any( aOldValue ) ) )
386 {
387 xSeries->setPropertyAlsoToAllAttributedDataPoints( u"LabelSeparator"_ustr , uno::Any( aNewValue ) );
388 bChanged = true;
389 }
390 }
391 else if( aOldValue != aNewValue )
392 {
393 GetPropertySet()->setPropertyValue( u"LabelSeparator"_ustr , uno::Any( aNewValue ));
394 bChanged = true;
395 }
396 }
397 catch( const uno::Exception& )
398 {
399 TOOLS_WARN_EXCEPTION("chart2", "" );
400 }
401 }
402 break;
403
404 case SCHATTR_DATADESCR_WRAP_TEXT:
405 {
406
407 try
408 {
409 bool bNew = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
410 bool bOld = false;
411 GetPropertySet()->getPropertyValue( u"TextWordWrap"_ustr ) >>= bOld;
412 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
413 {
414 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
415 if( bOld!=bNew ||
416 xSeries->hasAttributedDataPointDifferentValue( u"TextWordWrap"_ustr, uno::Any( bOld ) ) )
417 {
418 xSeries->setPropertyAlsoToAllAttributedDataPoints( u"TextWordWrap"_ustr, uno::Any( bNew ) );
419 bChanged = true;
420 }
421 }
422 else if( bOld!=bNew )
423 {
424 GetPropertySet()->setPropertyValue( u"TextWordWrap"_ustr, uno::Any( bNew ));
425 bChanged = true;
426 }
427 }
428 catch( const uno::Exception& )
429 {
430 TOOLS_WARN_EXCEPTION("chart2", "" );
431 }
432 }
433 break;
434
435 case SCHATTR_DATADESCR_PLACEMENT:
436 {
437
438 try
439 {
440 sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
441 sal_Int32 nOld = -1;
442 RelativePosition aCustomLabelPosition;
443 GetPropertySet()->getPropertyValue(u"LabelPlacement"_ustr) >>= nOld;
444 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
445 {
446 rtl::Reference<DataSeries> xSeries(dynamic_cast<DataSeries*>(GetPropertySet().get()));
447 if( nOld!=nNew ||
448 xSeries->hasAttributedDataPointDifferentValue( u"LabelPlacement"_ustr , uno::Any( nOld ) ) )
449 {
450 xSeries->setPropertyAlsoToAllAttributedDataPoints( u"LabelPlacement"_ustr , uno::Any( nNew ) );
451 bChanged = true;
452 }
453 }
454 else if( nOld!=nNew || (GetPropertySet()->getPropertyValue(u"CustomLabelPosition"_ustr) >>= aCustomLabelPosition) )
455 {
456 GetPropertySet()->setPropertyValue(u"LabelPlacement"_ustr, uno::Any(nNew));
457 GetPropertySet()->setPropertyValue(u"CustomLabelPosition"_ustr, uno::Any());
458 GetPropertySet()->setPropertyValue(u"CustomLabelSize"_ustr, uno::Any());
459 bChanged = true;
460 }
461 }
462 catch( const uno::Exception& )
463 {
464 TOOLS_WARN_EXCEPTION("chart2", "" );
465 }
466 }
467 break;
468
469 case SCHATTR_STYLE_SYMBOL:
470 {
471 sal_Int32 nStyle =
472 static_cast< const SfxInt32Item & >(
473 rItemSet.Get( nWhichId )).GetValue();
474 chart2::Symbol aSymbol;
475
476 GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
477 sal_Int32 nOldStyle = lcl_getSymbolStyleForSymbol( aSymbol );
478
479 if( nStyle != nOldStyle )
480 {
481 bool bDeleteSymbol = false;
482 switch( nStyle )
483 {
484 case SVX_SYMBOLTYPE_NONE:
485 aSymbol.Style = chart2::SymbolStyle_NONE;
486 break;
487 case SVX_SYMBOLTYPE_AUTO:
488 aSymbol.Style = chart2::SymbolStyle_AUTO;
489 break;
490 case SVX_SYMBOLTYPE_BRUSHITEM:
491 aSymbol.Style = chart2::SymbolStyle_GRAPHIC;
492 break;
493 case SVX_SYMBOLTYPE_UNKNOWN:
494 bDeleteSymbol = true;
495 break;
496
497 default:
498 aSymbol.Style = chart2::SymbolStyle_STANDARD;
499 aSymbol.StandardSymbol = nStyle;
500 }
501
502 if( bDeleteSymbol )
503 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any());
504 else
505 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
506 bChanged = true;
507 }
508 }
509 break;
510
511 case SCHATTR_SYMBOL_SIZE:
512 {
513 Size aSize = static_cast< const SvxSizeItem & >(
514 rItemSet.Get( nWhichId )).GetSize();
515 chart2::Symbol aSymbol;
516
517 GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
518 if( aSize.getWidth() != aSymbol.Size.Width ||
519 aSize.getHeight() != aSymbol.Size.Height )
520 {
521 aSymbol.Size.Width = aSize.getWidth();
522 aSymbol.Size.Height = aSize.getHeight();
523
524 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
525 bChanged = true;
526 }
527 }
528 break;
529
530 case SCHATTR_SYMBOL_BRUSH:
531 {
532 const SvxBrushItem & rBrshItem( static_cast< const SvxBrushItem & >(
533 rItemSet.Get( nWhichId )));
534 uno::Any aXGraphicAny;
535 const Graphic *pGraphic( rBrshItem.GetGraphic());
536 if( pGraphic )
537 {
538 uno::Reference< graphic::XGraphic > xGraphic( pGraphic->GetXGraphic());
539 if( xGraphic.is())
540 {
541 aXGraphicAny <<= xGraphic;
542 chart2::Symbol aSymbol;
543 GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
544 if( aSymbol.Graphic != xGraphic )
545 {
546 aSymbol.Graphic = std::move(xGraphic);
547 GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
548 bChanged = true;
549 }
550 }
551 }
552 }
553 break;
554
555 case SCHATTR_TEXT_DEGREES:
556 {
557 double fValue = toDegrees(rItemSet.Get(SCHATTR_TEXT_DEGREES).GetValue());
558 double fOldValue = 0.0;
559 bool bPropExisted =
560 ( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fOldValue );
561
562 if( ! bPropExisted || fOldValue != fValue )
563 {
564 GetPropertySet()->setPropertyValue( u"TextRotation"_ustr , uno::Any( fValue ));
565 bChanged = true;
566 }
567 }
568 break;
569
570 case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
571 {
572 bool bHideLegendEntry = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
573 if (bHideLegendEntry != m_bHideLegendEntry)
574 {
575 uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
576 // "DeletedLegendEntries"
577 m_xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
578 std::vector<sal_Int32> deletedLegendEntries;
579 for (const auto& deletedLegendEntry : deletedLegendEntriesSeq)
580 {
581 if (bHideLegendEntry || m_nPointIndex != deletedLegendEntry)
582 deletedLegendEntries.push_back(deletedLegendEntry);
583 }
584 if (bHideLegendEntry)
585 deletedLegendEntries.push_back(m_nPointIndex);
586 // "DeletedLegendEntries"
587 m_xSeries->setFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES, uno::Any(comphelper::containerToSequence(deletedLegendEntries)));
588 }
589 }
590 break;
591
592 case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
593 {
594 try
595 {
596 bool bNew = static_cast<const SfxBoolItem&>(rItemSet.Get(nWhichId)).GetValue();
597 bool bOld = true;
598 if( (m_xSeries->getFastPropertyValue(PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES) >>= bOld) && bOld != bNew )
599 {
600 m_xSeries->setFastPropertyValue(PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES, uno::Any(bNew));
601 bChanged = true;
602 }
603 }
604 catch (const uno::Exception&)
605 {
606 TOOLS_WARN_EXCEPTION("chart2", "");
607 }
608 }
609 break;
610 }
611
612 return bChanged;
613 }
614
615 void DataPointItemConverter::FillSpecialItem(
616 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
617 {
618 switch( nWhichId )
619 {
620 case SCHATTR_DATADESCR_SHOW_NUMBER:
621 case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
622 case SCHATTR_DATADESCR_SHOW_CATEGORY:
623 case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
624 case SCHATTR_DATADESCR_SHOW_SYMBOL:
625 {
626 chart2::DataPointLabel aLabel;
627 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel)
628 {
629 bool bValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
630 (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
631 (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
632 (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
633
634 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
635
636 DataSeries* pDataSeries = m_bOverwriteLabelsForAttributedDataPointsAlso
637 ? dynamic_cast<DataSeries*>(GetPropertySet().get())
638 : nullptr;
639 if (pDataSeries && pDataSeries->hasAttributedDataPointDifferentValue(
640 CHART_UNONAME_LABEL, uno::Any(aLabel)))
641 {
642 rOutItemSet.InvalidateItem(nWhichId);
643 }
644 }
645 }
646 break;
647
648 case SID_ATTR_NUMBERFORMAT_VALUE:
649 {
650 sal_Int32 nKey = 0;
651 if (!(GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nKey))
652 nKey = m_nNumberFormat;
653 rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
654 }
655 break;
656
657 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE:
658 {
659 sal_Int32 nKey = 0;
660 if( !(GetPropertySet()->getPropertyValue( u"PercentageNumberFormat"_ustr ) >>= nKey) )
661 nKey = m_nPercentNumberFormat;
662 rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
663 }
664 break;
665
666 case SID_ATTR_NUMBERFORMAT_SOURCE:
667 {
668 bool bUseSourceFormat = false;
669 try
670 {
671 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
672 }
673 catch (const uno::Exception&)
674 {
675 TOOLS_WARN_EXCEPTION("chart2", "");
676 }
677 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue() && !bUseSourceFormat;
678 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
679 }
680 break;
681 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
682 {
683 bool bUseSourceFormat = false;
684 try
685 {
686 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
687 }
688 catch (const uno::Exception&)
689 {
690 TOOLS_WARN_EXCEPTION("chart2", "");
691 }
692 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue( u"PercentageNumberFormat"_ustr ).hasValue() && !bUseSourceFormat;
693 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
694 }
695 break;
696
697 case SCHATTR_DATADESCR_SEPARATOR:
698 {
699 try
700 {
701 OUString aValue;
702 GetPropertySet()->getPropertyValue( u"LabelSeparator"_ustr ) >>= aValue;
703 rOutItemSet.Put( SfxStringItem( nWhichId, aValue ));
704 }
705 catch( const uno::Exception& )
706 {
707 TOOLS_WARN_EXCEPTION("chart2", "" );
708 }
709 }
710 break;
711
712 case SCHATTR_DATADESCR_WRAP_TEXT:
713 {
714 try
715 {
716 bool bValue = false;
717 GetPropertySet()->getPropertyValue( u"TextWordWrap"_ustr ) >>= bValue;
718 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
719 }
720 catch( const uno::Exception& )
721 {
722 TOOLS_WARN_EXCEPTION("chart2", "" );
723 }
724 }
725 break;
726
727 case SCHATTR_DATADESCR_PLACEMENT:
728 {
729 try
730 {
731 sal_Int32 nPlacement=0;
732 RelativePosition aCustomLabelPosition;
733 if( !m_bOverwriteLabelsForAttributedDataPointsAlso && (GetPropertySet()->getPropertyValue(u"CustomLabelPosition"_ustr) >>= aCustomLabelPosition) )
734 rOutItemSet.Put(SfxInt32Item(nWhichId, css::chart::DataLabelPlacement::CUSTOM));
735 else if( GetPropertySet()->getPropertyValue( u"LabelPlacement"_ustr ) >>= nPlacement )
736 rOutItemSet.Put( SfxInt32Item( nWhichId, nPlacement ));
737 else if( m_aAvailableLabelPlacements.hasElements() )
738 rOutItemSet.Put( SfxInt32Item( nWhichId, m_aAvailableLabelPlacements[0] ));
739 }
740 catch( const uno::Exception& )
741 {
742 TOOLS_WARN_EXCEPTION("chart2", "" );
743 }
744 }
745 break;
746
747 case SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS:
748 {
749 rOutItemSet.Put( SfxIntegerListItem( nWhichId, m_aAvailableLabelPlacements ) );
750 }
751 break;
752
753 case SCHATTR_DATADESCR_NO_PERCENTVALUE:
754 {
755 rOutItemSet.Put( SfxBoolItem( nWhichId, m_bForbidPercentValue ));
756 }
757 break;
758
759 case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
760 {
761 try
762 {
763 bool bValue = true;
764 if( m_xSeries->getFastPropertyValue( PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES ) >>= bValue )
765 rOutItemSet.Put(SfxBoolItem(nWhichId, bValue));
766 }
767 catch (const uno::Exception&)
768 {
769 TOOLS_WARN_EXCEPTION("chart2", "");
770 }
771 }
772 break;
773
774 case SCHATTR_STYLE_SYMBOL:
775 {
776 chart2::Symbol aSymbol;
777 if( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
778 rOutItemSet.Put( SfxInt32Item( nWhichId, lcl_getSymbolStyleForSymbol( aSymbol ) ));
779 }
780 break;
781
782 case SCHATTR_SYMBOL_SIZE:
783 {
784 chart2::Symbol aSymbol;
785 if( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
786 rOutItemSet.Put(
787 SvxSizeItem( nWhichId, Size( aSymbol.Size.Width, aSymbol.Size.Height ) ));
788 }
789 break;
790
791 case SCHATTR_SYMBOL_BRUSH:
792 {
793 chart2::Symbol aSymbol;
794 if(( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
795 && aSymbol.Graphic.is() )
796 {
797 rOutItemSet.Put( SvxBrushItem( Graphic( aSymbol.Graphic ), GPOS_MM, SCHATTR_SYMBOL_BRUSH ));
798 }
799 }
800 break;
801
802 case SCHATTR_TEXT_DEGREES:
803 {
804 double fValue = 0;
805
806 if( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fValue )
807 {
808 rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
809 ::rtl::math::round( fValue * 100.0 ) ) )));
810 }
811 }
812 break;
813
814 case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
815 {
816 rOutItemSet.Put(SfxBoolItem(nWhichId, m_bHideLegendEntry));
817 break;
818 }
819 break;
820 }
821 }
822
823 }
824
825 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */