1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <chartview/ExplicitValueProvider.hxx>
27 #include "SchWhichPairs.hxx"
28 #include <ChartModelHelper.hxx>
29 #include <AxisHelper.hxx>
30 #include <CommonConverters.hxx>
31 #include <ChartTypeHelper.hxx>
32 #include <unonames.hxx>
35 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
36 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
37 #include <com/sun/star/chart/ChartAxisPosition.hpp>
38 #include <com/sun/star/chart/TimeInterval.hpp>
39 #include <com/sun/star/chart2/XAxis.hpp>
40 #include <com/sun/star/chart2/XChartDocument.hpp>
41 #include <com/sun/star/chart2/AxisOrientation.hpp>
42 #include <com/sun/star/chart2/AxisType.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <osl/diagnose.h>
46 #include <o3tl/any.hxx>
47 #include <svl/eitem.hxx>
48 #include <svx/chrtitem.hxx>
49 #include <svl/intitem.hxx>
50 #include <rtl/math.hxx>
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::chart2
;
54 using ::com::sun::star::uno::Reference
;
55 using ::com::sun::star::chart::TimeInterval
;
56 using ::com::sun::star::chart::TimeIncrement
;
58 namespace chart::wrapper
{
62 ItemPropertyMapType
& lcl_GetAxisPropertyMap()
64 static ItemPropertyMapType aAxisPropertyMap
{
65 {SCHATTR_AXIS_SHOWDESCR
, {"DisplayLabels", 0}},
66 {SCHATTR_AXIS_TICKS
, {"MajorTickmarks", 0}},
67 {SCHATTR_AXIS_HELPTICKS
, {"MinorTickmarks", 0}},
68 {SCHATTR_AXIS_LABEL_ORDER
, {"ArrangeOrder", 0}},
69 {SCHATTR_TEXT_STACKED
, {"StackCharacters", 0}},
70 {SCHATTR_AXIS_LABEL_BREAK
, {"TextBreak", 0}},
71 {SCHATTR_AXIS_LABEL_OVERLAP
, {"TextOverlap", 0}}};
72 return aAxisPropertyMap
;
75 } // anonymous namespace
77 AxisItemConverter::AxisItemConverter(
78 const Reference
< beans::XPropertySet
> & rPropertySet
,
79 SfxItemPool
& rItemPool
,
81 const Reference
< chart2::XChartDocument
> & xChartDoc
,
82 ::chart::ExplicitScaleData
const * pScale
/* = NULL */,
83 ::chart::ExplicitIncrementData
const * pIncrement
/* = NULL */,
84 const awt::Size
* pRefSize
) :
85 ItemConverter( rPropertySet
, rItemPool
),
86 m_xChartDoc( xChartDoc
)
88 Reference
< lang::XMultiServiceFactory
> xNamedPropertyContainerFactory( xChartDoc
, uno::UNO_QUERY
);
91 m_pExplicitScale
.reset( new ::chart::ExplicitScaleData( *pScale
) );
93 m_pExplicitIncrement
.reset( new ::chart::ExplicitIncrementData( *pIncrement
) );
95 m_aConverters
.emplace_back( new GraphicPropertyItemConverter(
96 rPropertySet
, rItemPool
, rDrawModel
,
97 xNamedPropertyContainerFactory
,
98 GraphicObjectType::LineProperties
));
99 m_aConverters
.emplace_back(
100 new CharacterPropertyItemConverter(rPropertySet
, rItemPool
, pRefSize
, "ReferencePageSize"));
102 m_xAxis
.set( Reference
< chart2::XAxis
>( rPropertySet
, uno::UNO_QUERY
) );
103 OSL_ASSERT( m_xAxis
.is());
106 AxisItemConverter::~AxisItemConverter()
110 void AxisItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
112 for( const auto& pConv
: m_aConverters
)
113 pConv
->FillItemSet( rOutItemSet
);
116 ItemConverter::FillItemSet( rOutItemSet
);
119 bool AxisItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
121 bool bResult
= false;
123 for( const auto& pConv
: m_aConverters
)
124 bResult
= pConv
->ApplyItemSet( rItemSet
) || bResult
;
127 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
130 const sal_uInt16
* AxisItemConverter::GetWhichPairs() const
132 // must span all used items!
133 return nAxisWhichPairs
;
136 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const
138 ItemPropertyMapType
& rMap( lcl_GetAxisPropertyMap());
139 ItemPropertyMapType::const_iterator
aIt( rMap
.find( nWhichId
));
141 if( aIt
== rMap
.end())
144 rOutProperty
=(*aIt
).second
;
149 static bool lcl_hasTimeIntervalValue( const uno::Any
& rAny
)
153 if( rAny
>>= aValue
)
158 void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
163 const chart2::ScaleData
& rScale( m_xAxis
->getScaleData() );
164 const chart2::IncrementData
& rIncrement( rScale
.IncrementData
);
165 const uno::Sequence
< chart2::SubIncrement
>& rSubIncrements( rScale
.IncrementData
.SubIncrements
);
166 const TimeIncrement
& rTimeIncrement( rScale
.TimeIncrement
);
167 bool bDateAxis
= (rScale
.AxisType
== chart2::AxisType::DATE
);
168 if( m_pExplicitScale
)
169 bDateAxis
= (m_pExplicitScale
->AxisType
== chart2::AxisType::DATE
);
173 case SCHATTR_AXIS_AUTO_MAX
:
174 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !hasDoubleValue(rScale
.Maximum
) ) );
177 case SCHATTR_AXIS_MAX
:
180 if( rScale
.Maximum
>>= fMax
)
181 rOutItemSet
.Put( SvxDoubleItem( fMax
, nWhichId
) );
184 if( m_pExplicitScale
)
185 fMax
= m_pExplicitScale
->Maximum
;
186 rOutItemSet
.Put( SvxDoubleItem( fMax
, nWhichId
) );
191 case SCHATTR_AXIS_AUTO_MIN
:
192 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !hasDoubleValue(rScale
.Minimum
) ) );
195 case SCHATTR_AXIS_MIN
:
198 if( rScale
.Minimum
>>= fMin
)
199 rOutItemSet
.Put( SvxDoubleItem( fMin
, nWhichId
) );
200 else if( m_pExplicitScale
)
201 rOutItemSet
.Put( SvxDoubleItem( m_pExplicitScale
->Minimum
, nWhichId
));
205 case SCHATTR_AXIS_LOGARITHM
:
207 bool bValue
= AxisHelper::isLogarithmic( rScale
.Scaling
);
208 rOutItemSet
.Put( SfxBoolItem( nWhichId
, bValue
));
212 case SCHATTR_AXIS_REVERSE
:
213 rOutItemSet
.Put( SfxBoolItem( nWhichId
, (rScale
.Orientation
== AxisOrientation_REVERSE
) ));
217 case SCHATTR_AXIS_AUTO_STEP_MAIN
:
219 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !lcl_hasTimeIntervalValue(rTimeIncrement
.MajorTimeInterval
) ) );
221 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !hasDoubleValue(rIncrement
.Distance
) ) );
224 case SCHATTR_AXIS_MAIN_TIME_UNIT
:
226 TimeInterval aTimeInterval
;
227 if( rTimeIncrement
.MajorTimeInterval
>>= aTimeInterval
)
228 rOutItemSet
.Put( SfxInt32Item( nWhichId
, aTimeInterval
.TimeUnit
) );
229 else if( m_pExplicitIncrement
)
230 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitIncrement
->MajorTimeInterval
.TimeUnit
) );
234 case SCHATTR_AXIS_STEP_MAIN
:
237 TimeInterval aTimeInterval
;
238 if( rTimeIncrement
.MajorTimeInterval
>>= aTimeInterval
)
239 rOutItemSet
.Put( SvxDoubleItem(aTimeInterval
.Number
, nWhichId
));
240 else if( m_pExplicitIncrement
)
241 rOutItemSet
.Put( SvxDoubleItem( m_pExplicitIncrement
->MajorTimeInterval
.Number
, nWhichId
));
245 double fDistance
= 1.0;
246 if( rIncrement
.Distance
>>= fDistance
)
247 rOutItemSet
.Put( SvxDoubleItem(fDistance
, nWhichId
));
248 else if( m_pExplicitIncrement
)
249 rOutItemSet
.Put( SvxDoubleItem( m_pExplicitIncrement
->Distance
, nWhichId
));
254 case SCHATTR_AXIS_AUTO_STEP_HELP
:
256 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !lcl_hasTimeIntervalValue(rTimeIncrement
.MinorTimeInterval
) ) );
258 rOutItemSet
.Put( SfxBoolItem( nWhichId
,
259 ! ( rSubIncrements
.hasElements() && rSubIncrements
[0].IntervalCount
.hasValue() )));
262 case SCHATTR_AXIS_HELP_TIME_UNIT
:
264 TimeInterval aTimeInterval
;
265 if( rTimeIncrement
.MinorTimeInterval
>>= aTimeInterval
)
266 rOutItemSet
.Put( SfxInt32Item( nWhichId
, aTimeInterval
.TimeUnit
) );
267 else if( m_pExplicitIncrement
)
268 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitIncrement
->MinorTimeInterval
.TimeUnit
) );
272 case SCHATTR_AXIS_STEP_HELP
:
275 TimeInterval aTimeInterval
;
276 if( rTimeIncrement
.MinorTimeInterval
>>= aTimeInterval
)
277 rOutItemSet
.Put( SfxInt32Item( nWhichId
, aTimeInterval
.Number
));
278 else if( m_pExplicitIncrement
)
279 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitIncrement
->MinorTimeInterval
.Number
));
283 if( rSubIncrements
.hasElements() && rSubIncrements
[0].IntervalCount
.hasValue())
285 rOutItemSet
.Put( SfxInt32Item( nWhichId
,
286 *o3tl::doAccess
<sal_Int32
>(
287 rSubIncrements
[0].IntervalCount
) ));
291 if( m_pExplicitIncrement
&& !m_pExplicitIncrement
->SubIncrements
.empty() )
293 rOutItemSet
.Put( SfxInt32Item( nWhichId
,
294 m_pExplicitIncrement
->SubIncrements
[0].IntervalCount
));
300 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION
:
302 rOutItemSet
.Put( SfxBoolItem( nWhichId
,
303 !rTimeIncrement
.TimeResolution
.hasValue() ));
306 case SCHATTR_AXIS_TIME_RESOLUTION
:
308 tools::Long nTimeResolution
=0;
309 if( rTimeIncrement
.TimeResolution
>>= nTimeResolution
)
310 rOutItemSet
.Put( SfxInt32Item( nWhichId
, nTimeResolution
) );
311 else if( m_pExplicitScale
)
312 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitScale
->TimeResolution
) );
316 case SCHATTR_AXIS_AUTO_ORIGIN
:
318 rOutItemSet
.Put( SfxBoolItem( nWhichId
, ( !hasDoubleValue(rScale
.Origin
) )));
322 case SCHATTR_AXIS_ORIGIN
:
324 double fOrigin
= 0.0;
325 if( !(rScale
.Origin
>>= fOrigin
) )
327 if( m_pExplicitScale
)
328 fOrigin
= m_pExplicitScale
->Origin
;
330 rOutItemSet
.Put( SvxDoubleItem( fOrigin
, nWhichId
));
334 case SCHATTR_AXIS_POSITION
:
336 css::chart::ChartAxisPosition
eAxisPos( css::chart::ChartAxisPosition_ZERO
);
337 GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eAxisPos
;
338 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast<sal_Int32
>(eAxisPos
) ) );
342 case SCHATTR_AXIS_POSITION_VALUE
:
345 if( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fValue
)
346 rOutItemSet
.Put( SvxDoubleItem( fValue
, nWhichId
) );
350 case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT
:
353 //necessary tp display the crossing value with an appropriate format
355 Reference
< chart2::XCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemOfAxis(
356 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
358 Reference
< chart2::XAxis
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis
, xCooSys
) );
360 sal_Int32 nFormatKey
= ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
361 xCrossingMainAxis
, xCooSys
, m_xChartDoc
);
363 rOutItemSet
.Put( SfxUInt32Item( nWhichId
, nFormatKey
));
367 case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION
:
368 rOutItemSet
.Put(SfxBoolItem(nWhichId
, rScale
.ShiftedCategoryPosition
));
371 case SCHATTR_AXIS_LABEL_POSITION
:
373 css::chart::ChartAxisLabelPosition
ePos( css::chart::ChartAxisLabelPosition_NEAR_AXIS
);
374 GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= ePos
;
375 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast<sal_Int32
>(ePos
) ) );
379 case SCHATTR_AXIS_MARK_POSITION
:
381 css::chart::ChartAxisMarkPosition
ePos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS
);
382 GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= ePos
;
383 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast<sal_Int32
>(ePos
) ) );
387 case SCHATTR_TEXT_DEGREES
:
389 // convert double to int (times 100)
392 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal
)
394 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast< sal_Int32
>(
395 ::rtl::math::round( fVal
* 100.0 ) ) ));
400 case SID_ATTR_NUMBERFORMAT_VALUE
:
402 if( m_pExplicitScale
)
404 Reference
< chart2::XCoordinateSystem
> xCooSys(
405 AxisHelper::getCoordinateSystemOfAxis(
406 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
408 sal_Int32 nFormatKey
= ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
409 m_xAxis
, xCooSys
, m_xChartDoc
);
411 rOutItemSet
.Put( SfxUInt32Item( nWhichId
, nFormatKey
));
416 case SID_ATTR_NUMBERFORMAT_SOURCE
:
418 bool bLinkToSource
= true;
419 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkToSource
;
420 rOutItemSet
.Put(SfxBoolItem(nWhichId
, bLinkToSource
));
424 case SCHATTR_AXISTYPE
:
425 rOutItemSet
.Put( SfxInt32Item( nWhichId
, rScale
.AxisType
));
428 case SCHATTR_AXIS_AUTO_DATEAXIS
:
429 rOutItemSet
.Put( SfxBoolItem( nWhichId
, rScale
.AutoDateAxis
));
432 case SCHATTR_AXIS_ALLOW_DATEAXIS
:
434 Reference
< chart2::XCoordinateSystem
> xCooSys(
435 AxisHelper::getCoordinateSystemOfAxis( m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
436 sal_Int32 nDimensionIndex
=0; sal_Int32 nAxisIndex
=0;
437 AxisHelper::getIndicesForAxis(m_xAxis
, xCooSys
, nDimensionIndex
, nAxisIndex
);
438 bool bChartTypeAllowsDateAxis
= ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys
, 0 ), nDimensionIndex
);
439 rOutItemSet
.Put( SfxBoolItem( nWhichId
, bChartTypeAllowsDateAxis
));
445 static bool lcl_isDateAxis( const SfxItemSet
& rItemSet
)
447 sal_Int32 nAxisType
= rItemSet
.Get( SCHATTR_AXISTYPE
).GetValue();//css::chart2::AxisType
448 return (nAxisType
== chart2::AxisType::DATE
);
451 static bool lcl_isAutoMajor( const SfxItemSet
& rItemSet
)
453 bool bRet
= rItemSet
.Get( SCHATTR_AXIS_AUTO_STEP_MAIN
).GetValue();
457 static bool lcl_isAutoMinor( const SfxItemSet
& rItemSet
)
459 bool bRet
= rItemSet
.Get( SCHATTR_AXIS_AUTO_STEP_HELP
).GetValue();
463 bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
468 chart2::ScaleData
aScale( m_xAxis
->getScaleData() );
470 bool bSetScale
= false;
471 bool bChangedOtherwise
= false;
477 case SCHATTR_AXIS_AUTO_MAX
:
478 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
480 aScale
.Maximum
.clear();
483 // else SCHATTR_AXIS_MAX must have some value
486 case SCHATTR_AXIS_MAX
:
487 // only if auto if false
488 if( ! (rItemSet
.Get( SCHATTR_AXIS_AUTO_MAX
).GetValue() ))
490 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
492 if( aScale
.Maximum
!= aValue
)
494 aScale
.Maximum
= aValue
;
500 case SCHATTR_AXIS_AUTO_MIN
:
501 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
503 aScale
.Minimum
.clear();
506 // else SCHATTR_AXIS_MIN must have some value
509 case SCHATTR_AXIS_MIN
:
510 // only if auto if false
511 if( ! (rItemSet
.Get( SCHATTR_AXIS_AUTO_MIN
).GetValue() ))
513 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
515 if( aScale
.Minimum
!= aValue
)
517 aScale
.Minimum
= aValue
;
523 case SCHATTR_AXIS_LOGARITHM
:
525 bool bWasLogarithm
= AxisHelper::isLogarithmic( aScale
.Scaling
);
527 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
530 if( ! bWasLogarithm
)
532 aScale
.Scaling
= AxisHelper::createLogarithmicScaling( 10.0 );
538 // logarithm is false => linear scaling
541 aScale
.Scaling
= AxisHelper::createLinearScaling();
548 case SCHATTR_AXIS_REVERSE
:
550 bool bWasReverse
= ( aScale
.Orientation
== AxisOrientation_REVERSE
);
551 bool bNewReverse
= static_cast< const SfxBoolItem
& >(
552 rItemSet
.Get( nWhichId
)).GetValue();
553 if( bWasReverse
!= bNewReverse
)
555 aScale
.Orientation
= bNewReverse
? AxisOrientation_REVERSE
: AxisOrientation_MATHEMATICAL
;
562 case SCHATTR_AXIS_AUTO_STEP_MAIN
:
563 if( lcl_isAutoMajor(rItemSet
) )
565 aScale
.IncrementData
.Distance
.clear();
566 aScale
.TimeIncrement
.MajorTimeInterval
.clear();
569 // else SCHATTR_AXIS_STEP_MAIN must have some value
572 case SCHATTR_AXIS_MAIN_TIME_UNIT
:
573 if( !lcl_isAutoMajor(rItemSet
) )
575 if( rItemSet
.Get( nWhichId
).QueryValue( aValue
) )
577 TimeInterval aTimeInterval
;
578 aScale
.TimeIncrement
.MajorTimeInterval
>>= aTimeInterval
;
579 aValue
>>= aTimeInterval
.TimeUnit
;
580 aScale
.TimeIncrement
.MajorTimeInterval
<<= aTimeInterval
;
586 case SCHATTR_AXIS_STEP_MAIN
:
587 // only if auto if false
588 if( !lcl_isAutoMajor(rItemSet
) )
590 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
591 if( lcl_isDateAxis(rItemSet
) )
594 if( aValue
>>= fValue
)
596 TimeInterval aTimeInterval
;
597 aScale
.TimeIncrement
.MajorTimeInterval
>>= aTimeInterval
;
598 aTimeInterval
.Number
= static_cast<sal_Int32
>(fValue
);
599 aScale
.TimeIncrement
.MajorTimeInterval
<<= aTimeInterval
;
603 else if( aScale
.IncrementData
.Distance
!= aValue
)
605 aScale
.IncrementData
.Distance
= aValue
;
612 case SCHATTR_AXIS_AUTO_STEP_HELP
:
613 if( lcl_isAutoMinor(rItemSet
) )
615 if( aScale
.IncrementData
.SubIncrements
.hasElements() &&
616 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
.hasValue() )
618 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
.clear();
621 if( aScale
.TimeIncrement
.MinorTimeInterval
.hasValue() )
623 aScale
.TimeIncrement
.MinorTimeInterval
.clear();
627 // else SCHATTR_AXIS_STEP_MAIN must have some value
630 case SCHATTR_AXIS_HELP_TIME_UNIT
:
631 if( !lcl_isAutoMinor(rItemSet
) )
633 if( rItemSet
.Get( nWhichId
).QueryValue( aValue
) )
635 TimeInterval aTimeInterval
;
636 aScale
.TimeIncrement
.MinorTimeInterval
>>= aTimeInterval
;
637 aValue
>>= aTimeInterval
.TimeUnit
;
638 aScale
.TimeIncrement
.MinorTimeInterval
<<= aTimeInterval
;
644 case SCHATTR_AXIS_STEP_HELP
:
645 // only if auto is false
646 if( !lcl_isAutoMinor(rItemSet
) )
648 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
649 if( lcl_isDateAxis(rItemSet
) )
651 TimeInterval aTimeInterval
;
652 aScale
.TimeIncrement
.MinorTimeInterval
>>= aTimeInterval
;
653 aValue
>>= aTimeInterval
.Number
;
654 aScale
.TimeIncrement
.MinorTimeInterval
<<= aTimeInterval
;
657 else if( aScale
.IncrementData
.SubIncrements
.hasElements() )
659 if( ! aScale
.IncrementData
.SubIncrements
[0].IntervalCount
.hasValue() ||
660 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
!= aValue
)
662 OSL_ASSERT( aValue
.getValueTypeClass() == uno::TypeClass_LONG
);
663 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
= aValue
;
670 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION
:
671 if( static_cast< const SfxBoolItem
& >( rItemSet
.Get( nWhichId
)).GetValue() )
673 aScale
.TimeIncrement
.TimeResolution
.clear();
677 case SCHATTR_AXIS_TIME_RESOLUTION
:
678 // only if auto is false
679 if( ! ( rItemSet
.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION
).GetValue() ))
681 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
683 if( aScale
.TimeIncrement
.TimeResolution
!= aValue
)
685 aScale
.TimeIncrement
.TimeResolution
= aValue
;
691 case SCHATTR_AXIS_AUTO_ORIGIN
:
693 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
695 aScale
.Origin
.clear();
701 case SCHATTR_AXIS_ORIGIN
:
703 // only if auto is false
704 if( ! (rItemSet
.Get( SCHATTR_AXIS_AUTO_ORIGIN
).GetValue() ))
706 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
708 if( aScale
.Origin
!= aValue
)
710 aScale
.Origin
= aValue
;
713 if( !AxisHelper::isAxisPositioningEnabled() )
715 //keep old and new settings for axis positioning in sync somehow
716 Reference
< chart2::XCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemOfAxis(
717 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
719 sal_Int32 nDimensionIndex
=0;
720 sal_Int32 nAxisIndex
=0;
721 if( AxisHelper::getIndicesForAxis( m_xAxis
, xCooSys
, nDimensionIndex
, nAxisIndex
) && nAxisIndex
==0 )
723 Reference
< beans::XPropertySet
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis
, xCooSys
), uno::UNO_QUERY
);
724 if( xCrossingMainAxis
.is() )
727 if( aValue
>>= fValue
)
729 xCrossingMainAxis
->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_VALUE
));
730 xCrossingMainAxis
->setPropertyValue( "CrossoverValue" , uno::Any( fValue
));
733 xCrossingMainAxis
->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_START
));
742 case SCHATTR_AXIS_POSITION
:
744 css::chart::ChartAxisPosition eAxisPos
=
745 static_cast<css::chart::ChartAxisPosition
>(static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue());
747 css::chart::ChartAxisPosition
eOldAxisPos( css::chart::ChartAxisPosition_ZERO
);
748 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eOldAxisPos
);
750 if( !bPropExisted
|| ( eOldAxisPos
!= eAxisPos
))
752 GetPropertySet()->setPropertyValue( "CrossoverPosition" , uno::Any( eAxisPos
));
753 bChangedOtherwise
= true;
755 //move the parallel axes to the other side if necessary
756 if( eAxisPos
==css::chart::ChartAxisPosition_START
|| eAxisPos
==css::chart::ChartAxisPosition_END
)
758 Reference
< beans::XPropertySet
> xParallelAxis( AxisHelper::getParallelAxis( m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ), uno::UNO_QUERY
);
759 if( xParallelAxis
.is() )
761 css::chart::ChartAxisPosition eOtherPos
;
762 if( xParallelAxis
->getPropertyValue( "CrossoverPosition" ) >>= eOtherPos
)
764 if( eOtherPos
== eAxisPos
)
766 css::chart::ChartAxisPosition eOppositePos
=
767 (eAxisPos
==css::chart::ChartAxisPosition_START
)
768 ? css::chart::ChartAxisPosition_END
769 : css::chart::ChartAxisPosition_START
;
770 xParallelAxis
->setPropertyValue( "CrossoverPosition" , uno::Any( eOppositePos
));
779 case SCHATTR_AXIS_POSITION_VALUE
:
781 double fValue
= static_cast< const SvxDoubleItem
& >( rItemSet
.Get( nWhichId
)).GetValue();
783 double fOldValue
= 0.0;
784 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fOldValue
);
786 if( !bPropExisted
|| ( fOldValue
!= fValue
))
788 GetPropertySet()->setPropertyValue( "CrossoverValue" , uno::Any( fValue
));
789 bChangedOtherwise
= true;
791 //keep old and new settings for axis positioning in sync somehow
793 Reference
< chart2::XCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemOfAxis(
794 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
796 sal_Int32 nDimensionIndex
=0;
797 sal_Int32 nAxisIndex
=0;
798 if( AxisHelper::getIndicesForAxis( m_xAxis
, xCooSys
, nDimensionIndex
, nAxisIndex
) && nAxisIndex
==0 )
800 Reference
< chart2::XAxis
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis
, xCooSys
) );
801 if( xCrossingMainAxis
.is() )
803 ScaleData
aCrossingScale( xCrossingMainAxis
->getScaleData() );
804 aCrossingScale
.Origin
<<= fValue
;
805 xCrossingMainAxis
->setScaleData(aCrossingScale
);
813 case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION
:
815 bool bNewValue
= static_cast<const SfxBoolItem
&> (rItemSet
.Get(nWhichId
)).GetValue();
816 bool bOldValue
= aScale
.ShiftedCategoryPosition
;
817 if (bOldValue
!= bNewValue
)
819 aScale
.ShiftedCategoryPosition
= bNewValue
;
825 case SCHATTR_AXIS_LABEL_POSITION
:
827 css::chart::ChartAxisLabelPosition ePos
=
828 static_cast<css::chart::ChartAxisLabelPosition
>(static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue());
830 css::chart::ChartAxisLabelPosition
eOldPos( css::chart::ChartAxisLabelPosition_NEAR_AXIS
);
831 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= eOldPos
);
833 if( !bPropExisted
|| ( eOldPos
!= ePos
))
835 GetPropertySet()->setPropertyValue( "LabelPosition" , uno::Any( ePos
));
836 bChangedOtherwise
= true;
838 //move the parallel axes to the other side if necessary
839 if( ePos
==css::chart::ChartAxisLabelPosition_OUTSIDE_START
|| ePos
==css::chart::ChartAxisLabelPosition_OUTSIDE_END
)
841 Reference
< beans::XPropertySet
> xParallelAxis( AxisHelper::getParallelAxis( m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ), uno::UNO_QUERY
);
842 if( xParallelAxis
.is() )
844 css::chart::ChartAxisLabelPosition eOtherPos
;
845 if( xParallelAxis
->getPropertyValue( "LabelPosition" ) >>= eOtherPos
)
847 if( eOtherPos
== ePos
)
849 css::chart::ChartAxisLabelPosition eOppositePos
=
850 (ePos
==css::chart::ChartAxisLabelPosition_OUTSIDE_START
)
851 ? css::chart::ChartAxisLabelPosition_OUTSIDE_END
852 : css::chart::ChartAxisLabelPosition_OUTSIDE_START
;
853 xParallelAxis
->setPropertyValue( "LabelPosition" , uno::Any( eOppositePos
));
862 case SCHATTR_AXIS_MARK_POSITION
:
864 css::chart::ChartAxisMarkPosition ePos
=
865 static_cast<css::chart::ChartAxisMarkPosition
>(static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue());
867 css::chart::ChartAxisMarkPosition
eOldPos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS
);
868 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= eOldPos
);
870 if( !bPropExisted
|| ( eOldPos
!= ePos
))
872 GetPropertySet()->setPropertyValue( "MarkPosition" , uno::Any( ePos
));
873 bChangedOtherwise
= true;
878 case SCHATTR_TEXT_DEGREES
:
880 // convert int to double (divided by 100)
881 double fVal
= static_cast< double >(
882 static_cast< const SfxInt32Item
& >(
883 rItemSet
.Get( nWhichId
)).GetValue()) / 100.0;
884 double fOldVal
= 0.0;
886 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal
);
888 if( ! bPropExisted
|| fOldVal
!= fVal
)
890 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fVal
));
891 bChangedOtherwise
= true;
896 case SID_ATTR_NUMBERFORMAT_VALUE
:
898 if( m_pExplicitScale
)
900 bool bUseSourceFormat
=
901 static_cast< const SfxBoolItem
& >(
902 rItemSet
.Get( SID_ATTR_NUMBERFORMAT_SOURCE
)).GetValue();
904 if( ! bUseSourceFormat
)
906 sal_Int32 nFmt
= static_cast< sal_Int32
>(
907 static_cast< const SfxUInt32Item
& >(
908 rItemSet
.Get( nWhichId
)).GetValue());
911 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT
) != aValue
)
913 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT
, aValue
);
914 bChangedOtherwise
= true;
921 case SID_ATTR_NUMBERFORMAT_SOURCE
:
923 bool bUseSourceFormat
=
924 static_cast< const SfxBoolItem
& >(
925 rItemSet
.Get( nWhichId
)).GetValue();
926 GetPropertySet()->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
, uno::Any(bUseSourceFormat
));
928 bool bNumberFormatIsSet
= GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT
).hasValue();
930 bChangedOtherwise
= (bUseSourceFormat
== bNumberFormatIsSet
);
931 if( bChangedOtherwise
)
933 if( ! bUseSourceFormat
)
935 SfxItemState aState
= rItemSet
.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
);
936 if( aState
== SfxItemState::SET
)
938 sal_Int32 nFormatKey
= static_cast< sal_Int32
>(
939 rItemSet
.Get( SID_ATTR_NUMBERFORMAT_VALUE
).GetValue());
940 aValue
<<= nFormatKey
;
944 Reference
< chart2::XCoordinateSystem
> xCooSys(
945 AxisHelper::getCoordinateSystemOfAxis(
946 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
948 sal_Int32 nFormatKey
= ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
949 m_xAxis
, xCooSys
, m_xChartDoc
);
951 aValue
<<= nFormatKey
;
954 // else set a void Any
955 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT
, aValue
);
960 case SCHATTR_AXISTYPE
:
962 sal_Int32 nNewAxisType
= static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue();//css::chart2::AxisType
963 aScale
.AxisType
= nNewAxisType
;
968 case SCHATTR_AXIS_AUTO_DATEAXIS
:
970 bool bNewValue
= static_cast< const SfxBoolItem
& >( rItemSet
.Get( nWhichId
)).GetValue();
971 bool bOldValue
= aScale
.AutoDateAxis
;
972 if( bOldValue
!= bNewValue
)
974 aScale
.AutoDateAxis
= bNewValue
;
982 m_xAxis
->setScaleData( aScale
);
984 return (bSetScale
|| bChangedOtherwise
);
989 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */