b915be26750958cd92381ccd2ced34ca3417f69e
[ptas] / zouba / src / 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( const QString &x, const QString &y, const QString &label ) :
9   m_label(label),
10   m_address(),
11   m_x(x),
12   m_y(y),
13   m_valid(true)
14 {
15 }
16
17 LocationPrivate::LocationPrivate( const QString &label ) :
18   m_label(label),
19   m_address(),
20   m_x(0),
21   m_y(0),
22   m_valid(false)
23 {
24 }
25
26 LocationPrivate::~LocationPrivate()
27 {
28 }
29
30 void LocationPrivate::parseReply( const QByteArray &reply )
31 {
32   qDebug() << "parsing";
33   QXmlStreamReader xml( reply );
34
35   while ( !xml.atEnd() ) {
36     xml.readNext();
37     if ( xml.isStartElement() && xml.name() == "LOC" ) {
38       QXmlStreamAttributes attributes( xml.attributes() );
39       QStringRef xAttribute( attributes.value("x") );
40       QStringRef yAttribute( attributes.value("y") );
41       QString newX( xAttribute.toString() );
42       QString newY( yAttribute.toString() );
43
44       m_x = newX;
45       m_y = newY;
46     }
47   }
48
49   if ( xml.hasError() ) {
50     qDebug() << "xml error";
51     m_valid = false;
52   } else {
53     qDebug() << "(" << m_x << "," << m_y << ")";
54     if ( m_x.isEmpty() ||  m_y.isEmpty() ) {
55       qDebug() << "is NOT valid";
56       m_valid = false;
57     } else {
58       qDebug() << "is now valid";
59       m_valid = true;
60     }
61   }
62 }
63
64 void LocationPrivate::setLabel( const QString &label)
65 {
66   m_label = label;
67 }
68
69 QString LocationPrivate::label() const
70 {
71   return m_label;
72 }
73
74 void LocationPrivate::setAddress( const QString &address)
75 {
76   m_address = address;
77 }
78
79 QString LocationPrivate::address() const
80 {
81   return m_address;
82 }
83
84 void LocationPrivate::setX( uint x )
85 {
86   m_x = QString( "%1" ).arg( x );
87 }
88
89 void LocationPrivate::setX( const QString &x )
90 {
91   m_x = x;
92 }
93
94 QString LocationPrivate::x() const
95 {
96   return m_x;
97 }
98
99 void LocationPrivate::setY( uint y )
100 {
101   m_y = QString( "%1" ).arg( y );
102 }
103
104 void LocationPrivate::setY( const QString &y )
105 {
106   m_y = y;
107 }
108
109 QString LocationPrivate::y() const
110 {
111   return m_y;
112 }
113
114 void LocationPrivate::setValid( bool valid )
115 {
116   m_valid = valid;
117 }
118
119 bool LocationPrivate::isValid() const
120 {
121   return m_valid;
122 }