Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/itemsetwrapper/AxisItemConverter.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 <AxisItemConverter.hxx>
21
#include <ItemPropertyMap.hxx>
22
#include <CharacterPropertyItemConverter.hxx>
23
#include <GraphicPropertyItemConverter.hxx>
24
#include <chartview/ChartSfxItemIds.hxx>
25
#include <chartview/ExplicitScaleValues.hxx>
26
#include "SchWhichPairs.hxx"
27
#include <ChartModel.hxx>
28
#include <Axis.hxx>
29
#include <AxisHelper.hxx>
30
#include <CommonConverters.hxx>
31
#include <ChartType.hxx>
32
#include <Diagram.hxx>
33
#include <unonames.hxx>
34
#include <BaseCoordinateSystem.hxx>
35
#include <ChartView.hxx>
36
#include <memory>
37
38
#include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
39
#include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
40
#include <com/sun/star/chart/ChartAxisPosition.hpp>
41
#include <com/sun/star/chart/TimeInterval.hpp>
42
#include <com/sun/star/chart2/AxisOrientation.hpp>
43
#include <com/sun/star/chart2/AxisType.hpp>
44
45
#include <osl/diagnose.h>
46
#include <o3tl/any.hxx>
47
#include <svl/eitem.hxx>
48
#include <svx/chrtitem.hxx>
49
#include <svx/sdangitm.hxx>
50
#include <svl/intitem.hxx>
51
#include <rtl/math.hxx>
52
53
using namespace ::com::sun::star;
54
using namespace ::com::sun::star::chart2;
55
using ::com::sun::star::uno::Reference;
56
using ::com::sun::star::chart::TimeInterval;
57
using ::com::sun::star::chart::TimeIncrement;
58
59
namespace chart::wrapper {
60
61
namespace {
62
63
ItemPropertyMapType & lcl_GetAxisPropertyMap()
64
0
{
65
0
    static ItemPropertyMapType aAxisPropertyMap{
66
0
        {SCHATTR_AXIS_SHOWDESCR,     {"DisplayLabels",    0}},
67
0
        {SCHATTR_AXIS_TICKS,         {"MajorTickmarks",   0}},
68
0
        {SCHATTR_AXIS_HELPTICKS,     {"MinorTickmarks",   0}},
69
0
        {SCHATTR_AXIS_LABEL_ORDER,   {"ArrangeOrder",     0}},
70
0
        {SCHATTR_TEXT_STACKED,       {"StackCharacters",  0}},
71
0
        {SCHATTR_AXIS_LABEL_BREAK,   {"TextBreak",        0}},
72
0
        {SCHATTR_AXIS_LABEL_OVERLAP, {"TextOverlap",      0}}};
73
0
    return aAxisPropertyMap;
74
0
};
75
76
} // anonymous namespace
77
78
AxisItemConverter::AxisItemConverter(
79
    const Reference< beans::XPropertySet > & rPropertySet,
80
    SfxItemPool& rItemPool,
81
    SdrModel& rDrawModel,
82
    const rtl::Reference<::chart::ChartModel> & xChartDoc,
83
    ::chart::ExplicitScaleData const * pScale /* = NULL */,
84
    ::chart::ExplicitIncrementData const * pIncrement /* = NULL */,
85
    const std::optional<awt::Size>& pRefSize ) :
86
0
        ItemConverter( rPropertySet, rItemPool ),
87
0
        m_xChartDoc( xChartDoc )
88
0
{
89
0
    if( pScale )
90
0
        m_pExplicitScale.reset( new ::chart::ExplicitScaleData( *pScale ) );
91
0
    if( pIncrement )
92
0
        m_pExplicitIncrement.reset( new ::chart::ExplicitIncrementData( *pIncrement ) );
93
94
0
    m_aConverters.emplace_back( new GraphicPropertyItemConverter(
95
0
                                 rPropertySet, rItemPool, rDrawModel,
96
0
                                 xChartDoc,
97
0
                                 GraphicObjectType::LineProperties ));
98
0
    m_aConverters.emplace_back(
99
0
        new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, u"ReferencePageSize"_ustr));
100
101
0
    m_xAxis = dynamic_cast<::chart::Axis*>(rPropertySet.get());
102
0
    assert(m_xAxis);
103
0
}
104
105
AxisItemConverter::~AxisItemConverter()
106
0
{
107
0
}
108
109
void AxisItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
110
0
{
111
0
    for( const auto& pConv : m_aConverters )
112
0
        pConv->FillItemSet( rOutItemSet );
113
114
    // own items
115
0
    ItemConverter::FillItemSet( rOutItemSet );
116
0
}
117
118
bool AxisItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
119
0
{
120
0
    bool bResult = false;
121
122
0
    for( const auto& pConv : m_aConverters )
123
0
        bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
124
125
    // own items
126
0
    return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
127
0
}
128
129
const WhichRangesContainer& AxisItemConverter::GetWhichPairs() const
130
0
{
131
    // must span all used items!
132
0
    return nAxisWhichPairs;
133
0
}
134
135
bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
136
0
{
137
0
    ItemPropertyMapType & rMap( lcl_GetAxisPropertyMap());
138
0
    ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
139
140
0
    if( aIt == rMap.end())
141
0
        return false;
142
143
0
    rOutProperty =(*aIt).second;
144
145
0
    return true;
146
0
}
147
148
static bool lcl_hasTimeIntervalValue( const uno::Any& rAny )
149
0
{
150
0
    bool bRet = false;
151
0
    TimeInterval aValue;
152
0
    if( rAny >>= aValue )
153
0
        bRet = true;
154
0
    return bRet;
155
0
}
156
157
void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
158
0
{
159
0
    if( !m_xAxis.is() )
160
0
        return;
161
162
0
    const chart2::ScaleData      aScale( m_xAxis->getScaleData() );
163
0
    const chart2::IncrementData& rIncrement( aScale.IncrementData );
164
0
    const uno::Sequence< chart2::SubIncrement >& rSubIncrements( aScale.IncrementData.SubIncrements );
165
0
    const TimeIncrement& rTimeIncrement( aScale.TimeIncrement );
166
0
    bool bDateAxis = (aScale.AxisType == chart2::AxisType::DATE);
167
0
    if( m_pExplicitScale )
168
0
        bDateAxis = (m_pExplicitScale->AxisType == chart2::AxisType::DATE);
169
170
0
    switch( nWhichId )
171
0
    {
172
0
        case SCHATTR_AXIS_AUTO_MAX:
173
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(aScale.Maximum) ) );
174
0
            break;
