Example #1
0
void trackmap::loadTrackmap(QString path){
    QFile *file = new QFile( path );

    QList<QString> outsideLine;
    QList<QString> insideLine;
    QList<QString> coordinatePairs;
    QDomDocument doc;

    outsidePath.clear();
    insidePath.clear();

    file->open(QIODevice::ReadOnly | QIODevice::Text);

    doc.setContent(file);

    QDomElement root = doc.firstChildElement();

    QDomElement outsideCoordinates = root.elementsByTagName("outsidePath").at(0).firstChildElement("coordinates");
    QDomElement insideCoordinates = root.elementsByTagName("insidePath").at(0).firstChildElement("coordinates");
    QDomElement finishPoint1coordinates = root.elementsByTagName("finishPoint1").at(0).firstChildElement("coordinates");
    QDomElement finishPoint2coordinates = root.elementsByTagName("finishPoint2").at(0).firstChildElement("coordinates");

    outsideLine = outsideCoordinates.text().split("\n");
    insideLine = insideCoordinates.text().split("\n");

    for(int i = 0; i < outsideLine.length(); i++){
        coordinatePairs = outsideLine.at(i).split(",");
        outsidePath.append( new QVector3D( coordinatePairs.at(0).toFloat(), coordinatePairs.at(1).toFloat(), coordinatePairs.at(2).toFloat() ) );
    }

    for(int i = 0; i < insideLine.length(); i++){
        coordinatePairs = insideLine.at(i).split(",");
        insidePath.append( new QVector3D( coordinatePairs.at(0).toFloat(), coordinatePairs.at(1).toFloat(), coordinatePairs.at(2).toFloat() ) );
    }

    coordinatePairs = finishPoint1coordinates.text().split(",");
    finishPoint1.setX(coordinatePairs.at(0).toFloat());
    finishPoint1.setY(coordinatePairs.at(1).toFloat());
    finishPoint1.setZ(coordinatePairs.at(2).toFloat());

    coordinatePairs = finishPoint2coordinates.text().split(",");
    finishPoint2.setX(coordinatePairs.at(0).toFloat());
    finishPoint2.setY(coordinatePairs.at(1).toFloat());
    finishPoint2.setZ(coordinatePairs.at(2).toFloat());

    file->close();

    normalizeCoordinates();
    trackValidity = true;
}
Example #2
0
void SlippyMapWidget::ZoomTo(const QPoint & NewCenter, int NewZoom)
{
    if (NewZoom < MINZOOMLEVEL)
        NewZoom = MINZOOMLEVEL;
    if (NewZoom > MAXZOOMLEVEL)
        NewZoom = MAXZOOMLEVEL;
    if ((int)p->Zoom == NewZoom)
        return;

    qreal dx = (NewCenter.x()-width()/2)/(TILESIZE*1.0);
    qreal dy = (NewCenter.y()-height()/2)/(TILESIZE*1.0);

    p->Lon = (p->Lon + dx) * (1 << NewZoom) / (1 << p->Zoom) - dx;
    p->Lat = (p->Lat + dy) * (1 << NewZoom) / (1 << p->Zoom) - dy;
    p->Zoom = NewZoom;
    normalizeCoordinates();
    update();
}
Example #3
0
void SlippyMapWidget::mousePressEvent(QMouseEvent* ev)
{
    if (ev->button() == Qt::MidButton) {
        on_resetViewAction_triggered(true);
    } else if (ev->button() == Qt::LeftButton) {
        if (ev->pos().x() > width()-20)
        {
            if (ev->pos().y() < 20)
            {
                ZoomTo(QPoint(width()/2,height()/2),p->Zoom-1);
                emit redraw();
                return;
            }
            else if (ev->pos().y() > height()-20)
            {
                ZoomTo(QPoint(width()/2,height()/2),p->Zoom+1);
                emit redraw();
                return;
            }
            else if ((ev->pos().y() > (height()/2)-20) && (ev->pos().y() < (height()/2)))
            {
                p->Lon = p->VpLon;
                p->Lat = p->VpLat;
                p->Zoom = p->VpZoom;
                normalizeCoordinates();
                update();
                emit redraw();
                return;
            }
        }

        /* No special place, start selection */
        p->InSelection = true;
        p->SelectionStart = p->SelectionEnd = ev->pos();
        qDebug() << "Enter selection";
    } else {
        /* RightButton, start drag */
        p->PreviousDrag = ev->pos();
        p->InDrag = true;
    }
    emit redraw();
}