bool TTraceRecorder::createFile(const QWhereaboutsUpdate &update) { bool ret; _filename = update.updateDate().toString("yyyyMMdd") + '_' + update.updateTime().toString("hhmmss"); _tracks = new QFile(_tmpDir + '/' + _filename + ".trk"); _waypoints = new QFile(_tmpDir + '/' + _filename + ".wpt"); if(ret = (_tracks->open(QIODevice::WriteOnly) && _waypoints->open(QIODevice::WriteOnly))) { _trackName = QString("Transit"); _trackState = out; _firstSample = true; tUserLog() << _filename << " started"; emit signalRecordInfo(_filename, 0); } else { qDebug() << "Error opening trace file: " << _tmpDir + '/' + _filename + ".trk"; delete _tracks; delete _waypoints; _tracks = NULL; _waypoints = NULL; emit signalRecordInfo("Recording error", 0); } return ret; }
QDebug operator<<(QDebug dbg, const QWhereaboutsUpdate &update) { QWhereaboutsCoordinate coord = update.coordinate(); dbg.nospace() << "QWhereaboutsUpdate(" << update.updateDateTime().toString("yy/MM/dd hh:mm:ss").toLatin1().constData() << " (" << coord.latitude() << ", " << coord.longitude() << ", "; if (coord.type() == QWhereaboutsCoordinate::Coordinate3D) dbg.nospace() << coord.altitude(); else dbg.nospace() << '?'; dbg.nospace() << "))"; return dbg.space(); }
void TTraceRecorder::addSample(const QWhereaboutsUpdate &update) { if(_firstSample) { _firstSample = false; _minLat = _maxLat = update.coordinate().latitude(); _minLon = _maxLon = update.coordinate().longitude(); } else { _minLat = (_minLat < update.coordinate().latitude()) ? _minLat : update.coordinate().latitude(); _maxLat = (_maxLat > update.coordinate().latitude()) ? _maxLat : update.coordinate().latitude(); _minLon = (_minLon < update.coordinate().longitude()) ? _minLon : update.coordinate().longitude(); _maxLon = (_maxLon > update.coordinate().longitude()) ? _maxLon : update.coordinate().longitude(); } if(_trackState == out) { QString str = QString("\n <trk>\n <name>") + _trackName + QString("</name>\n <trkseg>\n"); _tracks->write(str.toAscii()); } else if(_trackState == onTrack) { _tracks->write(QString(" <trkseg>\n").toAscii()); } _trackState = onSeg; QString str; QString latitude = QString("%1").arg(update.coordinate().latitude(), 0, 'f', 10); QString longitude = QString("%1").arg(update.coordinate().longitude(), 0, 'f', 10); bool is3d = update.coordinate().type() == QWhereaboutsCoordinate::Coordinate3D; QString altitude = (is3d) ? QString::number(update.coordinate().altitude()) : QString("nan"); while(_pendingWaypoints.count() > 0) { str = QString("\n <wpt lat=\"") + latitude + QString("\" lon=\"") + longitude + QString("\">\n"); str += QString(" <name>") + _pendingWaypoints.takeFirst() + QString("</name>\n"); if(is3d) { str += QString(" <ele>") + altitude + QString("</ele>\n"); } str += QString(" </wpt>\n"); _waypoints->write(str.toAscii()); } str = QString(" <trkpt lat=\"") + latitude + QString("\" lon=\"") + longitude + QString("\">\n"); if(is3d) { str += QString(" <ele>") + altitude + QString("</ele>\n"); } str += QString(" <time>") + update.updateDateTime().toString("yyyy-MM-ddThh:mm:ssZ") + QString("</time>\n"); str += QString(" </trkpt>\n"); _tracks->write(str.toAscii()); _samples ++; emit signalRecordInfo(_filename, _samples); }