QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
20
21QgsLUDialog::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
31{
32 return mLowerEdit->text();
33}
34
36{
37 return mLowerEdit->value();
38}
39
41{
42 return mUpperEdit->text();
43}
44
46{
47 return mUpperEdit->value();
48}
49
50void 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
61void 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
72void 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
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)