QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsludialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsludialog.cpp - description
3  -------------------
4  begin : September 2004
5  copyright : (C) 2004 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsludialog.h"
19 
20 
21 QgsLUDialog::QgsLUDialog( QWidget *parent, Qt::WindowFlags fl )
22  : QDialog( parent, fl )
23 {
24  setupUi( this );
25 
26  connect( mLowerEdit, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ this ]( double value ) { setDecimalPlaces( mLowerEdit, value ); } );
27  connect( mUpperEdit, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ this ]( double value ) { setDecimalPlaces( mUpperEdit, value ); } );
28 }
29 
30 QString QgsLUDialog::lowerValue() const
31 {
32  return mLowerEdit->text();
33 }
34 
36 {
37  return mLowerEdit->value();
38 }
39 
40 QString QgsLUDialog::upperValue() const
41 {
42  return mUpperEdit->text();
43 }
44 
46 {
47  return mUpperEdit->value();
48 }
49 
50 void QgsLUDialog::setLowerValue( const QString &val )
51 {
52  bool ok;
53  const double value { QLocale().toDouble( val, &ok )};
54  mLowerEdit->setValue( value );
55  if ( ok )
56  {
57  setDecimalPlaces( mLowerEdit, value );
58  }
59 }
60 
61 void QgsLUDialog::setUpperValue( const QString &val )
62 {
63  bool ok;
64  const double value { QLocale().toDouble( val, &ok )};
65  mUpperEdit->setValue( value );
66  if ( ok )
67  {
68  setDecimalPlaces( mUpperEdit, value );
69  }
70 }
71 
72 void QgsLUDialog::setDecimalPlaces( QgsDoubleSpinBox *widget, double value ) const
73 {
74  const QString strVal { QVariant( value ).toString() };
75  const int dotPosition( strVal.indexOf( '.' ) );
76  int decimals {2};
77  if ( dotPosition >= 0 )
78  {
79  decimals = std::max<int>( 2, strVal.length() - dotPosition - 1 );
80  widget->setDecimals( decimals );
81  }
82 }
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
QString upperValue() const
Definition: qgsludialog.cpp:40
QString lowerValue() const
Definition: qgsludialog.cpp:30
QgsLUDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Definition: qgsludialog.cpp:21
double upperValueDouble() const
Returns the upper value.
Definition: qgsludialog.cpp:45
double lowerValueDouble() const
Returns the lower value.
Definition: qgsludialog.cpp:35
void setLowerValue(const QString &val)
Definition: qgsludialog.cpp:50
void setUpperValue(const QString &val)
Definition: qgsludialog.cpp:61