• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • routing
RoutingLayer.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2010 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "RoutingLayer.h"
12 
13 #include "GeoDataCoordinates.h"
14 #include "GeoDataLineString.h"
15 #include "GeoPainter.h"
16 #include "GeoSceneDocument.h"
17 #include "GeoSceneHead.h"
18 #include "MarblePlacemarkModel.h"
19 #include "MarbleWidget.h"
20 #include "MarbleWidgetPopupMenu.h"
21 #include "RoutingModel.h"
22 #include "RouteRequest.h"
23 #include "MarbleModel.h"
24 #include "AlternativeRoutesModel.h"
25 #include "RoutingManager.h"
26 #include "Maneuver.h"
27 
28 #include <QMap>
29 #include <QAbstractItemModel>
30 #include <QIcon>
31 #include <QItemSelectionModel>
32 #include <QKeyEvent>
33 #include <QMenu>
34 #include <QMouseEvent>
35 #include <QPixmap>
36 #include <QFileDialog>
37 
38 namespace Marble
39 {
40 
41 class RoutingLayerPrivate
42 {
43  template<class T>
44  struct PaintRegion {
45  T index;
46  QRegion region;
47 
48  PaintRegion( const T &index_, const QRegion &region_ ) :
49  index( index_ ), region( region_ )
50  {
51  // nothing to do
52  }
53  };
54 
55  typedef PaintRegion<QModelIndex> ModelRegion;
56  typedef PaintRegion<int> RequestRegion;
57 
58 public:
59  RoutingLayer *const q;
60 
61  QList<ModelRegion> m_instructionRegions;
62 
63  QList<RequestRegion> m_regions;
64 
65  QList<RequestRegion> m_alternativeRouteRegions;
66 
67  QList<ModelRegion> m_placemarks;
68 
69  QRegion m_routeRegion;
70 
71  int m_movingIndex;
72 
73  MarbleWidget *const m_marbleWidget;
74 
75  QPixmap m_targetPixmap;
76 
77  QRect m_dirtyRect;
78 
79  QPoint m_dropStopOver;
80 
81  QPoint m_dragStopOver;
82 
83  int m_dragStopOverRightIndex;
84 
85  RoutingModel *const m_routingModel;
86 
87  MarblePlacemarkModel *m_placemarkModel;
88 
89  QItemSelectionModel *m_selectionModel;
90 
91  bool m_routeDirty;
92 
93  QSize m_pixmapSize;
94 
95  RouteRequest *const m_routeRequest;
96 
97  MarbleWidgetPopupMenu *m_contextMenu;
98 
99  QAction *m_removeViaPointAction;
100 
101  int m_activeMenuIndex;
102 
103  AlternativeRoutesModel *const m_alternativeRoutesModel;
104 
105  ViewContext m_viewContext;
106 
107  bool m_viewportChanged;
108 
110  explicit RoutingLayerPrivate( RoutingLayer *parent, MarbleWidget *widget );
111 
113  void storeDragPosition( const QPoint &position );
114 
115  // The following methods are mostly only called at one place in the code, but often
116  // Inlined to avoid the function call overhead. Having functions here is just to
117  // keep the code clean
118 
120  inline QColor alphaAdjusted( const QColor &color, int alpha ) const;
121 
126  inline int viaInsertPosition( Qt::KeyboardModifiers modifiers ) const;
127 
129  inline void renderPlacemarks( GeoPainter *painter );
130 
132  inline void renderRoute( GeoPainter *painter );
133 
135  inline void renderAnnotations( GeoPainter *painter );
136 
138  inline void renderAlternativeRoutes( GeoPainter *painter );
139 
141  inline void renderRequest( GeoPainter *painter );
142 
144  void setRouteDirty( bool dirty );
145 
147  inline bool handleMouseButtonRelease( QMouseEvent *e );
148 
150  inline bool handleMouseButtonPress( QMouseEvent *e );
151 
153  inline bool handleMouseMove( QMouseEvent *e );
154 
156  inline bool isInfoPoint( const QPoint &point );
157 
159  inline bool isAlternativeRoutePoint( const QPoint &point );
160 
162  inline void paintStopOver( QRect position );
163 
165  inline void clearStopOver();
166 };
167 
168 RoutingLayerPrivate::RoutingLayerPrivate( RoutingLayer *parent, MarbleWidget *widget ) :
169  q( parent ), m_movingIndex( -1 ), m_marbleWidget( widget ),
170  m_targetPixmap( ":/data/bitmaps/routing_pick.png" ), m_dragStopOverRightIndex( -1 ),
171  m_routingModel( widget->model()->routingManager()->routingModel() ),
172  m_placemarkModel( 0 ), m_selectionModel( 0 ), m_routeDirty( false ), m_pixmapSize( 22, 22 ),
173  m_routeRequest( widget->model()->routingManager()->routeRequest() ),
174  m_activeMenuIndex( -1 ),
175  m_alternativeRoutesModel( widget->model()->routingManager()->alternativeRoutesModel() ),
176  m_viewContext( Still ), m_viewportChanged( true )
177 {
178  m_contextMenu = new MarbleWidgetPopupMenu( m_marbleWidget, m_marbleWidget->model() );
179  m_removeViaPointAction = new QAction( QObject::tr( "&Remove this destination" ), q );
180  QObject::connect( m_removeViaPointAction, SIGNAL(triggered()), q, SLOT(removeViaPoint()) );
181  m_contextMenu->addAction( Qt::RightButton, m_removeViaPointAction );
182  QAction *exportAction = new QAction( QObject::tr( "&Export route..." ), q );
183  QObject::connect( exportAction, SIGNAL(triggered()), q, SLOT(exportRoute()) );
184  m_contextMenu->addAction( Qt::RightButton, exportAction );
185  if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
186  m_pixmapSize = QSize( 38, 38 );
187  }
188 
189 }
190 
191 int RoutingLayerPrivate::viaInsertPosition( Qt::KeyboardModifiers modifiers ) const
192 {
193  if ( modifiers & Qt::ControlModifier ) {
194  bool leftHand = m_routeRequest->size() / 2 >= m_dragStopOverRightIndex;
195  if ( leftHand && m_routeRequest->size() > 2 ) {
196  return 0;
197  } else {
198  return m_routeRequest->size();
199  }
200  } else {
201  return m_dragStopOverRightIndex;
202  }
203 }
204 
205 void RoutingLayerPrivate::renderPlacemarks( GeoPainter *painter )
206 {
207  m_placemarks.clear();
208  painter->setPen( QColor( Qt::black ) );
209  for ( int i = 0; i < m_placemarkModel->rowCount(); ++i ) {
210  QModelIndex index = m_placemarkModel->index( i, 0 );
211  QVariant data = index.data( MarblePlacemarkModel::CoordinateRole );
212  if ( index.isValid() && !data.isNull() ) {
213  GeoDataCoordinates pos = data.value<GeoDataCoordinates>();
214 
215  QPixmap pixmap = index.data( Qt::DecorationRole ).value<QPixmap>();
216  if ( !pixmap.isNull() && m_selectionModel->isSelected( index ) ) {
217  QIcon selected = QIcon( pixmap );
218  QPixmap result = selected.pixmap( m_pixmapSize, QIcon::Selected, QIcon::On );
219  painter->drawPixmap( pos, result );
220  } else {
221  painter->drawPixmap( pos, pixmap );
222  }
223 
224  QRegion region = painter->regionFromRect( pos, m_targetPixmap.width(), m_targetPixmap.height() );
225  m_placemarks.push_back( ModelRegion( index, region ) );
226  }
227  }
228 }
229 
230 void RoutingLayerPrivate::renderAlternativeRoutes( GeoPainter *painter )
231 {
232  QPen alternativeRoutePen( m_marbleWidget->model()->routingManager()->routeColorAlternative() );
233  alternativeRoutePen.setWidth( 5 );
234  painter->setPen( alternativeRoutePen );
235 
236  for ( int i=0; i<m_alternativeRoutesModel->rowCount(); ++i ) {
237  GeoDataDocument* route = m_alternativeRoutesModel->route( i );
238  if ( route && route != m_alternativeRoutesModel->currentRoute() ) {
239  GeoDataLineString* points = AlternativeRoutesModel::waypoints( route );
240  if ( points ) {
241  painter->drawPolyline( *points );
242  if ( m_viewportChanged && m_viewContext == Still ) {
243  QRegion region = painter->regionFromPolyline( *points, 8 );
244  m_alternativeRouteRegions.push_back( RequestRegion( i, region ) );
245  }
246  }
247  }
248  }
249 }
250 
251 void RoutingLayerPrivate::renderRoute( GeoPainter *painter )
252 {
253  GeoDataLineString waypoints = m_routingModel->route().path();
254 
255  QPen standardRoutePen( m_marbleWidget->model()->routingManager()->routeColorStandard() );
256  standardRoutePen.setWidth( 5 );
257  if ( m_routeDirty ) {
258  standardRoutePen.setStyle( Qt::DotLine );
259  }
260  painter->setPen( standardRoutePen );
261 
262  painter->drawPolyline( waypoints );
263  if ( m_viewportChanged && m_viewContext == Still ) {
264  int const offset = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ? 24 : 8;
265  m_routeRegion = painter->regionFromPolyline( waypoints, offset );
266  }
267 
268 
269  standardRoutePen.setWidth( 2 );
270  painter->setPen( standardRoutePen );
271 
272  // Map matched position
273  //painter->setBrush( QBrush( Oxygen::brickRed4) );
274  //painter->drawEllipse( m_routingModel->route().positionOnRoute(), 8, 8 );
275 
276  painter->setBrush( QBrush( m_marbleWidget->model()->routingManager()->routeColorAlternative() ) );
277 
278  if ( !m_dropStopOver.isNull() ) {
279  int dx = 1 + m_pixmapSize.width() / 2;
280  int dy = 1 + m_pixmapSize.height() / 2;
281  QPoint center = m_dropStopOver - QPoint( dx, dy );
282  painter->drawPixmap( center, m_targetPixmap );
283 
284  if ( !m_dragStopOver.isNull() && m_dragStopOverRightIndex >= 0 && m_dragStopOverRightIndex <= m_routeRequest->size() ) {
285  QPoint moved = m_dropStopOver - m_dragStopOver;
286  if ( moved.manhattanLength() > 10 ) {
287  qreal lon( 0.0 ), lat( 0.0 );
288  if ( m_marbleWidget->geoCoordinates( m_dropStopOver.x(), m_dropStopOver.y(),
289  lon, lat, GeoDataCoordinates::Radian ) ) {
290  GeoDataCoordinates drag( lon, lat );
291  standardRoutePen.setStyle( Qt::DotLine );
292  painter->setPen( standardRoutePen );
293  GeoDataLineString lineString;
294  if ( m_dragStopOverRightIndex > 0 ) {
295  lineString << m_routeRequest->at( m_dragStopOverRightIndex-1 );
296  }
297  lineString << drag;
298  if ( m_dragStopOverRightIndex < m_routeRequest->size() ) {
299  lineString << m_routeRequest->at( m_dragStopOverRightIndex );
300  }
301  painter->drawPolyline( lineString );
302  standardRoutePen.setStyle( Qt::SolidLine );
303  painter->setPen( standardRoutePen );
304  }
305  }
306  }
307  }
308 
309  if ( m_viewContext == Animation ) {
310  return;
311  }
312 
313  m_instructionRegions.clear();
314  for ( int i = 0; i < m_routingModel->rowCount(); ++i ) {
315  QModelIndex index = m_routingModel->index( i, 0 );
316  GeoDataCoordinates pos = index.data( MarblePlacemarkModel::CoordinateRole ).value<GeoDataCoordinates>();
317 
318  painter->setBrush( QBrush( m_marbleWidget->model()->routingManager()->routeColorAlternative() ) );
319  if ( m_selectionModel && m_selectionModel->selection().contains( index ) ) {
320  for ( int j=0; j<m_routingModel->route().size(); ++j ) {
321  const RouteSegment & segment = m_routingModel->route().at( j );
322  if ( segment.maneuver().position() == pos ) {
323  GeoDataLineString currentRoutePoints = segment.path();
324 
325  QPen activeRouteSegmentPen( m_marbleWidget->model()->routingManager()->routeColorHighlighted() );
326 
327  activeRouteSegmentPen.setWidth( 6 );
328  if ( m_routeDirty ) {
329  activeRouteSegmentPen.setStyle( Qt::DotLine );
330  }
331  painter->setPen( activeRouteSegmentPen );
332  painter->drawPolyline( currentRoutePoints );
333 
334  painter->setPen( standardRoutePen );
335  painter->setBrush( QBrush( alphaAdjusted( Oxygen::hotOrange4, 200 ) ) );
336  }
337  }
338  }
339 
340  QRegion region = painter->regionFromEllipse( pos, 12, 12 );
341  m_instructionRegions.push_front( ModelRegion( index, region ) );
342  painter->drawEllipse( pos, 6, 6 );
343 
344  if( !m_routingModel->deviatedFromRoute() ) {
345  GeoDataCoordinates location = m_routingModel->route().currentSegment().nextRouteSegment().maneuver().position();
346  QString nextInstruction = m_routingModel->route().currentSegment().nextRouteSegment().maneuver().instructionText();
347  if( !nextInstruction.isEmpty() ) {
348  painter->setBrush( QBrush( Oxygen::hotOrange4 ) );
349  painter->drawEllipse( location, 6, 6 );
350  }
351  }
352  }
353 }
354 
355 void RoutingLayerPrivate::renderAnnotations( GeoPainter *painter )
356 {
357  if ( !m_selectionModel || m_selectionModel->selection().isEmpty() ) {
358  // nothing to do
359  return;
360  }
361 
362  for ( int i = 0; i < m_routingModel->rowCount(); ++i ) {
363  QModelIndex index = m_routingModel->index( i, 0 );
364 
365  if ( m_selectionModel->selection().contains( index ) ) {
366  bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
367  GeoDataCoordinates pos = index.data( MarblePlacemarkModel::CoordinateRole ).value<GeoDataCoordinates>();
368  painter->setPen( QColor( Qt::black ) );
369  painter->setBrush( QBrush( Oxygen::sunYellow6 ) );
370  painter->drawAnnotation( pos, index.data().toString(), QSize( smallScreen ? 240 : 120, 0 ), 10, 30, 5, 5 );
371  }
372  }
373 }
374 
375 void RoutingLayerPrivate::renderRequest( GeoPainter *painter )
376 {
377  m_regions.clear();
378  for ( int i = 0; i < m_routeRequest->size(); ++i ) {
379  GeoDataCoordinates pos = m_routeRequest->at( i );
380  if ( pos.longitude() != 0.0 && pos.latitude() != 0.0 ) {
381  QPixmap pixmap = m_routeRequest->pixmap( i );
382  painter->drawPixmap( pos, pixmap );
383  QRegion region = painter->regionFromRect( pos, pixmap.width(), pixmap.height() );
384  m_regions.push_front( RequestRegion( i, region ) );
385  }
386  }
387 }
388 
389 void RoutingLayerPrivate::storeDragPosition( const QPoint &pos )
390 {
391  m_dragStopOver = pos;
392  m_dragStopOverRightIndex = -1;
393 
394  qreal lon( 0.0 ), lat( 0.0 );
395  if ( m_routeRequest && !pos.isNull()
396  && m_marbleWidget->geoCoordinates( pos.x(), pos.y(), lon, lat, GeoDataCoordinates::Radian ) ) {
397  GeoDataCoordinates waypoint( lon, lat );
398  m_dragStopOverRightIndex = m_routingModel->rightNeighbor( waypoint, m_routeRequest );
399  }
400 }
401 
402 QColor RoutingLayerPrivate::alphaAdjusted( const QColor &color, int alpha ) const
403 {
404  QColor result( color );
405  result.setAlpha( alpha );
406  return result;
407 }
408 
409 bool RoutingLayerPrivate::handleMouseButtonPress( QMouseEvent *e )
410 {
411  foreach( const RequestRegion &region, m_regions ) {
412  if ( region.region.contains( e->pos() ) ) {
413  if ( e->button() == Qt::LeftButton ) {
414  m_movingIndex = region.index;
415  m_dropStopOver = QPoint();
416  m_dragStopOver = QPoint();
417  return true;
418  } else if ( e->button() == Qt::RightButton ) {
419  m_removeViaPointAction->setEnabled( true );
420  m_activeMenuIndex = region.index;
421  m_contextMenu->showRmbMenu( e->x(), e->y() );
422  return true;
423  } else
424  return false;
425  }
426  }
427 
428  foreach( const ModelRegion &region, m_instructionRegions ) {
429  if ( region.region.contains( e->pos() ) && m_selectionModel ) {
430  if ( e->button() == Qt::LeftButton ) {
431  QItemSelectionModel::SelectionFlag command = QItemSelectionModel::ClearAndSelect;
432  if ( m_selectionModel->isSelected( region.index ) ) {
433  command = QItemSelectionModel::Clear;
434  }
435  m_selectionModel->select( region.index, command );
436  m_dropStopOver = e->pos();
437  storeDragPosition( e->pos() );
438  // annotation and old annotation are dirty, large region
439  emit q->repaintNeeded();
440  return true;
441  } else if ( e->button() == Qt::RightButton ) {
442  m_removeViaPointAction->setEnabled( false );
443  m_contextMenu->showRmbMenu( e->x(), e->y() );
444  return true;
445  } else
446  return false;
447  }
448  }
449 
450  if ( m_routeRegion.contains( e->pos() ) ) {
451  if ( e->button() == Qt::LeftButton ) {
453  m_dropStopOver = e->pos();
454  storeDragPosition( e->pos() );
455  return true;
456  } else if ( e->button() == Qt::RightButton ) {
457  m_removeViaPointAction->setEnabled( false );
458  m_contextMenu->showRmbMenu( e->x(), e->y() );
459  return true;
460  } else
461  return false;
462  }
463 
464  if ( e->button() != Qt::LeftButton ) {
465  return false;
466  }
467 
468  foreach( const RequestRegion &region, m_alternativeRouteRegions ) {
469  if ( region.region.contains( e->pos() ) ) {
470  m_alternativeRoutesModel->setCurrentRoute( region.index );
471  return true;
472  }
473  }
474 
475  foreach( const ModelRegion &region, m_placemarks ) {
476  if ( region.region.contains( e->pos() ) ) {
477  emit q->placemarkSelected( region.index );
478  return true;
479  }
480  }
481 
482  return false;
483 }
484 
485 bool RoutingLayerPrivate::handleMouseButtonRelease( QMouseEvent *e )
486 {
487  if ( e->button() != Qt::LeftButton ) {
488  return false;
489  }
490 
491  if ( m_movingIndex >= 0 ) {
492  m_movingIndex = -1;
493  clearStopOver();
494  m_marbleWidget->model()->routingManager()->retrieveRoute();
495  return true;
496  }
497 
498  if ( !m_dropStopOver.isNull() && !m_dragStopOver.isNull() ) {
499  QPoint moved = e->pos() - m_dragStopOver;
500  if ( moved.manhattanLength() < 10 ) {
501  return false;
502  }
503 
504  qreal lon( 0.0 ), lat( 0.0 );
505  if ( m_dragStopOverRightIndex >= 0 && m_dragStopOverRightIndex <= m_routeRequest->size()
506  && m_marbleWidget->geoCoordinates( m_dropStopOver.x(), m_dropStopOver.y(), lon, lat, GeoDataCoordinates::Radian ) ) {
507  GeoDataCoordinates position( lon, lat );
508  m_dragStopOverRightIndex = viaInsertPosition( e->modifiers() );
509  m_routeRequest->insert( m_dragStopOverRightIndex, position );
510  clearStopOver();
511  m_marbleWidget->model()->routingManager()->retrieveRoute();
512  return true;
513  }
514  }
515 
516  return false;
517 }
518 
519 bool RoutingLayerPrivate::handleMouseMove( QMouseEvent *e )
520 {
521  qreal lon( 0.0 ), lat( 0.0 );
522  if ( m_marbleWidget->geoCoordinates( e->pos().x(), e->pos().y(),
523  lon, lat, GeoDataCoordinates::Radian ) ) {
524 
525  if ( m_movingIndex >= 0 ) {
526  GeoDataCoordinates moved( lon, lat );
527  m_routeRequest->setPosition( m_movingIndex, moved );
528  m_marbleWidget->setCursor( Qt::ArrowCursor );
529  } else if ( !m_dragStopOver.isNull() ) {
530  // Repaint only that region of the map that is affected by the change
531  m_dragStopOverRightIndex = viaInsertPosition( e->modifiers() );
532  QRect dirty = m_routeRegion.boundingRect();
533  dirty |= QRect( m_dropStopOver, m_pixmapSize );
534  dirty |= QRect( e->pos(), m_pixmapSize );
535  if ( e->buttons() & Qt::LeftButton ) {
536  m_dropStopOver = e->pos();
537  } else {
538  m_dragStopOver = QPoint();
539  m_dropStopOver = QPoint();
540  }
541  emit q->repaintNeeded( dirty );
542  m_marbleWidget->setCursor( Qt::ArrowCursor );
543  } else if ( isInfoPoint( e->pos() ) ) {
544  clearStopOver();
545  m_marbleWidget->setCursor( Qt::ArrowCursor );
546  } else if ( m_routeRegion.contains( e->pos() ) ) {
547  m_dropStopOver = e->pos();
548  m_marbleWidget->setCursor( Qt::ArrowCursor );
549  } else if ( !m_dropStopOver.isNull() ) {
550  clearStopOver();
551  } else if ( isAlternativeRoutePoint( e->pos() ) ) {
552  m_marbleWidget->setCursor( Qt::ArrowCursor );
553  }
554  else {
555  return false;
556  }
557 
558  // Update pixmap in the map (old and new position needs repaint)
559  paintStopOver( QRect( e->pos(), m_pixmapSize ) );
560  return true;
561  }
562 
563  return false;
564 }
565 
566 bool RoutingLayerPrivate::isInfoPoint( const QPoint &point )
567 {
568  foreach( const RequestRegion &region, m_regions ) {
569  if ( region.region.contains( point ) ) {
570  return true;
571  }
572  }
573 
574  foreach( const ModelRegion &region, m_instructionRegions ) {
575  if ( region.region.contains( point ) ) {
576  return true;
577  }
578  }
579 
580  return false;
581 }
582 
583  bool RoutingLayerPrivate::isAlternativeRoutePoint( const QPoint &point )
584  {
585  foreach( const RequestRegion &region, m_alternativeRouteRegions ) {
586  if ( region.region.contains( point ) ) {
587  return true;
588  }
589  }
590 
591  return false;
592  }
593 
594 void RoutingLayerPrivate::paintStopOver( QRect dirty )
595 {
596  emit q->repaintNeeded( m_dirtyRect );
597  int dx = 1 + m_pixmapSize.width() / 2;
598  int dy = 1 + m_pixmapSize.height() / 2;
599  dirty.adjust( -dx, -dy, -dx, -dy );
600  emit q->repaintNeeded( dirty );
601  m_dirtyRect = dirty;
602 }
603 
604 void RoutingLayerPrivate::clearStopOver()
605 {
606  m_dropStopOver = QPoint();
607  m_dragStopOver = QPoint();
608  emit q->repaintNeeded( m_dirtyRect );
609 }
610 
611 RoutingLayer::RoutingLayer( MarbleWidget *widget, QWidget *parent ) :
612  QObject( parent ), d( new RoutingLayerPrivate( this, widget ) )
613 {
614  connect( widget->model()->routingManager(), SIGNAL(stateChanged(RoutingManager::State)),
615  this, SLOT(updateRouteState(RoutingManager::State)) );
616  connect( widget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)),
617  this, SLOT(setViewportChanged()) );
618  connect( widget->model()->routingManager()->alternativeRoutesModel(), SIGNAL(currentRouteChanged(GeoDataDocument*)),
619  this, SLOT(setViewportChanged()) );
620  connect( widget->model()->routingManager()->alternativeRoutesModel(), SIGNAL(currentRouteChanged(GeoDataDocument*)),
621  this, SIGNAL(repaintNeeded()) );
622  connect( widget->model()->routingManager()->alternativeRoutesModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
623  this, SLOT(showAlternativeRoutes()) );
624 }
625 
626 RoutingLayer::~RoutingLayer()
627 {
628  delete d;
629 }
630 
631 QStringList RoutingLayer::renderPosition() const
632 {
633  return QStringList() << "HOVERS_ABOVE_SURFACE";
634 }
635 
636 qreal RoutingLayer::zValue() const
637 {
638  return 1.0;
639 }
640 
641 bool RoutingLayer::render( GeoPainter *painter, ViewportParams *viewport,
642  const QString& renderPos, GeoSceneLayer *layer )
643 {
644  Q_UNUSED( viewport )
645  Q_UNUSED( renderPos )
646  Q_UNUSED( layer )
647 
648  painter->save();
649 
650  if ( d->m_placemarkModel) {
651  d->renderPlacemarks( painter );
652  }
653 
654  if ( d->m_alternativeRoutesModel ) {
655  d->renderAlternativeRoutes( painter );
656  }
657 
658  d->renderRoute( painter );
659 
660  if ( d->m_routeRequest) {
661  d->renderRequest( painter );
662  }
663 
664  d->renderAnnotations( painter );
665 
666  painter->restore();
667  if ( d->m_viewportChanged && d->m_viewContext == Still ) {
668  d->m_viewportChanged = false;
669  }
670  return true;
671 }
672 
673 bool RoutingLayer::eventFilter( QObject *obj, QEvent *event )
674 {
675  Q_UNUSED( obj )
676 
677  if ( event->type() == QEvent::MouseButtonPress ) {
678  QMouseEvent *e = static_cast<QMouseEvent*>( event );
679  return d->handleMouseButtonPress( e );
680  }
681 
682  if ( event->type() == QEvent::MouseButtonRelease ) {
683  QMouseEvent *e = static_cast<QMouseEvent*>( event );
684  return d->handleMouseButtonRelease( e );
685  }
686 
687  if ( event->type() == QEvent::MouseMove ) {
688  QMouseEvent *e = static_cast<QMouseEvent*>( event );
689  return d->handleMouseMove( e );
690  }
691 
692  return false;
693 }
694 
695 void RoutingLayer::setPlacemarkModel ( MarblePlacemarkModel *model )
696 {
697  d->m_placemarkModel = model;
698  setViewportChanged();
699 }
700 
701 void RoutingLayer::synchronizeWith( QItemSelectionModel *selection )
702 {
703  d->m_selectionModel = selection;
704 }
705 
706 void RoutingLayerPrivate::setRouteDirty( bool dirty )
707 {
708  m_routeDirty = dirty;
709 
714  emit q->repaintNeeded();
715 }
716 
717 void RoutingLayer::removeViaPoint()
718 {
719  if ( d->m_activeMenuIndex >= 0 ) {
720  d->m_routeRequest->remove( d->m_activeMenuIndex );
721  d->m_activeMenuIndex = -1;
722  d->setRouteDirty( true );
723  d->m_marbleWidget->model()->routingManager()->retrieveRoute();
724  }
725 }
726 
727 void RoutingLayer::showAlternativeRoutes()
728 {
729  setViewportChanged();
730  emit repaintNeeded();
731 }
732 
733 void RoutingLayer::exportRoute()
734 {
735  QString fileName = QFileDialog::getSaveFileName( d->m_marbleWidget,
736  tr( "Export Route" ), // krazy:exclude=qclasses
737  QDir::homePath(),
738  tr( "GPX and KML files (*.gpx *.kml)" ) );
739 
740  if ( !fileName.isEmpty() ) {
741  if ( fileName.endsWith( QLatin1String( ".gpx" ), Qt::CaseInsensitive ) ) {
742  QFile gpx( fileName );
743  if ( gpx.open( QFile::WriteOnly) ) {
744  d->m_routingModel->exportGpx( &gpx );
745  gpx.close();
746  }
747  } else {
748  d->m_marbleWidget->model()->routingManager()->saveRoute( fileName );
749  }
750  }
751 }
752 
753 void RoutingLayer::updateRouteState( RoutingManager::State state )
754 {
755  d->setRouteDirty( state == RoutingManager::Downloading );
756  setViewportChanged();
757 }
758 
759 void RoutingLayer::setViewportChanged()
760 {
761  d->m_viewportChanged = true;
762  d->m_routeRegion = QRegion();
763  d->m_instructionRegions.clear();
764  d->m_alternativeRouteRegions.clear();
765 }
766 
767 void RoutingLayer::setViewContext( ViewContext viewContext )
768 {
769  d->m_viewContext = viewContext;
770 }
771 
772 } // namespace Marble
773 
774 #include "RoutingLayer.moc"
GeoSceneHead.h
GeoDataCoordinates.h
RoutingModel.h
Marble::MarblePlacemarkModel
This class represents a model of all place marks which are currently available through a given Placem...
Definition: MarblePlacemarkModel.h:37
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:64
Marble::RoutingLayer::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Overriding QWidget, used to make the layer interactive.
Definition: RoutingLayer.cpp:673
Marble::RoutingLayer::setViewContext
void setViewContext(ViewContext viewContext)
Set the view context to determine whether the map is used interactively.
Definition: RoutingLayer.cpp:767
Marble::RoutingLayer::repaintNeeded
void repaintNeeded(const QRect &rect=QRect())
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::RoutingLayer::zValue
qreal zValue() const
Reimplemented from LayerInterface.
Definition: RoutingLayer.cpp:636
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::ViewContext
ViewContext
This enum is used to choose context in which map quality gets used.
Definition: MarbleGlobal.h:72
QWidget
GeoSceneDocument.h
QObject
Marble::RoutingLayer::~RoutingLayer
~RoutingLayer()
Destructor.
Definition: RoutingLayer.cpp:626
Marble::Oxygen::hotOrange4
QColor const hotOrange4
Definition: MarbleColors.h:86
Maneuver.h
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:102
RoutingManager.h
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::Animation
animated view (e.g. while rotating the globe)
Definition: MarbleGlobal.h:74
Marble::MarbleModel::routingManager
RoutingManager * routingManager()
Definition: MarbleModel.cpp:605
RoutingLayer.h
MarbleWidgetPopupMenu.h
Marble::Still
still image
Definition: MarbleGlobal.h:73
GeoDataLineString.h
Marble::Oxygen::sunYellow6
QColor const sunYellow6
Definition: MarbleColors.h:78
Marble::RoutingLayer::renderPosition
QStringList renderPosition() const
Reimplemented from LayerInterface.
Definition: RoutingLayer.cpp:631
Marble::RoutingLayer::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos="NONE", GeoSceneLayer *layer=0)
Reimplemented from LayerInterface.
Definition: RoutingLayer.cpp:641
Marble::MarbleWidget::model
MarbleModel * model() const
Return the model that this view shows.
Definition: MarbleWidget.cpp:283
MarblePlacemarkModel.h
GeoPainter.h
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:268
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::RoutingManager::State
State
Definition: RoutingManager.h:42
Marble::RoutingLayer::setPlacemarkModel
void setPlacemarkModel(MarblePlacemarkModel *model)
Set the placemark model to use.
Definition: RoutingLayer.cpp:695
AlternativeRoutesModel.h
MarbleWidget.h
This file contains the headers for MarbleWidget.
RouteRequest.h
Marble::RoutingManager::Downloading
Definition: RoutingManager.h:43
Marble::RoutingLayer::synchronizeWith
void synchronizeWith(QItemSelectionModel *selection)
Set the proxy model another QAbstractItemView uses that should share its selection model with us...
Definition: RoutingLayer.cpp:701
MarbleWidget
Wraps a Marble::MarbleWidget, providing access to important properties and methods.
Definition: MarbleDeclarativeWidget.h:50
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::RoutingManager::alternativeRoutesModel
AlternativeRoutesModel * alternativeRoutesModel()
Provides access to the model which contains a list of alternative routes.
Definition: RoutingManager.cpp:311
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal