コード例 #1
0
ファイル: london.cpp プロジェクト: iksaif/lugdulov
void
StationsPluginLondon::handleInfos(const QByteArray & data)
{
  QRegExp re_stations("station\\=\\{(.*)\\}\\;");
  QRegExp re_items("\\s*(\\w+)\\s*:(.*),");
  int ofs = 0;

  re_stations.setMinimal(true);
  re_items.setMinimal(true);

  while ((ofs = re_stations.indexIn(data, ofs)) >= 0) {
    bool ok;
    int id;
    QPointF pos;
    Station *station;
    QMap<QString, QString> values;

    ofs += re_stations.matchedLength();

    int station_ofs = 0;
    QString station_data = re_stations.capturedTexts().at(1);

    while ((station_ofs = re_items.indexIn(station_data, station_ofs)) >= 0) {
      QStringList capt = re_items.capturedTexts();

      if (capt.size() < 3)
	continue ;

      station_ofs += re_items.matchedLength();
      values[capt.at(1)] = capt.at(2);
      values[capt.at(1)].replace("\"", "");
    }

    id = values["id"].toInt(&ok);
    pos = QPointF(values["lat"].toDouble(),
		  values["long"].toDouble());

    if (!ok)
      continue ;

    station = getOrCreateStation(id);

    if (station->name().isEmpty())
      station->setName(values["name"]);
    if (station->pos().isNull())
      station->setPos(pos);
    station->setBikes(values["nbBikes"].toInt());
    station->setFreeSlots(values["nbEmptyDocks"].toInt());
    station->setTotalSlots(station->bikes() + station->freeSlots());

    storeOrDropStation(station);
  }

  emit stationsCreated(stations.values());
  emit stationsUpdated(stations.values());
}
コード例 #2
0
ファイル: wien.cpp プロジェクト: iksaif/lugdulov
void
StationsPluginWien::handleInfos(const QByteArray & data)
{
  QDomDocument doc;
  QDomNode node;

  doc.setContent(data);
  node = doc.firstChildElement("stations").firstChildElement("station");

  while (!node.isNull()) {
    Station *station;
    QDomNamedNodeMap attrs = node.attributes();
    int id;
    bool ok;
    qreal lat, lng;

    id = node.firstChildElement("id").text().toInt(&ok);

    if (!ok)
      continue ;

    station = getOrCreateStation(id);

    station->setData(node.firstChildElement("internal_id").text().toInt());

    if (station->name().isEmpty())
      station->setName(node.firstChildElement("name").text());
    if (station->description().isEmpty())
      station->setDescription(node.firstChildElement("description").text());

    lng = node.firstChildElement("longitude").text().toDouble();
    lat = node.firstChildElement("latitude").text().toDouble();

    if (station->pos().isNull())
      station->setPos(QPointF(lat, lng));

    station->setBikes(node.firstChildElement("free_bikes").text().toInt());
    station->setFreeSlots(node.firstChildElement("free_boxes").text().toInt());
    station->setTotalSlots(node.firstChildElement("boxes").text().toInt());

    storeOrDropStation(station);

    node = node.nextSiblingElement("station");
  }

  emit stationsCreated(stations.values());
  emit stationsUpdated(stations.values());
}