175
176
0
        case SCHATTR_AXIS_MAX:
177
0
            {
178
0
                double fMax = 10.0;
179
0
                if( aScale.Maximum >>= fMax )
180
0
                    rOutItemSet.Put( SvxDoubleItem( fMax, SCHATTR_AXIS_MAX ) );
181
0
                else
182
0
                {
183
0
                    if( m_pExplicitScale )
184
0
                        fMax = m_pExplicitScale->Maximum;
185
0
                    rOutItemSet.Put( SvxDoubleItem( fMax, SCHATTR_AXIS_MAX ) );
186
0
                }
187
0
            }
188
0
            break;
189
190
0
        case SCHATTR_AXIS_AUTO_MIN:
191
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(aScale.Minimum) ) );
192
0
            break;
193
194
0
        case SCHATTR_AXIS_MIN:
195
0
            {
196
0
                double fMin = 0.0;
197
0
                if( aScale.Minimum >>= fMin )
198
0
                    rOutItemSet.Put( SvxDoubleItem( fMin, SCHATTR_AXIS_MIN ) );
199
0
                else if( m_pExplicitScale )
200
0
                    rOutItemSet.Put( SvxDoubleItem( m_pExplicitScale->Minimum, SCHATTR_AXIS_MIN ));
201
0
            }
202
0
            break;
203
204
0
        case SCHATTR_AXIS_LOGARITHM:
205
0
            {
206
0
                bool bValue = AxisHelper::isLogarithmic( aScale.Scaling );
207
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
208
0
            }
209
0
            break;
210
211
0
        case SCHATTR_AXIS_REVERSE:
212
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, (aScale.Orientation == AxisOrientation_REVERSE) ));
213
0
            break;
214
215
        // Increment
216
0
        case SCHATTR_AXIS_AUTO_STEP_MAIN:
217
0
            if( bDateAxis )
218
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MajorTimeInterval) ) );
219
0
            else
220
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rIncrement.Distance) ) );
221
0
            break;
222
223
0
        case SCHATTR_AXIS_MAIN_TIME_UNIT:
224
0
            {
225
0
                TimeInterval aTimeInterval;
226
0
                if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
227
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
228
0
                else if( m_pExplicitIncrement )
229
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MajorTimeInterval.TimeUnit ) );
230
0
            }
231
0
            break;
232
233
0
        case SCHATTR_AXIS_STEP_MAIN:
234
0
            if( bDateAxis )
235
0
            {
236
0
                TimeInterval aTimeInterval;
237
0
                if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
238
0
                    rOutItemSet.Put( SvxDoubleItem(aTimeInterval.Number, SCHATTR_AXIS_STEP_MAIN ));
239
0
                else if( m_pExplicitIncrement )
240
0
                    rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->MajorTimeInterval.Number, SCHATTR_AXIS_STEP_MAIN ));
241
0
            }
242
0
            else
243
0
            {
244
0
                double fDistance = 1.0;
245
0
                if( rIncrement.Distance >>= fDistance )
246
0
                    rOutItemSet.Put( SvxDoubleItem(fDistance, SCHATTR_AXIS_STEP_MAIN ));
247
0
                else if( m_pExplicitIncrement )
248
0
                    rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->Distance, SCHATTR_AXIS_STEP_MAIN ));
249
0
            }
250
0
            break;
251
252
        // SubIncrement
253
0
        case SCHATTR_AXIS_AUTO_STEP_HELP:
254
0
            if( bDateAxis )
255
0
                rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MinorTimeInterval) ) );
256
0
            else
257
0
                rOutItemSet.Put( SfxBoolItem( nWhichId,
258
0
                    ! ( rSubIncrements.hasElements() && rSubIncrements[0].IntervalCount.hasValue() )));
259
0
            break;
260
261
0
        case SCHATTR_AXIS_HELP_TIME_UNIT:
262
0
            {
263
0
                TimeInterval aTimeInterval;
264
0
                if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
265
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
266
0
                else if( m_pExplicitIncrement )
267
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.TimeUnit ) );
268
0
            }
269
0
            break;
270
271
0
        case SCHATTR_AXIS_STEP_HELP:
272
0
            if( bDateAxis )
273
0
            {
274
0
                TimeInterval aTimeInterval;
275
0
                if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
276
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.Number ));
277
0
                else if( m_pExplicitIncrement )
278
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.Number ));
279
0
            }
280
0
            else
281
0
            {
282
0
                if( rSubIncrements.hasElements() && rSubIncrements[0].IntervalCount.hasValue())
283
0
                {
284
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId,
285
0
                            *o3tl::doAccess<sal_Int32>(
286
0
                                rSubIncrements[0].IntervalCount) ));
287
0
                }
288
0
                else
289
0
                {
290
0
                    if( m_pExplicitIncrement && !m_pExplicitIncrement->SubIncrements.empty() )
291
0
                    {
292
0
                        rOutItemSet.Put( SfxInt32Item( nWhichId,
293
0
                                m_pExplicitIncrement->SubIncrements[0].IntervalCount ));
294
0
                    }
295
0
                }
296
0
            }
297
0
            break;
298
299
0
        case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
300
0
            {
301
0
                rOutItemSet.Put( SfxBoolItem( nWhichId,
302
0
                        !rTimeIncrement.TimeResolution.hasValue() ));
303
0
            }
304
0
            break;
305
0
        case SCHATTR_AXIS_TIME_RESOLUTION:
306
0
            {
307
0
                sal_Int32 nTimeResolution=0;
308
0
                if( rTimeIncrement.TimeResolution >>= nTimeResolution )
309
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, nTimeResolution ) );
310
0
                else if( m_pExplicitScale )
311
0
                    rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitScale->TimeResolution ) );
312
0
            }
313
0
            break;
314
315
0
        case SCHATTR_AXIS_AUTO_ORIGIN:
316
0
        {
317
0
            rOutItemSet.Put( SfxBoolItem( nWhichId, ( !hasDoubleValue(aScale.Origin) )));
318
0
        }
319
0
        break;
320
321
0
        case SCHATTR_AXIS_ORIGIN:
322
0
        {
323
0
            double fOrigin = 0.0;
324
0
            if( !(aScale.Origin >>= fOrigin) )
325
0
            {
326
0
                if( m_pExplicitScale )
327
0
                    fOrigin = m_pExplicitScale->Origin;
328
0
            }
329
0
            rOutItemSet.Put( SvxDoubleItem( fOrigin, SCHATTR_AXIS_ORIGIN ));
330
0
        }
331
0
        break;
332
333
0
        case SCHATTR_AXIS_POSITION:
334
0
        {
335
0
            css::chart::ChartAxisPosition eAxisPos( css::chart::ChartAxisPosition_ZERO );
336
0
            GetPropertySet()->getPropertyValue( u"CrossoverPosition"_ustr ) >>= eAxisPos;
337
0
            rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(eAxisPos) ) );
338
0
        }
339
0
        break;
340
341
0
        case SCHATTR_AXIS_POSITION_VALUE:
342
0
        {
343
0
            double fValue = 0.0;
344
0
            if( GetPropertySet()->getPropertyValue( u"CrossoverValue"_ustr ) >>= fValue )
345
0
                rOutItemSet.Put( SvxDoubleItem( fValue, SCHATTR_AXIS_POSITION_VALUE ) );
346
0
        }
347
0
        break;
348
349
0
        case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT:
350
0
        {
351
            //read only item
352
            //necessary tp display the crossing value with an appropriate format
353
354
0
            rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
355
0
                m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
356
357
0
            rtl::Reference< Axis > xCrossingMainAxis = AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys );
358
359
0
            sal_Int32 nFormatKey = ChartView::getExplicitNumberFormatKeyForAxis(
360
0
                xCrossingMainAxis, xCooSys, m_xChartDoc);
361
362
0
            rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
363
0
        }
364
0
        break;
365
366
0
        case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION:
367
0
            rOutItemSet.Put(SfxBoolItem(nWhichId, aScale.ShiftedCategoryPosition));
368
0
        break;
369
370
0
        case SCHATTR_AXIS_LABEL_POSITION:
371
0
        {
372
0
            css::chart::ChartAxisLabelPosition ePos( css::chart::ChartAxisLabelPosition_NEAR_AXIS );
373
0
            GetPropertySet()->getPropertyValue( u"LabelPosition"_ustr ) >>= ePos;
374
0
            rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(ePos) ) );
375
0
        }
376
0
        break;
377
378
0
        case SCHATTR_AXIS_MARK_POSITION:
379
0
        {
380
0
            css::chart::ChartAxisMarkPosition ePos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
381
0
            GetPropertySet()->getPropertyValue( u"MarkPosition"_ustr ) >>= ePos;
382
0
            rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(ePos) ) );
