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