vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / dialogs / res_ErrorBar.cxx
blob46407f7cc73208dbad6e045105d53679a1581ce1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <helpids.h>
24 #include <chartview/ChartSfxItemIds.hxx>
25 #include <com/sun/star/chart2/XChartDocument.hpp>
26 #include <vcl/weld.hxx>
28 #include <rtl/math.hxx>
29 #include <sal/log.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <osl/diagnose.h>
32 #include <svl/stritem.hxx>
34 #define CHART_LB_FUNCTION_STD_ERROR 0
35 #define CHART_LB_FUNCTION_STD_DEV 1
36 #define CHART_LB_FUNCTION_VARIANCE 2
37 #define CHART_LB_FUNCTION_ERROR_MARGIN 3
39 using namespace ::com::sun::star;
41 namespace
43 void lcl_enableRangeChoosing(bool bEnable, weld::DialogController* pController)
45 weld::Window* pWeldDialog = pController->getDialog();
46 pWeldDialog->set_modal(!bEnable);
47 pWeldDialog->set_visible(!bEnable);
50 sal_uInt16 lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind )
52 sal_uInt16 nResult = 0;
53 switch( eErrorKind )
55 // for these cases select the default in the list box
56 case SvxChartKindError::NONE:
57 case SvxChartKindError::Percent:
58 case SvxChartKindError::Const:
59 case SvxChartKindError::Range:
60 nResult = CHART_LB_FUNCTION_STD_DEV;
61 break;
62 case SvxChartKindError::Variant:
63 nResult = CHART_LB_FUNCTION_VARIANCE;
64 break;
65 case SvxChartKindError::Sigma:
66 nResult = CHART_LB_FUNCTION_STD_DEV;
67 break;
68 case SvxChartKindError::BigError:
69 nResult = CHART_LB_FUNCTION_ERROR_MARGIN;
70 break;
71 case SvxChartKindError::StdError:
72 nResult = CHART_LB_FUNCTION_STD_ERROR;
73 break;
75 return nResult;
77 } // anonymous namespace
79 namespace chart
82 ErrorBarResources::ErrorBarResources(weld::Builder* pParent, weld::DialogController* pController,
83 const SfxItemSet& rInAttrs, bool bNoneAvailable,
84 tErrorBarType eType /* = ERROR_BAR_Y */ )
85 : m_eErrorKind( SvxChartKindError::NONE )
86 , m_eIndicate( SvxChartIndicate::Both )
87 , m_bErrorKindUnique( true )
88 , m_bIndicatorUnique( true )
89 , m_bRangePosUnique( true )
90 , m_bRangeNegUnique( true )
91 , m_eErrorBarType( eType )
92 , m_nConstDecimalDigits( 1 )
93 , m_nConstSpinSize( 1 )
94 , m_fPlusValue(0.0)
95 , m_fMinusValue(0.0)
96 , m_pController(pController)
97 , m_pCurrentRangeChoosingField( nullptr )
98 , m_bHasInternalDataProvider( true )
99 , m_bEnableDataTableDialog( true )
100 , m_xRbNone(pParent->weld_radio_button("RB_NONE"))
101 , m_xRbConst(pParent->weld_radio_button("RB_CONST"))
102 , m_xRbPercent(pParent->weld_radio_button("RB_PERCENT"))
103 , m_xRbFunction(pParent->weld_radio_button("RB_FUNCTION"))
104 , m_xRbRange(pParent->weld_radio_button("RB_RANGE"))
105 , m_xLbFunction(pParent->weld_combo_box("LB_FUNCTION"))
106 , m_xFlParameters(pParent->weld_frame("framePARAMETERS"))
107 , m_xBxPositive(pParent->weld_widget("boxPOSITIVE"))
108 , m_xMfPositive(pParent->weld_metric_spin_button("MF_POSITIVE", FieldUnit::NONE))
109 , m_xEdRangePositive(pParent->weld_entry("ED_RANGE_POSITIVE"))
110 , m_xIbRangePositive(pParent->weld_button("IB_RANGE_POSITIVE"))
111 , m_xBxNegative(pParent->weld_widget("boxNEGATIVE"))
112 , m_xMfNegative(pParent->weld_metric_spin_button("MF_NEGATIVE", FieldUnit::NONE))
113 , m_xEdRangeNegative(pParent->weld_entry("ED_RANGE_NEGATIVE"))
114 , m_xIbRangeNegative(pParent->weld_button("IB_RANGE_NEGATIVE"))
115 , m_xCbSyncPosNeg(pParent->weld_check_button("CB_SYN_POS_NEG"))
116 , m_xRbBoth(pParent->weld_radio_button("RB_BOTH"))
117 , m_xRbPositive(pParent->weld_radio_button("RB_POSITIVE"))
118 , m_xRbNegative(pParent->weld_radio_button("RB_NEGATIVE"))
119 , m_xFiBoth(pParent->weld_image("FI_BOTH"))
120 , m_xFiPositive(pParent->weld_image("FI_POSITIVE"))
121 , m_xFiNegative(pParent->weld_image("FI_NEGATIVE"))
122 , m_xUIStringPos(pParent->weld_label("STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS"))
123 , m_xUIStringNeg(pParent->weld_label("STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS"))
124 , m_xUIStringRbRange(pParent->weld_label("STR_CONTROLTEXT_ERROR_BARS_FROM_DATA"))
126 if( bNoneAvailable )
127 m_xRbNone->connect_toggled(LINK(this, ErrorBarResources, CategoryChosen));
128 else
129 m_xRbNone->hide();
131 m_xRbConst->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
132 m_xRbPercent->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
133 m_xRbFunction->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
134 m_xRbRange->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
135 m_xLbFunction->connect_changed( LINK( this, ErrorBarResources, CategoryChosen2 ));
137 m_xCbSyncPosNeg->set_active( false );
138 m_xCbSyncPosNeg->connect_toggled( LINK( this, ErrorBarResources, SynchronizePosAndNeg ));
140 m_xMfPositive->connect_value_changed( LINK( this, ErrorBarResources, PosValueChanged ));
141 m_xEdRangePositive->connect_changed( LINK( this, ErrorBarResources, RangeChanged ));
142 m_xEdRangeNegative->connect_changed( LINK( this, ErrorBarResources, RangeChanged ));
144 m_xRbPositive->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
145 m_xRbNegative->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
146 m_xRbBoth->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
148 m_xIbRangePositive->connect_clicked( LINK( this, ErrorBarResources, ChooseRange ));
149 m_xIbRangeNegative->connect_clicked( LINK( this, ErrorBarResources, ChooseRange ));
151 FillValueSets();
152 Reset( rInAttrs );
155 ErrorBarResources::~ErrorBarResources()
159 void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType )
161 if( m_eErrorBarType != eNewType )
163 m_eErrorBarType = eNewType;
164 FillValueSets();
168 void ErrorBarResources::SetChartDocumentForRangeChoosing(
169 const uno::Reference< chart2::XChartDocument > & xChartDocument )
171 if( xChartDocument.is())
173 m_bHasInternalDataProvider = xChartDocument->hasInternalDataProvider();
174 uno::Reference< beans::XPropertySet > xProps( xChartDocument, uno::UNO_QUERY );
175 if ( xProps.is() )
179 xProps->getPropertyValue("EnableDataTableDialog") >>= m_bEnableDataTableDialog;
181 catch( const uno::Exception& )
183 TOOLS_WARN_EXCEPTION("chart2", "" );
187 m_apRangeSelectionHelper.reset( new RangeSelectionHelper( xChartDocument ));
189 // has internal data provider => rename "cell range" to "from data"
190 OSL_ASSERT(m_apRangeSelectionHelper);
191 if( m_bHasInternalDataProvider )
193 m_xRbRange->set_label(m_xUIStringRbRange->get_label());
194 m_xRbRange->set_help_id(HID_SCH_ERROR_BARS_FROM_DATA);
197 if( m_xRbRange->get_active())
199 isRangeFieldContentValid( *m_xEdRangePositive );
200 isRangeFieldContentValid( *m_xEdRangeNegative );
204 void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
206 if( fMinorStepWidth < 0 )
207 fMinorStepWidth = -fMinorStepWidth;
209 sal_Int32 nExponent = static_cast< sal_Int32 >( ::rtl::math::approxFloor( log10( fMinorStepWidth )));
210 if( nExponent <= 0 )
212 // one digit precision more
213 m_nConstDecimalDigits = static_cast< sal_uInt16 >( (-nExponent) + 1 );
214 m_nConstSpinSize = 10;
216 else
218 m_nConstDecimalDigits = 0;
219 m_nConstSpinSize = static_cast< sal_Int64 >( pow( 10.0, static_cast<int>(nExponent) ));
223 void ErrorBarResources::UpdateControlStates()
225 // function
226 bool bIsFunction = m_xRbFunction->get_active();
227 m_xLbFunction->set_sensitive( bIsFunction );
229 // range buttons
230 m_xRbRange->set_sensitive( !m_bHasInternalDataProvider || m_bEnableDataTableDialog );
231 bool bShowRange = m_xRbRange->get_active();
232 bool bCanChooseRange =
233 ( bShowRange &&
234 m_apRangeSelectionHelper.get() &&
235 m_apRangeSelectionHelper->hasRangeSelection());
237 m_xMfPositive->set_visible( ! bShowRange );
238 m_xMfNegative->set_visible( ! bShowRange );
240 // use range but without range chooser => hide controls
241 m_xEdRangePositive->set_visible( bShowRange && ! m_bHasInternalDataProvider );
242 m_xIbRangePositive->set_visible( bCanChooseRange );
243 m_xEdRangeNegative->set_visible( bShowRange && ! m_bHasInternalDataProvider );
244 m_xIbRangeNegative->set_visible( bCanChooseRange );
246 bool bShowPosNegAndSync = ! (bShowRange && m_bHasInternalDataProvider);
247 m_xFlParameters->set_visible( bShowPosNegAndSync );
249 // unit for metric fields
250 bool bIsErrorMargin(
251 ( m_xRbFunction->get_active()) &&
252 ( m_xLbFunction->get_active() == CHART_LB_FUNCTION_ERROR_MARGIN ));
253 bool bIsPercentage( m_xRbPercent->get_active() || bIsErrorMargin );
254 FieldUnit eFieldUnit = FieldUnit::NONE;
256 if( bIsPercentage )
258 eFieldUnit = FieldUnit::PERCENT;
259 m_xMfPositive->set_digits( 1 );
260 m_xMfPositive->set_increments(10, 100, FieldUnit::NONE);
261 m_xMfNegative->set_digits( 1 );
262 m_xMfNegative->set_increments(10, 100, FieldUnit::NONE);
264 else
266 m_xMfPositive->set_digits( m_nConstDecimalDigits );
267 m_xMfPositive->set_increments(m_nConstSpinSize, m_nConstSpinSize * 10, FieldUnit::NONE);
268 m_xMfNegative->set_digits( m_nConstDecimalDigits );
269 m_xMfNegative->set_increments(m_nConstSpinSize, m_nConstSpinSize * 10, FieldUnit::NONE);
272 sal_Int32 nPlusValue = static_cast< sal_Int32 >( m_fPlusValue * pow(10.0,m_xMfPositive->get_digits()) );
273 sal_Int32 nMinusValue = static_cast< sal_Int32 >( m_fMinusValue * pow(10.0,m_xMfNegative->get_digits()) );
275 m_xMfPositive->set_value(nPlusValue, FieldUnit::NONE);
276 m_xMfNegative->set_value(nMinusValue, FieldUnit::NONE);
278 m_xMfPositive->set_unit(eFieldUnit);
279 m_xMfNegative->set_unit(eFieldUnit);
281 // positive and negative value fields
282 bool bPosEnabled = ( m_xRbPositive->get_active() || m_xRbBoth->get_active());
283 bool bNegEnabled = ( m_xRbNegative->get_active() || m_xRbBoth->get_active());
284 if( !( bPosEnabled || bNegEnabled ))
286 // all three controls are not checked -> ambiguous state
287 bPosEnabled = true;
288 bNegEnabled = true;
291 // functions with only one parameter
292 bool bOneParameterCategory =
293 bIsErrorMargin || m_xRbPercent->get_active();
294 if( bOneParameterCategory )
296 m_xCbSyncPosNeg->set_active(true);
299 if( m_xCbSyncPosNeg->get_active())
301 bPosEnabled = true;
302 bNegEnabled = false;
305 // all functions except error margin take no arguments
306 if( m_xRbFunction->get_active() && ( m_xLbFunction->get_active() != CHART_LB_FUNCTION_ERROR_MARGIN ))
308 bPosEnabled = false;
309 bNegEnabled = false;
312 // enable/disable pos/neg fields
313 m_xBxPositive->set_sensitive( bPosEnabled );
314 m_xBxNegative->set_sensitive( bNegEnabled );
315 if( bShowRange )
317 m_xEdRangePositive->set_sensitive( bPosEnabled );
318 m_xIbRangePositive->set_sensitive( bPosEnabled );
319 m_xEdRangeNegative->set_sensitive( bNegEnabled );
320 m_xIbRangeNegative->set_sensitive( bNegEnabled );
322 else
324 m_xMfPositive->set_sensitive( bPosEnabled );
325 m_xMfNegative->set_sensitive( bNegEnabled );
328 m_xCbSyncPosNeg->set_sensitive( !bOneParameterCategory && ( bPosEnabled || bNegEnabled ));
330 // mark invalid entries in the range fields
331 if( bShowRange && ! m_bHasInternalDataProvider )
333 isRangeFieldContentValid( *m_xEdRangePositive );
334 isRangeFieldContentValid( *m_xEdRangeNegative );
338 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen2, weld::ComboBox&, void )
340 CategoryChosen(*m_xRbConst);
343 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen, weld::ToggleButton&, void )
345 m_bErrorKindUnique = true;
346 SvxChartKindError eOldError = m_eErrorKind;
348 if( m_xRbNone->get_active())
349 m_eErrorKind = SvxChartKindError::NONE;
350 else if( m_xRbConst->get_active())
351 m_eErrorKind = SvxChartKindError::Const;
352 else if( m_xRbPercent->get_active())
353 m_eErrorKind = SvxChartKindError::Percent;
354 else if( m_xRbRange->get_active())
355 m_eErrorKind = SvxChartKindError::Range;
356 else if( m_xRbFunction->get_active())
358 switch( m_xLbFunction->get_active())
360 case CHART_LB_FUNCTION_STD_ERROR:
361 m_eErrorKind = SvxChartKindError::StdError; break;
362 case CHART_LB_FUNCTION_STD_DEV:
363 m_eErrorKind = SvxChartKindError::Sigma; break;
364 case CHART_LB_FUNCTION_VARIANCE:
365 m_eErrorKind = SvxChartKindError::Variant; break;
366 case CHART_LB_FUNCTION_ERROR_MARGIN:
367 m_eErrorKind = SvxChartKindError::BigError; break;
368 default:
369 m_bErrorKindUnique = false;
372 else
374 OSL_FAIL( "Unknown category chosen" );
375 m_bErrorKindUnique = false;
378 // changed to range
379 if( m_eErrorKind == SvxChartKindError::Range &&
380 eOldError != SvxChartKindError::Range )
382 m_xCbSyncPosNeg->set_active(
383 (!m_xEdRangePositive->get_text().isEmpty()) &&
384 m_xEdRangePositive->get_text() == m_xEdRangeNegative->get_text());
386 // changed from range
387 else if( m_eErrorKind != SvxChartKindError::Range &&
388 eOldError == SvxChartKindError::Range )
390 m_xCbSyncPosNeg->set_active( m_xMfPositive->get_value(FieldUnit::NONE) == m_xMfNegative->get_value(FieldUnit::NONE));
393 UpdateControlStates();
396 IMPL_LINK_NOARG(ErrorBarResources, SynchronizePosAndNeg, weld::ToggleButton&, void)
398 UpdateControlStates();
399 PosValueChanged( *m_xMfPositive );
402 IMPL_LINK_NOARG(ErrorBarResources, PosValueChanged, weld::MetricSpinButton&, void)
404 if( m_xCbSyncPosNeg->get_active())
406 if( m_xRbRange->get_active())
408 m_xEdRangeNegative->set_text( m_xEdRangePositive->get_text());
409 m_bRangeNegUnique = m_bRangePosUnique;
411 else
412 m_xMfNegative->set_value(m_xMfPositive->get_value(FieldUnit::NONE), FieldUnit::NONE);
416 IMPL_LINK_NOARG(ErrorBarResources, IndicatorChanged, weld::ToggleButton&, void)
418 m_bIndicatorUnique = true;
419 if( m_xRbBoth->get_active())
420 m_eIndicate = SvxChartIndicate::Both;
421 else if( m_xRbPositive->get_active())
422 m_eIndicate = SvxChartIndicate::Up;
423 else if( m_xRbNegative->get_active())
424 m_eIndicate = SvxChartIndicate::Down;
425 else
426 m_bIndicatorUnique = false;
428 UpdateControlStates();
431 IMPL_LINK(ErrorBarResources, ChooseRange, weld::Button&, rButton, void)
433 OSL_ASSERT(m_apRangeSelectionHelper);
434 if (!m_apRangeSelectionHelper)
435 return;
436 OSL_ASSERT( m_pCurrentRangeChoosingField == nullptr );
438 OUString aUIString;
440 if (&rButton == m_xIbRangePositive.get())
442 m_pCurrentRangeChoosingField = m_xEdRangePositive.get();
443 aUIString = m_xUIStringPos->get_label();
445 else
447 m_pCurrentRangeChoosingField = m_xEdRangeNegative.get();
448 aUIString = m_xUIStringNeg->get_label();
451 lcl_enableRangeChoosing(true, m_pController);
452 m_apRangeSelectionHelper->chooseRange(
453 m_pCurrentRangeChoosingField->get_text(),
454 aUIString, *this );
457 IMPL_LINK( ErrorBarResources, RangeChanged, weld::Entry&, rEdit, void )
459 if( &rEdit == m_xEdRangePositive.get() )
461 m_bRangePosUnique = true;
462 PosValueChanged( *m_xMfPositive );
464 else
466 m_bRangeNegUnique = true;
469 isRangeFieldContentValid( rEdit );
472 void ErrorBarResources::Reset(const SfxItemSet& rInAttrs)
474 const SfxPoolItem *pPoolItem = nullptr;
476 // category
477 m_eErrorKind = SvxChartKindError::NONE;
478 SfxItemState aState = rInAttrs.GetItemState( SCHATTR_STAT_KIND_ERROR, true, &pPoolItem );
479 m_bErrorKindUnique = ( aState != SfxItemState::DONTCARE );
481 if( aState == SfxItemState::SET )
482 m_eErrorKind = static_cast<const SvxChartKindErrorItem*>(pPoolItem)->GetValue();
484 m_xLbFunction->set_active( lcl_getLbEntryPosByErrorKind( m_eErrorKind ));
486 if( m_bErrorKindUnique )
488 switch( m_eErrorKind )
490 case SvxChartKindError::NONE:
491 m_xRbNone->set_active(true);
492 break;
493 case SvxChartKindError::Percent:
494 m_xRbPercent->set_active(true);
495 break;
496 case SvxChartKindError::Const:
497 m_xRbConst->set_active(true);
498 break;
499 case SvxChartKindError::StdError:
500 case SvxChartKindError::Variant:
501 case SvxChartKindError::Sigma:
502 case SvxChartKindError::BigError:
503 m_xRbFunction->set_active(true);
504 break;
505 case SvxChartKindError::Range:
506 m_xRbRange->set_active(true);
507 break;
510 else
512 m_xRbNone->set_active( false );
513 m_xRbConst->set_active( false );
514 m_xRbPercent->set_active( false );
515 m_xRbFunction->set_active( false );
518 // parameters
519 aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTPLUS, true, &pPoolItem );
520 if( aState == SfxItemState::SET )
522 m_fPlusValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
525 aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTMINUS, true, &pPoolItem );
526 if( aState == SfxItemState::SET )
528 m_fMinusValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
530 if( m_eErrorKind != SvxChartKindError::Range &&
531 m_fPlusValue == m_fMinusValue )
532 m_xCbSyncPosNeg->set_active(true);
535 // indicator
536 aState = rInAttrs.GetItemState( SCHATTR_STAT_INDICATE, true, &pPoolItem );
537 m_bIndicatorUnique = ( aState != SfxItemState::DONTCARE );
538 if( aState == SfxItemState::SET)
539 m_eIndicate = static_cast<const SvxChartIndicateItem *>(pPoolItem)->GetValue();
541 if( m_bIndicatorUnique )
543 switch( m_eIndicate )
545 case SvxChartIndicate::NONE :
546 // no longer used, use both as default
547 m_eIndicate = SvxChartIndicate::Both;
548 [[fallthrough]]; // to BOTH
549 case SvxChartIndicate::Both :
550 m_xRbBoth->set_active(true); break;
551 case SvxChartIndicate::Up :
552 m_xRbPositive->set_active(true); break;
553 case SvxChartIndicate::Down :
554 m_xRbNegative->set_active(true); break;
557 else
559 m_xRbBoth->set_active( false );
560 m_xRbPositive->set_active( false );
561 m_xRbNegative->set_active( false );
564 // ranges
565 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_POS, true, &pPoolItem );
566 m_bRangePosUnique = ( aState != SfxItemState::DONTCARE );
567 if( aState == SfxItemState::SET )
569 OUString sRangePositive = static_cast< const SfxStringItem * >( pPoolItem )->GetValue();
570 m_xEdRangePositive->set_text( sRangePositive );
573 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_NEG, true, &pPoolItem );
574 m_bRangeNegUnique = ( aState != SfxItemState::DONTCARE );
575 if( aState == SfxItemState::SET )
577 OUString sRangeNegative = static_cast< const SfxStringItem * >( pPoolItem )->GetValue();
578 m_xEdRangeNegative->set_text( sRangeNegative );
579 if( m_eErrorKind == SvxChartKindError::Range &&
580 !sRangeNegative.isEmpty() &&
581 sRangeNegative == m_xEdRangePositive->get_text() )
582 m_xCbSyncPosNeg->set_active(true);
585 UpdateControlStates();
588 void ErrorBarResources::FillItemSet(SfxItemSet& rOutAttrs) const
590 if( m_bErrorKindUnique )
591 rOutAttrs.Put( SvxChartKindErrorItem( m_eErrorKind, SCHATTR_STAT_KIND_ERROR ));
592 if( m_bIndicatorUnique )
593 rOutAttrs.Put( SvxChartIndicateItem( m_eIndicate, SCHATTR_STAT_INDICATE ));
595 if( m_bErrorKindUnique )
597 if( m_eErrorKind == SvxChartKindError::Range )
599 OUString aPosRange;
600 OUString aNegRange;
601 if( m_bHasInternalDataProvider )
603 // the strings aPosRange/aNegRange have to be set to a non-empty
604 // arbitrary string to generate error-bar sequences
605 aPosRange = "x";
606 aNegRange = aPosRange;
608 else
610 aPosRange = m_xEdRangePositive->get_text();
611 if( m_xCbSyncPosNeg->get_active())
612 aNegRange = aPosRange;
613 else
614 aNegRange = m_xEdRangeNegative->get_text();
617 if( m_bRangePosUnique )
618 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS, aPosRange ));
619 if( m_bRangeNegUnique )
620 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG, aNegRange ));
622 else if( m_eErrorKind == SvxChartKindError::Const ||
623 m_eErrorKind == SvxChartKindError::Percent ||
624 m_eErrorKind == SvxChartKindError::BigError )
626 double fPosValue = static_cast< double >( m_xMfPositive->get_value(FieldUnit::NONE)) /
627 pow( 10.0, m_xMfPositive->get_digits());
628 double fNegValue = 0.0;
630 if( m_xCbSyncPosNeg->get_active())
631 fNegValue = fPosValue;
632 else
633 fNegValue = static_cast< double >( m_xMfNegative->get_value(FieldUnit::NONE)) /
634 pow( 10.0, m_xMfNegative->get_digits());
636 rOutAttrs.Put( SvxDoubleItem( fPosValue, SCHATTR_STAT_CONSTPLUS ));
637 rOutAttrs.Put( SvxDoubleItem( fNegValue, SCHATTR_STAT_CONSTMINUS ));
641 rOutAttrs.Put( SfxBoolItem( SCHATTR_STAT_ERRORBAR_TYPE , m_eErrorBarType == ERROR_BAR_Y ));
644 void ErrorBarResources::FillValueSets()
646 if( m_eErrorBarType == ERROR_BAR_Y )
648 m_xFiNegative->set_from_icon_name(BMP_INDICATE_DOWN);
649 m_xFiPositive->set_from_icon_name(BMP_INDICATE_UP);
650 m_xFiBoth->set_from_icon_name(BMP_INDICATE_BOTH_VERTI);
652 else if( m_eErrorBarType == ERROR_BAR_X )
654 m_xFiNegative->set_from_icon_name(BMP_INDICATE_LEFT);
655 m_xFiPositive->set_from_icon_name(BMP_INDICATE_RIGHT);
656 m_xFiBoth->set_from_icon_name(BMP_INDICATE_BOTH_HORI);
660 void ErrorBarResources::listeningFinished(
661 const OUString & rNewRange )
663 OSL_ASSERT(m_apRangeSelectionHelper);
664 if (!m_apRangeSelectionHelper)
665 return;
667 // rNewRange becomes invalid after removing the listener
668 OUString aRange( rNewRange );
670 // stop listening
671 m_apRangeSelectionHelper->stopRangeListening();
673 // change edit field
674 // if( m_pParentWindow )
675 // {
676 // m_pParentWindow->ToTop();
677 // m_pParentWindow->grab_focus();
678 // }
680 if( m_pCurrentRangeChoosingField )
682 m_pCurrentRangeChoosingField->set_text( aRange );
683 m_pCurrentRangeChoosingField->grab_focus();
684 PosValueChanged( *m_xMfPositive );
687 m_pCurrentRangeChoosingField = nullptr;
689 UpdateControlStates();
690 lcl_enableRangeChoosing(false, m_pController);
693 void ErrorBarResources::disposingRangeSelection()
695 OSL_ASSERT(m_apRangeSelectionHelper);
696 if (m_apRangeSelectionHelper)
697 m_apRangeSelectionHelper->stopRangeListening( false );
700 void ErrorBarResources::isRangeFieldContentValid(weld::Entry& rEdit)
702 OUString aRange( rEdit.get_text());
703 bool bIsValid = ( aRange.isEmpty() ) ||
704 ( m_apRangeSelectionHelper.get() &&
705 m_apRangeSelectionHelper->verifyCellRange( aRange ));
707 if( bIsValid || !rEdit.get_sensitive())
709 rEdit.set_message_type(weld::EntryMessageType::Normal);
711 else
713 rEdit.set_message_type(weld::EntryMessageType::Error);
717 } //namespace chart
719 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */