Debian Codegraph @

chart2/source/controller/dialogs/res_ErrorBar.cxx

raw
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 <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
28 #include <rtl/math.hxx>
29 #include <comphelper/diagnose_ex.hxx>
30 #include <osl/diagnose.h>
31 #include <svl/stritem.hxx>
32
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
37
38 using namespace ::com::sun::star;
39
40 namespace
41 {
42
43 sal_uInt16 lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind )
44 {
45 sal_uInt16 nResult = 0;
46 switch( eErrorKind )
47 {
48 // for these cases select the default in the list box
49 case SvxChartKindError::NONE:
50 case SvxChartKindError::Percent:
51 case SvxChartKindError::Const:
52 case SvxChartKindError::Range:
53 case SvxChartKindError::Sigma:
54 nResult = CHART_LB_FUNCTION_STD_DEV;
55 break;
56 case SvxChartKindError::Variant:
57 nResult = CHART_LB_FUNCTION_VARIANCE;
58 break;
59 case SvxChartKindError::BigError:
60 nResult = CHART_LB_FUNCTION_ERROR_MARGIN;
61 break;
62 case SvxChartKindError::StdError:
63 nResult = CHART_LB_FUNCTION_STD_ERROR;
64 break;
65 }
66 return nResult;
67 }
68 } // anonymous namespace
69
70 namespace chart
71 {
72
73 ErrorBarResources::ErrorBarResources(weld::Builder* pParent, weld::DialogController* pController,
74 const SfxItemSet& rInAttrs, bool bNoneAvailable,
75 tErrorBarType eType /* = ERROR_BAR_Y */ )
76 : m_eErrorKind( SvxChartKindError::NONE )
77 , m_eIndicate( SvxChartIndicate::Both )
78 , m_bErrorKindUnique( true )
79 , m_bIndicatorUnique( true )
80 , m_bRangePosUnique( true )
81 , m_bRangeNegUnique( true )
82 , m_eErrorBarType( eType )
83 , m_nConstDecimalDigits( 1 )
84 , m_nConstSpinSize( 1 )
85 , m_fPlusValue(0.0)
86 , m_fMinusValue(0.0)
87 , m_pController(pController)
88 , m_pCurrentRangeChoosingField( nullptr )
89 , m_bHasInternalDataProvider( true )
90 , m_bEnableDataTableDialog( true )
91 , m_xRbNone(pParent->weld_radio_button(u"RB_NONE"_ustr))
92 , m_xRbConst(pParent->weld_radio_button(u"RB_CONST"_ustr))
93 , m_xRbPercent(pParent->weld_radio_button(u"RB_PERCENT"_ustr))
94 , m_xRbFunction(pParent->weld_radio_button(u"RB_FUNCTION"_ustr))
95 , m_xRbRange(pParent->weld_radio_button(u"RB_RANGE"_ustr))
96 , m_xLbFunction(pParent->weld_combo_box(u"LB_FUNCTION"_ustr))
97 , m_xFlParameters(pParent->weld_frame(u"framePARAMETERS"_ustr))
98 , m_xBxPositive(pParent->weld_widget(u"boxPOSITIVE"_ustr))
99 , m_xMfPositive(pParent->weld_metric_spin_button(u"MF_POSITIVE"_ustr, FieldUnit::NONE))
100 , m_xEdRangePositive(pParent->weld_entry(u"ED_RANGE_POSITIVE"_ustr))
101 , m_xIbRangePositive(pParent->weld_button(u"IB_RANGE_POSITIVE"_ustr))
102 , m_xBxNegative(pParent->weld_widget(u"boxNEGATIVE"_ustr))
103 , m_xMfNegative(pParent->weld_metric_spin_button(u"MF_NEGATIVE"_ustr, FieldUnit::NONE))
104 , m_xEdRangeNegative(pParent->weld_entry(u"ED_RANGE_NEGATIVE"_ustr))
105 , m_xIbRangeNegative(pParent->weld_button(u"IB_RANGE_NEGATIVE"_ustr))
106 , m_xCbSyncPosNeg(pParent->weld_check_button(u"CB_SYN_POS_NEG"_ustr))
107 , m_xRbBoth(pParent->weld_radio_button(u"RB_BOTH"_ustr))
108 , m_xRbPositive(pParent->weld_radio_button(u"RB_POSITIVE"_ustr))
109 , m_xRbNegative(pParent->weld_radio_button(u"RB_NEGATIVE"_ustr))
110 , m_xFiBoth(pParent->weld_image(u"FI_BOTH"_ustr))
111 , m_xFiPositive(pParent->weld_image(u"FI_POSITIVE"_ustr))
112 , m_xFiNegative(pParent->weld_image(u"FI_NEGATIVE"_ustr))
113 , m_xUIStringPos(pParent->weld_label(u"STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS"_ustr))
114 , m_xUIStringNeg(pParent->weld_label(u"STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS"_ustr))
115 , m_xUIStringRbRange(pParent->weld_label(u"STR_CONTROLTEXT_ERROR_BARS_FROM_DATA"_ustr))
116 {
117 if( bNoneAvailable )
118 m_xRbNone->connect_toggled(LINK(this, ErrorBarResources, CategoryChosen));
119 else
120 m_xRbNone->hide();
121
122 m_xRbConst->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
123 m_xRbPercent->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
124 m_xRbFunction->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
125 m_xRbRange->connect_toggled( LINK( this, ErrorBarResources, CategoryChosen ));
126 m_xLbFunction->connect_changed( LINK( this, ErrorBarResources, CategoryChosen2 ));
127
128 m_xCbSyncPosNeg->set_active( false );
129 m_xCbSyncPosNeg->connect_toggled( LINK( this, ErrorBarResources, SynchronizePosAndNeg ));
130
131 m_xMfPositive->connect_value_changed( LINK( this, ErrorBarResources, PosValueChanged ));
132 m_xEdRangePositive->connect_changed( LINK( this, ErrorBarResources, RangeChanged ));
133 m_xEdRangeNegative->connect_changed( LINK( this, ErrorBarResources, RangeChanged ));
134
135 m_xRbPositive->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
136 m_xRbNegative->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
137 m_xRbBoth->connect_toggled( LINK( this, ErrorBarResources, IndicatorChanged ));
138
139 m_xIbRangePositive->connect_clicked( LINK( this, ErrorBarResources, ChooseRange ));
140 m_xIbRangeNegative->connect_clicked( LINK( this, ErrorBarResources, ChooseRange ));
141
142 FillValueSets();
143 Reset( rInAttrs );
144 }
145
146 ErrorBarResources::~ErrorBarResources()
147 {
148 }
149
150 void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType )
151 {
152 if( m_eErrorBarType != eNewType )
153 {
154 m_eErrorBarType = eNewType;
155 FillValueSets();
156 }
157 }
158
159 void ErrorBarResources::SetChartDocumentForRangeChoosing(
160 const rtl::Reference<::chart::ChartModel> & xChartDocument )
161 {
162 if( xChartDocument.is())
163 {
164 m_bHasInternalDataProvider = xChartDocument->hasInternalDataProvider();
165 uno::Reference< beans::XPropertySet > xProps( static_cast<cppu::OWeakObject*>(xChartDocument.get()), uno::UNO_QUERY );
166 if ( xProps.is() )
167 {
168 try
169 {
170 xProps->getPropertyValue(u"EnableDataTableDialog"_ustr) >>= m_bEnableDataTableDialog;
171 }
172 catch( const uno::Exception& )
173 {
174 TOOLS_WARN_EXCEPTION("chart2", "" );
175 }
176 }
177 }
178 m_apRangeSelectionHelper.reset( new RangeSelectionHelper( xChartDocument ));
179
180 // has internal data provider => rename "cell range" to "from data"
181 OSL_ASSERT(m_apRangeSelectionHelper);
182 if( m_bHasInternalDataProvider )
183 {
184 m_xRbRange->set_label(m_xUIStringRbRange->get_label());
185 m_xRbRange->set_help_id(HID_SCH_ERROR_BARS_FROM_DATA);
186 }
187
188 if( m_xRbRange->get_active())
189 {
190 isRangeFieldContentValid( *m_xEdRangePositive );
191 isRangeFieldContentValid( *m_xEdRangeNegative );
192 }
193 }
194
195 void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
196 {
197 if( fMinorStepWidth < 0 )
198 fMinorStepWidth = -fMinorStepWidth;
199
200 sal_Int32 nExponent = static_cast< sal_Int32 >( ::rtl::math::approxFloor( log10( fMinorStepWidth )));
201 if( nExponent <= 0 )
202 {
203 // one digit precision more
204 m_nConstDecimalDigits = static_cast< sal_uInt16 >( (-nExponent) + 1 );
205 m_nConstSpinSize = 10;
206 }
207 else
208 {
209 m_nConstDecimalDigits = 0;
210 m_nConstSpinSize = static_cast< sal_Int64 >( pow( 10.0, static_cast<int>(nExponent) ));
211 }
212 }
213
214 void ErrorBarResources::UpdateControlStates()
215 {
216 // function
217 bool bIsFunction = m_xRbFunction->get_active();
218 m_xLbFunction->set_sensitive( bIsFunction );
219
220 // range buttons
221 m_xRbRange->set_sensitive( !m_bHasInternalDataProvider || m_bEnableDataTableDialog );
222 bool bShowRange = m_xRbRange->get_active();
223 bool bCanChooseRange =
224 ( bShowRange &&
225 m_apRangeSelectionHelper &&
226 m_apRangeSelectionHelper->hasRangeSelection());
227
228 m_xMfPositive->set_visible( ! bShowRange );
229 m_xMfNegative->set_visible( ! bShowRange );
230
231 // use range but without range chooser => hide controls
232 m_xEdRangePositive->set_visible( bShowRange && ! m_bHasInternalDataProvider );
233 m_xIbRangePositive->set_visible( bCanChooseRange );
234 m_xEdRangeNegative->set_visible( bShowRange && ! m_bHasInternalDataProvider );
235 m_xIbRangeNegative->set_visible( bCanChooseRange );
236
237 bool bShowPosNegAndSync = ! (bShowRange && m_bHasInternalDataProvider);
238 m_xFlParameters->set_visible( bShowPosNegAndSync );
239
240 // unit for metric fields
241 bool bIsErrorMargin(
242 ( m_xRbFunction->get_active()) &&
243 ( m_xLbFunction->get_active() == CHART_LB_FUNCTION_ERROR_MARGIN ));
244 bool bIsPercentage( m_xRbPercent->get_active() || bIsErrorMargin );
245 FieldUnit eFieldUnit = FieldUnit::NONE;
246
247 if( bIsPercentage )
248 {
249 eFieldUnit = FieldUnit::PERCENT;
250 m_xMfPositive->set_digits( 1 );
251 m_xMfPositive->set_increments(10, 100, FieldUnit::NONE);
252 m_xMfNegative->set_digits( 1 );
253 m_xMfNegative->set_increments(10, 100, FieldUnit::NONE);
254 }
255 else
256 {
257 m_xMfPositive->set_digits( m_nConstDecimalDigits );
258 m_xMfPositive->set_increments(m_nConstSpinSize, m_nConstSpinSize * 10, FieldUnit::NONE);
259 m_xMfNegative->set_digits( m_nConstDecimalDigits );
260 m_xMfNegative->set_increments(m_nConstSpinSize, m_nConstSpinSize * 10, FieldUnit::NONE);
261 }
262
263 sal_Int32 nPlusValue = static_cast< sal_Int32 >( m_fPlusValue * pow(10.0,m_xMfPositive->get_digits()) );
264 sal_Int32 nMinusValue = static_cast< sal_Int32 >( m_fMinusValue * pow(10.0,m_xMfNegative->get_digits()) );
265
266 m_xMfPositive->set_value(nPlusValue, FieldUnit::NONE);
267 m_xMfNegative->set_value(nMinusValue, FieldUnit::NONE);
268
269 m_xMfPositive->set_unit(eFieldUnit);
270 m_xMfNegative->set_unit(eFieldUnit);
271
272 // positive and negative value fields
273 bool bPosEnabled = ( m_xRbPositive->get_active() || m_xRbBoth->get_active());
274 bool bNegEnabled = ( m_xRbNegative->get_active() || m_xRbBoth->get_active());
275 if( !( bPosEnabled || bNegEnabled ))
276 {
277 // all three controls are not checked -> ambiguous state
278 bPosEnabled = true;
279 bNegEnabled = true;
280 }
281
282 // functions with only one parameter
283 bool bOneParameterCategory =
284 bIsErrorMargin || m_xRbPercent->get_active();
285 if( bOneParameterCategory )
286 {
287 m_xCbSyncPosNeg->set_active(true);
288 }
289
290 if( m_xCbSyncPosNeg->get_active())
291 {
292 bPosEnabled = true;
293 bNegEnabled = false;
294 }
295
296 // all functions except error margin take no arguments
297 if( m_xRbFunction->get_active() && ( m_xLbFunction->get_active() != CHART_LB_FUNCTION_ERROR_MARGIN ))
298 {
299 bPosEnabled = false;
300 bNegEnabled = false;
301 }
302
303 // enable/disable pos/neg fields
304 m_xBxPositive->set_sensitive( bPosEnabled );
305 m_xBxNegative->set_sensitive( bNegEnabled );
306 if( bShowRange )
307 {
308 m_xEdRangePositive->set_sensitive( bPosEnabled );
309 m_xIbRangePositive->set_sensitive( bPosEnabled );
310 m_xEdRangeNegative->set_sensitive( bNegEnabled );
311 m_xIbRangeNegative->set_sensitive( bNegEnabled );
312 }
313 else
314 {
315 m_xMfPositive->set_sensitive( bPosEnabled );
316 m_xMfNegative->set_sensitive( bNegEnabled );
317 }
318
319 m_xCbSyncPosNeg->set_sensitive( !bOneParameterCategory && ( bPosEnabled || bNegEnabled ));
320
321 // mark invalid entries in the range fields
322 if( bShowRange && ! m_bHasInternalDataProvider )
323 {
324 isRangeFieldContentValid( *m_xEdRangePositive );
325 isRangeFieldContentValid( *m_xEdRangeNegative );
326 }
327 }
328
329 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen2, weld::ComboBox&, void )
330 {
331 CategoryChosen(*m_xRbConst);
332 }
333
334 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen, weld::Toggleable&, void )
335 {
336 m_bErrorKindUnique = true;
337 SvxChartKindError eOldError = m_eErrorKind;
338
339 if( m_xRbNone->get_active())
340 m_eErrorKind = SvxChartKindError::NONE;
341 else if( m_xRbConst->get_active())
342 m_eErrorKind = SvxChartKindError::Const;
343 else if( m_xRbPercent->get_active())
344 m_eErrorKind = SvxChartKindError::Percent;
345 else if( m_xRbRange->get_active())
346 m_eErrorKind = SvxChartKindError::Range;
347 else if( m_xRbFunction->get_active())
348 {
349 switch( m_xLbFunction->get_active())
350 {
351 case CHART_LB_FUNCTION_STD_ERROR:
352 m_eErrorKind = SvxChartKindError::StdError; break;
353 case CHART_LB_FUNCTION_STD_DEV:
354 m_eErrorKind = SvxChartKindError::Sigma; break;
355 case CHART_LB_FUNCTION_VARIANCE:
356 m_eErrorKind = SvxChartKindError::Variant; break;
357 case CHART_LB_FUNCTION_ERROR_MARGIN:
358 m_eErrorKind = SvxChartKindError::BigError; break;
359 default:
360 m_bErrorKindUnique = false;
361 }
362 }
363 else
364 {
365 OSL_FAIL( "Unknown category chosen" );
366 m_bErrorKindUnique = false;
367 }
368
369 // changed to range
370 if( m_eErrorKind == SvxChartKindError::Range &&
371 eOldError != SvxChartKindError::Range )
372 {
373 m_xCbSyncPosNeg->set_active(
374 (!m_xEdRangePositive->get_text().isEmpty()) &&
375 m_xEdRangePositive->get_text() == m_xEdRangeNegative->get_text());
376 }
377 // changed from range
378 else if( m_eErrorKind != SvxChartKindError::Range &&
379 eOldError == SvxChartKindError::Range )
380 {
381 m_xCbSyncPosNeg->set_active( m_xMfPositive->get_value(FieldUnit::NONE) == m_xMfNegative->get_value(FieldUnit::NONE));
382 }
383
384 UpdateControlStates();
385 }
386
387 IMPL_LINK_NOARG(ErrorBarResources, SynchronizePosAndNeg, weld::Toggleable&, void)
388 {
389 UpdateControlStates();
390 PosValueChanged( *m_xMfPositive );
391 }
392
393 IMPL_LINK_NOARG(ErrorBarResources, PosValueChanged, weld::MetricSpinButton&, void)
394 {
395 if( m_xCbSyncPosNeg->get_active())
396 {
397 if( m_xRbRange->get_active())
398 {
399 m_xEdRangeNegative->set_text( m_xEdRangePositive->get_text());
400 m_bRangeNegUnique = m_bRangePosUnique;
401 }
402 else
403 m_xMfNegative->set_value(m_xMfPositive->get_value(FieldUnit::NONE), FieldUnit::NONE);
404 }
405 }
406
407 IMPL_LINK_NOARG(ErrorBarResources, IndicatorChanged, weld::Toggleable&, void)
408 {
409 m_bIndicatorUnique = true;
410 if( m_xRbBoth->get_active())
411 m_eIndicate = SvxChartIndicate::Both;
412 else if( m_xRbPositive->get_active())
413 m_eIndicate = SvxChartIndicate::Up;
414 else if( m_xRbNegative->get_active())
415 m_eIndicate = SvxChartIndicate::Down;
416 else
417 m_bIndicatorUnique = false;
418
419 UpdateControlStates();
420 }
421
422 IMPL_LINK(ErrorBarResources, ChooseRange, weld::Button&, rButton, void)
423 {
424 OSL_ASSERT(m_apRangeSelectionHelper);
425 if (!m_apRangeSelectionHelper)
426 return;
427 OSL_ASSERT( m_pCurrentRangeChoosingField == nullptr );
428
429 OUString aUIString;
430
431 if (&rButton == m_xIbRangePositive.get())
432 {
433 m_pCurrentRangeChoosingField = m_xEdRangePositive.get();
434 aUIString = m_xUIStringPos->get_label();
435 }
436 else
437 {
438 m_pCurrentRangeChoosingField = m_xEdRangeNegative.get();
439 aUIString = m_xUIStringNeg->get_label();
440 }
441
442 enableRangeChoosing(true, m_pController);
443 m_apRangeSelectionHelper->chooseRange(
444 m_pCurrentRangeChoosingField->get_text(),
445 aUIString, *this );
446 }
447
448 IMPL_LINK( ErrorBarResources, RangeChanged, weld::Entry&, rEdit, void )
449 {
450 if( &rEdit == m_xEdRangePositive.get() )
451 {
452 m_bRangePosUnique = true;
453 PosValueChanged( *m_xMfPositive );
454 }
455 else
456 {
457 m_bRangeNegUnique = true;
458 }
459
460 isRangeFieldContentValid( rEdit );
461 }
462
463 void ErrorBarResources::Reset(const SfxItemSet& rInAttrs)
464 {
465 const SfxPoolItem *pPoolItem = nullptr;
466
467 // category
468 m_eErrorKind = SvxChartKindError::NONE;
469 SfxItemState aState = rInAttrs.GetItemState( SCHATTR_STAT_KIND_ERROR, true, &pPoolItem );
470 m_bErrorKindUnique = ( aState != SfxItemState::INVALID );
471
472 if( aState == SfxItemState::SET )
473 m_eErrorKind = static_cast<const SvxChartKindErrorItem*>(pPoolItem)->GetValue();
474
475 m_xLbFunction->set_active( lcl_getLbEntryPosByErrorKind( m_eErrorKind ));
476
477 if( m_bErrorKindUnique )
478 {
479 switch( m_eErrorKind )
480 {
481 case SvxChartKindError::NONE:
482 m_xRbNone->set_active(true);
483 break;
484 case SvxChartKindError::Percent:
485 m_xRbPercent->set_active(true);
486 break;
487 case SvxChartKindError::Const:
488 m_xRbConst->set_active(true);
489 break;
490 case SvxChartKindError::StdError:
491 case SvxChartKindError::Variant:
492 case SvxChartKindError::Sigma:
493 case SvxChartKindError::BigError:
494 m_xRbFunction->set_active(true);
495 break;
496 case SvxChartKindError::Range:
497 m_xRbRange->set_active(true);
498 break;
499 }
500 }
501 else
502 {
503 m_xRbNone->set_active( false );
504 m_xRbConst->set_active( false );
505 m_xRbPercent->set_active( false );
506 m_xRbFunction->set_active( false );
507 }
508
509 // parameters
510 if( const SvxDoubleItem* pDoubleItem = rInAttrs.GetItemIfSet( SCHATTR_STAT_CONSTPLUS ) )
511 {
512 m_fPlusValue = pDoubleItem->GetValue();
513 }
514
515 if( const SvxDoubleItem* pStatItem = rInAttrs.GetItemIfSet( SCHATTR_STAT_CONSTMINUS ) )
516 {
517 m_fMinusValue = pStatItem->GetValue();
518
519 if( m_eErrorKind != SvxChartKindError::Range &&
520 m_fPlusValue == m_fMinusValue )
521 m_xCbSyncPosNeg->set_active(true);
522 }
523
524 // indicator
525 aState = rInAttrs.GetItemState( SCHATTR_STAT_INDICATE, true, &pPoolItem );
526 m_bIndicatorUnique = ( aState != SfxItemState::INVALID );
527 if( aState == SfxItemState::SET)
528 m_eIndicate = static_cast<const SvxChartIndicateItem *>(pPoolItem)->GetValue();
529
530 if( m_bIndicatorUnique )
531 {
532 switch( m_eIndicate )
533 {
534 case SvxChartIndicate::NONE :
535 // no longer used, use both as default
536 m_eIndicate = SvxChartIndicate::Both;
537 [[fallthrough]]; // to BOTH
538 case SvxChartIndicate::Both :
539 m_xRbBoth->set_active(true); break;
540 case SvxChartIndicate::Up :
541 m_xRbPositive->set_active(true); break;
542 case SvxChartIndicate::Down :
543 m_xRbNegative->set_active(true); break;
544 }
545 }
546 else
547 {
548 m_xRbBoth->set_active( false );
549 m_xRbPositive->set_active( false );
550 m_xRbNegative->set_active( false );
551 }
552
553 // ranges
554 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_POS, true, &pPoolItem );
555 m_bRangePosUnique = ( aState != SfxItemState::INVALID );
556 if( aState == SfxItemState::SET )
557 {
558 OUString sRangePositive = static_cast< const SfxStringItem * >( pPoolItem )->GetValue();
559 m_xEdRangePositive->set_text( sRangePositive );
560 }
561
562 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_NEG, true, &pPoolItem );
563 m_bRangeNegUnique = ( aState != SfxItemState::INVALID );
564 if( aState == SfxItemState::SET )
565 {
566 OUString sRangeNegative = static_cast< const SfxStringItem * >( pPoolItem )->GetValue();
567 m_xEdRangeNegative->set_text( sRangeNegative );
568 if( m_eErrorKind == SvxChartKindError::Range &&
569 !sRangeNegative.isEmpty() &&
570 sRangeNegative == m_xEdRangePositive->get_text() )
571 m_xCbSyncPosNeg->set_active(true);
572 }
573
574 UpdateControlStates();
575 }
576
577 void ErrorBarResources::FillItemSet(SfxItemSet& rOutAttrs) const
578 {
579 if( m_bErrorKindUnique )
580 rOutAttrs.Put( SvxChartKindErrorItem( m_eErrorKind, SCHATTR_STAT_KIND_ERROR ));
581 if( m_bIndicatorUnique )
582 rOutAttrs.Put( SvxChartIndicateItem( m_eIndicate, SCHATTR_STAT_INDICATE ));
583
584 if( m_bErrorKindUnique )
585 {
586 if( m_eErrorKind == SvxChartKindError::Range )
587 {
588 OUString aPosRange;
589 OUString aNegRange;
590 if( m_bHasInternalDataProvider )
591 {
592 // the strings aPosRange/aNegRange have to be set to a non-empty
593 // arbitrary string to generate error-bar sequences
594 aPosRange = "x";
595 aNegRange = aPosRange;
596 }
597 else
598 {
599 aPosRange = m_xEdRangePositive->get_text();
600 if( m_xCbSyncPosNeg->get_active())
601 aNegRange = aPosRange;
602 else
603 aNegRange = m_xEdRangeNegative->get_text();
604 }
605
606 if( m_bRangePosUnique )
607 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS, aPosRange ));
608 if( m_bRangeNegUnique )
609 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG, aNegRange ));
610 }
611 else if( m_eErrorKind == SvxChartKindError::Const ||
612 m_eErrorKind == SvxChartKindError::Percent ||
613 m_eErrorKind == SvxChartKindError::BigError )
614 {
615 double fPosValue = static_cast< double >( m_xMfPositive->get_value(FieldUnit::NONE)) /
616 pow( 10.0, m_xMfPositive->get_digits());
617 double fNegValue = 0.0;
618
619 if( m_xCbSyncPosNeg->get_active())
620 fNegValue = fPosValue;
621 else
622 fNegValue = static_cast< double >( m_xMfNegative->get_value(FieldUnit::NONE)) /
623 pow( 10.0, m_xMfNegative->get_digits());
624
625 rOutAttrs.Put( SvxDoubleItem( fPosValue, SCHATTR_STAT_CONSTPLUS ));
626 rOutAttrs.Put( SvxDoubleItem( fNegValue, SCHATTR_STAT_CONSTMINUS ));
627 }
628 }
629
630 rOutAttrs.Put( SfxBoolItem( SCHATTR_STAT_ERRORBAR_TYPE , m_eErrorBarType == ERROR_BAR_Y ));
631 }
632
633 void ErrorBarResources::FillValueSets()
634 {
635 if( m_eErrorBarType == ERROR_BAR_Y )
636 {
637 m_xFiNegative->set_from_icon_name(BMP_INDICATE_DOWN);
638 m_xFiPositive->set_from_icon_name(BMP_INDICATE_UP);
639 m_xFiBoth->set_from_icon_name(BMP_INDICATE_BOTH_VERTI);
640 }
641 else if( m_eErrorBarType == ERROR_BAR_X )
642 {
643 m_xFiNegative->set_from_icon_name(BMP_INDICATE_LEFT);
644 m_xFiPositive->set_from_icon_name(BMP_INDICATE_RIGHT);
645 m_xFiBoth->set_from_icon_name(BMP_INDICATE_BOTH_HORI);
646 }
647 }
648
649 void ErrorBarResources::listeningFinished(
650 const OUString & rNewRange )
651 {
652 OSL_ASSERT(m_apRangeSelectionHelper);
653 if (!m_apRangeSelectionHelper)
654 return;
655
656 // rNewRange becomes invalid after removing the listener
657 OUString aRange( rNewRange );
658
659 // stop listening
660 m_apRangeSelectionHelper->stopRangeListening();
661
662 // change edit field
663 // if( m_pParentWindow )
664 // {
665 // m_pParentWindow->ToTop();
666 // m_pParentWindow->grab_focus();
667 // }
668
669 if( m_pCurrentRangeChoosingField )
670 {
671 m_pCurrentRangeChoosingField->set_text( aRange );
672 m_pCurrentRangeChoosingField->grab_focus();
673 PosValueChanged( *m_xMfPositive );
674 }
675
676 m_pCurrentRangeChoosingField = nullptr;
677
678 UpdateControlStates();
679 enableRangeChoosing(false, m_pController);
680 }
681
682 void ErrorBarResources::disposingRangeSelection()
683 {
684 OSL_ASSERT(m_apRangeSelectionHelper);
685 if (m_apRangeSelectionHelper)
686 m_apRangeSelectionHelper->stopRangeListening( false );
687 }
688
689 void ErrorBarResources::isRangeFieldContentValid(weld::Entry& rEdit)
690 {
691 OUString aRange( rEdit.get_text());
692 bool bIsValid = ( aRange.isEmpty() ) ||
693 ( m_apRangeSelectionHelper &&
694 m_apRangeSelectionHelper->verifyCellRange( aRange ));
695
696 if( bIsValid || !rEdit.get_sensitive())
697 {
698 rEdit.set_message_type(weld::EntryMessageType::Normal);
699 }
700 else
701 {
702 rEdit.set_message_type(weld::EntryMessageType::Error);
703 }
704 }
705
706 } //namespace chart
707
708 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */