Esempio n. 1
0
void bacra::RouteContainer::addRouteItem(QString from, QString to)
{
    if (from.trimmed().length() == 0 || to.trimmed().length() == 0) {
        emit invalidRoute();
        return;
    }

    /* fetch & process data */
    /* import data to model */
    /* if valid data */
    beginInsertRows(QModelIndex(), 0, 0);
    Route *r = new Route();
    if (!r->parseLines(from)) {
        delete r;
        emit invalidRoute();
        return;
    }
    mRoutes.prepend(r);
    endInsertRows();
    emit routeAdded();


    /* else nonvalid data */
    // emit invalidRoute();
}
Esempio n. 2
0
void bacra::RouteContainer::stopDataReceived(const QString &data)
{
    qDebug() << "RouteContainer::stopDataReceived()";
    QStringList stopNameAndLine = data.split(';');
    if (stopNameAndLine.size() != 2) {
        qDebug() << "invalid data";
        return;
    }
    QRegExp rx(".+[(](\\d{1,6})[)]");
    rx.indexIn(stopNameAndLine.at(0));
    QString stopId = rx.cap(1);
    QList<Route *>::ConstIterator it;
    bool routeUpdated = false;
    for (it = mRoutes.begin(); it != mRoutes.end(); it++) {
        qDebug() << "checking " << (*it)->stopId();
        if ((*it)->stopId() == stopId) {
              (*it)->parseLines(data);
              emit updatedDepartures();
              routeUpdated = true;
              qDebug() << "updating " << stopId;
        }
    }
    if (routeUpdated) {
        emit stopAdded();
        return;
    }

    Route *r = bacra::RouteFactory::createStop(data);
    if (!r->parseLines(data)) {
        qDebug() << "RouteContainer::stopDataReceived()";
        emit invalidStop();
        return;
    }

    beginInsertRows(QModelIndex(), 0, 0);
    mRoutes.prepend(r);
    endInsertRows();

    //ok for testing purpose save
    //saveRoutes("./savedata.txt");

    emit stopAdded();
}