Add ability to check train details
[quandoparte] / application / stationlistmodel.cpp
index eeb444e..e370016 100644 (file)
@@ -1,6 +1,28 @@
+/*
+
+Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
 #include "stationlistmodel.h"
 
 #include <QFile>
+#include <QFileInfo>
 #include <QDebug>
 #include <QStandardItem>
 #include <QGeoCoordinate>
@@ -10,7 +32,6 @@ Q_DECLARE_METATYPE(QGeoCoordinate)
 
 StationListModel::StationListModel(QObject *parent) :
     QStandardItemModel(parent)
-
 {
     setRowCount(0);
 }
@@ -18,9 +39,12 @@ StationListModel::StationListModel(QObject *parent) :
 bool StationListModel::load(const QString &filename)
 {
     QFile file(filename);
+    QFileInfo fi(file);
 
-    qDebug() << "loading filename:" << filename;
+    qDebug() << "loading file:" << fi.absoluteFilePath();
 
+    emit layoutAboutToBeChanged();
+    beginResetModel();
     if (!file.open(QFile::ReadOnly | QFile::Text)) {
         qDebug() << "cannot open file:" << filename;
         return false;
@@ -46,11 +70,7 @@ bool StationListModel::load(const QString &filename)
         qDebug() << "file error for:" << filename;
         return false;
     }
-    /*
-    QModelIndex first = index(0, 0);
-    QModelIndex last = index(rowCount(), columnCount());
-    emit dataChanged(first, last);
-    */
+    endResetModel();
     emit layoutChanged();
     return true;
 }
@@ -102,7 +122,6 @@ void StationListModel::readPosElement(QStandardItem *item)
     QStringList coordinates = m_reader.readElementText().split(",");
     QGeoCoordinate pos = QGeoCoordinate(coordinates[0].toDouble(), coordinates[1].toDouble());
     item->setData(QVariant::fromValue(pos), PositionRole);
-    qDebug() << "pos:" << pos;
     m_reader.readElementText();
     if (m_reader.isEndElement()) {
         m_reader.readNext();
@@ -112,7 +131,6 @@ void StationListModel::readPosElement(QStandardItem *item)
 void StationListModel::readNameElement(QStandardItem *item)
 {
     item->setText(m_reader.readElementText());
-    qDebug() << "name:" << item->text();
     if (m_reader.isEndElement()) {
         m_reader.readNext();
     }