Coverage Report

Created: 2026-09-28 10:59

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 = rItemSet.Get( SCHATTR_DATADESCR_SEPARATOR ).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 = rItemSet.Get( SCHATTR_DATADESCR_WRAP_TEXT ).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 = rItemSet.Get( SCHATTR_DATADESCR_PLACEMENT ).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 = rItemSet.Get( SCHATTR_STYLE_SYMBOL ).GetValue();
472
0
            chart2::Symbol aSymbol;
473
474
0
            GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
475
0
            sal_Int32 nOldStyle = lcl_getSymbolStyleForSymbol( aSymbol );
476
477
0
            if( nStyle != nOldStyle )
478
0
            {
479
0
                bool bDeleteSymbol = false;
480
0
                switch( nStyle )
481
0
                {
482
0
                    case SVX_SYMBOLTYPE_NONE:
483
0
                        aSymbol.Style = chart2::SymbolStyle_NONE;
484
0
                        break;
485
0
                    case SVX_SYMBOLTYPE_AUTO:
486
0
                        aSymbol.Style = chart2::SymbolStyle_AUTO;
487
0
                        break;
488
0
                    case SVX_SYMBOLTYPE_BRUSHITEM:
489
0
                        aSymbol.Style = chart2::SymbolStyle_GRAPHIC;
490
0
                        break;
491
0
                    case SVX_SYMBOLTYPE_UNKNOWN:
492
0
                        bDeleteSymbol = true;
493
0
                        break;
494
495
0
                    default:
496
0
                        aSymbol.Style = chart2::SymbolStyle_STANDARD;
497
0
                        aSymbol.StandardSymbol = nStyle;
498
0
                }
499
500
0
                if( bDeleteSymbol )
501
0
                    GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any());
502
0
                else
503
0
                    GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
504
0
                bChanged = true;
505
0
            }
506
0
        }
507
0
        break;
508
509
0
        case SCHATTR_SYMBOL_SIZE:
510
0
        {
511
0
            Size aSize = rItemSet.Get( SCHATTR_SYMBOL_SIZE ).GetSize();
512
0
            chart2::Symbol aSymbol;
513
514
0
            GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
515
0
            if( aSize.getWidth() != aSymbol.Size.Width ||
516
0
                aSize.getHeight() != aSymbol.Size.Height )
517
0
            {
518
0
                aSymbol.Size.Width = aSize.getWidth();
519
0
                aSymbol.Size.Height = aSize.getHeight();
520
521
0
                GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
522
0
                bChanged = true;
523
0
            }
524
0
        }
525
0
        break;
526
527
0
        case SCHATTR_SYMBOL_BRUSH:
528
0
        {
529
0
            const SvxBrushItem & rBrshItem( static_cast< const SvxBrushItem & >(
530
0
                                                rItemSet.Get( nWhichId )));
531
0
            uno::Any aXGraphicAny;
532
0
            const Graphic *pGraphic( rBrshItem.GetGraphic());
533
0
            if( pGraphic )
534
0
            {
535
0
                uno::Reference< graphic::XGraphic > xGraphic( pGraphic->GetXGraphic());
536
0
                if( xGraphic.is())
537
0
                {
538
0
                    aXGraphicAny <<= xGraphic;
539
0
                    chart2::Symbol aSymbol;
540
0
                    GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol;
541
0
                    if( aSymbol.Graphic != xGraphic )
542
0
                    {
543
0
                        aSymbol.Graphic = std::move(xGraphic);
544
0
                        GetPropertySet()->setPropertyValue( u"Symbol"_ustr , uno::Any( aSymbol ));
545
0
                        bChanged = true;
546
0
                    }
547
0
                }
548
0
            }
549
0
        }
550
0
        break;
551
552
0
        case SCHATTR_TEXT_DEGREES:
553
0
        {
554
0
            double fValue = toDegrees(rItemSet.Get(SCHATTR_TEXT_DEGREES).GetValue());
555
0
            double fOldValue = 0.0;
556
0
            bool bPropExisted =
557
0
                ( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fOldValue );
558
559
0
            if( ! bPropExisted || fOldValue != fValue )
560
0
            {
561
0
                GetPropertySet()->setPropertyValue( u"TextRotation"_ustr , uno::Any( fValue ));
562
0
                bChanged = true;
563
0
            }
564
0
        }
565
0
        break;
566
567
0
        case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
568
0
        {
569
0
            bool bHideLegendEntry = static_cast<const SfxBoolItem &>(rItemSet.Get(nWhichId)).GetValue();
570
0
            if (bHideLegendEntry != m_bHideLegendEntry)
571
0
            {
572
0
                uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
573
                // "DeletedLegendEntries"
574
0
                m_xSeries->getFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES) >>= deletedLegendEntriesSeq;
575
0
                std::vector<sal_Int32> deletedLegendEntries;
576
0
                for (const auto& deletedLegendEntry : deletedLegendEntriesSeq)
577
0
                {
578
0
                    if (bHideLegendEntry || m_nPointIndex != deletedLegendEntry)
579
0
                        deletedLegendEntries.push_back(deletedLegendEntry);
580
0
                }
581
0
                if (bHideLegendEntry)
582
0
                    deletedLegendEntries.push_back(m_nPointIndex);
583
                // "DeletedLegendEntries"
584
0
                m_xSeries->setFastPropertyValue(PROP_DATASERIES_DELETED_LEGEND_ENTRIES, uno::Any(comphelper::containerToSequence(deletedLegendEntries)));
585
0
            }
586
0
        }
587
0
        break;
588
589
0
        case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
590
0
        {
591
0
            try
592
0
            {
593
0
                bool bNew = static_cast<const SfxBoolItem&>(rItemSet.Get(nWhichId)).GetValue();
594
0
                bool bOld = true;
595
0
                if( (m_xSeries->getFastPropertyValue(PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES) >>= bOld) && bOld != bNew )
596
0
                {
597
0
                    m_xSeries->setFastPropertyValue(PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES, uno::Any(bNew));
598
0
                    bChanged = true;
599
0
                }
600
0
            }
601
0
            catch (const uno::Exception&)
602
0
            {
603
0
                TOOLS_WARN_EXCEPTION("chart2", "");
604
0
            }
605
0
        }
606
0
        break;
607
0
    }
608
609
0
    return bChanged;
610
0
}
611
612
void DataPointItemConverter::FillSpecialItem(
613
    sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
614
0
{
615
0
    switch( nWhichId )
616
0
    {
617
0
        case SCHATTR_DATADESCR_SHOW_NUMBER:
618
0
        case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
619
0
        case SCHATTR_DATADESCR_SHOW_CATEGORY:
620
0
        case SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME:
621
0
        case SCHATTR_DATADESCR_SHOW_SYMBOL:
622
0
        {
623
0
            chart2::DataPointLabel aLabel;
624
0
            if (GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel)
625
0
            {
626
0
                bool bValue = (nWhichId==SCHATTR_DATADESCR_SHOW_NUMBER) ? aLabel.ShowNumber : (
627
0
                    (nWhichId==SCHATTR_DATADESCR_SHOW_PERCENTAGE) ? aLabel.ShowNumberInPercent : (
628
0
                    (nWhichId==SCHATTR_DATADESCR_SHOW_CATEGORY) ? aLabel.ShowCategoryName : (
629
0
                    (nWhichId==SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME) ? aLabel.ShowSeriesName : aLabel.ShowLegendSymbol )));
630
631
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
632
633
0
                DataSeries* pDataSeries = m_bOverwriteLabelsForAttributedDataPointsAlso
634
0
                    ? dynamic_cast<DataSeries*>(GetPropertySet().get())
635
0
                    : nullptr;
636
0
                if (pDataSeries && pDataSeries->hasAttributedDataPointDifferentValue(
637
0
                            CHART_UNONAME_LABEL, uno::Any(aLabel)))
638
0
                {
639
0
                    rOutItemSet.InvalidateItem(nWhichId);
640
0
                }
641
0
            }
642
0
        }
643
0
        break;
644
645
0
        case SID_ATTR_NUMBERFORMAT_VALUE:
646
0
        {
647
0
            sal_Int32 nKey = 0;
648
0
            if (!(GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nKey))
649
0
                nKey = m_nNumberFormat;
650
0
            rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
651
0
        }
652
0
        break;
653
654
0
        case SCHATTR_PERCENT_NUMBERFORMAT_VALUE:
655
0
        {
656
0
            sal_Int32 nKey = 0;
657
0
            if( !(GetPropertySet()->getPropertyValue( u"PercentageNumberFormat"_ustr ) >>= nKey) )
658
0
                nKey = m_nPercentNumberFormat;
659
0
            rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
660
0
        }
661
0
        break;
662
663
0
        case SID_ATTR_NUMBERFORMAT_SOURCE:
664
0
        {
665
0
            bool bUseSourceFormat = false;
666
0
            try
667
0
            {
668
0
                GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
669
0
            }
670
0
            catch (const uno::Exception&)
671
0
            {
672
0
                TOOLS_WARN_EXCEPTION("chart2", "");
673
0
            }
674
0
            bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue() && !bUseSourceFormat;
675
0
            rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
676
0
        }
677
0
        break;
678
0
        case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
679
0
        {
680
0
            bool bUseSourceFormat = false;
681
0
            try
682
0
            {
683
0
                GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bUseSourceFormat;
684
0
            }
685
0
            catch (const uno::Exception&)
686
0
            {
687
0
                TOOLS_WARN_EXCEPTION("chart2", "");
688
0
            }
689
0
            bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue( u"PercentageNumberFormat"_ustr ).hasValue() && !bUseSourceFormat;
690
0
            rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
691
0
        }
692
0
        break;
693
694
0
        case SCHATTR_DATADESCR_SEPARATOR:
695
0
        {
696
0
            try
697
0
            {
698
0
                OUString aValue;
699
0
                GetPropertySet()->getPropertyValue( u"LabelSeparator"_ustr ) >>= aValue;
700
0
                rOutItemSet.Put( SfxStringItem( nWhichId, aValue ));
701
0
            }
702
0
            catch( const uno::Exception& )
703
0
            {
704
0
                TOOLS_WARN_EXCEPTION("chart2", "" );
705
0
            }
706
0
        }
707
0
        break;
708
709
0
        case SCHATTR_DATADESCR_WRAP_TEXT:
710
0
        {
711
0
            try
712
0
            {
713
0
                bool bValue = false;
714
0
                GetPropertySet()->getPropertyValue( u"TextWordWrap"_ustr ) >>= bValue;
715
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
716
0
            }
717
0
            catch( const uno::Exception& )
718
0
            {
719
0
                TOOLS_WARN_EXCEPTION("chart2", "" );
720
0
            }
721
0
        }
722
0
        break;
723
724
0
        case SCHATTR_DATADESCR_PLACEMENT:
725
0
        {
726
0
            try
727
0
            {
728
0
                sal_Int32 nPlacement=0;
729
0
                RelativePosition aCustomLabelPosition;
730
0
                if( !m_bOverwriteLabelsForAttributedDataPointsAlso && (GetPropertySet()->getPropertyValue(u"CustomLabelPosition"_ustr) >>= aCustomLabelPosition) )
731
0
                    rOutItemSet.Put(SfxInt32Item(nWhichId, css::chart::DataLabelPlacement::CUSTOM));
732
0
                else if( GetPropertySet()->getPropertyValue( u"LabelPlacement"_ustr ) >>= nPlacement )
733
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, nPlacement ));
734
0
                else if( m_aAvailableLabelPlacements.hasElements() )
735
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, m_aAvailableLabelPlacements[0] ));
736
0
            }
