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