Fixed encoding issue so can now enter addresses in the UI.
[ptas] / zouba / location_p.cpp
1 #include "location_p.h"
2
3 #include <QXmlStreamReader>
4 #include <QByteArray>
5 #include <QDebug>
6
7 LocationPrivate::LocationPrivate( QString x, QString y ) :
8   m_x(x),
9   m_y(y),
10   m_valid(true)
11 {
12 }
13
14 LocationPrivate::LocationPrivate() :
15   m_x(0),
16   m_y(0),
17   m_valid(false)
18 {
19 }
20
21 void LocationPrivate::parseReply( const QByteArray &reply )
22 {
23   QXmlStreamReader xml( reply );
24
25   while ( !xml.atEnd() ) {
26     xml.readNext();
27     if ( xml.isStartElement() && xml.name() == "LOC" ) {
28       QXmlStreamAttributes attributes( xml.attributes() );
29       QStringRef xAttribute( attributes.value("x") );
30       QStringRef yAttribute( attributes.value("y") );
31       QString newX( xAttribute.toString() );
32       QString newY( yAttribute.toString() );
33
34       m_x = newX;
35       m_y = newY;
36     }
37   }
38
39   if ( xml.hasError() ) {
40     qDebug() << "xml error";
41     m_valid = false;
42   } else {
43     m_valid = true;
44   }
45 }
46
47 void LocationPrivate::setX( QString x )
48 {
49   m_x = x;
50 }
51
52 QString LocationPrivate::x() const
53 {
54   return m_x;
55 }
56
57 void LocationPrivate::setY( QString y )
58 {
59   m_y = y;
60 }
61
62 QString LocationPrivate::y() const
63 {
64   return m_y;
65 }
66
67 void LocationPrivate::setValid( bool valid )
68 {
69   m_valid = valid;
70 }
71
72 bool LocationPrivate::isValid() const
73 {
74   return m_valid;
75 }