737
0
            catch( const uno::Exception& )
738
0
            {
739
0
                TOOLS_WARN_EXCEPTION("chart2", "" );
740
0
            }
741
0
        }
742
0
        break;
743
744
0
        case SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS:
745
0
        {
746
0
            rOutItemSet.Put( SfxIntegerListItem( nWhichId, m_aAvailableLabelPlacements ) );
747
0
        }
748
0
        break;
749
750
0
        case SCHATTR_DATADESCR_NO_PERCENTVALUE:
751
0
        {
752
0
            rOutItemSet.Put( SfxBoolItem( nWhichId, m_bForbidPercentValue ));
753
0
        }
754
0
        break;
755
756
0
        case SCHATTR_DATADESCR_CUSTOM_LEADER_LINES:
757
0
        {
758
0
            try
759
0
            {
760
0
                bool bValue = true;
761
0
                if( m_xSeries->getFastPropertyValue( PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES ) >>= bValue )
762
0
                    rOutItemSet.Put(SfxBoolItem(nWhichId, bValue));
763
0
            }
764
0
            catch (const uno::Exception&)
765
0
            {
766
0
                TOOLS_WARN_EXCEPTION("chart2", "");
767
0
            }
768
0
        }
769
0
        break;
770
771
0
        case SCHATTR_STYLE_SYMBOL:
772
0
        {
773
0
            chart2::Symbol aSymbol;
774
0
            if( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
775
0
                rOutItemSet.Put( SfxInt32Item( nWhichId, lcl_getSymbolStyleForSymbol( aSymbol ) ));
776
0
        }
777
0
        break;
778
779
0
        case SCHATTR_SYMBOL_SIZE:
780
0
        {
781
0
            chart2::Symbol aSymbol;
782
0
            if( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
783
0
                rOutItemSet.Put(
784
0
                    SvxSizeItem( nWhichId, Size( aSymbol.Size.Width, aSymbol.Size.Height ) ));
785
0
        }
786
0
        break;
787
788
0
        case SCHATTR_SYMBOL_BRUSH:
789
0
        {
790
0
            chart2::Symbol aSymbol;
791
0
            if(( GetPropertySet()->getPropertyValue( u"Symbol"_ustr ) >>= aSymbol )
792
0
               && aSymbol.Graphic.is() )
793
0
            {
794
0
                rOutItemSet.Put( SvxBrushItem( Graphic( aSymbol.Graphic ), GPOS_MM, SCHATTR_SYMBOL_BRUSH ));
795
0
            }
796
0
        }
797
0
        break;
798
799
0
        case SCHATTR_TEXT_DEGREES:
800
0
        {
801
0
            double fValue = 0;
802
803
0
            if( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fValue )
804
0
            {
805
0
                rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
806
0
                                                   ::rtl::math::round( fValue * 100.0 ) ) )));
807
0
            }
808
0
        }
809
0
        break;
810
811
0
        case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY:
812
0
        {
813
0
            rOutItemSet.Put(SfxBoolItem(nWhichId, m_bHideLegendEntry));
814
0
            break;
815
0
        }
816
0
        break;
817
0
   }
818
0
}
819
820
}
821
822
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */