• 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
  • render
  • elevationprofilemarker
ElevationProfileMarker.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 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
9 // Copyright 2011-2012 Florian Eßer <f.esser@rwth-aachen.de>
10 //
11 
12 #include "ElevationProfileMarker.h"
13 
14 #include <QRect>
15 
16 #include "MarbleLocale.h"
17 #include "MarbleModel.h"
18 #include "GeoDataDocument.h"
19 #include "GeoDataPlacemark.h"
20 #include "GeoPainter.h"
21 #include "GeoDataTreeModel.h"
22 #include "ViewportParams.h"
23 #include "MarbleGraphicsGridLayout.h"
24 
25 namespace Marble
26 {
27 
28 ElevationProfileMarker::ElevationProfileMarker()
29  : RenderPlugin( 0 )
30 {
31 }
32 
33 ElevationProfileMarker::ElevationProfileMarker( const MarbleModel *marbleModel )
34  : RenderPlugin( marbleModel ),
35  m_fontHeight( 10 ),
36  m_markerPlacemark( 0 ),
37  m_markerItem(),
38  m_markerIcon( &m_markerItem ),
39  m_markerText( &m_markerItem )
40 {
41  setVisible( false );
42  m_markerItem.setCacheMode( MarbleGraphicsItem::ItemCoordinateCache );
43 
44  connect( const_cast<MarbleModel *>( marbleModel )->treeModel(), SIGNAL(added(GeoDataObject*)),
45  this, SLOT(onGeoObjectAdded(GeoDataObject*)) );
46  connect( const_cast<MarbleModel *>( marbleModel )->treeModel(), SIGNAL(removed(GeoDataObject*)),
47  this, SLOT(onGeoObjectRemoved(GeoDataObject*)) );
48 }
49 
50 ElevationProfileMarker::~ElevationProfileMarker()
51 {
52 }
53 
54 QStringList ElevationProfileMarker::backendTypes() const
55 {
56  return QStringList( "elevationprofilemarker" );
57 }
58 
59 QString ElevationProfileMarker::renderPolicy() const
60 {
61  return "ALWAYS";
62 }
63 
64 QStringList ElevationProfileMarker::renderPosition() const
65 {
66  return QStringList() << "HOVERS_ABOVE_SURFACE";
67 }
68 
69 qreal ElevationProfileMarker::zValue() const
70 {
71  return 3.0;
72 }
73 
74 QString ElevationProfileMarker::name() const
75 {
76  return tr( "Elevation Profile Marker" );
77 }
78 
79 QString ElevationProfileMarker::guiString() const
80 {
81  return tr( "&Elevation Profile Marker" );
82 }
83 
84 QString ElevationProfileMarker::nameId() const
85 {
86  return QString( "elevationprofilemarker" );
87 }
88 
89 QString ElevationProfileMarker::version() const
90 {
91  return "1.0";
92 }
93 
94 QString ElevationProfileMarker::description() const
95 {
96  return tr( "Marks the current elevation of the elevation profile on the map." );
97 }
98 
99 QString ElevationProfileMarker::copyrightYears() const
100 {
101  return "2011, 2012";
102 }
103 
104 QList<PluginAuthor> ElevationProfileMarker::pluginAuthors() const
105 {
106  return QList<PluginAuthor>()
107  << PluginAuthor( "Bernhard Beschow", "bbeschow@cs.tu-berlin.de" )
108  << PluginAuthor( QString::fromUtf8 ( "Florian Eßer" ), "f.esser@rwth-aachen.de" );
109 }
110 
111 QIcon ElevationProfileMarker::icon() const
112 {
113  return QIcon(":/icons/elevationprofile.png");
114 }
115 
116 void ElevationProfileMarker::initialize()
117 {
118  m_markerIcon.setImage( QImage( ":/flag-red-mirrored.png" ) );
119 
120  MarbleGraphicsGridLayout *topLayout = new MarbleGraphicsGridLayout( 1, 2 );
121  m_markerItem.setLayout( topLayout );
122  topLayout->addItem( &m_markerIcon, 0, 0 );
123 
124  m_markerText.setFrame( LabelGraphicsItem::RoundedRectFrame );
125  m_markerText.setPadding( 1 );
126  topLayout->addItem( &m_markerText, 0, 1 );
127 }
128 
129 bool ElevationProfileMarker::isInitialized() const
130 {
131  return !m_markerIcon.image().isNull();
132 }
133 
134 bool ElevationProfileMarker::render( GeoPainter* painter, ViewportParams* viewport, const QString& renderPos, GeoSceneLayer* layer )
135 {
136  Q_UNUSED( renderPos )
137  Q_UNUSED( layer )
138 
139  if ( !m_markerPlacemark )
140  return true;
141 
142  if ( m_currentPosition != m_markerPlacemark->coordinate() ) {
143  m_currentPosition = m_markerPlacemark->coordinate();
144 
145  if ( m_currentPosition.isValid() ) {
146  QString unitString = tr( "m" );
147  int displayScale = 1.0;
148  const QLocale::MeasurementSystem measurementSystem = MarbleGlobal::getInstance()->locale()->measurementSystem();
149  switch ( measurementSystem ) {
150  case QLocale::MetricSystem:
151  /* nothing to do */
152  break;
153  case QLocale::ImperialSystem:
154  unitString = tr( "ft" );
155  displayScale = M2FT;
156  break;
157  }
158 
159  QString intervalStr;
160  intervalStr.setNum( m_currentPosition.altitude() * displayScale, 'f', 1 );
161  intervalStr += ' ' + unitString;
162  m_markerText.setText( intervalStr );
163  }
164  }
165 
166  if ( m_currentPosition.isValid() ) {
167  qreal x;
168  qreal y;
169  qreal lon;
170  qreal lat;
171  // move the icon by some pixels, so that the pole of the flag sits at the exact point
172  int dx = +3 + m_markerItem.size().width() / 2 - m_markerIcon.contentRect().right();//-4;
173  int dy = -6;
174  viewport->screenCoordinates( m_currentPosition.longitude( GeoDataCoordinates::Radian ),
175  m_currentPosition.latitude ( GeoDataCoordinates::Radian ),
176  x, y );
177  viewport->geoCoordinates( x + dx, y + dy, lon, lat, GeoDataCoordinates::Radian );
178  m_markerItem.setCoordinate( GeoDataCoordinates( lon, lat, m_currentPosition.altitude(),
179  GeoDataCoordinates::Radian ) );
180 
181  painter->save();
182 
183  m_markerItem.paintEvent( painter, viewport );
184 
185  painter->restore();
186  }
187 
188  return true;
189 }
190 
191 void ElevationProfileMarker::onGeoObjectAdded( GeoDataObject *object )
192 {
193  if ( m_markerPlacemark )
194  return;
195 
196  GeoDataDocument *document = dynamic_cast<GeoDataDocument *>( object );
197 
198  if ( !document )
199  return;
200 
201  if ( document->name() != "Elevation Profile" )
202  return;
203 
204  if ( document->size() < 1 )
205  return;
206 
207  m_markerPlacemark = dynamic_cast<GeoDataPlacemark *>( document->child( 0 ) );
208 
209  setVisible( m_markerPlacemark != 0 );
210 }
211 
212 void ElevationProfileMarker::onGeoObjectRemoved( GeoDataObject *object )
213 {
214  GeoDataDocument *const document = dynamic_cast<GeoDataDocument *>( object );
215  if ( !document )
216  return;
217 
218  if ( document->name() != "Elevation Profile" )
219  return;
220 
221  m_markerPlacemark = 0;
222 
223  emit repaintNeeded();
224 }
225 
226 }
227 
228 Q_EXPORT_PLUGIN2(ElevationProfileMarker, Marble::ElevationProfileMarker)
229 
230 #include "ElevationProfileMarker.moc"
GeoDataDocument.h
Marble::ElevationProfileMarker::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: ElevationProfileMarker.cpp:134
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
ElevationProfileMarker.h
Marble::ElevationProfileMarker::~ElevationProfileMarker
~ElevationProfileMarker()
Definition: ElevationProfileMarker.cpp:50
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:64
Marble::GeoDataContainer::child
GeoDataFeature * child(int)
returns the requested child item
Definition: GeoDataContainer.cpp:132
Marble::MarbleLocale::measurementSystem
QLocale::MeasurementSystem measurementSystem() const
Definition: MarbleLocale.cpp:45
Marble::ElevationProfileMarker::ElevationProfileMarker
ElevationProfileMarker()
Definition: ElevationProfileMarker.cpp:28
Marble::ElevationProfileMarker::copyrightYears
QString copyrightYears() const
Definition: ElevationProfileMarker.cpp:99
Marble::ElevationProfileMarker
Definition: ElevationProfileMarker.h:27
Marble::RenderPlugin::repaintNeeded
void repaintNeeded(QRegion dirtyRegion=QRegion())
This signal is emitted if an update of the view is needed.
Marble::ViewportParams::geoCoordinates
bool geoCoordinates(const int x, const int y, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Degree) const
Get the earth coordinates corresponding to a pixel in the map.
Definition: ViewportParams.cpp:391
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::ElevationProfileMarker::zValue
qreal zValue() const
Returns the z value of the layer (default: 0.0).
Definition: ElevationProfileMarker.cpp:69
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
Marble::ElevationProfileMarker::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: ElevationProfileMarker.cpp:64
Marble::ElevationProfileMarker::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: ElevationProfileMarker.cpp:104
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::GeoDataPlacemark::coordinate
GeoDataCoordinates coordinate(const QDateTime &dateTime=QDateTime(), bool *iconAtCoordinates=0) const
Return the coordinates of the placemark at time dateTime as a GeoDataCoordinates. ...
Definition: GeoDataPlacemark.cpp:78
Marble::LabelGraphicsItem::setImage
void setImage(const QImage &image, const QSize &size=QSize())
Definition: LabelGraphicsItem.cpp:85
Marble::MarbleGraphicsItem::size
QSizeF size() const
Returns the size of the item.
Definition: MarbleGraphicsItem.cpp:136
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Marble::MarbleGraphicsItem::setLayout
void setLayout(AbstractMarbleGraphicsLayout *layout)
Set the layout of the graphics item.
Definition: MarbleGraphicsItem.cpp:146
Marble::MarbleGraphicsGridLayout::addItem
void addItem(ScreenGraphicsItem *item, int row, int column)
Definition: MarbleGraphicsGridLayout.cpp:74
Marble::GeoDataCoordinates::altitude
qreal altitude() const
return the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1197
Marble::ElevationProfileMarker::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: ElevationProfileMarker.cpp:111
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::M2FT
const qreal M2FT
Definition: MarbleGlobal.h:192
Marble::FrameGraphicsItem::RoundedRectFrame
Definition: FrameGraphicsItem.h:31
Marble::LabelGraphicsItem::setText
void setText(const QString &text)
Definition: LabelGraphicsItem.cpp:71
Marble::FrameGraphicsItem::contentRect
QRectF contentRect() const
Returns the rect of the content in item coordinates.
Definition: FrameGraphicsItem.cpp:171
Marble::MarbleGraphicsItem::ItemCoordinateCache
Definition: MarbleGraphicsItem.h:41
Marble::ViewportParams::screenCoordinates
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: ViewportParams.cpp:357
Marble::MarbleGraphicsGridLayout
Definition: MarbleGraphicsGridLayout.h:27
Marble::GeoDataContainer::size
int size() const
size of the container
Definition: GeoDataContainer.cpp:179
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
Marble::ElevationProfileMarker::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: ElevationProfileMarker.cpp:79
Marble::RenderPlugin::setVisible
void setVisible(bool visible)
settting visible
Definition: RenderPlugin.cpp:149
MarbleLocale.h
GeoPainter.h
GeoDataPlacemark.h
GeoDataTreeModel.h
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::ElevationProfileMarker::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: ElevationProfileMarker.cpp:84
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
Marble::ElevationProfileMarker::description
QString description() const
Returns a user description of the plugin.
Definition: ElevationProfileMarker.cpp:94
MarbleGraphicsGridLayout.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::ElevationProfileMarker::name
QString name() const
Returns the user-visible name of the plugin.
Definition: ElevationProfileMarker.cpp:74
Marble::ElevationProfileMarker::version
QString version() const
Definition: ElevationProfileMarker.cpp:89
Marble::ElevationProfileMarker::backendTypes
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
Definition: ElevationProfileMarker.cpp:54
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::ElevationProfileMarker::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: ElevationProfileMarker.cpp:59
Marble::MarbleGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
Definition: MarbleGraphicsItem.cpp:159
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:480
Marble::FrameGraphicsItem::setFrame
void setFrame(FrameType type)
Sets the type of the Frame.
Definition: FrameGraphicsItem.cpp:47
Marble::ElevationProfileMarker::initialize
void initialize()
Definition: ElevationProfileMarker.cpp:116
Marble::ElevationProfileMarker::isInitialized
bool isInitialized() const
Definition: ElevationProfileMarker.cpp:129
Marble::MarbleGraphicsItem::paintEvent
bool paintEvent(QPainter *painter, const ViewportParams *viewport)
Paints the item on the screen in view coordinates.
Definition: MarbleGraphicsItem.cpp:38
Marble::LabelGraphicsItem::image
QImage image() const
Definition: LabelGraphicsItem.cpp:80
Marble::GeoDataCoordinates::isValid
bool isValid() const
Returns.
Definition: GeoDataCoordinates.cpp:624
Marble::FrameGraphicsItem::setPadding
void setPadding(qreal width)
Set the padding of the item.
Definition: FrameGraphicsItem.cpp:130
Marble::BillboardGraphicsItem::setCoordinate
void setCoordinate(const GeoDataCoordinates &coordinates)
Definition: BillboardGraphicsItem.cpp:98
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 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