Parse the "code" element in the qpl file
authorLuciano Montanaro <mikelima@cirulla.net>
Fri, 13 Jan 2012 01:18:21 +0000 (02:18 +0100)
committerLuciano Montanaro <mikelima@cirulla.net>
Fri, 13 Jan 2012 01:18:21 +0000 (02:18 +0100)
application/resources/stations/stations.qpl
application/stationlistmodel.cpp
application/stationlistmodel.h

index d39ca8d..9b4701b 100644 (file)
     <station>
         <pos>45.0609728,7.6778693</pos>
         <name>Torino Porta Nuova</name>
+        <code>S00219Torino P.Nuova</code>
     </station>
     <station>
         <pos>44.3513022,9.2313884</pos>
index 40fb75f..5838c4a 100644 (file)
@@ -109,6 +109,8 @@ void StationListModel::readStationElement()
                 readPosElement(item);
             } else  if (m_reader.name() == "name") {
                 readNameElement(item);
+            } else  if (m_reader.name() == "code") {
+                readCodeElement(item);
             } else {
                 skipUnknownElement();
             }
@@ -137,6 +139,17 @@ void StationListModel::readNameElement(QStandardItem *item)
     }
 }
 
+void StationListModel::readCodeElement(QStandardItem *item)
+{
+    const QString code = m_reader.readElementText();
+    qDebug() << "reading code element" << code;
+
+    item->setData(QVariant::fromValue(code), StationCodeRole);
+    if (m_reader.isEndElement()) {
+        m_reader.readNext();
+    }
+}
+
 void StationListModel::skipUnknownElement()
 {
     qDebug() << "skipping unknown element";
index 5d3d5e8..b497fb5 100644 (file)
@@ -35,7 +35,7 @@ class StationListModel : public QStandardItemModel
 public:
     enum StationListRole {
         PositionRole = Qt::UserRole + 1, //< QGeoCoordinate - Station coordinate
-        StationIdRole, //< QString - Station Id (Precise name if the Display name is known to fail)
+        StationCodeRole, //< QString - Station Code (Precise name if the Display name is known to fail)
         RecentIndicatorRole //<bool - If the station has been recently looked up
     };
 
@@ -52,6 +52,7 @@ private:
     void readStationElement();
     void readPosElement(QStandardItem *item);
     void readNameElement(QStandardItem *item);
+    void readCodeElement(QStandardItem *item);
     void skipUnknownElement();
 
     QXmlStreamReader m_reader;