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