Add debugging for station list parsing
authorLuciano Montanaro <mikelima@cirulla.net>
Sun, 10 Nov 2013 13:36:49 +0000 (14:36 +0100)
committerLuciano Montanaro <mikelima@cirulla.net>
Sun, 10 Nov 2013 13:36:49 +0000 (14:36 +0100)
application/stationlistmodel.cpp
application/stationlistmodel.h

index 5770141..2ee009d 100644 (file)
@@ -90,6 +90,12 @@ QHash<int, QByteArray> StationListModel::roleNames() const
     return roles;
 }
 
+int StationListModel::rowCount(const QModelIndex &parent) const
+{
+    return QStandardItemModel::rowCount(parent);
+
+}
+
 void StationListModel::readStationsElement()
 {
     m_reader.readNext();
@@ -101,7 +107,7 @@ void StationListModel::readStationsElement()
             if (m_reader.name() == "station") {
                 readStationElement();
             } else {
-                skipUnknownElement();
+                skipUnknownElement(m_reader.name().toString());
             }
         } else {
             m_reader.readNext();
@@ -126,7 +132,7 @@ void StationListModel::readStationElement()
             } else  if (m_reader.name() == "code") {
                 readCodeElement(item);
             } else {
-                skipUnknownElement();
+                skipUnknownElement(m_reader.name().toString());
             }
         } else {
             m_reader.readNext();
@@ -164,9 +170,9 @@ void StationListModel::readCodeElement(QStandardItem *item)
     }
 }
 
-void StationListModel::skipUnknownElement()
+void StationListModel::skipUnknownElement(const QString &name)
 {
-    qDebug() << "skipping unknown element";
+    qDebug() << "skipping unknown element" << name << "at line" << m_reader.lineNumber();
 
     m_reader.readNext();
     while (!m_reader.atEnd()) {
@@ -174,7 +180,7 @@ void StationListModel::skipUnknownElement()
             m_reader.readNext();
             break;
         } else if (!m_reader.isStartElement()) {
-            skipUnknownElement();
+            skipUnknownElement(m_reader.name().toString());
         } else {
             m_reader.readNext();
         }
index 7913e06..d59f99b 100644 (file)
@@ -32,6 +32,8 @@ class StationListModel : public QStandardItemModel
 {
     Q_OBJECT
     Q_ENUMS(StationListRole)
+    Q_PROPERTY(int count READ rowCount)
+
 public:
     enum StationListRole {
         PositionRole = Qt::UserRole + 1, //< QGeoCoordinate - Station coordinate
@@ -45,6 +47,10 @@ public:
 
     QHash<int, QByteArray> roleNames() const;
 
+    // Needed to make SectionScroller happy.
+    Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
+
+
 signals:
 
 public slots:
@@ -55,7 +61,7 @@ private:
     void readPosElement(QStandardItem *item);
     void readNameElement(QStandardItem *item);
     void readCodeElement(QStandardItem *item);
-    void skipUnknownElement();
+    void skipUnknownElement(const QString &name = QString());
 
     QXmlStreamReader m_reader;
 };