QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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
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#include "moc_qgsludialog.cpp"
20
21
22QgsLUDialog::QgsLUDialog( QWidget *parent, Qt::WindowFlags fl )
23 : QDialog( parent, fl )
24{
25 setupUi( this );
26
27 connect( mLowerEdit, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ this ]( double value ) { setDecimalPlaces( mLowerEdit, value ); } );
28 connect( mUpperEdit, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ this ]( double value ) { setDecimalPlaces( mUpperEdit, value ); } );
29}
30
32{
33 return mLowerEdit->text();
34}
35
37{
38 return mLowerEdit->value();
39}
40
42{
43 return mUpperEdit->text();
44}
45
47{
48 return mUpperEdit->value();
49}
50
51void QgsLUDialog::setLowerValue( const QString &val )
52{
53 bool ok;
54 const double value { QLocale().toDouble( val, &ok )};
55 mLowerEdit->setValue( value );
56 if ( ok )
57 {
58 setDecimalPlaces( mLowerEdit, value );
59 }
60}
61
62void QgsLUDialog::setUpperValue( const QString &val )
63{
64 bool ok;
65 const double value { QLocale().toDouble( val, &ok )};
66 mUpperEdit->setValue( value );
67 if ( ok )
68 {
69 setDecimalPlaces( mUpperEdit, value );
70 }
71}
72
73void QgsLUDialog::setDecimalPlaces( QgsDoubleSpinBox *widget, double value ) const
74{
75 const QString strVal { QVariant( value ).toString() };
76 const int dotPosition( strVal.indexOf( '.' ) );
77 int decimals {2};
78 if ( dotPosition >= 0 )
79 {
80 decimals = std::max<int>( 2, strVal.length() - dotPosition - 1 );
81 widget->setDecimals( decimals );
82 }
83}
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
QString upperValue() const
QString lowerValue() const
QgsLUDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
double upperValueDouble() const
Returns the upper value.
double lowerValueDouble() const
Returns the lower value.
void setLowerValue(const QString &val)
void setUpperValue(const QString &val)