383
0
        }
384
0
        break;
385
386
0
        case SCHATTR_TEXT_DEGREES:
387
0
        {
388
            // convert double to int (times 100)
389
0
            double fVal = 0;
390
391
0
            if( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fVal )
392
0
            {
393
0
                rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
394
0
                                                   ::rtl::math::round( fVal * 100.0 )) ) ));
395
0
            }
396
0
        }
397
0
        break;
398
399
0
        case SID_ATTR_NUMBERFORMAT_VALUE:
400
0
        {
401
0
            if( m_pExplicitScale )
402
0
            {
403
0
                rtl::Reference< BaseCoordinateSystem > xCooSys(
404
0
                        AxisHelper::getCoordinateSystemOfAxis(
405
0
                              m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
406
407
0
                sal_Int32 nFormatKey = ChartView::getExplicitNumberFormatKeyForAxis(
408
0
                    m_xAxis, xCooSys, m_xChartDoc);
409
410
0
                rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
411
0
            }
412
0
        }
413
0
        break;
414
415
0
        case SID_ATTR_NUMBERFORMAT_SOURCE:
416
0
        {
417
0
            bool bLinkToSource = true;
418
0
            GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkToSource;
419
0
            rOutItemSet.Put(SfxBoolItem(nWhichId, bLinkToSource));
420
0
        }
421
0
        break;
422
423
0
        case SCHATTR_AXISTYPE:
424
0
            rOutItemSet.Put( SfxInt32Item( nWhichId, aScale.AxisType ));
425
0
        break;
426
427
0
        case SCHATTR_AXIS_AUTO_DATEAXIS:
428
0
            rOutItemSet.Put( SfxBoolItem( nWhichId, aScale.AutoDateAxis ));
429
0
        break;
430
431
0
        case SCHATTR_AXIS_ALLOW_DATEAXIS:
432
0
        {
433
0
            rtl::Reference< BaseCoordinateSystem > xCooSys(
434
0
                AxisHelper::getCoordinateSystemOfAxis( m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
435
0
            sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
436
0
            AxisHelper::getIndicesForAxis(m_xAxis, xCooSys, nDimensionIndex, nAxisIndex );
437
0
            auto xChartType = AxisHelper::getChartTypeByIndex(xCooSys, 0);
438
0
            bool bChartTypeAllowsDateAxis = xChartType.is() ? xChartType->isSupportingDateAxis(nDimensionIndex) : true;
439
0
            rOutItemSet.Put( SfxBoolItem( nWhichId, bChartTypeAllowsDateAxis ));
440
0
        }
441
0
        break;
442
0
    }
443
0
}
444
445
static bool lcl_isDateAxis( const SfxItemSet & rItemSet )
446
0
{
447
0
    sal_Int32 nAxisType = rItemSet.Get( SCHATTR_AXISTYPE ).GetValue();//css::chart2::AxisType
448
0
    return (nAxisType == chart2::AxisType::DATE);
449
0
}
450
451
static bool lcl_isAutoMajor( const SfxItemSet & rItemSet )
452
0
{
453
0
    bool bRet = rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_MAIN ).GetValue();
454
0
    return bRet;
455
0
}
456
457
static bool lcl_isAutoMinor( const SfxItemSet & rItemSet )
458
0
{
459
0
    bool bRet = rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_HELP ).GetValue();
460
0
    return bRet;
461
0
}
462
463
bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
464
0
{
465
0
    if( !m_xAxis.is() )
466
0
        return false;
467
468
0
    chart2::ScaleData     aScale( m_xAxis->getScaleData() );
469
470
0
    bool bSetScale    = false;
471
0
    bool bChangedOtherwise = false;
472
473
0
    uno::Any aValue;
474
475
0
    switch( nWhichId )
476
0
    {
477
0
        case SCHATTR_AXIS_AUTO_MAX:
478
0
            if( rItemSet.Get( SCHATTR_AXIS_AUTO_MAX ).GetValue() )
479
0
            {
480
0
                aScale.Maximum.clear();
481
0
                bSetScale = true;
482
0
            }
483
            // else SCHATTR_AXIS_MAX must have some value
484
0
            break;
485
486
0
        case SCHATTR_AXIS_MAX:
487
            // only if auto if false
488
0
            if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_MAX ).GetValue() ))
489
0
            {
490
0
                rItemSet.Get( nWhichId ).QueryValue( aValue );
491
492
0
                if( aScale.Maximum != aValue )
493
0
                {
494
0
                    aScale.Maximum = aValue;
495
0
                    bSetScale = true;
496
0
                }
497
0
            }
498
0
            break;
499
500
0
        case SCHATTR_AXIS_AUTO_MIN:
501
0
            if( rItemSet.Get( SCHATTR_AXIS_AUTO_MIN ).GetValue() )
502
0
            {
503
0
                aScale.Minimum.clear();
504
0
                bSetScale = true;
505
0
            }
506
            // else SCHATTR_AXIS_MIN must have some value
507
0
            break;
508
509
0
        case SCHATTR_AXIS_MIN:
510
            // only if auto if false
