QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
52 explicit QgsDoubleValidator( QObject *parent );
53
62 QgsDoubleValidator( const QRegularExpression &expression, double bottom, double top, QObject *parent );
63
71 QgsDoubleValidator( double bottom, double top, QObject *parent );
72
81 QgsDoubleValidator( double bottom, double top, int decimal, QObject *parent );
82
90 QgsDoubleValidator( int decimal, QObject *parent );
91
97 void setMaxDecimals( int maxDecimals );
98
99
100 QValidator::State validate( QString &input, int & ) const override SIP_SKIP;
101
106 QValidator::State validate( QString &input ) const;
107
113 static double toDouble( const QString &input, bool *ok ) SIP_SKIP;
114
120 static double toDouble( const QString &input );
121
127 void setBottom( double bottom ) { mMinimum = bottom; }
128
134 void setTop( double top ) { mMaximum = top; }
135
141 virtual void setRange( double bottom, double top )
142 {
143 mMinimum = bottom;
144 mMaximum = top;
145 }
146
151 double bottom() const { return mMinimum; }
152
157 double top() const { return mMaximum; }
158
159 private:
160 // Disables copy constructing
161 Q_DISABLE_COPY( QgsDoubleValidator )
162
163
166 double mMinimum;
167
171 double mMaximum;
172};
173
174#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