Coverage Report

Created: 2026-04-09 11:41

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