tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / dialogs / res_ErrorBar.cxx
blob1e30311ae28bbc06c8538e3fa0e16cdd5a8ab3cc
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 <vcl/weld.hxx>
26 #include <ChartModel.hxx>
27 #include "DialogModel.hxx"
29 #include <rtl/math.hxx>
30 #include <comphelper/diagnose_ex.hxx>
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
44 sal_uInt16 lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind )
46 sal_uInt16 nResult = 0;
47 switch( eErrorKind )
49 // for these cases select the default in the list box
50 case SvxChartKindError::NONE:
51 case SvxChartKindError::Percent:
52 case SvxChartKindError::Const:
53 case SvxChartKindError::Range:
54 case SvxChartKindError::Sigma:
55 nResult = CHART_LB_FUNCTION_STD_DEV;
56 break;
57 case SvxChartKindError::Variant:
58 nResult = CHART_LB_FUNCTION_VARIANCE;
59 break;
60 case SvxChartKindError::BigError:
61 nResult = CHART_LB_FUNCTION_ERROR_MARGIN;
62 break;
63 case SvxChartKindError::StdError:
64 nResult = CHART_LB_FUNCTION_STD_ERROR;
65 break;
67 return nResult;
69 } // anonymous namespace
71 namespace chart
74 ErrorBarResources::ErrorBarResources(weld::Builder* pParent, weld::DialogController* pController,
75 const SfxItemSet& rInAttrs, bool bNoneAvailable,
76 tErrorBarType eType /* = ERROR_BAR_Y */ )
77 : m_eErrorKind( SvxChartKindError::NONE )
78 , m_eIndicate( SvxChartIndicate::Both )
79 , m_bErrorKindUnique( true )
80 , m_bIndicatorUnique( true )
81 , m_bRangePosUnique( true )
82 , m_bRangeNegUnique( true )
83 , m_eErrorBarType( eType )
84 , m_nConstDecimalDigits( 1 )
85 , m_nConstSpinSize( 1 )
86 , m_fPlusValue(0.0)
87 , m_fMinusValue(0.0)
88 , m_pController(pController)
89 , m_pCurrentRangeChoosingField( nullptr )
90 , m_bHasInternalDataProvider( true )
91 , m_bEnableDataTableDialog( true )
92 , m_xRbNone(pParent->weld_radio_button(u"RB_NONE"_ustr))
93 , m_xRbConst(pParent->weld_radio_button(u"RB_CONST"_ustr))
94 , m_xRbPercent(pParent->weld_radio_button(u"RB_PERCENT"_ustr))
95 , m_xRbFunction(pParent->weld_radio_button(u"RB_FUNCTION"_ustr))
96 , m_xRbRange(pParent->weld_radio_button(u"RB_RANGE"_ustr))
97 , m_xLbFunction(pParent->weld_combo_box(u"LB_FUNCTION"_ustr))
98 , m_xFlParameters(pParent->weld_frame(u"framePARAMETERS"_ustr))
99 , m_xBxPositive(pParent->weld_widget(u"boxPOSITIVE"_ustr))
100 , m_xMfPositive(pParent->weld_metric_spin_button(u"MF_POSITIVE"_ustr, FieldUnit::NONE))
101 , m_xEdRangePositive(pParent->weld_entry(u"ED_RANGE_POSITIVE"_ustr))
102 , m_xIbRangePositive(pParent->weld_button(u"IB_RANGE_POSITIVE"_ustr))
103 , m_xBxNegative(pParent->weld_widget(u"boxNEGATIVE"_ustr))
104 , m_xMfNegative(pParent->weld_metric_spin_button(u"MF_NEGATIVE"_ustr, FieldUnit::NONE))
105 , m_xEdRangeNegative(pParent->weld_entry(u"ED_RANGE_NEGATIVE"_ustr))
106 , m_xIbRangeNegative(pParent->weld_button(u"IB_RANGE_NEGATIVE"_ustr))
107 , m_xCbSyncPosNeg(pParent->weld_check_button(u"CB_SYN_POS_NEG"_ustr))
108 , m_xRbBoth(pParent->weld_radio_button(u"RB_BOTH"_ustr))
109 , m_xRbPositive(pParent->weld_radio_button(u"RB_POSITIVE"_ustr))
110 , m_xRbNegative(pParent->weld_radio_button(u"RB_NEGATIVE"_ustr))
111 , m_xFiBoth(pParent->weld_image(u"FI_BOTH"_ustr))
112 , m_xFiPositive(pParent->weld_image(u"FI_POSITIVE"_ustr))
113 , m_xFiNegative(pParent->weld_image(u"FI_NEGATIVE"_ustr))
114 , m_xUIStringPos(pParent->weld_label(u"STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS"_ustr))
115 , m_xUIStringNeg(pParent->weld_label(u"STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS"_ustr))
116 , m_xUIStringRbRange(pParent->weld_label(u"STR_CONTROLTEXT_ERROR_BARS_FROM_DATA"_ustr))
118 if( bNoneAvailable )
119 m_xRbNone->connect_toggled(LINK(this, ErrorBarResources, CategoryChosen));
120 else
121 m_xRbNone->hide();
123 m_xRbConst->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
124 m_xRbPercent->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
125 m_xRbFunction->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
126 m_xRbRange->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
127 m_xLbFunction->connect_changed( LINK( this, ErrorBarResources, CategoryChosen2 ));
129 m_xCbSyncPosNeg->set_active( false );
130 m_xCbSyncPosNeg->connect_toggled( LINK( this, ErrorBarResources, SynchronizePosAndNeg ));
132 m_xMfPositive->connect_value_changed( LINK( this, ErrorBarResources, PosValueChanged ));
133 m_xEdRangePositive->connect_changed( LINK( this, ErrorBarResources, RangeChanged ));
134 m_xEdRangeNegative->connect_changed( LINK( this, ErrorBarResources, RangeChanged ));
136 m_xRbPositive->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
137 m_xRbNegative->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
138 m_xRbBoth->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
140 m_xIbRangePositive->connect_clicked( LINK( this, ErrorBarResources, ChooseRange ));
141 m_xIbRangeNegative->connect_clicked( LINK( this, ErrorBarResources, ChooseRange ));
143 FillValueSets();
144 Reset( rInAttrs );
147 ErrorBarResources::~ErrorBarResources()
151 void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType )
153 if( m_eErrorBarType != eNewType )
155 m_eErrorBarType = eNewType;
156 FillValueSets();
160 void ErrorBarResources::SetChartDocumentForRangeChoosing(
161 const rtl::Reference<::chart::ChartModel> & xChartDocument )
163 if( xChartDocument.is())
165 m_bHasInternalDataProvider = xChartDocument->hasInternalDataProvider();
166 uno::Reference< beans::XPropertySet > xProps( static_cast<cppu::OWeakObject*>(xChartDocument.get()), uno::UNO_QUERY );
167 if ( xProps.is() )
171 xProps->getPropertyValue(u"EnableDataTableDialog"_ustr) >>= m_bEnableDataTableDialog;
173 catch( const uno::Exception& )
175 TOOLS_WARN_EXCEPTION("chart2", "" );
179 m_apRangeSelectionHelper.reset( new RangeSelectionHelper( xChartDocument ));
181 // has internal data provider => rename "cell range" to "from data"
182 OSL_ASSERT(m_apRangeSelectionHelper);
183 if( m_bHasInternalDataProvider )
185 m_xRbRange->set_label(m_xUIStringRbRange->get_label());
186 m_xRbRange->set_help_id(HID_SCH_ERROR_BARS_FROM_DATA);
189 if( m_xRbRange->get_active())
191 isRangeFieldContentValid( *m_xEdRangePositive );
192 isRangeFieldContentValid( *m_xEdRangeNegative );
196 void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
198 if( fMinorStepWidth < 0 )
199 fMinorStepWidth = -fMinorStepWidth;
201 sal_Int32 nExponent = static_cast< sal_Int32 >( ::rtl::math::approxFloor( log10( fMinorStepWidth )));
202 if( nExponent <= 0 )
204 // one digit precision more
205 m_nConstDecimalDigits = static_cast< sal_uInt16 >( (-nExponent) + 1 );
206 m_nConstSpinSize = 10;
208 else
210 m_nConstDecimalDigits = 0;
211 m_nConstSpinSize = static_cast< sal_Int64 >( pow( 10.0, static_cast<int>(nExponent) ));
215 void ErrorBarResources::UpdateControlStates()
217 // function
218 bool bIsFunction = m_xRbFunction->get_active();
219 m_xLbFunction->set_sensitive( bIsFunction );
221 // range buttons
222 m_xRbRange->set_sensitive( !m_bHasInternalDataProvider || m_bEnableDataTableDialog );
223 bool bShowRange = m_xRbRange->get_active();
224 bool bCanChooseRange =
225 ( bShowRange &&
226 m_apRangeSelectionHelper &&
227 m_apRangeSelectionHelper->hasRangeSelection());
229 m_xMfPositive->set_visible( ! bShowRange );
230 m_xMfNegative->set_visible( ! bShowRange );
232 // use range but without range chooser => hide controls
233 m_xEdRangePositive->set_visible( bShowRange && ! m_bHasInternalDataProvider );
234 m_xIbRangePositive->set_visible( bCanChooseRange );
235 m_xEdRangeNegative->set_visible( bShowRange && ! m_bHasInternalDataProvider );
236 m_xIbRangeNegative->set_visible( bCanChooseRange );
238 bool bShowPosNegAndSync = ! (bShowRange && m_bHasInternalDataProvider);
239 m_xFlParameters->set_visible( bShowPosNegAndSync );
241 // unit for metric fields
242 bool bIsErrorMargin(
243 ( m_xRbFunction->get_active()) &&
244 ( m_xLbFunction->get_active() == CHART_LB_FUNCTION_ERROR_MARGIN ));
245 bool bIsPercentage( m_xRbPercent->get_active() || bIsErrorMargin );
246 FieldUnit eFieldUnit = FieldUnit::NONE;
248 if( bIsPercentage )
250 eFieldUnit = FieldUnit::PERCENT;
251 m_xMfPositive->set_digits( 1 );
252 m_xMfPositive->set_increments(10, 100, FieldUnit::NONE);
253 m_xMfNegative->set_digits( 1 );
254 m_xMfNegative->set_increments(10, 100, FieldUnit::NONE);
256 else
258 m_xMfPositive->set_digits( m_nConstDecimalDigits );
259 m_xMfPositive->set_increments(m_nConstSpinSize, m_nConstSpinSize * 10, FieldUnit::NONE);
260 m_xMfNegative->set_digits( m_nConstDecimalDigits );
261 m_xMfNegative->set_increments(m_nConstSpinSize, m_nConstSpinSize * 10, FieldUnit::NONE);
264 sal_Int32 nPlusValue = static_cast< sal_Int32 >( m_fPlusValue * pow(10.0,m_xMfPositive->get_digits()) );
265 sal_Int32 nMinusValue = static_cast< sal_Int32 >( m_fMinusValue * pow(10.0,m_xMfNegative->get_digits()) );
267 m_xMfPositive->set_value(nPlusValue, FieldUnit::NONE);
268 m_xMfNegative->set_value(nMinusValue, FieldUnit::NONE);
270 m_xMfPositive->set_unit(eFieldUnit);
271 m_xMfNegative->set_unit(eFieldUnit);
273 // positive and negative value fields
274 bool bPosEnabled = ( m_xRbPositive->get_active() || m_xRbBoth->get_active());
275 bool bNegEnabled = ( m_xRbNegative->get_active() || m_xRbBoth->get_active());
276 if( !( bPosEnabled || bNegEnabled ))
278 // all three controls are not checked -> ambiguous state
279 bPosEnabled = true;
280 bNegEnabled = true;
283 // functions with only one parameter
284 bool bOneParameterCategory =
285 bIsErrorMargin || m_xRbPercent->get_active();
286 if( bOneParameterCategory )
288 m_xCbSyncPosNeg->set_active(true);
291 if( m_xCbSyncPosNeg->get_active())
293 bPosEnabled = true;
294 bNegEnabled = false;
297 // all functions except error margin take no arguments
298 if( m_xRbFunction->get_active() && ( m_xLbFunction->get_active() != CHART_LB_FUNCTION_ERROR_MARGIN ))
300 bPosEnabled = false;
301 bNegEnabled = false;
304 // enable/disable pos/neg fields
305 m_xBxPositive->set_sensitive( bPosEnabled );
306 m_xBxNegative->set_sensitive( bNegEnabled );
307 if( bShowRange )
309 m_xEdRangePositive->set_sensitive( bPosEnabled );
310 m_xIbRangePositive->set_sensitive( bPosEnabled );
311 m_xEdRangeNegative->set_sensitive( bNegEnabled );
312 m_xIbRangeNegative->set_sensitive( bNegEnabled );
314 else
316 m_xMfPositive->set_sensitive( bPosEnabled );
317 m_xMfNegative->set_sensitive( bNegEnabled );
320 m_xCbSyncPosNeg->set_sensitive( !bOneParameterCategory && ( bPosEnabled || bNegEnabled ));
322 // mark invalid entries in the range fields
323 if( bShowRange && ! m_bHasInternalDataProvider )
325 isRangeFieldContentValid( *m_xEdRangePositive );
326 isRangeFieldContentValid( *m_xEdRangeNegative );
330 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen2, weld::ComboBox&, void )
332 CategoryChosen(*m_xRbConst);
335 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen, weld::Toggleable&, void )
337 m_bErrorKindUnique = true;
338 SvxChartKindError eOldError = m_eErrorKind;
340 if( m_xRbNone->get_active())
341 m_eErrorKind = SvxChartKindError::NONE;
342 else if( m_xRbConst->get_active())
343 m_eErrorKind = SvxChartKindError::Const;
344 else if( m_xRbPercent->get_active())
345 m_eErrorKind = SvxChartKindError::Percent;
346 else if( m_xRbRange->get_active())
347 m_eErrorKind = SvxChartKindError::Range;
348 else if( m_xRbFunction->get_active())
350 switch( m_xLbFunction->get_active())
352 case CHART_LB_FUNCTION_STD_ERROR:
353 m_eErrorKind = SvxChartKindError::StdError; break;
354 case CHART_LB_FUNCTION_STD_DEV:
355 m_eErrorKind = SvxChartKindError::Sigma; break;
356 case CHART_LB_FUNCTION_VARIANCE:
357 m_eErrorKind = SvxChartKindError::Variant; break;
358 case CHART_LB_FUNCTION_ERROR_MARGIN:
359 m_eErrorKind = SvxChartKindError::BigError; break;
360 default:
361 m_bErrorKindUnique = false;
364 else
366 OSL_FAIL( "Unknown category chosen" );
367 m_bErrorKindUnique = false;
370 // changed to range
371 if( m_eErrorKind == SvxChartKindError::Range &&
372 eOldError != SvxChartKindError::Range )
374 m_xCbSyncPosNeg->set_active(
375 (!m_xEdRangePositive->get_text().isEmpty()) &&
376 m_xEdRangePositive->get_text() == m_xEdRangeNegative->get_text());
378 // changed from range
379 else if( m_eErrorKind != SvxChartKindError::Range &&
380 eOldError == SvxChartKindError::Range )
382 m_xCbSyncPosNeg->set_active( m_xMfPositive->get_value(FieldUnit::NONE) == m_xMfNegative->get_value(FieldUnit::NONE));
385 UpdateControlStates();
388 IMPL_LINK_NOARG(ErrorBarResources, SynchronizePosAndNeg, weld::Toggleable&, void)
390 UpdateControlStates();
391 PosValueChanged( *m_xMfPositive );
394 IMPL_LINK_NOARG(ErrorBarResources, PosValueChanged, weld::MetricSpinButton&, void)
396 if( m_xCbSyncPosNeg->get_active())
398 if( m_xRbRange->get_active())
400 m_xEdRangeNegative->set_text( m_xEdRangePositive->get_text());
401 m_bRangeNegUnique = m_bRangePosUnique;
403 else
404 m_xMfNegative->set_value(m_xMfPositive->get_value(FieldUnit::NONE), FieldUnit::NONE);
408 IMPL_LINK_NOARG(ErrorBarResources, IndicatorChanged, weld::Toggleable&, void)
410 m_bIndicatorUnique = true;
411 if( m_xRbBoth->get_active())
412 m_eIndicate = SvxChartIndicate::Both;
413 else if( m_xRbPositive->get_active())
414 m_eIndicate = SvxChartIndicate::Up;
415 else if( m_xRbNegative->get_active())
416 m_eIndicate = SvxChartIndicate::Down;
417 else
418 m_bIndicatorUnique = false;
420 UpdateControlStates();
423 IMPL_LINK(ErrorBarResources, ChooseRange, weld::Button&, rButton, void)
425 OSL_ASSERT(m_apRangeSelectionHelper);
426 if (!m_apRangeSelectionHelper)
427 return;
428 OSL_ASSERT( m_pCurrentRangeChoosingField == nullptr );
430 OUString aUIString;
432 if (&rButton == m_xIbRangePositive.get())
434 m_pCurrentRangeChoosingField = m_xEdRangePositive.get();
435 aUIString = m_xUIStringPos->get_label();
437 else
439 m_pCurrentRangeChoosingField = m_xEdRangeNegative.get();
440 aUIString = m_xUIStringNeg->get_label();
443 enableRangeChoosing(true, m_pController);
444 m_apRangeSelectionHelper->chooseRange(
445 m_pCurrentRangeChoosingField->get_text(),
446 aUIString, *this );
449 IMPL_LINK( ErrorBarResources, RangeChanged, weld::Entry&, rEdit, void )
451 if( &rEdit == m_xEdRangePositive.get() )
453 m_bRangePosUnique = true;
454 PosValueChanged( *m_xMfPositive );
456 else
458 m_bRangeNegUnique = true;
461 isRangeFieldContentValid( rEdit );
464 void ErrorBarResources::Reset(const SfxItemSet& rInAttrs)
466 const SfxPoolItem *pPoolItem = nullptr;
468 // category
469 m_eErrorKind = SvxChartKindError::NONE;
470 SfxItemState aState = rInAttrs.GetItemState( SCHATTR_STAT_KIND_ERROR, true, &pPoolItem );
471 m_bErrorKindUnique = ( aState != SfxItemState::INVALID );
473 if( aState == SfxItemState::SET )
474 m_eErrorKind = static_cast<const SvxChartKindErrorItem*>(pPoolItem)->GetValue();
476 m_xLbFunction->set_active( lcl_getLbEntryPosByErrorKind( m_eErrorKind ));
478 if( m_bErrorKindUnique )
480 switch( m_eErrorKind )
482 case SvxChartKindError::NONE:
483 m_xRbNone->set_active(true);
484 break;
485 case SvxChartKindError::Percent:
486 m_xRbPercent->set_active(true);
487 break;
488 case SvxChartKindError::Const:
489 m_xRbConst->set_active(true);
490 break;
491 case SvxChartKindError::StdError:
492 case SvxChartKindError::Variant:
493 case SvxChartKindError::Sigma:
494 case SvxChartKindError::BigError:
495 m_xRbFunction->set_active(true);
496 break;
497 case SvxChartKindError::Range:
498 m_xRbRange->set_active(true);
499 break;
502 else
504 m_xRbNone->set_active( false );
505 m_xRbConst->set_active( false );
506 m_xRbPercent->set_active( false );
507 m_xRbFunction->set_active( false );
510 // parameters
511 if( const SvxDoubleItem* pDoubleItem = rInAttrs.GetItemIfSet( SCHATTR_STAT_CONSTPLUS ) )
513 m_fPlusValue = pDoubleItem->GetValue();
516 if( const SvxDoubleItem* pStatItem = rInAttrs.GetItemIfSet( SCHATTR_STAT_CONSTMINUS ) )
518 m_fMinusValue = pStatItem->GetValue();
520 if( m_eErrorKind != SvxChartKindError::Range &&
521 m_fPlusValue == m_fMinusValue )
522 m_xCbSyncPosNeg->set_active(true);
525 // indicator
526 aState = rInAttrs.GetItemState( SCHATTR_STAT_INDICATE, true, &pPoolItem );
527 m_bIndicatorUnique = ( aState != SfxItemState::INVALID );
528 if( aState == SfxItemState::SET)
529 m_eIndicate = static_cast<const SvxChartIndicateItem *>(pPoolItem)->GetValue();
531 if( m_bIndicatorUnique )
533 switch( m_eIndicate )
535 case SvxChartIndicate::NONE :
536 // no longer used, use both as default
537 m_eIndicate = SvxChartIndicate::Both;
538 [[fallthrough]]; // to BOTH
539 case SvxChartIndicate::Both :
540 m_xRbBoth->set_active(true); break;
541 case SvxChartIndicate::Up :
542 m_xRbPositive->set_active(true); break;
543 case SvxChartIndicate::Down :
544 m_xRbNegative->set_active(true); break;
547 else
549 m_xRbBoth->set_active( false );
550 m_xRbPositive->set_active( false );
551 m_xRbNegative->set_active( false );
554 // ranges
555 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_POS, true, &pPoolItem );
556 m_bRangePosUnique = ( aState != SfxItemState::INVALID );
557 if( aState == SfxItemState::SET )
559 OUString sRangePositive = static_cast< const SfxStringItem * >( pPoolItem )->GetValue();
560 m_xEdRangePositive->set_text( sRangePositive );
563 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_NEG, true, &pPoolItem );
564 m_bRangeNegUnique = ( aState != SfxItemState::INVALID );
565 if( aState == SfxItemState::SET )
567 OUString sRangeNegative = static_cast< const SfxStringItem * >( pPoolItem )->GetValue();
568 m_xEdRangeNegative->set_text( sRangeNegative );
569 if( m_eErrorKind == SvxChartKindError::Range &&
570 !sRangeNegative.isEmpty() &&
571 sRangeNegative == m_xEdRangePositive->get_text() )
572 m_xCbSyncPosNeg->set_active(true);
575 UpdateControlStates();
578 void ErrorBarResources::FillItemSet(SfxItemSet& rOutAttrs) const
580 if( m_bErrorKindUnique )
581 rOutAttrs.Put( SvxChartKindErrorItem( m_eErrorKind, SCHATTR_STAT_KIND_ERROR ));
582 if( m_bIndicatorUnique )
583 rOutAttrs.Put( SvxChartIndicateItem( m_eIndicate, SCHATTR_STAT_INDICATE ));
585 if( m_bErrorKindUnique )
587 if( m_eErrorKind == SvxChartKindError::Range )
589 OUString aPosRange;
590 OUString aNegRange;
591 if( m_bHasInternalDataProvider )
593 // the strings aPosRange/aNegRange have to be set to a non-empty
594 // arbitrary string to generate error-bar sequences
595 aPosRange = "x";
596 aNegRange = aPosRange;
598 else
600 aPosRange = m_xEdRangePositive->get_text();
601 if( m_xCbSyncPosNeg->get_active())
602 aNegRange = aPosRange;
603 else
604 aNegRange = m_xEdRangeNegative->get_text();
607 if( m_bRangePosUnique )
608 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS, aPosRange ));
609 if( m_bRangeNegUnique )
610 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG, aNegRange ));
612 else if( m_eErrorKind == SvxChartKindError::Const ||
613 m_eErrorKind == SvxChartKindError::Percent ||
614 m_eErrorKind == SvxChartKindError::BigError )
616 double fPosValue = static_cast< double >( m_xMfPositive->get_value(FieldUnit::NONE)) /
617 pow( 10.0, m_xMfPositive->get_digits());
618 double fNegValue = 0.0;
620 if( m_xCbSyncPosNeg->get_active())
621 fNegValue = fPosValue;
622 else
623 fNegValue = static_cast< double >( m_xMfNegative->get_value(FieldUnit::NONE)) /
624 pow( 10.0, m_xMfNegative->get_digits());
626 rOutAttrs.Put( SvxDoubleItem( fPosValue, SCHATTR_STAT_CONSTPLUS ));
627 rOutAttrs.Put( SvxDoubleItem( fNegValue, SCHATTR_STAT_CONSTMINUS ));
631 rOutAttrs.Put( SfxBoolItem( SCHATTR_STAT_ERRORBAR_TYPE , m_eErrorBarType == ERROR_BAR_Y ));
634 void ErrorBarResources::FillValueSets()
636 if( m_eErrorBarType == ERROR_BAR_Y )
638 m_xFiNegative->set_from_icon_name(BMP_INDICATE_DOWN);
639 m_xFiPositive->set_from_icon_name(BMP_INDICATE_UP);
640 m_xFiBoth->set_from_icon_name(BMP_INDICATE_BOTH_VERTI);
642 else if( m_eErrorBarType == ERROR_BAR_X )
644 m_xFiNegative->set_from_icon_name(BMP_INDICATE_LEFT);
645 m_xFiPositive->set_from_icon_name(BMP_INDICATE_RIGHT);
646 m_xFiBoth->set_from_icon_name(BMP_INDICATE_BOTH_HORI);
650 void ErrorBarResources::listeningFinished(
651 const OUString & rNewRange )
653 OSL_ASSERT(m_apRangeSelectionHelper);
654 if (!m_apRangeSelectionHelper)
655 return;
657 // rNewRange becomes invalid after removing the listener
658 OUString aRange( rNewRange );
660 // stop listening
661 m_apRangeSelectionHelper->stopRangeListening();
663 // change edit field
664 // if( m_pParentWindow )
665 // {
666 // m_pParentWindow->ToTop();
667 // m_pParentWindow->grab_focus();
668 // }
670 if( m_pCurrentRangeChoosingField )
672 m_pCurrentRangeChoosingField->set_text( aRange );
673 m_pCurrentRangeChoosingField->grab_focus();
674 PosValueChanged( *m_xMfPositive );
677 m_pCurrentRangeChoosingField = nullptr;
679 UpdateControlStates();
680 enableRangeChoosing(false, m_pController);
683 void ErrorBarResources::disposingRangeSelection()
685 OSL_ASSERT(m_apRangeSelectionHelper);
686 if (m_apRangeSelectionHelper)
687 m_apRangeSelectionHelper->stopRangeListening( false );
690 void ErrorBarResources::isRangeFieldContentValid(weld::Entry& rEdit)
692 OUString aRange( rEdit.get_text());
693 bool bIsValid = ( aRange.isEmpty() ) ||
694 ( m_apRangeSelectionHelper &&
695 m_apRangeSelectionHelper->verifyCellRange( aRange ));
697 if( bIsValid || !rEdit.get_sensitive())
699 rEdit.set_message_type(weld::EntryMessageType::Normal);
701 else
703 rEdit.set_message_type(weld::EntryMessageType::Error);
707 } //namespace chart
709 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */