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 <res_ErrorBar.hxx>
21 #include <bitmaps.hlst>
22 #include <RangeSelectionHelper.hxx>
24 #include <chartview/ChartSfxItemIds.hxx>
25 #include <vcl/weld.hxx>
26 #include <ChartModel.hxx>
28 #include <rtl/math.hxx>
29 #include <comphelper/diagnose_ex.hxx>
30 #include <osl/diagnose.h>
31 #include <svl/stritem.hxx>
33 #define CHART_LB_FUNCTION_STD_ERROR 0
34 #define CHART_LB_FUNCTION_STD_DEV 1
35 #define CHART_LB_FUNCTION_VARIANCE 2
36 #define CHART_LB_FUNCTION_ERROR_MARGIN 3
38 using namespace ::com::sun::star
;
42 void lcl_enableRangeChoosing(bool bEnable
, weld::DialogController
* pController
)
44 weld::Window
* pWeldDialog
= pController
->getDialog();
45 pWeldDialog
->set_modal(!bEnable
);
46 pWeldDialog
->set_visible(!bEnable
);
49 sal_uInt16
lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind
)
51 sal_uInt16 nResult
= 0;
54 // for these cases select the default in the list box
55 case SvxChartKindError::NONE
:
56 case SvxChartKindError::Percent
:
57 case SvxChartKindError::Const
:
58 case SvxChartKindError::Range
:
59 nResult
= CHART_LB_FUNCTION_STD_DEV
;
61 case SvxChartKindError::Variant
:
62 nResult
= CHART_LB_FUNCTION_VARIANCE
;
64 case SvxChartKindError::Sigma
:
65 nResult
= CHART_LB_FUNCTION_STD_DEV
;
67 case SvxChartKindError::BigError
:
68 nResult
= CHART_LB_FUNCTION_ERROR_MARGIN
;
70 case SvxChartKindError::StdError
:
71 nResult
= CHART_LB_FUNCTION_STD_ERROR
;
76 } // anonymous namespace
81 ErrorBarResources::ErrorBarResources(weld::Builder
* pParent
, weld::DialogController
* pController
,
82 const SfxItemSet
& rInAttrs
, bool bNoneAvailable
,
83 tErrorBarType eType
/* = ERROR_BAR_Y */ )
84 : m_eErrorKind( SvxChartKindError::NONE
)
85 , m_eIndicate( SvxChartIndicate::Both
)
86 , m_bErrorKindUnique( true )
87 , m_bIndicatorUnique( true )
88 , m_bRangePosUnique( true )
89 , m_bRangeNegUnique( true )
90 , m_eErrorBarType( eType
)
91 , m_nConstDecimalDigits( 1 )
92 , m_nConstSpinSize( 1 )
95 , m_pController(pController
)
96 , m_pCurrentRangeChoosingField( nullptr )
97 , m_bHasInternalDataProvider( true )
98 , m_bEnableDataTableDialog( true )
99 , m_xRbNone(pParent
->weld_radio_button("RB_NONE"))
100 , m_xRbConst(pParent
->weld_radio_button("RB_CONST"))
101 , m_xRbPercent(pParent
->weld_radio_button("RB_PERCENT"))
102 , m_xRbFunction(pParent
->weld_radio_button("RB_FUNCTION"))
103 , m_xRbRange(pParent
->weld_radio_button("RB_RANGE"))
104 , m_xLbFunction(pParent
->weld_combo_box("LB_FUNCTION"))
105 , m_xFlParameters(pParent
->weld_frame("framePARAMETERS"))
106 , m_xBxPositive(pParent
->weld_widget("boxPOSITIVE"))
107 , m_xMfPositive(pParent
->weld_metric_spin_button("MF_POSITIVE", FieldUnit::NONE
))
108 , m_xEdRangePositive(pParent
->weld_entry("ED_RANGE_POSITIVE"))
109 , m_xIbRangePositive(pParent
->weld_button("IB_RANGE_POSITIVE"))
110 , m_xBxNegative(pParent
->weld_widget("boxNEGATIVE"))
111 , m_xMfNegative(pParent
->weld_metric_spin_button("MF_NEGATIVE", FieldUnit::NONE
))
112 , m_xEdRangeNegative(pParent
->weld_entry("ED_RANGE_NEGATIVE"))
113 , m_xIbRangeNegative(pParent
->weld_button("IB_RANGE_NEGATIVE"))
114 , m_xCbSyncPosNeg(pParent
->weld_check_button("CB_SYN_POS_NEG"))
115 , m_xRbBoth(pParent
->weld_radio_button("RB_BOTH"))
116 , m_xRbPositive(pParent
->weld_radio_button("RB_POSITIVE"))
117 , m_xRbNegative(pParent
->weld_radio_button("RB_NEGATIVE"))
118 , m_xFiBoth(pParent
->weld_image("FI_BOTH"))
119 , m_xFiPositive(pParent
->weld_image("FI_POSITIVE"))
120 , m_xFiNegative(pParent
->weld_image("FI_NEGATIVE"))
121 , m_xUIStringPos(pParent
->weld_label("STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS"))
122 , m_xUIStringNeg(pParent
->weld_label("STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS"))
123 , m_xUIStringRbRange(pParent
->weld_label("STR_CONTROLTEXT_ERROR_BARS_FROM_DATA"))
126 m_xRbNone
->connect_toggled(LINK(this, ErrorBarResources
, CategoryChosen
));
130 m_xRbConst
->connect_toggled( LINK( this, ErrorBarResources
, CategoryChosen
));
131 m_xRbPercent
->connect_toggled( LINK( this, ErrorBarResources
, CategoryChosen
));
132 m_xRbFunction
->connect_toggled( LINK( this, ErrorBarResources
, CategoryChosen
));
133 m_xRbRange
->connect_toggled( LINK( this, ErrorBarResources
, CategoryChosen
));
134 m_xLbFunction
->connect_changed( LINK( this, ErrorBarResources
, CategoryChosen2
));
136 m_xCbSyncPosNeg
->set_active( false );
137 m_xCbSyncPosNeg
->connect_toggled( LINK( this, ErrorBarResources
, SynchronizePosAndNeg
));
139 m_xMfPositive
->connect_value_changed( LINK( this, ErrorBarResources
, PosValueChanged
));
140 m_xEdRangePositive
->connect_changed( LINK( this, ErrorBarResources
, RangeChanged
));
141 m_xEdRangeNegative
->connect_changed( LINK( this, ErrorBarResources
, RangeChanged
));
143 m_xRbPositive
->connect_toggled( LINK( this, ErrorBarResources
, IndicatorChanged
));
144 m_xRbNegative
->connect_toggled( LINK( this, ErrorBarResources
, IndicatorChanged
));
145 m_xRbBoth
->connect_toggled( LINK( this, ErrorBarResources
, IndicatorChanged
));
147 m_xIbRangePositive
->connect_clicked( LINK( this, ErrorBarResources
, ChooseRange
));
148 m_xIbRangeNegative
->connect_clicked( LINK( this, ErrorBarResources
, ChooseRange
));
154 ErrorBarResources::~ErrorBarResources()
158 void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType
)
160 if( m_eErrorBarType
!= eNewType
)
162 m_eErrorBarType
= eNewType
;
167 void ErrorBarResources::SetChartDocumentForRangeChoosing(
168 const rtl::Reference
<::chart::ChartModel
> & xChartDocument
)
170 if( xChartDocument
.is())
172 m_bHasInternalDataProvider
= xChartDocument
->hasInternalDataProvider();
173 uno::Reference
< beans::XPropertySet
> xProps( static_cast<cppu::OWeakObject
*>(xChartDocument
.get()), uno::UNO_QUERY
);
178 xProps
->getPropertyValue("EnableDataTableDialog") >>= m_bEnableDataTableDialog
;
180 catch( const uno::Exception
& )
182 TOOLS_WARN_EXCEPTION("chart2", "" );
186 m_apRangeSelectionHelper
.reset( new RangeSelectionHelper( xChartDocument
));
188 // has internal data provider => rename "cell range" to "from data"
189 OSL_ASSERT(m_apRangeSelectionHelper
);
190 if( m_bHasInternalDataProvider
)
192 m_xRbRange
->set_label(m_xUIStringRbRange
->get_label());
193 m_xRbRange
->set_help_id(HID_SCH_ERROR_BARS_FROM_DATA
);
196 if( m_xRbRange
->get_active())
198 isRangeFieldContentValid( *m_xEdRangePositive
);
199 isRangeFieldContentValid( *m_xEdRangeNegative
);
203 void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth
)
205 if( fMinorStepWidth
< 0 )
206 fMinorStepWidth
= -fMinorStepWidth
;
208 sal_Int32 nExponent
= static_cast< sal_Int32
>( ::rtl::math::approxFloor( log10( fMinorStepWidth
)));
211 // one digit precision more
212 m_nConstDecimalDigits
= static_cast< sal_uInt16
>( (-nExponent
) + 1 );
213 m_nConstSpinSize
= 10;
217 m_nConstDecimalDigits
= 0;
218 m_nConstSpinSize
= static_cast< sal_Int64
>( pow( 10.0, static_cast<int>(nExponent
) ));
222 void ErrorBarResources::UpdateControlStates()
225 bool bIsFunction
= m_xRbFunction
->get_active();
226 m_xLbFunction
->set_sensitive( bIsFunction
);
229 m_xRbRange
->set_sensitive( !m_bHasInternalDataProvider
|| m_bEnableDataTableDialog
);
230 bool bShowRange
= m_xRbRange
->get_active();
231 bool bCanChooseRange
=
233 m_apRangeSelectionHelper
&&
234 m_apRangeSelectionHelper
->hasRangeSelection());
236 m_xMfPositive
->set_visible( ! bShowRange
);
237 m_xMfNegative
->set_visible( ! bShowRange
);
239 // use range but without range chooser => hide controls
240 m_xEdRangePositive
->set_visible( bShowRange
&& ! m_bHasInternalDataProvider
);
241 m_xIbRangePositive
->set_visible( bCanChooseRange
);
242 m_xEdRangeNegative
->set_visible( bShowRange
&& ! m_bHasInternalDataProvider
);
243 m_xIbRangeNegative
->set_visible( bCanChooseRange
);
245 bool bShowPosNegAndSync
= ! (bShowRange
&& m_bHasInternalDataProvider
);
246 m_xFlParameters
->set_visible( bShowPosNegAndSync
);
248 // unit for metric fields
250 ( m_xRbFunction
->get_active()) &&
251 ( m_xLbFunction
->get_active() == CHART_LB_FUNCTION_ERROR_MARGIN
));
252 bool bIsPercentage( m_xRbPercent
->get_active() || bIsErrorMargin
);
253 FieldUnit eFieldUnit
= FieldUnit::NONE
;
257 eFieldUnit
= FieldUnit::PERCENT
;
258 m_xMfPositive
->set_digits( 1 );
259 m_xMfPositive
->set_increments(10, 100, FieldUnit::NONE
);
260 m_xMfNegative
->set_digits( 1 );
261 m_xMfNegative
->set_increments(10, 100, FieldUnit::NONE
);
265 m_xMfPositive
->set_digits( m_nConstDecimalDigits
);
266 m_xMfPositive
->set_increments(m_nConstSpinSize
, m_nConstSpinSize
* 10, FieldUnit::NONE
);
267 m_xMfNegative
->set_digits( m_nConstDecimalDigits
);
268 m_xMfNegative
->set_increments(m_nConstSpinSize
, m_nConstSpinSize
* 10, FieldUnit::NONE
);
271 sal_Int32 nPlusValue
= static_cast< sal_Int32
>( m_fPlusValue
* pow(10.0,m_xMfPositive
->get_digits()) );
272 sal_Int32 nMinusValue
= static_cast< sal_Int32
>( m_fMinusValue
* pow(10.0,m_xMfNegative
->get_digits()) );
274 m_xMfPositive
->set_value(nPlusValue
, FieldUnit::NONE
);
275 m_xMfNegative
->set_value(nMinusValue
, FieldUnit::NONE
);
277 m_xMfPositive
->set_unit(eFieldUnit
);
278 m_xMfNegative
->set_unit(eFieldUnit
);
280 // positive and negative value fields
281 bool bPosEnabled
= ( m_xRbPositive
->get_active() || m_xRbBoth
->get_active());
282 bool bNegEnabled
= ( m_xRbNegative
->get_active() || m_xRbBoth
->get_active());
283 if( !( bPosEnabled
|| bNegEnabled
))
285 // all three controls are not checked -> ambiguous state
290 // functions with only one parameter
291 bool bOneParameterCategory
=
292 bIsErrorMargin
|| m_xRbPercent
->get_active();
293 if( bOneParameterCategory
)
295 m_xCbSyncPosNeg
->set_active(true);
298 if( m_xCbSyncPosNeg
->get_active())
304 // all functions except error margin take no arguments
305 if( m_xRbFunction
->get_active() && ( m_xLbFunction
->get_active() != CHART_LB_FUNCTION_ERROR_MARGIN
))
311 // enable/disable pos/neg fields
312 m_xBxPositive
->set_sensitive( bPosEnabled
);
313 m_xBxNegative
->set_sensitive( bNegEnabled
);
316 m_xEdRangePositive
->set_sensitive( bPosEnabled
);
317 m_xIbRangePositive
->set_sensitive( bPosEnabled
);
318 m_xEdRangeNegative
->set_sensitive( bNegEnabled
);
319 m_xIbRangeNegative
->set_sensitive( bNegEnabled
);
323 m_xMfPositive
->set_sensitive( bPosEnabled
);
324 m_xMfNegative
->set_sensitive( bNegEnabled
);
327 m_xCbSyncPosNeg
->set_sensitive( !bOneParameterCategory
&& ( bPosEnabled
|| bNegEnabled
));
329 // mark invalid entries in the range fields
330 if( bShowRange
&& ! m_bHasInternalDataProvider
)
332 isRangeFieldContentValid( *m_xEdRangePositive
);
333 isRangeFieldContentValid( *m_xEdRangeNegative
);
337 IMPL_LINK_NOARG( ErrorBarResources
, CategoryChosen2
, weld::ComboBox
&, void )
339 CategoryChosen(*m_xRbConst
);
342 IMPL_LINK_NOARG( ErrorBarResources
, CategoryChosen
, weld::Toggleable
&, void )
344 m_bErrorKindUnique
= true;
345 SvxChartKindError eOldError
= m_eErrorKind
;
347 if( m_xRbNone
->get_active())
348 m_eErrorKind
= SvxChartKindError::NONE
;
349 else if( m_xRbConst
->get_active())
350 m_eErrorKind
= SvxChartKindError::Const
;
351 else if( m_xRbPercent
->get_active())
352 m_eErrorKind
= SvxChartKindError::Percent
;
353 else if( m_xRbRange
->get_active())
354 m_eErrorKind
= SvxChartKindError::Range
;
355 else if( m_xRbFunction
->get_active())
357 switch( m_xLbFunction
->get_active())
359 case CHART_LB_FUNCTION_STD_ERROR
:
360 m_eErrorKind
= SvxChartKindError::StdError
; break;
361 case CHART_LB_FUNCTION_STD_DEV
:
362 m_eErrorKind
= SvxChartKindError::Sigma
; break;
363 case CHART_LB_FUNCTION_VARIANCE
:
364 m_eErrorKind
= SvxChartKindError::Variant
; break;
365 case CHART_LB_FUNCTION_ERROR_MARGIN
:
366 m_eErrorKind
= SvxChartKindError::BigError
; break;
368 m_bErrorKindUnique
= false;
373 OSL_FAIL( "Unknown category chosen" );
374 m_bErrorKindUnique
= false;
378 if( m_eErrorKind
== SvxChartKindError::Range
&&
379 eOldError
!= SvxChartKindError::Range
)
381 m_xCbSyncPosNeg
->set_active(
382 (!m_xEdRangePositive
->get_text().isEmpty()) &&
383 m_xEdRangePositive
->get_text() == m_xEdRangeNegative
->get_text());
385 // changed from range
386 else if( m_eErrorKind
!= SvxChartKindError::Range
&&
387 eOldError
== SvxChartKindError::Range
)
389 m_xCbSyncPosNeg
->set_active( m_xMfPositive
->get_value(FieldUnit::NONE
) == m_xMfNegative
->get_value(FieldUnit::NONE
));
392 UpdateControlStates();
395 IMPL_LINK_NOARG(ErrorBarResources
, SynchronizePosAndNeg
, weld::Toggleable
&, void)
397 UpdateControlStates();
398 PosValueChanged( *m_xMfPositive
);
401 IMPL_LINK_NOARG(ErrorBarResources
, PosValueChanged
, weld::MetricSpinButton
&, void)
403 if( m_xCbSyncPosNeg
->get_active())
405 if( m_xRbRange
->get_active())
407 m_xEdRangeNegative
->set_text( m_xEdRangePositive
->get_text());
408 m_bRangeNegUnique
= m_bRangePosUnique
;
411 m_xMfNegative
->set_value(m_xMfPositive
->get_value(FieldUnit::NONE
), FieldUnit::NONE
);
415 IMPL_LINK_NOARG(ErrorBarResources
, IndicatorChanged
, weld::Toggleable
&, void)
417 m_bIndicatorUnique
= true;
418 if( m_xRbBoth
->get_active())
419 m_eIndicate
= SvxChartIndicate::Both
;
420 else if( m_xRbPositive
->get_active())
421 m_eIndicate
= SvxChartIndicate::Up
;
422 else if( m_xRbNegative
->get_active())
423 m_eIndicate
= SvxChartIndicate::Down
;
425 m_bIndicatorUnique
= false;
427 UpdateControlStates();
430 IMPL_LINK(ErrorBarResources
, ChooseRange
, weld::Button
&, rButton
, void)
432 OSL_ASSERT(m_apRangeSelectionHelper
);
433 if (!m_apRangeSelectionHelper
)
435 OSL_ASSERT( m_pCurrentRangeChoosingField
== nullptr );
439 if (&rButton
== m_xIbRangePositive
.get())
441 m_pCurrentRangeChoosingField
= m_xEdRangePositive
.get();
442 aUIString
= m_xUIStringPos
->get_label();
446 m_pCurrentRangeChoosingField
= m_xEdRangeNegative
.get();
447 aUIString
= m_xUIStringNeg
->get_label();
450 lcl_enableRangeChoosing(true, m_pController
);
451 m_apRangeSelectionHelper
->chooseRange(
452 m_pCurrentRangeChoosingField
->get_text(),
456 IMPL_LINK( ErrorBarResources
, RangeChanged
, weld::Entry
&, rEdit
, void )
458 if( &rEdit
== m_xEdRangePositive
.get() )
460 m_bRangePosUnique
= true;
461 PosValueChanged( *m_xMfPositive
);
465 m_bRangeNegUnique
= true;
468 isRangeFieldContentValid( rEdit
);
471 void ErrorBarResources::Reset(const SfxItemSet
& rInAttrs
)
473 const SfxPoolItem
*pPoolItem
= nullptr;
476 m_eErrorKind
= SvxChartKindError::NONE
;
477 SfxItemState aState
= rInAttrs
.GetItemState( SCHATTR_STAT_KIND_ERROR
, true, &pPoolItem
);
478 m_bErrorKindUnique
= ( aState
!= SfxItemState::DONTCARE
);
480 if( aState
== SfxItemState::SET
)
481 m_eErrorKind
= static_cast<const SvxChartKindErrorItem
*>(pPoolItem
)->GetValue();
483 m_xLbFunction
->set_active( lcl_getLbEntryPosByErrorKind( m_eErrorKind
));
485 if( m_bErrorKindUnique
)
487 switch( m_eErrorKind
)
489 case SvxChartKindError::NONE
:
490 m_xRbNone
->set_active(true);
492 case SvxChartKindError::Percent
:
493 m_xRbPercent
->set_active(true);
495 case SvxChartKindError::Const
:
496 m_xRbConst
->set_active(true);
498 case SvxChartKindError::StdError
:
499 case SvxChartKindError::Variant
:
500 case SvxChartKindError::Sigma
:
501 case SvxChartKindError::BigError
:
502 m_xRbFunction
->set_active(true);
504 case SvxChartKindError::Range
:
505 m_xRbRange
->set_active(true);
511 m_xRbNone
->set_active( false );
512 m_xRbConst
->set_active( false );
513 m_xRbPercent
->set_active( false );
514 m_xRbFunction
->set_active( false );
518 if( const SvxDoubleItem
* pDoubleItem
= rInAttrs
.GetItemIfSet( SCHATTR_STAT_CONSTPLUS
) )
520 m_fPlusValue
= pDoubleItem
->GetValue();
523 if( const SvxDoubleItem
* pStatItem
= rInAttrs
.GetItemIfSet( SCHATTR_STAT_CONSTMINUS
) )
525 m_fMinusValue
= pStatItem
->GetValue();
527 if( m_eErrorKind
!= SvxChartKindError::Range
&&
528 m_fPlusValue
== m_fMinusValue
)
529 m_xCbSyncPosNeg
->set_active(true);
533 aState
= rInAttrs
.GetItemState( SCHATTR_STAT_INDICATE
, true, &pPoolItem
);
534 m_bIndicatorUnique
= ( aState
!= SfxItemState::DONTCARE
);
535 if( aState
== SfxItemState::SET
)
536 m_eIndicate
= static_cast<const SvxChartIndicateItem
*>(pPoolItem
)->GetValue();
538 if( m_bIndicatorUnique
)
540 switch( m_eIndicate
)
542 case SvxChartIndicate::NONE
:
543 // no longer used, use both as default
544 m_eIndicate
= SvxChartIndicate::Both
;
545 [[fallthrough
]]; // to BOTH
546 case SvxChartIndicate::Both
:
547 m_xRbBoth
->set_active(true); break;
548 case SvxChartIndicate::Up
:
549 m_xRbPositive
->set_active(true); break;
550 case SvxChartIndicate::Down
:
551 m_xRbNegative
->set_active(true); break;
556 m_xRbBoth
->set_active( false );
557 m_xRbPositive
->set_active( false );
558 m_xRbNegative
->set_active( false );
562 aState
= rInAttrs
.GetItemState( SCHATTR_STAT_RANGE_POS
, true, &pPoolItem
);
563 m_bRangePosUnique
= ( aState
!= SfxItemState::DONTCARE
);
564 if( aState
== SfxItemState::SET
)
566 OUString sRangePositive
= static_cast< const SfxStringItem
* >( pPoolItem
)->GetValue();
567 m_xEdRangePositive
->set_text( sRangePositive
);
570 aState
= rInAttrs
.GetItemState( SCHATTR_STAT_RANGE_NEG
, true, &pPoolItem
);
571 m_bRangeNegUnique
= ( aState
!= SfxItemState::DONTCARE
);
572 if( aState
== SfxItemState::SET
)
574 OUString sRangeNegative
= static_cast< const SfxStringItem
* >( pPoolItem
)->GetValue();
575 m_xEdRangeNegative
->set_text( sRangeNegative
);
576 if( m_eErrorKind
== SvxChartKindError::Range
&&
577 !sRangeNegative
.isEmpty() &&
578 sRangeNegative
== m_xEdRangePositive
->get_text() )
579 m_xCbSyncPosNeg
->set_active(true);
582 UpdateControlStates();
585 void ErrorBarResources::FillItemSet(SfxItemSet
& rOutAttrs
) const
587 if( m_bErrorKindUnique
)
588 rOutAttrs
.Put( SvxChartKindErrorItem( m_eErrorKind
, SCHATTR_STAT_KIND_ERROR
));
589 if( m_bIndicatorUnique
)
590 rOutAttrs
.Put( SvxChartIndicateItem( m_eIndicate
, SCHATTR_STAT_INDICATE
));
592 if( m_bErrorKindUnique
)
594 if( m_eErrorKind
== SvxChartKindError::Range
)
598 if( m_bHasInternalDataProvider
)
600 // the strings aPosRange/aNegRange have to be set to a non-empty
601 // arbitrary string to generate error-bar sequences
603 aNegRange
= aPosRange
;
607 aPosRange
= m_xEdRangePositive
->get_text();
608 if( m_xCbSyncPosNeg
->get_active())
609 aNegRange
= aPosRange
;
611 aNegRange
= m_xEdRangeNegative
->get_text();
614 if( m_bRangePosUnique
)
615 rOutAttrs
.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS
, aPosRange
));
616 if( m_bRangeNegUnique
)
617 rOutAttrs
.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG
, aNegRange
));
619 else if( m_eErrorKind
== SvxChartKindError::Const
||
620 m_eErrorKind
== SvxChartKindError::Percent
||
621 m_eErrorKind
== SvxChartKindError::BigError
)
623 double fPosValue
= static_cast< double >( m_xMfPositive
->get_value(FieldUnit::NONE
)) /
624 pow( 10.0, m_xMfPositive
->get_digits());
625 double fNegValue
= 0.0;
627 if( m_xCbSyncPosNeg
->get_active())
628 fNegValue
= fPosValue
;
630 fNegValue
= static_cast< double >( m_xMfNegative
->get_value(FieldUnit::NONE
)) /
631 pow( 10.0, m_xMfNegative
->get_digits());
633 rOutAttrs
.Put( SvxDoubleItem( fPosValue
, SCHATTR_STAT_CONSTPLUS
));
634 rOutAttrs
.Put( SvxDoubleItem( fNegValue
, SCHATTR_STAT_CONSTMINUS
));
638 rOutAttrs
.Put( SfxBoolItem( SCHATTR_STAT_ERRORBAR_TYPE
, m_eErrorBarType
== ERROR_BAR_Y
));
641 void ErrorBarResources::FillValueSets()
643 if( m_eErrorBarType
== ERROR_BAR_Y
)
645 m_xFiNegative
->set_from_icon_name(BMP_INDICATE_DOWN
);
646 m_xFiPositive
->set_from_icon_name(BMP_INDICATE_UP
);
647 m_xFiBoth
->set_from_icon_name(BMP_INDICATE_BOTH_VERTI
);
649 else if( m_eErrorBarType
== ERROR_BAR_X
)
651 m_xFiNegative
->set_from_icon_name(BMP_INDICATE_LEFT
);
652 m_xFiPositive
->set_from_icon_name(BMP_INDICATE_RIGHT
);
653 m_xFiBoth
->set_from_icon_name(BMP_INDICATE_BOTH_HORI
);
657 void ErrorBarResources::listeningFinished(
658 const OUString
& rNewRange
)
660 OSL_ASSERT(m_apRangeSelectionHelper
);
661 if (!m_apRangeSelectionHelper
)
664 // rNewRange becomes invalid after removing the listener
665 OUString
aRange( rNewRange
);
668 m_apRangeSelectionHelper
->stopRangeListening();
671 // if( m_pParentWindow )
673 // m_pParentWindow->ToTop();
674 // m_pParentWindow->grab_focus();
677 if( m_pCurrentRangeChoosingField
)
679 m_pCurrentRangeChoosingField
->set_text( aRange
);
680 m_pCurrentRangeChoosingField
->grab_focus();
681 PosValueChanged( *m_xMfPositive
);
684 m_pCurrentRangeChoosingField
= nullptr;
686 UpdateControlStates();
687 lcl_enableRangeChoosing(false, m_pController
);
690 void ErrorBarResources::disposingRangeSelection()
692 OSL_ASSERT(m_apRangeSelectionHelper
);
693 if (m_apRangeSelectionHelper
)
694 m_apRangeSelectionHelper
->stopRangeListening( false );
697 void ErrorBarResources::isRangeFieldContentValid(weld::Entry
& rEdit
)
699 OUString
aRange( rEdit
.get_text());
700 bool bIsValid
= ( aRange
.isEmpty() ) ||
701 ( m_apRangeSelectionHelper
&&
702 m_apRangeSelectionHelper
->verifyCellRange( aRange
));
704 if( bIsValid
|| !rEdit
.get_sensitive())
706 rEdit
.set_message_type(weld::EntryMessageType::Normal
);
710 rEdit
.set_message_type(weld::EntryMessageType::Error
);
716 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */