MapView* SampleLapViewer::createLapView(int refRace, int refLap)
{
    QVector<QPointF> positions;
    QSqlQuery posQuery;
    posQuery.prepare("select longitude, latitude from POSITION where ref_lap_race = ? and ref_lap_num = ?");
    posQuery.addBindValue(refRace);
    posQuery.addBindValue(refLap);

    if (posQuery.exec())
    {
        while (posQuery.next())
        {
            GeoCoordinate tmp;
            tmp.setLongitude(posQuery.value(0).toFloat());
            tmp.setLatitude(posQuery.value(1).toFloat());

            positions << tmp.projection();
        }
    }

    MapScene* sc = new MapScene(50 * 1000, this);
    sc->addTrack(positions);

    MapView* view = new MapView(this);
    view->setDragMode(QGraphicsView::ScrollHandDrag);
    view->setScene(sc);
    connect(view, SIGNAL(zoomedAround(int,QPointF)), this, SLOT(zoomView(int)));

    return view;
}
Exemplo n.º 2
0
void DocumentManager::addDocument(MapDocument *mapDocument)
{
    Q_ASSERT(mapDocument);
    Q_ASSERT(!mDocuments.contains(mapDocument));

    mDocuments.append(mapDocument);
    mUndoGroup->addStack(mapDocument->undoStack());

    MapView *view = new MapView(mTabWidget);
    MapScene *scene = new MapScene(view); // scene is owned by the view

    scene->setMapDocument(mapDocument);
    view->setScene(scene);

    const int documentIndex = mDocuments.size() - 1;

    mTabWidget->addTab(view, mapDocument->displayName());
    mTabWidget->setTabToolTip(documentIndex, mapDocument->fileName());
    connect(mapDocument, SIGNAL(fileNameChanged()), SLOT(updateDocumentTab()));
    connect(mapDocument, SIGNAL(modifiedChanged()), SLOT(updateDocumentTab()));

    switchToDocument(documentIndex);
    centerViewOn(0, 0);
}