~ubuntu-branches/ubuntu/precise/fritzing/precise

« back to all changes in this revision

Viewing changes to src/utils/boundedregexpvalidator.h

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2011-08-26 10:11:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110826101105-w5hmn7zcf93ig5v6
Tags: 0.6.3b-1
* upgrapded to the newer upstream version
* parameters of the function GraphicsUtils::distanceFromLine in 
  src/svg/groundplanegenerator.cpp:767 are now declared as doubles,
  which Closes: #636441
* the new version fixes src/utils/folderutils.cpp, which
  Closes: #636061

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************
2
 
 
3
 
Part of the Fritzing project - http://fritzing.org
4
 
Copyright (c) 2007-2010 Fachhochschule Potsdam - http://fh-potsdam.de
5
 
 
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.
10
 
 
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.
15
 
 
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/>.
18
 
 
19
 
********************************************************************
20
 
 
21
 
$Revision: 4492 $:
22
 
$Author: cohen@irascible.com $:
23
 
$Date: 2010-10-03 11:53:17 +0200 (Sun, 03 Oct 2010) $
24
 
 
25
 
********************************************************************/
26
 
 
27
 
#ifndef BOUNDEDREGEXPVALIDATOR_H
28
 
#define BOUNDEDREGEXPVALIDATOR_H
29
 
 
30
 
#include <QRegExpValidator>
31
 
#include <limits>
32
 
 
33
 
typedef qreal (*Converter)(const QString &, const QString & symbol);
34
 
 
35
 
class BoundedRegExpValidator : public QRegExpValidator 
36
 
{
37
 
public:
38
 
        BoundedRegExpValidator(QObject * parent) : QRegExpValidator(parent) {
39
 
                m_max = std::numeric_limits<double>::max();
40
 
                m_min = std::numeric_limits<double>::min();
41
 
                m_converter = NULL;
42
 
                m_symbol = "";
43
 
        }
44
 
 
45
 
        void setBounds(qreal min, qreal max) {
46
 
                m_min = min;
47
 
                m_max = max;
48
 
        }
49
 
 
50
 
        void setConverter(Converter converter) {
51
 
                m_converter = converter;
52
 
        }
53
 
 
54
 
        void setSymbol(const QString & symbol) {
55
 
                m_symbol = symbol;
56
 
        }
57
 
 
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;
63
 
 
64
 
                qreal converted = m_converter(input, m_symbol);
65
 
                if (converted < m_min) return QValidator::Invalid;
66
 
                if (converted > m_max) return QValidator::Invalid;
67
 
 
68
 
                return QValidator::Acceptable;
69
 
        }
70
 
 
71
 
protected:
72
 
        qreal m_min;
73
 
        qreal m_max;
74
 
        QString m_symbol;
75
 
        Converter m_converter;
76
 
};
77
 
 
78
 
#endif
 
1
/*******************************************************************
 
2
 
 
3
Part of the Fritzing project - http://fritzing.org
 
4
Copyright (c) 2007-2011 Fachhochschule Potsdam - http://fh-potsdam.de
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
 
 
19
********************************************************************
 
20
 
 
21
$Revision: 5309 $:
 
22
$Author: cohen@irascible.com $:
 
23
$Date: 2011-07-30 21:17:22 +0200 (Sat, 30 Jul 2011) $
 
24
 
 
25
********************************************************************/
 
26
 
 
27
#ifndef BOUNDEDREGEXPVALIDATOR_H
 
28
#define BOUNDEDREGEXPVALIDATOR_H
 
29
 
 
30
#include <QRegExpValidator>
 
31
#include <limits>
 
32
 
 
33
typedef double (*Converter)(const QString &, const QString & symbol);
 
34
 
 
35
class BoundedRegExpValidator : public QRegExpValidator 
 
36
{
 
37
public:
 
38
        BoundedRegExpValidator(QObject * parent) : QRegExpValidator(parent) {
 
39
                m_max = std::numeric_limits<double>::max();
 
40
                m_min = std::numeric_limits<double>::min();
 
41
                m_converter = NULL;
 
42
                m_symbol = "";
 
43
        }
 
44
 
 
45
        void setBounds(double min, double max) {
 
46
                m_min = min;
 
47
                m_max = max;
 
48
        }
 
49
 
 
50
        void setConverter(Converter converter) {
 
51
                m_converter = converter;
 
52
        }
 
53
 
 
54
        void setSymbol(const QString & symbol) {
 
55
                m_symbol = symbol;
 
56
        }
 
57
 
 
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;
 
63
 
 
64
                double converted = m_converter(input, m_symbol);
 
65
                if (converted < m_min) return QValidator::Invalid;
 
66
                if (converted > m_max) return QValidator::Invalid;
 
67
 
 
68
                return QValidator::Acceptable;
 
69
        }
 
70
 
 
71
protected:
 
72
        double m_min;
 
73
        double m_max;
 
74
        QString m_symbol;
 
75
        Converter m_converter;
 
76
};
 
77
 
 
78
#endif