511
0
            if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_MIN ).GetValue() ))
512
0
            {
513
0
                rItemSet.Get( nWhichId ).QueryValue( aValue );
514
515
0
                if( aScale.Minimum != aValue )
516
0
                {
517
0
                    aScale.Minimum = aValue;
518
0
                    bSetScale = true;
519
0
                }
520
0
            }
521
0
            break;
522
523
0
        case SCHATTR_AXIS_LOGARITHM:
524
0
        {
525
0
            bool bWasLogarithm = AxisHelper::isLogarithmic( aScale.Scaling );
526
527
0
            if( rItemSet.Get( SCHATTR_AXIS_LOGARITHM ).GetValue() )
528
0
            {
529
                // logarithm is true
530
0
                if( ! bWasLogarithm )
531
0
                {
532
0
                    aScale.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
533
0
                    bSetScale = true;
534
0
                }
535
0
            }
536
0
            else
537
0
            {
538
                // logarithm is false => linear scaling
539
0
                if( bWasLogarithm )
540
0
                {
541
0
                    aScale.Scaling = AxisHelper::createLinearScaling();
542
0
                    bSetScale = true;
543
0
                }
544
0
            }
545
0
        }
546
0
        break;
547
548
0
        case SCHATTR_AXIS_REVERSE:
549
0
        {
550
0
            bool bWasReverse = ( aScale.Orientation == AxisOrientation_REVERSE );
551
0
            bool bNewReverse = rItemSet.Get( SCHATTR_AXIS_REVERSE ).GetValue();
552
0
            if( bWasReverse != bNewReverse )
553
0
            {
554
0
                aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
555
0
                bSetScale = true;
556
0
            }
557
0
        }
558
0
        break;
559
560
        // Increment
561
0
        case SCHATTR_AXIS_AUTO_STEP_MAIN:
562
0
            if( lcl_isAutoMajor(rItemSet) )
563
0
            {
564
0
                aScale.IncrementData.Distance.clear();
565
0
                aScale.TimeIncrement.MajorTimeInterval.clear();
566
0
                bSetScale = true;
567
0
            }
568
            // else SCHATTR_AXIS_STEP_MAIN must have some value
569
0
            break;
570
571
0
        case SCHATTR_AXIS_MAIN_TIME_UNIT:
572
0
            if( !lcl_isAutoMajor(rItemSet) )
573
0
            {
574
0
                if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
575
0
                {
576
0
                    TimeInterval aTimeInterval;
577
0
                    aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
578
0
                    aValue >>= aTimeInterval.TimeUnit;
579
0
                    aScale.TimeIncrement.MajorTimeInterval <<= aTimeInterval;
580
0
                    bSetScale = true;
581
0
                }
582
0
            }
583
0
            break;
584
585
0
        case SCHATTR_AXIS_STEP_MAIN:
586
            // only if auto if false
587
0
            if( !lcl_isAutoMajor(rItemSet) )
588
0
            {
589
0
                rItemSet.Get( nWhichId ).QueryValue( aValue );
590
0
                if( lcl_isDateAxis(rItemSet) )
591
0
                {
592
0
                    double fValue = 1.0;
593
0
                    if( aValue >>= fValue )
594
0
                    {
595
0
                        TimeInterval aTimeInterval;
596
0
                        aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
597
0
                        aTimeInterval.Number = static_cast<sal_Int32>(fValue);
598
0
                        aScale.TimeIncrement.MajorTimeInterval <<= aTimeInterval;
599
0
                        bSetScale = true;
600
0
                    }
601
0
                }
602
0
                else if( aScale.IncrementData.Distance != aValue )
603
0
                {
604
0
                    aScale.IncrementData.Distance = aValue;
605
0
                    bSetScale = true;
606
0
                }
607
0
            }
608
0
            break;
609
610
        // SubIncrement
611
0
        case SCHATTR_AXIS_AUTO_STEP_HELP:
612
0
            if( lcl_isAutoMinor(rItemSet) )
613
0
            {
614
0
                if( aScale.IncrementData.SubIncrements.hasElements() &&
615
0
                    aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() )
616
0
                {
617
0
                        aScale.IncrementData.SubIncrements.getArray()[0].IntervalCount.clear();
618
0
                        bSetScale = true;
619
0
                }
620
0
                if( aScale.TimeIncrement.MinorTimeInterval.hasValue() )
621
0
                {
622
0
                    aScale.TimeIncrement.MinorTimeInterval.clear();
623
0
                    bSetScale = true;
624
0
                }
625
0
            }
626
            // else SCHATTR_AXIS_STEP_MAIN must have some value
627
0
            break;
628
629
0
        case SCHATTR_AXIS_HELP_TIME_UNIT:
630
0
            if( !lcl_isAutoMinor(rItemSet) )
631
0
            {
632
0
                if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
633
0
                {
634
0
                    TimeInterval aTimeInterval;
635
0
                    aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
636
0
                    aValue >>= aTimeInterval.TimeUnit;
637
0
                    aScale.TimeIncrement.MinorTimeInterval <<= aTimeInterval;
638
0
                    bSetScale = true;
639
0
                }
640
0
            }
641
0
            break;
642
643
0
        case SCHATTR_AXIS_STEP_HELP:
644
            // only if auto is false
645
0
            if( !lcl_isAutoMinor(rItemSet) )
646
0
            {
647
0
                rItemSet.Get( nWhichId ).QueryValue( aValue );
648
0
                if( lcl_isDateAxis(rItemSet) )
649
0
                {
650
0
                    TimeInterval aTimeInterval;
651
0
                    aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
652
0
                    aValue >>= aTimeInterval.Number;
653
0
                    aScale.TimeIncrement.MinorTimeInterval <<= aTimeInterval;
654
0
                    bSetScale = true;
655
0
                }
656
0
                else if( aScale.IncrementData.SubIncrements.hasElements() )
657
0
                {
658
0
                    if( ! aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ||
659
0
                        aScale.IncrementData.SubIncrements[0].IntervalCount != aValue )
660
0
                    {
661
0
                        OSL_ASSERT( aValue.getValueTypeClass() == uno::TypeClass_LONG );
662
0
                        aScale.IncrementData.SubIncrements.getArray()[0].IntervalCount = aValue;
663
0
                        bSetScale = true;
664
0
                    }
665
0
                }
666
0
            }
667
0
            break;
668
669
0
        case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
670
0
            if( rItemSet.Get(SCHATTR_AXIS_AUTO_TIME_RESOLUTION).GetValue() )
671
0
            {
672
0
                aScale.TimeIncrement.TimeResolution.clear();
673
0
                bSetScale = true;
674
0
            }
675
0
            break;
676
0
        case SCHATTR_AXIS_TIME_RESOLUTION:
677
            // only if auto is false
678
0
            if( ! ( rItemSet.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION ).GetValue() ))
679
0
            {
680
0
                rItemSet.Get( nWhichId ).QueryValue( aValue );
681
682
0
                if( aScale.TimeIncrement.TimeResolution != aValue )
683
0
                {
684
0
                    aScale.TimeIncrement.TimeResolution = aValue;
685
0
                    bSetScale = true;
686
0
                }
687
0
            }
688
0
            break;
689
690
0
        case SCHATTR_AXIS_AUTO_ORIGIN:
691
0
        {
692
0
            if( rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN ).GetValue() )
693
0
            {
694
0
                aScale.Origin.clear();
695
0
                bSetScale = true;
696
0
            }
697
0
        }
698
0
        break;
699
700
0
        case SCHATTR_AXIS_ORIGIN:
701
0
        {
702
            // only if auto is false
703
0
            if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN ).GetValue() ))
704
0
            {
705
0
                rItemSet.Get( nWhichId ).QueryValue( aValue );
706
707
0
                if( aScale.Origin != aValue )
708
0
                {
709
0
                    aScale.Origin = aValue;
710
0
                    bSetScale = true;
711
712
0
                    if( !AxisHelper::isAxisPositioningEnabled() )
713
0
                    {
714
                        //keep old and new settings for axis positioning in sync somehow
715
0
                        rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
716
0
                            m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
717
718
0
                        sal_Int32 nDimensionIndex=0;
719
0
                        sal_Int32 nAxisIndex=0;
720
0
                        if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
721
0
                        {
722
0
                            rtl::Reference< Axis > xCrossingMainAxis = AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys );
723
0
                            if( xCrossingMainAxis.is() )
724
0
                            {
725
0
                                double fValue = 0.0;
726
0
                                if( aValue >>= fValue )
727
0
                                {
728
0
                                    xCrossingMainAxis->setPropertyValue( u"CrossoverPosition"_ustr , uno::Any( css::chart::ChartAxisPosition_VALUE ));
729
0
                                    xCrossingMainAxis->setPropertyValue( u"CrossoverValue"_ustr , uno::Any( fValue ));
730
0
                                }
731
0
                                else
732
0
                                    xCrossingMainAxis->setPropertyValue( u"CrossoverPosition"_ustr , uno::Any( css::chart::ChartAxisPosition_START ));
733
0
                            }
734
0
                        }
735
0
                    }
736
0
                }
737
0
            }
738
0
        }
739
0
        break;
740
741
0
        case SCHATTR_AXIS_POSITION:
742
0
        {
743
0
            css::chart::ChartAxisPosition eAxisPos =
744
0
                static_cast<css::chart::ChartAxisPosition>( rItemSet.Get( SCHATTR_AXIS_POSITION ).GetValue());
745
746
0
            css::chart::ChartAxisPosition eOldAxisPos( css::chart::ChartAxisPosition_ZERO );
747
0
            bool bPropExisted = ( GetPropertySet()->getPropertyValue( u"CrossoverPosition"_ustr ) >>= eOldAxisPos );
748
749
0
            if( !bPropExisted || ( eOldAxisPos != eAxisPos ))
750
0
            {
751
0
                GetPropertySet()->setPropertyValue( u"CrossoverPosition"_ustr , uno::Any( eAxisPos ));
752
0
                bChangedOtherwise = true;
753
754
                //move the parallel axes to the other side if necessary
755
0
                if( eAxisPos==css::chart::ChartAxisPosition_START || eAxisPos==css::chart::ChartAxisPosition_END )
756
0
                {
757
0
                    rtl::Reference<Diagram> xDiagram = m_xChartDoc->getFirstChartDiagram();
758
0
                    rtl::Reference< Axis > xParallelAxis = AxisHelper::getParallelAxis( m_xAxis, xDiagram );
759
0
                    if( xParallelAxis.is() )
760
0
                    {
761
0
                        css::chart::ChartAxisPosition eOtherPos;
762
0
                        if( xParallelAxis->getPropertyValue( u"CrossoverPosition"_ustr ) >>= eOtherPos )
763
0
                        {
764
0
                            if( eOtherPos == eAxisPos )
765
0
                            {
766
0
                                css::chart::ChartAxisPosition eOppositePos =
767
0
                                    (eAxisPos==css::chart::ChartAxisPosition_START)
768
0
                                    ? css::chart::ChartAxisPosition_END
769
0
                                    : css::chart::ChartAxisPosition_START;
770
0
                                xParallelAxis->setPropertyValue( u"CrossoverPosition"_ustr , uno::Any( eOppositePos ));
771
0
                            }
772
0
                        }
773
0
                    }
774
0
                }
775
0
            }
776
0
        }
777
0
        break;
778
779
0
        case SCHATTR_AXIS_POSITION_VALUE:
780
0
        {
781
0
            double fValue = rItemSet.Get( SCHATTR_AXIS_POSITION_VALUE ).GetValue();
782
783
0
            double fOldValue = 0.0;
784
0
            bool bPropExisted = ( GetPropertySet()->getPropertyValue( u"CrossoverValue"_ustr ) >>= fOldValue );
785
786
0
            if( !bPropExisted || ( fOldValue != fValue ))
787
0
            {
788
0
                GetPropertySet()->setPropertyValue( u"CrossoverValue"_ustr , uno::Any( fValue ));
789
0
                bChangedOtherwise = true;
790
791
                //keep old and new settings for axis positioning in sync somehow
792
0
                {
793
0
                    rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
794
0
                        m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
795
796
0
                    sal_Int32 nDimensionIndex=0;
797
0
                    sal_Int32 nAxisIndex=0;
798
0
                    if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
799
0
                    {
800
0
                        rtl::Reference< Axis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
801
0
                        if( xCrossingMainAxis.is() )
802
0
                        {
803
0
                            ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
804
0
                            aCrossingScale.Origin <<= fValue;
805
0
                            xCrossingMainAxis->setScaleData(aCrossingScale);
806
0
                        }
807
0
                    }
808
0
                }
809
0
            }
810
0
        }
811
0
        break;
812
813
0
        case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION:
814
0
        {
815
0
            bool bNewValue = rItemSet.Get(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION).GetValue();
816
0
            bool bOldValue = aScale.ShiftedCategoryPosition;
817
0
            if (bOldValue != bNewValue)
818
0
            {
819
0
                aScale.ShiftedCategoryPosition = bNewValue;
820
0
                bSetScale = true;
821
0
            }
822
0
        }
823
0
        break;
824
825
0
        case SCHATTR_AXIS_LABEL_POSITION:
826
0
        {
827
0
            css::chart::ChartAxisLabelPosition ePos =
828
0
                static_cast<css::chart::ChartAxisLabelPosition>(rItemSet.Get( SCHATTR_AXIS_LABEL_POSITION ).GetValue());
829
830
0
            css::chart::ChartAxisLabelPosition eOldPos( css::chart::ChartAxisLabelPosition_NEAR_AXIS );
831
0
            bool bPropExisted = ( GetPropertySet()->getPropertyValue( u"LabelPosition"_ustr ) >>= eOldPos );
832
833
0
            if( !bPropExisted || ( eOldPos != ePos ))
834
0
            {
835
0
                GetPropertySet()->setPropertyValue( u"LabelPosition"_ustr , uno::Any( ePos ));
836
0
                bChangedOtherwise = true;
837
838
                //move the parallel axes to the other side if necessary
839
0
                if( ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_START || ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_END )
840
0
                {
841
0
                    rtl::Reference<Diagram> xDiagram = m_xChartDoc->getFirstChartDiagram();
842
0
                    rtl::Reference< Axis > xParallelAxis = AxisHelper::getParallelAxis( m_xAxis, xDiagram );
843
0
                    if( xParallelAxis.is() )
844
0
                    {
845
0
                        css::chart::ChartAxisLabelPosition eOtherPos;
846
0
                        if( xParallelAxis->getPropertyValue( u"LabelPosition"_ustr ) >>= eOtherPos )
847
0
                        {
848
0
                            if( eOtherPos == ePos )
849
0
                            {
850
0
                                css::chart::ChartAxisLabelPosition eOppositePos =
851
0
                                    (ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_START)
852
0
                                    ? css::chart::ChartAxisLabelPosition_OUTSIDE_END
853
0
                                    : css::chart::ChartAxisLabelPosition_OUTSIDE_START;
854
0
                                xParallelAxis->setPropertyValue( u"LabelPosition"_ustr , uno::Any( eOppositePos ));
855
0
                            }
856
0
                        }
857
0
                    }
858
0
                }
859
0
            }
860
0
        }
