Beispiel #1
0
MapView::MapView(QWidget *parent) :
    QGraphicsView(parent)
{
    QGraphicsScene* scene = new QGraphicsScene(this);
    setScene(scene);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setInteractive(true);

    QGeoServiceProvider *serviceProvider = new QGeoServiceProvider("nokia");
    QGeoMappingManager *manager = serviceProvider->mappingManager();

    geo_map = new Map(manager);
    connect(geo_map, SIGNAL(markerClicked(QStringList)), SIGNAL(markerClicked(QStringList)));
    geo_map->setMapType(QGraphicsGeoMap::StreetMap);
    geo_map->setCenter(QGeoCoordinate(0.0, 0.0));
    geo_map->setZoomLevel(5);
    scene->addItem(geo_map);

    track = new QGeoMapPolylineObject;
    QPen pen(Qt::red);
    pen.setWidth(3);
    track->setPen(pen);
    track->setZValue(1);
    setMouseTracking(true);
}
Beispiel #2
0
/**
 * @brief Mouse right click on map
 * @param p_x
 * @param p_y
 * @note  If a marker is clicked, the markerClicked() signal 
 *        containing the marker id is emitted, otherwise the context menu
 *        to save the new place is shown
 */
void MarbleMap::mouseRightClick(int p_x, int p_y)
{
#ifdef DBG_MARBLE_MAP
  qDebug() << "MarbleMap::mouseRightClick() pt = " << p_x << ", " << p_y;
#endif
  int l_id = -1;
  
  QVector<const GeoDataPlacemark *> l_v = whichFeatureAt(QPoint(p_x, p_y));
  
  if(0 < l_v.size())        // since we can have more placemarks (e.g. zoom too low)
  {
    l_id = l_v.at(0)->id(); // then, get the first one
    emit markerClicked(l_id);
  }
  else
  {
    QMenu l_menu;
    l_menu.addAction("Save this location?");
    
    QPoint l_pos = mapToGlobal(QPoint(p_x, p_y)); // the menu position is relative to screen and not to widget
    QAction* l_action = l_menu.exec(l_pos);
    if (l_action)
    {
      qreal l_lng;
      qreal l_lat;
      geoCoordinates(p_x, p_y, l_lng, l_lat);
#ifdef DBG_MARBLE_MAP
      qDebug() << "MarbleMap::mouseRightClick() going to create marker at " << l_lat << ", " << l_lng;
#endif
      createMarker(l_lat, l_lng);
    }
  }
}
Beispiel #3
0
void MapView::addData(const QTime &time, qreal lat, qreal lon, const QStringList &metadata)
{
    // Add marker
    Marker *marker = new Marker(time, lat, lon, metadata);
    marker->setZValue(2);

    markers.append(marker);
    qSort(markers.begin(), markers.end(), markerLessThan);

    geo_map->addMapObject(marker);
    geo_map->setCenter(marker->coordinate());
    QStringList md = marker->metadata();
    md.prepend(marker->time().toString());
    emit markerClicked(md);

    // Add point to track
    QList<QGeoCoordinate> path;
    foreach (const Marker *marker, markers)
        path.append(marker->coordinate());

    track->setPath(path);

    // QGeoMapPolylineObject cannot be added to map if it's empty
    if (!path.isEmpty() && !geo_map->mapObjects().contains(track))
        geo_map->addMapObject(track);
}
Beispiel #4
0
/**
 * @brief Mouse left click on marker
 * @param p_x
 * @param p_y
 * @note  If a marker is clicked, the markerClicked() signal 
 *        containing the marker id is emitted 
 */
void MarbleMap::mouseLeftClick(int p_x, int p_y)
{
  int l_id = -1;
#ifdef DBG_MARBLE_MAP
  qDebug() << "MarbleMap::mouseLeftClick() pt = " << p_x << ", " << p_y;
#endif
  QVector<const GeoDataPlacemark *> l_v = whichFeatureAt(QPoint(p_x, p_y));
  
  if(0 < l_v.size())         // since we can have more placemarks (e.g. zoom too low)
  {
    l_id = l_v.at(0)->id();  // then, get the first one
    
    m_curr_popup_x = p_x;
    m_curr_popup_y = p_y;
    
    emit markerClicked(l_id);
  }
}