QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
qgsludialog.h
QgsLUDialog::QgsLUDialog
QgsLUDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Definition: qgsludialog.cpp:21
QgsLUDialog::setLowerValue
void setLowerValue(const QString &val)
Definition: qgsludialog.cpp:50
QgsLUDialog::lowerValueDouble
double lowerValueDouble() const
Returns the lower value.
Definition: qgsludialog.cpp:35
QgsLUDialog::lowerValue
QString lowerValue() const
Definition: qgsludialog.cpp:30
QgsLUDialog::setUpperValue
void setUpperValue(const QString &val)
Definition: qgsludialog.cpp:61
QgsLUDialog::upperValueDouble
double upperValueDouble() const
Returns the upper value.
Definition: qgsludialog.cpp:45
QgsDoubleSpinBox
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value....
Definition: qgsdoublespinbox.h:42
QgsLUDialog::upperValue
QString upperValue() const
Definition: qgsludialog.cpp:40