861
0
        break;
862
863
0
        case SCHATTR_AXIS_MARK_POSITION:
864
0
        {
865
0
            css::chart::ChartAxisMarkPosition ePos =
866
0
                static_cast<css::chart::ChartAxisMarkPosition>( rItemSet.Get( SCHATTR_AXIS_MARK_POSITION ).GetValue());
867
868
0
            css::chart::ChartAxisMarkPosition eOldPos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
869
0
            bool bPropExisted = ( GetPropertySet()->getPropertyValue( u"MarkPosition"_ustr ) >>= eOldPos );
870
871
0
            if( !bPropExisted || ( eOldPos != ePos ))
872
0
            {
873
0
                GetPropertySet()->setPropertyValue( u"MarkPosition"_ustr , uno::Any( ePos ));
874
0
                bChangedOtherwise = true;
875
0
            }
876
0
        }
877
0
        break;
878
879
0
        case SCHATTR_TEXT_DEGREES:
880
0
        {
881
0
            double fVal = toDegrees(rItemSet.Get(SCHATTR_TEXT_DEGREES).GetValue());
882
0
            double fOldVal = 0.0;
883
0
            bool bPropExisted =
884
0
                ( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fOldVal );
885
886
0
            if( ! bPropExisted || fOldVal != fVal )
887
0
            {
888
0
                GetPropertySet()->setPropertyValue( u"TextRotation"_ustr , uno::Any( fVal ));
889
0
                bChangedOtherwise = true;
890
0
            }
891
0
        }
892
0
        break;
893
894
0
        case SID_ATTR_NUMBERFORMAT_VALUE:
895
0
        {
896
0
            if( m_pExplicitScale )
897
0
            {
898
0
                bool bUseSourceFormat =
899
0
                        rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE ).GetValue();
900
901
0
                if( ! bUseSourceFormat )
902
0
                {
903
0
                    sal_Int32 nFmt = static_cast< sal_Int32 >( rItemSet.Get( SID_ATTR_NUMBERFORMAT_VALUE ).GetValue());
904
905
0
                    aValue <<= nFmt;
906
0
                    if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) != aValue)
907
0
                    {
908
0
                        GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT , aValue);
909
0
                        bChangedOtherwise = true;
910
0
                    }
911
0
                }
912
0
            }
913
0
        }
914
0
        break;
915
916
0
        case SID_ATTR_NUMBERFORMAT_SOURCE:
917
0
        {
918
0
            bool bUseSourceFormat = rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE ).GetValue();
919
0
            GetPropertySet()->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::Any(bUseSourceFormat));
920
921
0
            bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue();
922
923
0
            bChangedOtherwise = (bUseSourceFormat == bNumberFormatIsSet);
924
0
            if( bChangedOtherwise )
925
0
            {
926
0
                if( ! bUseSourceFormat )
927
0
                {
928
0
                    SfxItemState aState = rItemSet.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE );
929
0
                    if( aState == SfxItemState::SET )
930
0
                    {
931
0
                        sal_Int32 nFormatKey = static_cast< sal_Int32 >(
932
0
                            rItemSet.Get( SID_ATTR_NUMBERFORMAT_VALUE ).GetValue());
933
0
                        aValue <<= nFormatKey;
934
0
                    }
935
0
                    else
936
0
                    {
937
0
                        rtl::Reference< BaseCoordinateSystem > xCooSys =
938
0
                            AxisHelper::getCoordinateSystemOfAxis(
939
0
                                m_xAxis, m_xChartDoc->getFirstChartDiagram() );
940
941
0
                        sal_Int32 nFormatKey = ChartView::getExplicitNumberFormatKeyForAxis(
942
0
                            m_xAxis, xCooSys, m_xChartDoc);
943
944
0
                        aValue <<= nFormatKey;
945
0
                    }
946
0
                }
947
                // else set a void Any
948
0
                GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT , aValue);
949
0
            }
950
0
        }
951
0
        break;
952
953
0
        case SCHATTR_AXISTYPE:
954
0
        {
955
0
            sal_Int32 nNewAxisType = rItemSet.Get( SCHATTR_AXISTYPE ).GetValue();//css::chart2::AxisType
956
0
            aScale.AxisType = nNewAxisType;
957
0
            bSetScale = true;
958
0
        }
959
0
        break;
960
961
0
        case SCHATTR_AXIS_AUTO_DATEAXIS:
962
0
        {
963
0
            bool bNewValue = rItemSet.Get( SCHATTR_AXIS_AUTO_DATEAXIS ).GetValue();
964
0
            bool bOldValue = aScale.AutoDateAxis;
965
0
            if( bOldValue != bNewValue )
966
0
            {
967
0
                aScale.AutoDateAxis = bNewValue;
968
0
                bSetScale = true;
969
0
            }
970
0
        }
971
0
        break;
972
0
    }
973
974
0
    if( bSetScale )
975
0
        m_xAxis->setScaleData( aScale );
976
977
0
    return (bSetScale || bChangedOtherwise);
978
0
}
979
980
}
981
982
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */