~ubuntu-branches/ubuntu/hardy/libterralib/hardy

« back to all changes in this revision

Viewing changes to src/terralib/application/qt/TeQtLatEdit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-25 22:32:59 UTC
  • Revision ID: james.westby@ubuntu.com-20051125223259-3zubal8ux4ki4fjg
Tags: upstream-3.0.3b2
ImportĀ upstreamĀ versionĀ 3.0.3b2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <qregexp.h>
 
2
#include <qstringlist.h> 
 
3
#include <math.h>
 
4
 
 
5
#include "TeQtLatEdit.h"
 
6
 
 
7
TeQtLatEdit::TeQtLatEdit(QWidget* parent, const char *name)
 
8
        :QLineEdit(parent, name)
 
9
{}
 
10
 
 
11
bool
 
12
TeQtLatEdit::decode(QString lado, short& dg, short& mn, float& sc, double& grauDec)
 
13
{
 
14
        short   posat,lim = 90;
 
15
 
 
16
        double  dd,pi;                  
 
17
        posat = 0;
 
18
        pi = 4.*atan((double)1.);
 
19
 
 
20
        // Longitude 
 
21
        if(dg < 0 || dg > lim)  
 
22
                return false;
 
23
 
 
24
        if(mn < 0 || mn > 60)
 
25
                return false;
 
26
 
 
27
        if(sc < 0. || sc > 60.)
 
28
                return false;
 
29
 
 
30
        if(lado == "s" || lado == "S")
 
31
        {
 
32
                if(dg > 0) dg = dg * -1;
 
33
                else if(mn > 0) mn = mn * -1;
 
34
                     else sc = sc * -1.;
 
35
        }
 
36
 
 
37
        dd = (double)(abs(dg)) + ((double)abs(mn)/60.) + fabs(sc)/3600.;
 
38
        if (dg < 0 || mn < 0 || (int)sc < 0)
 
39
                dd = -dd;
 
40
 
 
41
//      dd = dd*pi/180.;
 
42
        grauDec = dd;
 
43
        return true;
 
44
}
 
45
 
 
46
 
 
47
void TeQtLatEdit::focusOutEvent( QFocusEvent *e )
 
48
{
 
49
        int mat;
 
50
    QString str = text();
 
51
        QStringList myList;
 
52
        QRegExp exp1("^[nNsS][ ]\\d\\d?\\d?[ ]?\\d?\\d?[ ]?\\d?\\d?\\.?[0-9]?" );
 
53
        QRegExp exp2("^[nNsS][;]\\d\\d?\\d?[;]?\\d?\\d?[;]?\\d?\\d?\\.?[0-9]?" ); 
 
54
        QRegExp exp3("^[nNsS][:]\\d\\d?\\d?[:]?\\d?\\d?[:]?\\d?\\d?\\.?[0-9]?" ); 
 
55
        QRegExp exp4("^[+-]?\\d\\d?\\d?\\.?[0-9]?" ); 
 
56
        QString echo_;
 
57
 
 
58
        double grauDec;
 
59
 
 
60
    if ( (mat=exp1.match( str )) != -1 )
 
61
        {
 
62
                myList = QStringList::split(" ",str);
 
63
        }
 
64
        else if ((mat=exp2.match( str )) != -1 )
 
65
        {
 
66
                myList = QStringList::split(";",str);
 
67
        }
 
68
        else if ((mat=exp3.match( str )) != -1 )
 
69
        {
 
70
                myList = QStringList::split(":",str);
 
71
        }
 
72
        else if ((mat=exp4.match( str )) != -1 )
 
73
        {
 
74
                grauDec = str.toDouble();
 
75
                if ((grauDec >= -90.0 && grauDec <=90.0))
 
76
                {
 
77
                        echo_.sprintf("%3.10f",grauDec);
 
78
                        setText(echo_);
 
79
                        emit coordValidator(grauDec);
 
80
                        return;
 
81
                }
 
82
                else
 
83
                {
 
84
                        setSelection( 0, text().length() );
 
85
                        emit coordValidator(TeLATINVALID);
 
86
                        return;
 
87
                }
 
88
        }
 
89
        else
 
90
        {
 
91
                setSelection( 0, text().length() );
 
92
                emit coordValidator(TeLATINVALID);
 
93
                return;
 
94
        }
 
95
 
 
96
        int nelementos = myList.count();
 
97
        short graus, minutos = 0;
 
98
        float segundos = 0.0;
 
99
        
 
100
        graus = myList[1].toShort();
 
101
 
 
102
        if (nelementos > 2)
 
103
                minutos = myList[2].toShort();
 
104
        
 
105
        if (nelementos > 3)
 
106
                segundos = myList[3].toFloat();
 
107
 
 
108
        bool dec = decode(myList[0],graus, minutos, segundos, grauDec);
 
109
        if (dec)
 
110
        {
 
111
                echo_.sprintf("%s %d %d %2.2f",(const char*) myList[0], abs(graus), minutos, segundos);
 
112
                setText(echo_);
 
113
                emit coordValidator(grauDec);
 
114
                return;
 
115
        }
 
116
        else
 
117
        {
 
118
                setSelection( 0, text().length() );
 
119
                emit coordValidator(TeLATINVALID);
 
120
                return;
 
121
        }
 
122
}
 
123
 
 
124
void TeQtLatEdit::keyPressEvent( QKeyEvent *e )
 
125
{
 
126
    QLineEdit::keyPressEvent( e );
 
127
    if ( e->key() == Key_Enter || e->key() == Key_Return )
 
128
    {
 
129
        emit focusOutEvent(0);
 
130
    }
 
131
}
 
 
b'\\ No newline at end of file'