Coverage Report

Created: 2026-03-31 11:00

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