LibreOffice Module chart2 (master) 1
tp_Scale.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 "tp_Scale.hxx"
21
22#include <ResId.hxx>
23#include <strings.hrc>
25#include <AxisHelper.hxx>
26
27#include <svx/svxids.hrc>
28#include <osl/diagnose.h>
29#include <sfx2/dialoghelper.hxx>
30#include <svx/chrtitem.hxx>
31#include <svl/eitem.hxx>
32#include <svl/intitem.hxx>
33#include <svl/numformat.hxx>
34#include <vcl/formatter.hxx>
35#include <vcl/weld.hxx>
36#include <svl/zformat.hxx>
37#include <vcl/svapp.hxx>
38
39#include <com/sun/star/chart2/AxisType.hpp>
40
41using namespace ::com::sun::star;
42
43namespace chart
44{
45
46namespace
47{
48
49void lcl_setValue(weld::FormattedSpinButton& rFmtField, double fValue)
50{
51 rFmtField.GetFormatter().SetValue(fValue);
52}
53
54}
55
57 : SfxTabPage(pPage, pController, "modules/schart/ui/tp_Scale.ui", "tp_Scale", &rInAttrs)
58 , fMin(0.0)
59 , fMax(0.0)
60 , fStepMain(0.0)
61 , nStepHelp(0)
62 , fOrigin(0.0)
63 , m_nTimeResolution(1)
64 , m_nMainTimeUnit(1)
65 , m_nHelpTimeUnit(1)
66 , m_nAxisType(chart2::AxisType::REALNUMBER)
67 , m_bAllowDateAxis(false)
68 , pNumFormatter(nullptr)
69 , m_bShowAxisOrigin(false)
70 , m_xCbxReverse(m_xBuilder->weld_check_button("CBX_REVERSE"))
71 , m_xCbxLogarithm(m_xBuilder->weld_check_button("CBX_LOGARITHM"))
72 , m_xBxType(m_xBuilder->weld_widget("boxTYPE"))
73 , m_xLB_AxisType(m_xBuilder->weld_combo_box("LB_AXIS_TYPE"))
74 , m_xBxMinMax(m_xBuilder->weld_widget("gridMINMAX"))
75 , m_xFmtFldMin(m_xBuilder->weld_formatted_spin_button("EDT_MIN"))
76 , m_xCbxAutoMin(m_xBuilder->weld_check_button("CBX_AUTO_MIN"))
77 , m_xFmtFldMax(m_xBuilder->weld_formatted_spin_button("EDT_MAX"))
78 , m_xCbxAutoMax(m_xBuilder->weld_check_button("CBX_AUTO_MAX"))
79 , m_xBxResolution(m_xBuilder->weld_widget("boxRESOLUTION"))
80 , m_xLB_TimeResolution(m_xBuilder->weld_combo_box("LB_TIME_RESOLUTION"))
81 , m_xCbx_AutoTimeResolution(m_xBuilder->weld_check_button("CBX_AUTO_TIME_RESOLUTION"))
82 , m_xTxtMain(m_xBuilder->weld_label("TXT_STEP_MAIN"))
83 , m_xFmtFldStepMain(m_xBuilder->weld_formatted_spin_button("EDT_STEP_MAIN"))
84 , m_xMt_MainDateStep(m_xBuilder->weld_spin_button("MT_MAIN_DATE_STEP"))
85 , m_xLB_MainTimeUnit(m_xBuilder->weld_combo_box("LB_MAIN_TIME_UNIT"))
86 , m_xCbxAutoStepMain(m_xBuilder->weld_check_button("CBX_AUTO_STEP_MAIN"))
87 , m_xTxtHelpCount(m_xBuilder->weld_label("TXT_STEP_HELP_COUNT"))
88 , m_xTxtHelp(m_xBuilder->weld_label("TXT_STEP_HELP"))
89 , m_xMtStepHelp(m_xBuilder->weld_spin_button("MT_STEPHELP"))
90 , m_xLB_HelpTimeUnit(m_xBuilder->weld_combo_box("LB_HELP_TIME_UNIT"))
91 , m_xCbxAutoStepHelp(m_xBuilder->weld_check_button("CBX_AUTO_STEP_HELP"))
92 , m_xFmtFldOrigin(m_xBuilder->weld_formatted_spin_button("EDT_ORIGIN"))
93 , m_xCbxAutoOrigin(m_xBuilder->weld_check_button("CBX_AUTO_ORIGIN"))
94 , m_xBxOrigin(m_xBuilder->weld_widget("boxORIGIN"))
95{
96 m_xCbxAutoMin->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
97 m_xCbxAutoMax->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
98 m_xCbxAutoStepMain->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
99 m_xCbxAutoStepHelp->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
100 m_xCbxAutoOrigin->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
101 m_xCbx_AutoTimeResolution->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
102
103 Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter();
104 rFmtFldMax.ClearMinValue();
105 rFmtFldMax.ClearMaxValue();
106 Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter();
107 rFmtFldMin.ClearMinValue();
108 rFmtFldMin.ClearMaxValue();
109 Formatter& rFmtFldStepMain = m_xFmtFldStepMain->GetFormatter();
110 rFmtFldStepMain.ClearMinValue();
111 rFmtFldStepMain.ClearMaxValue();
112 Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter();
113 rFmtFldOrigin.ClearMinValue();
114 rFmtFldOrigin.ClearMaxValue();
115
116 m_xLB_AxisType->connect_changed(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
117
119}
120
122{
123}
124
126{
127 bool bValueAxis = m_nAxisType == chart2::AxisType::REALNUMBER
128 || m_nAxisType == chart2::AxisType::PERCENT
129 || m_nAxisType == chart2::AxisType::DATE;
130 bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
131
132 m_xBxType->set_visible(m_bAllowDateAxis);
133
134 m_xCbxLogarithm->set_visible( bValueAxis && !bDateAxis );
135
136 m_xBxMinMax->set_visible(bValueAxis);
137
138 m_xTxtMain->set_visible( bValueAxis );
139 m_xCbxAutoStepMain->set_visible( bValueAxis );
140
141 m_xTxtHelpCount->set_visible( bValueAxis && !bDateAxis );
142 m_xTxtHelp->set_visible( bDateAxis );
143 m_xMtStepHelp->set_visible( bValueAxis );
144 m_xCbxAutoStepHelp->set_visible( bValueAxis );
145
146 m_xBxOrigin->set_visible( m_bShowAxisOrigin && bValueAxis );
147 m_xBxResolution->set_visible( bDateAxis );
148
149 bool bWasDateAxis = m_xMt_MainDateStep->get_visible();
150 if( bWasDateAxis != bDateAxis )
151 {
152 //transport value from one to other control
153 if( bWasDateAxis )
155 else
156 m_xMt_MainDateStep->set_value(m_xFmtFldStepMain->GetFormatter().GetValue());
157 }
158
159 m_xFmtFldStepMain->set_visible( bValueAxis && !bDateAxis );
160 m_xMt_MainDateStep->set_visible( bDateAxis );
161
162 m_xLB_MainTimeUnit->set_visible( bDateAxis );
163 m_xLB_HelpTimeUnit->set_visible( bDateAxis );
164
165 EnableValueHdl(*m_xCbxAutoMin);
166 EnableValueHdl(*m_xCbxAutoMax);
167 EnableValueHdl(*m_xCbxAutoStepMain);
168 EnableValueHdl(*m_xCbxAutoStepHelp);
169 EnableValueHdl(*m_xCbxAutoOrigin);
170 EnableValueHdl(*m_xCbx_AutoTimeResolution);
171}
172
173IMPL_LINK( ScaleTabPage, EnableValueHdl, weld::Toggleable&, rCbx, void )
174{
175 bool bEnable = !rCbx.get_active() && rCbx.get_sensitive();
176 if (&rCbx == m_xCbxAutoMin.get())
177 {
178 m_xFmtFldMin->set_sensitive( bEnable );
179 }
180 else if (&rCbx == m_xCbxAutoMax.get())
181 {
182 m_xFmtFldMax->set_sensitive( bEnable );
183 }
184 else if (&rCbx == m_xCbxAutoStepMain.get())
185 {
186 m_xFmtFldStepMain->set_sensitive( bEnable );
187 m_xMt_MainDateStep->set_sensitive( bEnable );
188 m_xLB_MainTimeUnit->set_sensitive( bEnable );
189 }
190 else if (&rCbx == m_xCbxAutoStepHelp.get())
191 {
192 m_xMtStepHelp->set_sensitive( bEnable );
193 m_xLB_HelpTimeUnit->set_sensitive( bEnable );
194 }
195 else if (&rCbx == m_xCbx_AutoTimeResolution.get())
196 {
197 m_xLB_TimeResolution->set_sensitive( bEnable );
198 }
199 else if (&rCbx == m_xCbxAutoOrigin.get())
200 {
201 m_xFmtFldOrigin->set_sensitive( bEnable );
202 }
203}
204
205namespace {
206
207enum AxisTypeListBoxEntry
208{
209 TYPE_AUTO=0,
210 TYPE_TEXT=1,
211 TYPE_DATE=2
212};
213
214}
215
216IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl, weld::ComboBox&, void)
217{
218 const sal_Int32 nPos = m_xLB_AxisType->get_active();
219 if( nPos==TYPE_DATE )
220 m_nAxisType = chart2::AxisType::DATE;
221 else
222 m_nAxisType = chart2::AxisType::CATEGORY;
223 if( m_nAxisType == chart2::AxisType::DATE )
224 m_xCbxLogarithm->set_active(false);
225 EnableControls();
226 SetNumFormat();
227}
228
229std::unique_ptr<SfxTabPage> ScaleTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
230{
231 return std::make_unique<ScaleTabPage>(pPage, pController, *rOutAttrs);
232}
233
235{
236 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
237
240 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, m_xLB_AxisType->get_active()==TYPE_AUTO));
241
242 bool bAutoScale = false;
243 if( m_nAxisType==chart2::AxisType::CATEGORY )
244 bAutoScale = true;//reset scaling for category charts
245
246 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,bAutoScale || m_xCbxAutoMin->get_active()));
247 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,bAutoScale || m_xCbxAutoMax->get_active()));
248 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_xCbxAutoStepHelp->get_active()));
249 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,bAutoScale || m_xCbxAutoOrigin->get_active()));
250 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,m_xCbxLogarithm->get_active()));
251 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_REVERSE ,m_xCbxReverse->get_active()));
252 rOutAttrs->Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX));
253 rOutAttrs->Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN));
256
257 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_xCbxAutoStepMain->get_active()));
259
260 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_xCbx_AutoTimeResolution->get_active()));
262
265
266 return true;
267}
268
269void ScaleTabPage::Reset(const SfxItemSet* rInAttrs)
270{
271 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
272 if(!pNumFormatter)
273 return;
274
275 if (const SfxBoolItem* pDateAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_ALLOW_DATEAXIS))
276 m_bAllowDateAxis = pDateAxisItem->GetValue();
277 m_nAxisType=chart2::AxisType::REALNUMBER;
278 if (const SfxInt32Item* pAxisTypeItem = rInAttrs->GetItemIfSet(SCHATTR_AXISTYPE))
279 m_nAxisType = static_cast<int>(pAxisTypeItem->GetValue());
280 if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
281 m_nAxisType=chart2::AxisType::CATEGORY;
282 if( m_bAllowDateAxis )
283 {
284 bool bAutoDateAxis = false;
285 if (const SfxBoolItem* pDateAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_DATEAXIS))
286 bAutoDateAxis = pDateAxisItem->GetValue();
287
288 sal_uInt16 nPos = 0;
289 if( m_nAxisType==chart2::AxisType::DATE )
291 else if( bAutoDateAxis )
292 nPos=TYPE_AUTO;
293 else
295 m_xLB_AxisType->set_active( nPos );
296 }
297
298 m_xCbxAutoMin->set_active(true);
299 m_xCbxAutoMax->set_active(true);
300 m_xCbxAutoStepMain->set_active(true);
301 m_xCbxAutoStepHelp->set_active(true);
302 m_xCbxAutoOrigin->set_active(true);
303 m_xCbx_AutoTimeResolution->set_active(true);
304
305 if (const SfxBoolItem* pAutoMinItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_MIN))
306 m_xCbxAutoMin->set_active(pAutoMinItem->GetValue());
307
308 if (const SvxDoubleItem* pAxisMinItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MIN))
309 {
310 fMin = pAxisMinItem->GetValue();
312 m_xFmtFldMin->save_value();
313 }
314
315 if (const SfxBoolItem* pAutoMaxItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_MAX))
316 m_xCbxAutoMax->set_active(pAutoMaxItem->GetValue());
317
318 if (const SvxDoubleItem* pAxisMaxItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MAX))
319 {
320 fMax = pAxisMaxItem->GetValue();
322 m_xFmtFldMax->save_value();
323 }
324
325 if (const SfxBoolItem* pAutoStepMainItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_MAIN))
326 m_xCbxAutoStepMain->set_active(pAutoStepMainItem->GetValue());
327
328 if (const SvxDoubleItem* pStepMainItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_STEP_MAIN))
329 {
330 fStepMain = pStepMainItem->GetValue();
332 m_xFmtFldStepMain->save_value();
333 m_xMt_MainDateStep->set_value( static_cast<sal_Int32>(fStepMain) );
334 m_xMt_MainDateStep->save_value();
335 }
336 if (const SfxBoolItem* pAutoStepHelpItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_HELP))
337 m_xCbxAutoStepHelp->set_active(pAutoStepHelpItem->GetValue());
338 if (const SfxBoolItem* pLogItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_LOGARITHM))
339 m_xCbxLogarithm->set_active(pLogItem->GetValue());
340 if (const SfxBoolItem* pReverseItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_REVERSE))
341 m_xCbxReverse->set_active(pReverseItem->GetValue());
342 if (const SfxInt32Item* pStepHelpItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_STEP_HELP))
343 {
344 nStepHelp = pStepHelpItem->GetValue();
345 m_xMtStepHelp->set_value( nStepHelp );
346 m_xMtStepHelp->save_value();
347 }
348 if (const SfxBoolItem* pOriginItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_ORIGIN))
349 m_xCbxAutoOrigin->set_active(pOriginItem->GetValue());
350 if (const SvxDoubleItem* pOriginItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_ORIGIN))
351 {
352 fOrigin = pOriginItem->GetValue();
354 m_xFmtFldOrigin->save_value();
355 }
356
357 if (const SfxBoolItem* pAutoTimeResItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_TIME_RESOLUTION))
358 m_xCbx_AutoTimeResolution->set_active(pAutoTimeResItem->GetValue());
359 if (const SfxInt32Item* pTimeResItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_TIME_RESOLUTION))
360 {
361 m_nTimeResolution = pTimeResItem->GetValue();
363 }
364
365 if (const SfxInt32Item* pMainTimeUnitItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MAIN_TIME_UNIT))
366 {
367 m_nMainTimeUnit = pMainTimeUnitItem->GetValue();
368 m_xLB_MainTimeUnit->set_active( m_nMainTimeUnit );
369 }
370 if (const SfxInt32Item* pHelpTimeUnitItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_HELP_TIME_UNIT))
371 {
372 m_nHelpTimeUnit = pHelpTimeUnitItem->GetValue();
373 m_xLB_HelpTimeUnit->set_active( m_nHelpTimeUnit );
374 }
375
377 SetNumFormat();
378}
379
381{
382 if( !pNumFormatter )
383 {
384 OSL_FAIL( "No NumberFormatter available" );
385 return DeactivateRC::LeavePage;
386 }
387
388 bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
389
390 sal_uInt32 nMinMaxOriginFmt = m_xFmtFldMax->GetFormatter().GetFormatKey();
391 if (pNumFormatter->GetType(nMinMaxOriginFmt) == SvNumFormatType::TEXT)
392 nMinMaxOriginFmt = 0;
393 // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
394 sal_uInt32 nStepFmt = m_xFmtFldStepMain->GetFormatter().GetFormatKey();
395 if (pNumFormatter->GetType(nStepFmt) == SvNumFormatType::TEXT)
396 nStepFmt = 0;
397
398 weld::Widget* pControl = nullptr;
399 TranslateId pErrStrId;
400 double fDummy;
401
402 fMax = m_xFmtFldMax->GetFormatter().GetValue();
403 fMin = m_xFmtFldMin->GetFormatter().GetValue();
404 fOrigin = m_xFmtFldOrigin->GetFormatter().GetValue();
405 fStepMain = bDateAxis ? m_xMt_MainDateStep->get_value() : m_xFmtFldStepMain->GetFormatter().GetValue();
406 nStepHelp = m_xMtStepHelp->get_value();
408 m_nMainTimeUnit = m_xLB_MainTimeUnit->get_active();
409 m_nHelpTimeUnit = m_xLB_HelpTimeUnit->get_active();
410
411 if( m_nAxisType != chart2::AxisType::REALNUMBER )
412 m_xCbxLogarithm->hide();
413
414 //check which entries need user action
415
416 if ( m_xCbxLogarithm->get_active() &&
417 ( ( !m_xCbxAutoMin->get_active() && fMin <= 0.0 )
418 || ( !m_xCbxAutoMax->get_active() && fMax <= 0.0 ) ) )
419 {
420 pControl = m_xFmtFldMin.get();
421 pErrStrId = STR_BAD_LOGARITHM;
422 }
423 // check for entries that cannot be parsed for the current number format
424 else if ( m_xFmtFldMin->get_value_changed_from_saved()
425 && !m_xCbxAutoMin->get_active()
426 && !pNumFormatter->IsNumberFormat( m_xFmtFldMin->get_text(), nMinMaxOriginFmt, fDummy))
427 {
428 pControl = m_xFmtFldMin.get();
429 pErrStrId = STR_INVALID_NUMBER;
430 }
431 else if ( m_xFmtFldMax->get_value_changed_from_saved()
432 && !m_xCbxAutoMax->get_active()
433 && !pNumFormatter->IsNumberFormat( m_xFmtFldMax->get_text(), nMinMaxOriginFmt, fDummy))
434 {
435 pControl = m_xFmtFldMax.get();
436 pErrStrId = STR_INVALID_NUMBER;
437 }
438 else if ( !bDateAxis && m_xFmtFldStepMain->get_value_changed_from_saved()
439 && !m_xCbxAutoStepMain->get_active()
440 && !pNumFormatter->IsNumberFormat( m_xFmtFldStepMain->get_text(), nStepFmt, fDummy))
441 {
442 pControl = m_xFmtFldStepMain.get();
443 pErrStrId = STR_INVALID_NUMBER;
444 }
445 else if (m_xFmtFldOrigin->get_value_changed_from_saved() && !m_xCbxAutoOrigin->get_active() &&
446 !pNumFormatter->IsNumberFormat( m_xFmtFldOrigin->get_text(), nMinMaxOriginFmt, fDummy))
447 {
448 pControl = m_xFmtFldOrigin.get();
449 pErrStrId = STR_INVALID_NUMBER;
450 }
451 else if (!m_xCbxAutoStepMain->get_active() && fStepMain <= 0.0)
452 {
453 pControl = m_xFmtFldStepMain.get();
454 pErrStrId = STR_STEP_GT_ZERO;
455 }
456 else if (!m_xCbxAutoMax->get_active() && !m_xCbxAutoMin->get_active() &&
457 fMin >= fMax)
458 {
459 pControl = m_xFmtFldMin.get();
460 pErrStrId = STR_MIN_GREATER_MAX;
461 }
462 else if( bDateAxis )
463 {
464 if( !m_xCbxAutoStepMain->get_active() && !m_xCbxAutoStepHelp->get_active() )
465 {
467 {
468 pControl = m_xLB_MainTimeUnit.get();
469 pErrStrId = STR_INVALID_INTERVALS;
470 }
472 {
473 pControl = m_xLB_MainTimeUnit.get();
474 pErrStrId = STR_INVALID_INTERVALS;
475 }
476 }
477 if( !pErrStrId && !m_xCbx_AutoTimeResolution->get_active() )
478 {
479 if( (!m_xCbxAutoStepMain->get_active() && m_nTimeResolution > m_nMainTimeUnit )
480 ||
482 )
483 {
484 pControl = m_xLB_TimeResolution.get();
485 pErrStrId = STR_INVALID_TIME_UNIT;
486 }
487 }
488 }
489
490 if( ShowWarning( pErrStrId, pControl ) )
491 return DeactivateRC::KeepPage;
492
493 if( pItemSet )
494 FillItemSet( pItemSet );
495
496 return DeactivateRC::LeavePage;
497}
498
500{
501 pNumFormatter = pFormatter;
502
503 Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter();
504 Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter();
505 Formatter& rFmtFldStepMain = m_xFmtFldStepMain->GetFormatter();
506 Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter();
507
508 rFmtFldMax.SetFormatter( pNumFormatter );
509 rFmtFldMin.SetFormatter( pNumFormatter );
510 rFmtFldStepMain.SetFormatter( pNumFormatter );
511 rFmtFldOrigin.SetFormatter( pNumFormatter );
512
513 // #i6278# allow more decimal places than the output format. As
514 // the numbers shown in the edit fields are used for input, it makes more
515 // sense to display the values in the input format rather than the output
516 // format.
517 rFmtFldMax.UseInputStringForFormatting();
518 rFmtFldMin.UseInputStringForFormatting();
519 rFmtFldStepMain.UseInputStringForFormatting();
520 rFmtFldOrigin.UseInputStringForFormatting();
521
522 SetNumFormat();
523}
524
526{
527 const SfxUInt32Item *pNumFormatItem = GetItemSet().GetItemIfSet( SID_ATTR_NUMBERFORMAT_VALUE );
528
529 if( !pNumFormatItem )
530 return;
531
532 sal_uInt32 nFmt = pNumFormatItem->GetValue();
533
534 Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter();
535 rFmtFldMax.SetFormatKey(nFmt);
536 Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter();
537 rFmtFldMin.SetFormatKey(nFmt);
538 Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter();
539 rFmtFldOrigin.SetFormatKey(nFmt);
540
541 if( pNumFormatter )
542 {
544 if( eType == SvNumFormatType::DATE )
545 {
546 // for intervals use standard format for dates (so you can enter a number of days)
547 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
548 if( pFormat )
549 nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
550 else
552 }
553 else if( eType == SvNumFormatType::DATETIME )
554 {
555 // for intervals use time format for date times
556 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
557 if( pFormat )
558 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME, pFormat->GetLanguage() );
559 else
560 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME );
561
562 // tdf#141625 give enough space to see full date+time
563 int nWidestTime(m_xFmtFldMin->get_pixel_size(getWidestDateTime(Application::GetSettings().GetLocaleDataWrapper(), true)).Width());
564 int nWidthChars = std::ceil(nWidestTime / m_xFmtFldMin->get_approximate_digit_width()) + 1;
565 m_xFmtFldMin->set_width_chars(nWidthChars);
566 m_xFmtFldMax->set_width_chars(nWidthChars);
567 }
568
569 if( m_nAxisType == chart2::AxisType::DATE && ( eType != SvNumFormatType::DATE && eType != SvNumFormatType::DATETIME) )
570 {
571 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
572 if( pFormat )
573 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE, pFormat->GetLanguage() );
574 else
575 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE );
576
577 rFmtFldMax.SetFormatKey(nFmt);
578 rFmtFldMin.SetFormatKey(nFmt);
579 rFmtFldOrigin.SetFormatKey(nFmt);
580 }
581 }
582
583 m_xFmtFldStepMain->GetFormatter().SetFormatKey(nFmt);
584}
585
586void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
587{
588 m_bShowAxisOrigin = bShowOrigin;
590 m_bShowAxisOrigin = true;
591}
592
593bool ScaleTabPage::ShowWarning(TranslateId pResIdMessage, weld::Widget* pControl /* = nullptr */)
594{
595 if (!pResIdMessage)
596 return false;
597
598 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
599 VclMessageType::Warning, VclButtonsType::Ok,
600 SchResId(pResIdMessage)));
601 xWarn->run();
602 if (pControl)
603 {
604 pControl->grab_focus();
605 weld::Entry* pEdit = dynamic_cast<weld::Entry*>(pControl);
606 if (pEdit)
607 pEdit->select_region(0, -1);
608 }
609 return true;
610}
611
613{
614 // We need to set these controls invisible when the class is instantiated
615 // since some code in EnableControls() depends on that logic. The real
616 // visibility of these controls depend on axis data type, and are
617 // set in EnableControls().
618
619 m_xBxType->hide();
620 m_xCbxLogarithm->hide();
621 m_xBxMinMax->hide();
622 m_xTxtMain->hide();
623 m_xFmtFldStepMain->hide();
624 m_xMt_MainDateStep->hide();
625 m_xLB_MainTimeUnit->hide();
626 m_xCbxAutoStepMain->hide();
627 m_xTxtHelpCount->hide();
628 m_xTxtHelp->hide();
629 m_xMtStepHelp->hide();
630 m_xCbxAutoStepHelp->hide();
631 m_xBxOrigin->hide();
632 m_xBxResolution->hide();
633}
634
635} //namespace chart
636
637/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nPos
constexpr TypedWhichId< SfxBoolItem > SCHATTR_AXIS_AUTO_DATEAXIS(SCHATTR_AXIS_START+15)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_STEP_HELP(SCHATTR_AXIS_START+10)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_AXIS_AUTO_MAX(SCHATTR_AXIS_START+4)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_AXIS_AUTO_STEP_MAIN(SCHATTR_AXIS_START+6)
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_AUTO_MIN(SCHATTR_AXIS_START+2)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_AXIS_ORIGIN(SCHATTR_AXIS_START+18)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_HELP_TIME_UNIT(SCHATTR_AXIS_START+11)
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_MAIN_TIME_UNIT(SCHATTR_AXIS_START+8)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_AXIS_LOGARITHM(SCHATTR_AXIS_START+14)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_AXIS_AUTO_TIME_RESOLUTION(SCHATTR_AXIS_START+12)
static const AllSettings & GetSettings()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
sal_uInt32 GetValue() const
void SetValue(double dVal)
void UseInputStringForFormatting()
virtual void ClearMinValue()
void SetFormatter(SvNumberFormatter *pFormatter, bool bResetFormat=true)
void SetFormatKey(sal_uLong nFormatKey)
virtual void ClearMaxValue()
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxItemSet & GetItemSet() const
weld::Window * GetFrameWeld() const
sal_uInt32 GetStandardIndex(LanguageType eLnge=LANGUAGE_DONTKNOW)
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
SvNumFormatType GetType(sal_uInt32 nFIndex) const
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
LanguageType GetLanguage() const
static bool isAxisPositioningEnabled()
std::unique_ptr< weld::Widget > m_xBxMinMax
Definition: tp_Scale.hxx:62
sal_Int32 nStepHelp
Definition: tp_Scale.hxx:47
virtual DeactivateRC DeactivatePage(SfxItemSet *pItemSet) override
Definition: tp_Scale.cxx:380
std::unique_ptr< weld::FormattedSpinButton > m_xFmtFldOrigin
Definition: tp_Scale.hxx:80
std::unique_ptr< weld::CheckButton > m_xCbxAutoMin
Definition: tp_Scale.hxx:64
SvNumberFormatter * pNumFormatter
Definition: tp_Scale.hxx:54
std::unique_ptr< weld::SpinButton > m_xMt_MainDateStep
Definition: tp_Scale.hxx:72
std::unique_ptr< weld::Label > m_xTxtMain
Definition: tp_Scale.hxx:70
ScaleTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tp_Scale.cxx:56
sal_Int32 m_nTimeResolution
Definition: tp_Scale.hxx:49
std::unique_ptr< weld::CheckButton > m_xCbxAutoOrigin
Definition: tp_Scale.hxx:81
std::unique_ptr< weld::SpinButton > m_xMtStepHelp
Definition: tp_Scale.hxx:77
sal_Int32 m_nHelpTimeUnit
Definition: tp_Scale.hxx:51
virtual ~ScaleTabPage() override
Definition: tp_Scale.cxx:121
std::unique_ptr< weld::FormattedSpinButton > m_xFmtFldStepMain
Definition: tp_Scale.hxx:71
void SetNumFormatter(SvNumberFormatter *pFormatter)
Definition: tp_Scale.cxx:499
std::unique_ptr< weld::ComboBox > m_xLB_HelpTimeUnit
Definition: tp_Scale.hxx:78
std::unique_ptr< weld::ComboBox > m_xLB_MainTimeUnit
Definition: tp_Scale.hxx:73
void ShowAxisOrigin(bool bShowOrigin)
Definition: tp_Scale.cxx:586
sal_Int32 m_nMainTimeUnit
Definition: tp_Scale.hxx:50
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rInAttrs)
Definition: tp_Scale.cxx:229
std::unique_ptr< weld::CheckButton > m_xCbxAutoMax
Definition: tp_Scale.hxx:66
std::unique_ptr< weld::CheckButton > m_xCbxAutoStepMain
Definition: tp_Scale.hxx:74
std::unique_ptr< weld::Widget > m_xBxOrigin
Definition: tp_Scale.hxx:82
std::unique_ptr< weld::CheckButton > m_xCbxReverse
Definition: tp_Scale.hxx:58
std::unique_ptr< weld::Widget > m_xBxType
Definition: tp_Scale.hxx:60
std::unique_ptr< weld::FormattedSpinButton > m_xFmtFldMin
Definition: tp_Scale.hxx:63
std::unique_ptr< weld::CheckButton > m_xCbx_AutoTimeResolution
Definition: tp_Scale.hxx:69
virtual void Reset(const SfxItemSet *rInAttrs) override
Definition: tp_Scale.cxx:269
std::unique_ptr< weld::CheckButton > m_xCbxAutoStepHelp
Definition: tp_Scale.hxx:79
std::unique_ptr< weld::ComboBox > m_xLB_AxisType
Definition: tp_Scale.hxx:61
std::unique_ptr< weld::Label > m_xTxtHelp
Definition: tp_Scale.hxx:76
std::unique_ptr< weld::Widget > m_xBxResolution
Definition: tp_Scale.hxx:67
bool ShowWarning(TranslateId pResIdMessage, weld::Widget *pControl)
shows a warning window due to an invalid input.
Definition: tp_Scale.cxx:593
std::unique_ptr< weld::FormattedSpinButton > m_xFmtFldMax
Definition: tp_Scale.hxx:65
std::unique_ptr< weld::Label > m_xTxtHelpCount
Definition: tp_Scale.hxx:75
std::unique_ptr< weld::CheckButton > m_xCbxLogarithm
Definition: tp_Scale.hxx:59
virtual bool FillItemSet(SfxItemSet *rOutAttrs) override
Definition: tp_Scale.cxx:234
std::unique_ptr< weld::ComboBox > m_xLB_TimeResolution
Definition: tp_Scale.hxx:68
virtual void select_region(int nStartPos, int nEndPos)=0
virtual Formatter & GetFormatter()=0
virtual void grab_focus()=0
OUString SFX2_DLLPUBLIC getWidestDateTime(const LocaleDataWrapper &rWrapper, bool bWithSec)
DocumentType eType
static void lcl_setValue(weld::FormattedSpinButton &rFmtField, double fValue)
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
IMPL_LINK(StackingResourceGroup, StackingChangeHdl, weld::Toggleable &, rRadio, void)
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)
const sal_uInt16 TYPE_DATE
const sal_uInt16 TYPE_TEXT
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
AxisType
DeactivateRC
SvNumFormatType