QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsdoublevalidator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdoublevalidator.h - description
3 -------------------
4 begin : June 2020
5 copyright : (C) 2020 by Sebastien Peillet
7
8 adapted version of Qgslonglongvalidator + QgsFieldValidator
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#ifndef QGSDOUBLEVALIDATOR_H
21#define QGSDOUBLEVALIDATOR_H
22
23#include <limits>
24
25#include "qgis_gui.h"
26#include "qgis_sip.h"
27
28#include <QLocale>
29#include <QRegularExpressionValidator>
30
31class QRegularExpression;
32
44class GUI_EXPORT QgsDoubleValidator : public QRegularExpressionValidator
45{
46 Q_OBJECT
47
48 public:
49
53 explicit QgsDoubleValidator( QObject *parent );
54
63 QgsDoubleValidator( const QRegularExpression &expression, double bottom, double top, QObject *parent );
64
72 QgsDoubleValidator( double bottom, double top, QObject *parent );
73
82 QgsDoubleValidator( double bottom, double top, int decimal, QObject *parent );
83
91 QgsDoubleValidator( int decimal, QObject *parent );
92
98 void setMaxDecimals( int maxDecimals );
99
100
101 QValidator::State validate( QString &input, int & ) const override SIP_SKIP;
102
107 QValidator::State validate( QString &input ) const;
108
114 static double toDouble( const QString &input, bool *ok ) SIP_SKIP;
115
121 static double toDouble( const QString &input );
122
128 void setBottom( double bottom ) { mMinimum = bottom; }
129
135 void setTop( double top ) { mMaximum = top; }
136
142 virtual void setRange( double bottom, double top )
143 {
144 mMinimum = bottom;
145 mMaximum = top;
146 }
147
152 double bottom() const { return mMinimum; }
153
158 double top() const { return mMaximum; }
159
160 private:
161 // Disables copy constructing
162 Q_DISABLE_COPY( QgsDoubleValidator )
163
164
167 double mMinimum;
168
172 double mMaximum;
173};
174
175#endif // QGSDOUBLEVALIDATOR_H
A custom validator which allows entry of doubles in a locale-tolerant way.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
QgsDoubleValidator(QObject *parent)
Constructor for QgsDoubleValidator.
double top() const
Returns top range limit.
virtual void setRange(double bottom, double top)
Set bottom and top range limits.
QValidator::State validate(QString &input, int &) const override
void setTop(double top)
Set top range limit.
void setMaxDecimals(int maxDecimals)
Sets the number of decimals accepted by the validator to maxDecimals.
double bottom() const
Returns top range limit.
void setBottom(double bottom)
Set top range limit.
#define SIP_SKIP
Definition qgis_sip.h:134