1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2010 Fachhochschule Potsdam - http://fh-potsdam.de
6
Fritzing is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
Fritzing is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************
22
$Author: cohen@irascible.com $:
23
$Date: 2010-10-03 11:53:17 +0200 (Sun, 03 Oct 2010) $
25
********************************************************************/
27
#ifndef BOUNDEDREGEXPVALIDATOR_H
28
#define BOUNDEDREGEXPVALIDATOR_H
30
#include <QRegExpValidator>
33
typedef qreal (*Converter)(const QString &, const QString & symbol);
35
class BoundedRegExpValidator : public QRegExpValidator
38
BoundedRegExpValidator(QObject * parent) : QRegExpValidator(parent) {
39
m_max = std::numeric_limits<double>::max();
40
m_min = std::numeric_limits<double>::min();
45
void setBounds(qreal min, qreal max) {
50
void setConverter(Converter converter) {
51
m_converter = converter;
54
void setSymbol(const QString & symbol) {
58
QValidator::State validate ( QString & input, int & pos ) const {
59
QValidator::State state = QRegExpValidator::validate(input, pos);
60
if (state == QValidator::Invalid) return state;
61
if (state == QValidator::Intermediate) return state;
62
if (m_converter == NULL) return state;
64
qreal converted = m_converter(input, m_symbol);
65
if (converted < m_min) return QValidator::Invalid;
66
if (converted > m_max) return QValidator::Invalid;
68
return QValidator::Acceptable;
75
Converter m_converter;
1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2011 Fachhochschule Potsdam - http://fh-potsdam.de
6
Fritzing is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
Fritzing is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************
22
$Author: cohen@irascible.com $:
23
$Date: 2011-07-30 21:17:22 +0200 (Sat, 30 Jul 2011) $
25
********************************************************************/
27
#ifndef BOUNDEDREGEXPVALIDATOR_H
28
#define BOUNDEDREGEXPVALIDATOR_H
30
#include <QRegExpValidator>
33
typedef double (*Converter)(const QString &, const QString & symbol);
35
class BoundedRegExpValidator : public QRegExpValidator
38
BoundedRegExpValidator(QObject * parent) : QRegExpValidator(parent) {
39
m_max = std::numeric_limits<double>::max();
40
m_min = std::numeric_limits<double>::min();
45
void setBounds(double min, double max) {
50
void setConverter(Converter converter) {
51
m_converter = converter;
54
void setSymbol(const QString & symbol) {
58
QValidator::State validate ( QString & input, int & pos ) const {
59
QValidator::State state = QRegExpValidator::validate(input, pos);
60
if (state == QValidator::Invalid) return state;
61
if (state == QValidator::Intermediate) return state;
62
if (m_converter == NULL) return state;
64
double converted = m_converter(input, m_symbol);
65
if (converted < m_min) return QValidator::Invalid;
66
if (converted > m_max) return QValidator::Invalid;
68
return QValidator::Acceptable;
75
Converter m_converter;