• 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
  • plugins
  • declarative
RouteRequestModel.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 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "RouteRequestModel.h"
12 
13 #include "routing/RoutingManager.h"
14 #include "routing/RouteRequest.h"
15 #include "MarbleDeclarativeWidget.h"
16 #include "MarbleModel.h"
17 #include "Routing.h"
18 
19 RouteRequestModel::RouteRequestModel( QObject *parent ) :
20  QAbstractListModel( parent ),
21  m_request( 0 ),
22  m_routing( 0 )
23 {
24  QHash<int,QByteArray> roles;
25  roles[LongitudeRole] = "longitude";
26  roles[LatitudeRole] = "latitude";
27 #if QT_VERSION < 0x050000
28  setRoleNames( roles );
29 #else
30  m_roleNames = roles;
31 #endif
32 }
33 
34 RouteRequestModel::~RouteRequestModel()
35 {
36  // nothing to do
37 }
38 
39 int RouteRequestModel::rowCount ( const QModelIndex &parent ) const
40 {
41  if ( !parent.isValid() && m_request ) {
42  return m_request->size();
43  }
44 
45  return 0;
46 }
47 
48 #if QT_VERSION >= 0x050000
49 QHash<int, QByteArray> RouteRequestModel::roleNames() const
50 {
51  return m_roleNames;
52 }
53 #endif
54 
55 QVariant RouteRequestModel::headerData ( int section, Qt::Orientation orientation, int role ) const
56 {
57  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 ) {
58  return QString( "Waypoint" );
59  }
60 
61  return QVariant();
62 }
63 
64 QVariant RouteRequestModel::data ( const QModelIndex &index, int role ) const
65 {
66  if ( index.isValid() && m_request && index.row() >= 0 && index.row() < m_request->size() ) {
67  switch ( role ) {
68  case Qt::DisplayRole: return m_request->name( index.row() );
69  case LongitudeRole: return m_request->at( index.row() ).longitude( Marble::GeoDataCoordinates::Degree );
70  case LatitudeRole: return m_request->at( index.row() ).latitude( Marble::GeoDataCoordinates::Degree );
71  }
72  }
73 
74  return QVariant();
75 }
76 
77 Routing *RouteRequestModel::routing()
78 {
79  return m_routing;
80 }
81 
82 void RouteRequestModel::setRouting( Routing *routing )
83 {
84  if ( routing != m_routing ) {
85  m_routing = routing;
86  updateMap();
87  connect( m_routing, SIGNAL(mapChanged()), this, SLOT(updateMap()) );
88  emit routingChanged();
89  }
90 }
91 
92 void RouteRequestModel::updateMap()
93 {
94  if ( m_routing && m_routing->map() ) {
95  m_request = m_routing->map()->model()->routingManager()->routeRequest();
96 
97  connect( m_request, SIGNAL(positionChanged(int,GeoDataCoordinates)),
98  this, SLOT(updateData(int)) );
99  connect( m_request, SIGNAL(positionAdded(int)),
100  this, SLOT(updateAfterAddition(int)) );
101  connect( m_request, SIGNAL(positionRemoved(int)),
102  this, SLOT(updateAfterRemoval(int)) );
103 
104  emit layoutChanged();
105  }
106 }
107 
108 void RouteRequestModel::updateData( int idx )
109 {
110  QModelIndex affected = index( idx );
111  emit dataChanged( affected, affected );
112 }
113 
114 void RouteRequestModel::updateAfterRemoval( int idx )
115 {
116  beginRemoveRows( QModelIndex(), idx, idx );
117  removeRow( idx );
118  endRemoveRows();
119 }
120 
121 void RouteRequestModel::updateAfterAddition( int idx )
122 {
123  beginInsertRows( QModelIndex(), idx, idx );
124  insertRow( idx );
125  endInsertRows();
126 }
127 
128 void RouteRequestModel::setPosition ( int index, qreal longitude, qreal latitude )
129 {
130  if ( index >= 0 && index < m_request->size() ) {
131  m_request->setPosition( index, Marble::GeoDataCoordinates( longitude, latitude, 0.0, Marble::GeoDataCoordinates::Degree ) );
132  }
133 }
134 
135 #include "RouteRequestModel.moc"
Marble::RouteRequest::size
int size() const
Number of points in the route.
Definition: RouteRequest.cpp:126
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
RouteRequestModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Overload of QAbstractListModel.
Definition: RouteRequestModel.cpp:39
MarbleDeclarativeWidget.h
MarbleModel.h
This file contains the headers for MarbleModel.
RouteRequestModel::setRouting
void setRouting(Routing *routing)
Definition: RouteRequestModel.cpp:82
QObject
Routing
Definition: Routing.qml:15
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::RoutingManager::routeRequest
RouteRequest * routeRequest()
Returns the current route request.
Definition: RoutingManager.cpp:270
RouteRequestModel::LongitudeRole
Definition: RouteRequestModel.h:28
RoutingManager.h
Routing.h
Marble::MarbleModel::routingManager
RoutingManager * routingManager()
Definition: MarbleModel.cpp:605
RouteRequestModel::~RouteRequestModel
~RouteRequestModel()
Destructor.
Definition: RouteRequestModel.cpp:34
RouteRequestModel.h
Marble::RouteRequest::name
QString name(int index) const
Definition: RouteRequest.cpp:268
RouteRequestModel::routingChanged
void routingChanged()
RouteRequestModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Overload of QAbstractListModel.
Definition: RouteRequestModel.cpp:55
Routing::map
MarbleWidget map
Definition: Routing.h:29
RouteRequest.h
Marble::RouteRequest::setPosition
void setPosition(int index, const GeoDataCoordinates &position, const QString &name=QString())
Change the value of the element at the given position.
Definition: RouteRequest.cpp:249
MarbleWidget::model
Marble::MarbleModel * model()
Definition: MarbleDeclarativeWidget.cpp:85
RouteRequestModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Overload of QAbstractListModel.
Definition: RouteRequestModel.cpp:64
RouteRequestModel::RouteRequestModel
RouteRequestModel(QObject *parent=0)
Constructor.
Definition: RouteRequestModel.cpp:19
RouteRequestModel::setPosition
void setPosition(int index, qreal longitude, qreal latitude)
Definition: RouteRequestModel.cpp:128
RouteRequestModel::LatitudeRole
Definition: RouteRequestModel.h:29
RouteRequestModel::routing
Routing * routing()
Marble::RouteRequest::at
GeoDataCoordinates at(int index) const
Accessor for the n-th position.
Definition: RouteRequest.cpp:149
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