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/ExplicitValueProvider.hxx>
26 #include "SchWhichPairs.hxx"
27 #include <ChartModelHelper.hxx>
28 #include <AxisHelper.hxx>
29 #include <CommonConverters.hxx>
30 #include <ChartTypeHelper.hxx>
31 #include <unonames.hxx>
34 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
35 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
36 #include <com/sun/star/chart/ChartAxisPosition.hpp>
37 #include <com/sun/star/chart2/XAxis.hpp>
38 #include <com/sun/star/chart2/AxisOrientation.hpp>
39 #include <com/sun/star/chart2/AxisType.hpp>
41 #include <o3tl/any.hxx>
42 #include <svl/eitem.hxx>
43 #include <svx/chrtitem.hxx>
44 #include <svl/intitem.hxx>
45 #include <rtl/math.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::chart2
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::chart::TimeInterval
;
53 using ::com::sun::star::chart::TimeIncrement
;
55 namespace chart
{ namespace wrapper
{
59 ItemPropertyMapType
& lcl_GetAxisPropertyMap()
61 static ItemPropertyMapType aAxisPropertyMap
{
62 {SCHATTR_AXIS_SHOWDESCR
, {"DisplayLabels", 0}},
63 {SCHATTR_AXIS_TICKS
, {"MajorTickmarks", 0}},
64 {SCHATTR_AXIS_HELPTICKS
, {"MinorTickmarks", 0}},
65 {SCHATTR_AXIS_LABEL_ORDER
, {"ArrangeOrder", 0}},
66 {SCHATTR_TEXT_STACKED
, {"StackCharacters", 0}},
67 {SCHATTR_AXIS_LABEL_BREAK
, {"TextBreak", 0}},
68 {SCHATTR_AXIS_LABEL_OVERLAP
, {"TextOverlap", 0}}};
69 return aAxisPropertyMap
;
72 } // anonymous namespace
74 AxisItemConverter::AxisItemConverter(
75 const Reference
< beans::XPropertySet
> & rPropertySet
,
76 SfxItemPool
& rItemPool
,
78 const Reference
< chart2::XChartDocument
> & xChartDoc
,
79 ::chart::ExplicitScaleData
const * pScale
/* = NULL */,
80 ::chart::ExplicitIncrementData
const * pIncrement
/* = NULL */,
81 const awt::Size
* pRefSize
) :
82 ItemConverter( rPropertySet
, rItemPool
),
83 m_xChartDoc( xChartDoc
)
85 Reference
< lang::XMultiServiceFactory
> xNamedPropertyContainerFactory( xChartDoc
, uno::UNO_QUERY
);
88 m_pExplicitScale
.reset( new ::chart::ExplicitScaleData( *pScale
) );
90 m_pExplicitIncrement
.reset( new ::chart::ExplicitIncrementData( *pIncrement
) );
92 m_aConverters
.emplace_back( new GraphicPropertyItemConverter(
93 rPropertySet
, rItemPool
, rDrawModel
,
94 xNamedPropertyContainerFactory
,
95 GraphicObjectType::LineProperties
));
96 m_aConverters
.emplace_back(
97 new CharacterPropertyItemConverter(rPropertySet
, rItemPool
, pRefSize
, "ReferencePageSize"));
99 m_xAxis
.set( Reference
< chart2::XAxis
>( rPropertySet
, uno::UNO_QUERY
) );
100 OSL_ASSERT( m_xAxis
.is());
103 AxisItemConverter::~AxisItemConverter()
107 void AxisItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
109 for( const auto& pConv
: m_aConverters
)
110 pConv
->FillItemSet( rOutItemSet
);
113 ItemConverter::FillItemSet( rOutItemSet
);
116 bool AxisItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
118 bool bResult
= false;
120 for( const auto& pConv
: m_aConverters
)
121 bResult
= pConv
->ApplyItemSet( rItemSet
) || bResult
;
124 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
127 const sal_uInt16
* AxisItemConverter::GetWhichPairs() const
129 // must span all used items!
130 return nAxisWhichPairs
;
133 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const
135 ItemPropertyMapType
& rMap( lcl_GetAxisPropertyMap());
136 ItemPropertyMapType::const_iterator
aIt( rMap
.find( nWhichId
));
138 if( aIt
== rMap
.end())
141 rOutProperty
=(*aIt
).second
;
146 bool lcl_hasTimeIntervalValue( const uno::Any
& rAny
)
150 if( rAny
>>= aValue
)
155 void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
160 const chart2::ScaleData
& rScale( m_xAxis
->getScaleData() );
161 const chart2::IncrementData
& rIncrement( rScale
.IncrementData
);
162 const uno::Sequence
< chart2::SubIncrement
>& rSubIncrements( rScale
.IncrementData
.SubIncrements
);
163 const TimeIncrement
& rTimeIncrement( rScale
.TimeIncrement
);
164 bool bDateAxis
= (rScale
.AxisType
== chart2::AxisType::DATE
);
165 if( m_pExplicitScale
)
166 bDateAxis
= (m_pExplicitScale
->AxisType
== chart2::AxisType::DATE
);
170 case SCHATTR_AXIS_AUTO_MAX
:
171 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !hasDoubleValue(rScale
.Maximum
) ) );
174 case SCHATTR_AXIS_MAX
:
177 if( rScale
.Maximum
>>= fMax
)
178 rOutItemSet
.Put( SvxDoubleItem( fMax
, nWhichId
) );
181 if( m_pExplicitScale
)
182 fMax
= m_pExplicitScale
->Maximum
;
183 rOutItemSet
.Put( SvxDoubleItem( fMax
, nWhichId
) );
188 case SCHATTR_AXIS_AUTO_MIN
:
189 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !hasDoubleValue(rScale
.Minimum
) ) );
192 case SCHATTR_AXIS_MIN
:
195 if( rScale
.Minimum
>>= fMin
)
196 rOutItemSet
.Put( SvxDoubleItem( fMin
, nWhichId
) );
197 else if( m_pExplicitScale
)
198 rOutItemSet
.Put( SvxDoubleItem( m_pExplicitScale
->Minimum
, nWhichId
));
202 case SCHATTR_AXIS_LOGARITHM
:
204 bool bValue
= AxisHelper::isLogarithmic( rScale
.Scaling
);
205 rOutItemSet
.Put( SfxBoolItem( nWhichId
, bValue
));
209 case SCHATTR_AXIS_REVERSE
:
210 rOutItemSet
.Put( SfxBoolItem( nWhichId
, (rScale
.Orientation
== AxisOrientation_REVERSE
) ));
214 case SCHATTR_AXIS_AUTO_STEP_MAIN
:
216 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !lcl_hasTimeIntervalValue(rTimeIncrement
.MajorTimeInterval
) ) );
218 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !hasDoubleValue(rIncrement
.Distance
) ) );
221 case SCHATTR_AXIS_MAIN_TIME_UNIT
:
223 TimeInterval aTimeInterval
;
224 if( rTimeIncrement
.MajorTimeInterval
>>= aTimeInterval
)
225 rOutItemSet
.Put( SfxInt32Item( nWhichId
, aTimeInterval
.TimeUnit
) );
226 else if( m_pExplicitIncrement
)
227 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitIncrement
->MajorTimeInterval
.TimeUnit
) );
231 case SCHATTR_AXIS_STEP_MAIN
:
234 TimeInterval aTimeInterval
;
235 if( rTimeIncrement
.MajorTimeInterval
>>= aTimeInterval
)
236 rOutItemSet
.Put( SvxDoubleItem(aTimeInterval
.Number
, nWhichId
));
237 else if( m_pExplicitIncrement
)
238 rOutItemSet
.Put( SvxDoubleItem( m_pExplicitIncrement
->MajorTimeInterval
.Number
, nWhichId
));
242 double fDistance
= 1.0;
243 if( rIncrement
.Distance
>>= fDistance
)
244 rOutItemSet
.Put( SvxDoubleItem(fDistance
, nWhichId
));
245 else if( m_pExplicitIncrement
)
246 rOutItemSet
.Put( SvxDoubleItem( m_pExplicitIncrement
->Distance
, nWhichId
));
251 case SCHATTR_AXIS_AUTO_STEP_HELP
:
253 rOutItemSet
.Put( SfxBoolItem( nWhichId
, !lcl_hasTimeIntervalValue(rTimeIncrement
.MinorTimeInterval
) ) );
255 rOutItemSet
.Put( SfxBoolItem( nWhichId
,
256 ! ( rSubIncrements
.getLength() > 0 && rSubIncrements
[0].IntervalCount
.hasValue() )));
259 case SCHATTR_AXIS_HELP_TIME_UNIT
:
261 TimeInterval aTimeInterval
;
262 if( rTimeIncrement
.MinorTimeInterval
>>= aTimeInterval
)
263 rOutItemSet
.Put( SfxInt32Item( nWhichId
, aTimeInterval
.TimeUnit
) );
264 else if( m_pExplicitIncrement
)
265 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitIncrement
->MinorTimeInterval
.TimeUnit
) );
269 case SCHATTR_AXIS_STEP_HELP
:
272 TimeInterval aTimeInterval
;
273 if( rTimeIncrement
.MinorTimeInterval
>>= aTimeInterval
)
274 rOutItemSet
.Put( SfxInt32Item( nWhichId
, aTimeInterval
.Number
));
275 else if( m_pExplicitIncrement
)
276 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitIncrement
->MinorTimeInterval
.Number
));
280 if( rSubIncrements
.getLength() > 0 && rSubIncrements
[0].IntervalCount
.hasValue())
282 rOutItemSet
.Put( SfxInt32Item( nWhichId
,
283 *o3tl::doAccess
<sal_Int32
>(
284 rSubIncrements
[0].IntervalCount
) ));
288 if( m_pExplicitIncrement
&& !m_pExplicitIncrement
->SubIncrements
.empty() )
290 rOutItemSet
.Put( SfxInt32Item( nWhichId
,
291 m_pExplicitIncrement
->SubIncrements
[0].IntervalCount
));
297 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION
:
299 rOutItemSet
.Put( SfxBoolItem( nWhichId
,
300 !rTimeIncrement
.TimeResolution
.hasValue() ));
303 case SCHATTR_AXIS_TIME_RESOLUTION
:
305 long nTimeResolution
=0;
306 if( rTimeIncrement
.TimeResolution
>>= nTimeResolution
)
307 rOutItemSet
.Put( SfxInt32Item( nWhichId
, nTimeResolution
) );
308 else if( m_pExplicitScale
)
309 rOutItemSet
.Put( SfxInt32Item( nWhichId
, m_pExplicitScale
->TimeResolution
) );
313 case SCHATTR_AXIS_AUTO_ORIGIN
:
315 rOutItemSet
.Put( SfxBoolItem( nWhichId
, ( !hasDoubleValue(rScale
.Origin
) )));
319 case SCHATTR_AXIS_ORIGIN
:
321 double fOrigin
= 0.0;
322 if( !(rScale
.Origin
>>= fOrigin
) )
324 if( m_pExplicitScale
)
325 fOrigin
= m_pExplicitScale
->Origin
;
327 rOutItemSet
.Put( SvxDoubleItem( fOrigin
, nWhichId
));
331 case SCHATTR_AXIS_POSITION
:
333 css::chart::ChartAxisPosition
eAxisPos( css::chart::ChartAxisPosition_ZERO
);
334 GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eAxisPos
;
335 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast<sal_Int32
>(eAxisPos
) ) );
339 case SCHATTR_AXIS_POSITION_VALUE
:
342 if( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fValue
)
343 rOutItemSet
.Put( SvxDoubleItem( fValue
, nWhichId
) );
347 case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT
:
350 //necessary tp display the crossing value with an appropriate format
352 Reference
< chart2::XCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemOfAxis(
353 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
355 Reference
< chart2::XAxis
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis
, xCooSys
) );
357 sal_Int32 nFormatKey
= ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
358 xCrossingMainAxis
, xCooSys
, m_xChartDoc
);
360 rOutItemSet
.Put( SfxUInt32Item( nWhichId
, nFormatKey
));
364 case SCHATTR_AXIS_LABEL_POSITION
:
366 css::chart::ChartAxisLabelPosition
ePos( css::chart::ChartAxisLabelPosition_NEAR_AXIS
);
367 GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= ePos
;
368 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast<sal_Int32
>(ePos
) ) );
372 case SCHATTR_AXIS_MARK_POSITION
:
374 css::chart::ChartAxisMarkPosition
ePos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS
);
375 GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= ePos
;
376 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast<sal_Int32
>(ePos
) ) );
380 case SCHATTR_TEXT_DEGREES
:
382 // convert double to int (times 100)
385 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal
)
387 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast< sal_Int32
>(
388 ::rtl::math::round( fVal
* 100.0 ) ) ));
393 case SID_ATTR_NUMBERFORMAT_VALUE
:
395 if( m_pExplicitScale
)
397 Reference
< chart2::XCoordinateSystem
> xCooSys(
398 AxisHelper::getCoordinateSystemOfAxis(
399 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
401 sal_Int32 nFormatKey
= ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
402 m_xAxis
, xCooSys
, m_xChartDoc
);
404 rOutItemSet
.Put( SfxUInt32Item( nWhichId
, nFormatKey
));
409 case SID_ATTR_NUMBERFORMAT_SOURCE
:
411 bool bLinkToSource
= true;
412 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkToSource
;
413 rOutItemSet
.Put(SfxBoolItem(nWhichId
, bLinkToSource
));
417 case SCHATTR_AXISTYPE
:
418 rOutItemSet
.Put( SfxInt32Item( nWhichId
, rScale
.AxisType
));
421 case SCHATTR_AXIS_AUTO_DATEAXIS
:
422 rOutItemSet
.Put( SfxBoolItem( nWhichId
, rScale
.AutoDateAxis
));
425 case SCHATTR_AXIS_ALLOW_DATEAXIS
:
427 Reference
< chart2::XCoordinateSystem
> xCooSys(
428 AxisHelper::getCoordinateSystemOfAxis( m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
429 sal_Int32 nDimensionIndex
=0; sal_Int32 nAxisIndex
=0;
430 AxisHelper::getIndicesForAxis(m_xAxis
, xCooSys
, nDimensionIndex
, nAxisIndex
);
431 bool bChartTypeAllowsDateAxis
= ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys
, 0 ), nDimensionIndex
);
432 rOutItemSet
.Put( SfxBoolItem( nWhichId
, bChartTypeAllowsDateAxis
));
438 bool lcl_isDateAxis( const SfxItemSet
& rItemSet
)
440 sal_Int32 nAxisType
= rItemSet
.Get( SCHATTR_AXISTYPE
).GetValue();//css::chart2::AxisType
441 return (nAxisType
== chart2::AxisType::DATE
);
444 bool lcl_isAutoMajor( const SfxItemSet
& rItemSet
)
446 bool bRet
= rItemSet
.Get( SCHATTR_AXIS_AUTO_STEP_MAIN
).GetValue();
450 bool lcl_isAutoMinor( const SfxItemSet
& rItemSet
)
452 bool bRet
= rItemSet
.Get( SCHATTR_AXIS_AUTO_STEP_HELP
).GetValue();
456 bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
461 chart2::ScaleData
aScale( m_xAxis
->getScaleData() );
463 bool bSetScale
= false;
464 bool bChangedOtherwise
= false;
470 case SCHATTR_AXIS_AUTO_MAX
:
471 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
473 aScale
.Maximum
.clear();
476 // else SCHATTR_AXIS_MAX must have some value
479 case SCHATTR_AXIS_MAX
:
480 // only if auto if false
481 if( ! (rItemSet
.Get( SCHATTR_AXIS_AUTO_MAX
).GetValue() ))
483 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
485 if( aScale
.Maximum
!= aValue
)
487 aScale
.Maximum
= aValue
;
493 case SCHATTR_AXIS_AUTO_MIN
:
494 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
496 aScale
.Minimum
.clear();
499 // else SCHATTR_AXIS_MIN must have some value
502 case SCHATTR_AXIS_MIN
:
503 // only if auto if false
504 if( ! (rItemSet
.Get( SCHATTR_AXIS_AUTO_MIN
).GetValue() ))
506 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
508 if( aScale
.Minimum
!= aValue
)
510 aScale
.Minimum
= aValue
;
516 case SCHATTR_AXIS_LOGARITHM
:
518 bool bWasLogarithm
= AxisHelper::isLogarithmic( aScale
.Scaling
);
520 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
523 if( ! bWasLogarithm
)
525 aScale
.Scaling
= AxisHelper::createLogarithmicScaling( 10.0 );
531 // logarithm is false => linear scaling
534 aScale
.Scaling
= AxisHelper::createLinearScaling();
541 case SCHATTR_AXIS_REVERSE
:
543 bool bWasReverse
= ( aScale
.Orientation
== AxisOrientation_REVERSE
);
544 bool bNewReverse
= static_cast< const SfxBoolItem
& >(
545 rItemSet
.Get( nWhichId
)).GetValue();
546 if( bWasReverse
!= bNewReverse
)
548 aScale
.Orientation
= bNewReverse
? AxisOrientation_REVERSE
: AxisOrientation_MATHEMATICAL
;
555 case SCHATTR_AXIS_AUTO_STEP_MAIN
:
556 if( lcl_isAutoMajor(rItemSet
) )
558 aScale
.IncrementData
.Distance
.clear();
559 aScale
.TimeIncrement
.MajorTimeInterval
.clear();
562 // else SCHATTR_AXIS_STEP_MAIN must have some value
565 case SCHATTR_AXIS_MAIN_TIME_UNIT
:
566 if( !lcl_isAutoMajor(rItemSet
) )
568 if( rItemSet
.Get( nWhichId
).QueryValue( aValue
) )
570 TimeInterval aTimeInterval
;
571 aScale
.TimeIncrement
.MajorTimeInterval
>>= aTimeInterval
;
572 aValue
>>= aTimeInterval
.TimeUnit
;
573 aScale
.TimeIncrement
.MajorTimeInterval
<<= aTimeInterval
;
579 case SCHATTR_AXIS_STEP_MAIN
:
580 // only if auto if false
581 if( !lcl_isAutoMajor(rItemSet
) )
583 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
584 if( lcl_isDateAxis(rItemSet
) )
587 if( aValue
>>= fValue
)
589 TimeInterval aTimeInterval
;
590 aScale
.TimeIncrement
.MajorTimeInterval
>>= aTimeInterval
;
591 aTimeInterval
.Number
= static_cast<sal_Int32
>(fValue
);
592 aScale
.TimeIncrement
.MajorTimeInterval
<<= aTimeInterval
;
596 else if( aScale
.IncrementData
.Distance
!= aValue
)
598 aScale
.IncrementData
.Distance
= aValue
;
605 case SCHATTR_AXIS_AUTO_STEP_HELP
:
606 if( lcl_isAutoMinor(rItemSet
) )
608 if( aScale
.IncrementData
.SubIncrements
.getLength() > 0 &&
609 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
.hasValue() )
611 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
.clear();
614 if( aScale
.TimeIncrement
.MinorTimeInterval
.hasValue() )
616 aScale
.TimeIncrement
.MinorTimeInterval
.clear();
620 // else SCHATTR_AXIS_STEP_MAIN must have some value
623 case SCHATTR_AXIS_HELP_TIME_UNIT
:
624 if( !lcl_isAutoMinor(rItemSet
) )
626 if( rItemSet
.Get( nWhichId
).QueryValue( aValue
) )
628 TimeInterval aTimeInterval
;
629 aScale
.TimeIncrement
.MinorTimeInterval
>>= aTimeInterval
;
630 aValue
>>= aTimeInterval
.TimeUnit
;
631 aScale
.TimeIncrement
.MinorTimeInterval
<<= aTimeInterval
;
637 case SCHATTR_AXIS_STEP_HELP
:
638 // only if auto is false
639 if( !lcl_isAutoMinor(rItemSet
) )
641 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
642 if( lcl_isDateAxis(rItemSet
) )
644 TimeInterval aTimeInterval
;
645 aScale
.TimeIncrement
.MinorTimeInterval
>>= aTimeInterval
;
646 aValue
>>= aTimeInterval
.Number
;
647 aScale
.TimeIncrement
.MinorTimeInterval
<<= aTimeInterval
;
650 else if( aScale
.IncrementData
.SubIncrements
.getLength() > 0 )
652 if( ! aScale
.IncrementData
.SubIncrements
[0].IntervalCount
.hasValue() ||
653 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
!= aValue
)
655 OSL_ASSERT( aValue
.getValueTypeClass() == uno::TypeClass_LONG
);
656 aScale
.IncrementData
.SubIncrements
[0].IntervalCount
= aValue
;
663 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION
:
664 if( static_cast< const SfxBoolItem
& >( rItemSet
.Get( nWhichId
)).GetValue() )
666 aScale
.TimeIncrement
.TimeResolution
.clear();
670 case SCHATTR_AXIS_TIME_RESOLUTION
:
671 // only if auto is false
672 if( ! ( rItemSet
.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION
).GetValue() ))
674 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
676 if( aScale
.TimeIncrement
.TimeResolution
!= aValue
)
678 aScale
.TimeIncrement
.TimeResolution
= aValue
;
684 case SCHATTR_AXIS_AUTO_ORIGIN
:
686 if( static_cast< const SfxBoolItem
& >(rItemSet
.Get( nWhichId
)).GetValue() )
688 aScale
.Origin
.clear();
694 case SCHATTR_AXIS_ORIGIN
:
696 // only if auto is false
697 if( ! (rItemSet
.Get( SCHATTR_AXIS_AUTO_ORIGIN
).GetValue() ))
699 rItemSet
.Get( nWhichId
).QueryValue( aValue
);
701 if( aScale
.Origin
!= aValue
)
703 aScale
.Origin
= aValue
;
706 if( !AxisHelper::isAxisPositioningEnabled() )
708 //keep old and new settings for axis positioning in sync somehow
709 Reference
< chart2::XCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemOfAxis(
710 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
712 sal_Int32 nDimensionIndex
=0;
713 sal_Int32 nAxisIndex
=0;
714 if( AxisHelper::getIndicesForAxis( m_xAxis
, xCooSys
, nDimensionIndex
, nAxisIndex
) && nAxisIndex
==0 )
716 Reference
< beans::XPropertySet
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis
, xCooSys
), uno::UNO_QUERY
);
717 if( xCrossingMainAxis
.is() )
720 if( aValue
>>= fValue
)
722 xCrossingMainAxis
->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_VALUE
));
723 xCrossingMainAxis
->setPropertyValue( "CrossoverValue" , uno::Any( fValue
));
726 xCrossingMainAxis
->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_START
));
735 case SCHATTR_AXIS_POSITION
:
737 css::chart::ChartAxisPosition eAxisPos
=
738 static_cast<css::chart::ChartAxisPosition
>(static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue());
740 css::chart::ChartAxisPosition
eOldAxisPos( css::chart::ChartAxisPosition_ZERO
);
741 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eOldAxisPos
);
743 if( !bPropExisted
|| ( eOldAxisPos
!= eAxisPos
))
745 GetPropertySet()->setPropertyValue( "CrossoverPosition" , uno::Any( eAxisPos
));
746 bChangedOtherwise
= true;
748 //move the parallel axes to the other side if necessary
749 if( eAxisPos
==css::chart::ChartAxisPosition_START
|| eAxisPos
==css::chart::ChartAxisPosition_END
)
751 Reference
< beans::XPropertySet
> xParallelAxis( AxisHelper::getParallelAxis( m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ), uno::UNO_QUERY
);
752 if( xParallelAxis
.is() )
754 css::chart::ChartAxisPosition eOtherPos
;
755 if( xParallelAxis
->getPropertyValue( "CrossoverPosition" ) >>= eOtherPos
)
757 if( eOtherPos
== eAxisPos
)
759 css::chart::ChartAxisPosition eOppositePos
=
760 (eAxisPos
==css::chart::ChartAxisPosition_START
)
761 ? css::chart::ChartAxisPosition_END
762 : css::chart::ChartAxisPosition_START
;
763 xParallelAxis
->setPropertyValue( "CrossoverPosition" , uno::Any( eOppositePos
));
772 case SCHATTR_AXIS_POSITION_VALUE
:
774 double fValue
= static_cast< const SvxDoubleItem
& >( rItemSet
.Get( nWhichId
)).GetValue();
776 double fOldValue
= 0.0;
777 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fOldValue
);
779 if( !bPropExisted
|| ( fOldValue
!= fValue
))
781 GetPropertySet()->setPropertyValue( "CrossoverValue" , uno::Any( fValue
));
782 bChangedOtherwise
= true;
784 //keep old and new settings for axis positioning in sync somehow
786 Reference
< chart2::XCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemOfAxis(
787 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
789 sal_Int32 nDimensionIndex
=0;
790 sal_Int32 nAxisIndex
=0;
791 if( AxisHelper::getIndicesForAxis( m_xAxis
, xCooSys
, nDimensionIndex
, nAxisIndex
) && nAxisIndex
==0 )
793 Reference
< chart2::XAxis
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis
, xCooSys
) );
794 if( xCrossingMainAxis
.is() )
796 ScaleData
aCrossingScale( xCrossingMainAxis
->getScaleData() );
797 aCrossingScale
.Origin
<<= fValue
;
798 xCrossingMainAxis
->setScaleData(aCrossingScale
);
806 case SCHATTR_AXIS_LABEL_POSITION
:
808 css::chart::ChartAxisLabelPosition ePos
=
809 static_cast<css::chart::ChartAxisLabelPosition
>(static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue());
811 css::chart::ChartAxisLabelPosition
eOldPos( css::chart::ChartAxisLabelPosition_NEAR_AXIS
);
812 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= eOldPos
);
814 if( !bPropExisted
|| ( eOldPos
!= ePos
))
816 GetPropertySet()->setPropertyValue( "LabelPosition" , uno::Any( ePos
));
817 bChangedOtherwise
= true;
819 //move the parallel axes to the other side if necessary
820 if( ePos
==css::chart::ChartAxisLabelPosition_OUTSIDE_START
|| ePos
==css::chart::ChartAxisLabelPosition_OUTSIDE_END
)
822 Reference
< beans::XPropertySet
> xParallelAxis( AxisHelper::getParallelAxis( m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ), uno::UNO_QUERY
);
823 if( xParallelAxis
.is() )
825 css::chart::ChartAxisLabelPosition eOtherPos
;
826 if( xParallelAxis
->getPropertyValue( "LabelPosition" ) >>= eOtherPos
)
828 if( eOtherPos
== ePos
)
830 css::chart::ChartAxisLabelPosition eOppositePos
=
831 (ePos
==css::chart::ChartAxisLabelPosition_OUTSIDE_START
)
832 ? css::chart::ChartAxisLabelPosition_OUTSIDE_END
833 : css::chart::ChartAxisLabelPosition_OUTSIDE_START
;
834 xParallelAxis
->setPropertyValue( "LabelPosition" , uno::Any( eOppositePos
));
843 case SCHATTR_AXIS_MARK_POSITION
:
845 css::chart::ChartAxisMarkPosition ePos
=
846 static_cast<css::chart::ChartAxisMarkPosition
>(static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue());
848 css::chart::ChartAxisMarkPosition
eOldPos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS
);
849 bool bPropExisted
= ( GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= eOldPos
);
851 if( !bPropExisted
|| ( eOldPos
!= ePos
))
853 GetPropertySet()->setPropertyValue( "MarkPosition" , uno::Any( ePos
));
854 bChangedOtherwise
= true;
859 case SCHATTR_TEXT_DEGREES
:
861 // convert int to double (divided by 100)
862 double fVal
= static_cast< double >(
863 static_cast< const SfxInt32Item
& >(
864 rItemSet
.Get( nWhichId
)).GetValue()) / 100.0;
865 double fOldVal
= 0.0;
867 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal
);
869 if( ! bPropExisted
|| fOldVal
!= fVal
)
871 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fVal
));
872 bChangedOtherwise
= true;
877 case SID_ATTR_NUMBERFORMAT_VALUE
:
879 if( m_pExplicitScale
)
881 bool bUseSourceFormat
=
882 static_cast< const SfxBoolItem
& >(
883 rItemSet
.Get( SID_ATTR_NUMBERFORMAT_SOURCE
)).GetValue();
885 if( ! bUseSourceFormat
)
887 sal_Int32 nFmt
= static_cast< sal_Int32
>(
888 static_cast< const SfxUInt32Item
& >(
889 rItemSet
.Get( nWhichId
)).GetValue());
892 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT
) != aValue
)
894 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT
, aValue
);
895 bChangedOtherwise
= true;
902 case SID_ATTR_NUMBERFORMAT_SOURCE
:
904 bool bUseSourceFormat
=
905 static_cast< const SfxBoolItem
& >(
906 rItemSet
.Get( nWhichId
)).GetValue();
907 GetPropertySet()->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
, uno::Any(bUseSourceFormat
));
909 bool bNumberFormatIsSet
= GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT
).hasValue();
911 bChangedOtherwise
= (bUseSourceFormat
== bNumberFormatIsSet
);
912 if( bChangedOtherwise
)
914 if( ! bUseSourceFormat
)
916 SfxItemState aState
= rItemSet
.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
);
917 if( aState
== SfxItemState::SET
)
919 sal_Int32 nFormatKey
= static_cast< sal_Int32
>(
920 rItemSet
.Get( SID_ATTR_NUMBERFORMAT_VALUE
).GetValue());
921 aValue
<<= nFormatKey
;
925 Reference
< chart2::XCoordinateSystem
> xCooSys(
926 AxisHelper::getCoordinateSystemOfAxis(
927 m_xAxis
, ChartModelHelper::findDiagram( m_xChartDoc
) ) );
929 sal_Int32 nFormatKey
= ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
930 m_xAxis
, xCooSys
, m_xChartDoc
);
932 aValue
<<= nFormatKey
;
935 // else set a void Any
936 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT
, aValue
);
941 case SCHATTR_AXISTYPE
:
943 sal_Int32 nNewAxisType
= static_cast< const SfxInt32Item
& >( rItemSet
.Get( nWhichId
)).GetValue();//css::chart2::AxisType
944 aScale
.AxisType
= nNewAxisType
;
949 case SCHATTR_AXIS_AUTO_DATEAXIS
:
951 bool bNewValue
= static_cast< const SfxBoolItem
& >( rItemSet
.Get( nWhichId
)).GetValue();
952 bool bOldValue
= aScale
.AutoDateAxis
;
953 if( bOldValue
!= bNewValue
)
955 aScale
.AutoDateAxis
= bNewValue
;
963 m_xAxis
->setScaleData( aScale
);
965 return (bSetScale
|| bChangedOtherwise
);
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */