318630db5ce13d495a670609a7815919e3dce5d1
[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   } else {
42     m_valid = true;
43   }
44 }
45
46 void LocationPrivate::setX( QString x )
47 {
48   m_x = x;
49 }
50
51 QString LocationPrivate::x() const
52 {
53   return m_x;
54 }
55
56 void LocationPrivate::setY( QString y )
57 {
58   m_y = y;
59 }
60
61 QString LocationPrivate::y() const
62 {
63   return m_y;
64 }
65
66 void LocationPrivate::setValid( bool valid )
67 {
68   m_valid = valid;
69 }
70
71 bool LocationPrivate::isValid() const
72 {
73   return m_valid;
74 }