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