Skip to content

Commit 2525372

Browse files
committed
Validators for updated NumericLineEdit
1 parent 4197fd5 commit 2525372

4 files changed

Lines changed: 115 additions & 0 deletions

File tree

src/qdoublevalidatorex.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "qdoublevalidatorex.h"
2+
3+
///
4+
/// \brief QDoubleValidatorEx::QDoubleValidatorEx
5+
/// \param bottom
6+
/// \param top
7+
/// \param decimals
8+
/// \param allowEmpty
9+
/// \param parent
10+
///
11+
QDoubleValidatorEx::QDoubleValidatorEx(double bottom, double top, int decimals, bool allowEmpty, QObject* parent)
12+
: QDoubleValidator(bottom, top, decimals, parent)
13+
, _allowEmpty(allowEmpty)
14+
{
15+
}
16+
17+
///
18+
/// \brief QDoubleValidatorEx::validate
19+
/// \param input
20+
/// \param pos
21+
/// \return
22+
///
23+
QValidator::State QDoubleValidatorEx::validate(QString& input, int& pos) const
24+
{
25+
if(_allowEmpty && input.isEmpty()) return Acceptable;
26+
return QDoubleValidator::validate(input, pos);
27+
}
28+
29+
///
30+
/// \brief QDoubleValidatorEx::fixup
31+
/// \param input
32+
///
33+
void QDoubleValidatorEx::fixup(QString& input) const
34+
{
35+
if(_allowEmpty && input.isEmpty()) return;
36+
QDoubleValidator::fixup(input);
37+
}

src/qdoublevalidatorex.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef QDOUBLEVALIDATOREX_H
2+
#define QDOUBLEVALIDATOREX_H
3+
4+
#include <QDoubleValidator>
5+
6+
///
7+
/// \brief The QDoubleValidatorEx class
8+
///
9+
class QDoubleValidatorEx final : public QDoubleValidator
10+
{
11+
public:
12+
QDoubleValidatorEx(double bottom, double top, int decimals, bool allowEmpty, QObject* parent = nullptr);
13+
14+
State validate(QString& input, int& pos) const override;
15+
void fixup(QString& input) const override;
16+
17+
private:
18+
bool _allowEmpty;
19+
};
20+
21+
#endif // QDOUBLEVALIDATOREX_H

src/qintvalidatorex.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "qintvalidatorex.h"
2+
3+
///
4+
/// \brief QIntValidatorEx::QIntValidatorEx
5+
/// \param bottom
6+
/// \param top
7+
/// \param allowEmpty
8+
/// \param parent
9+
///
10+
QIntValidatorEx::QIntValidatorEx(int bottom, int top, bool allowEmpty, QObject* parent)
11+
: QIntValidator(bottom, top, parent)
12+
, _allowEmpty(allowEmpty)
13+
{
14+
}
15+
16+
///
17+
/// \brief QIntValidatorEx::validate
18+
/// \param input
19+
/// \param pos
20+
/// \return
21+
///
22+
QValidator::State QIntValidatorEx::validate(QString& input, int& pos) const
23+
{
24+
if(_allowEmpty && input.isEmpty()) return Acceptable;
25+
return QIntValidator::validate(input, pos);
26+
}
27+
28+
///
29+
/// \brief QIntValidatorEx::fixup
30+
/// \param input
31+
///
32+
void QIntValidatorEx::fixup(QString& input) const
33+
{
34+
if(_allowEmpty && input.isEmpty()) return;
35+
QIntValidator::fixup(input);
36+
}

src/qintvalidatorex.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef QINTVALIDATOREX_H
2+
#define QINTVALIDATOREX_H
3+
4+
#include <QIntValidator>
5+
6+
///
7+
/// \brief The QIntValidatorEx class
8+
///
9+
class QIntValidatorEx final : public QIntValidator
10+
{
11+
public:
12+
QIntValidatorEx(int bottom, int top, bool allowEmpty, QObject* parent = nullptr);
13+
14+
State validate(QString& input, int& pos) const override;
15+
void fixup(QString& input) const override;
16+
17+
private:
18+
bool _allowEmpty;
19+
};
20+
21+
#endif // QINTVALIDATOREX_H

0 commit comments

Comments
 (0)