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

marble

  • sources
  • kde-4.14
  • 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( const MarbleModel *marbleModel )
29  : RenderPlugin( marbleModel ),
30  m_markerPlacemark( 0 ),
31  m_markerItem(),
32  m_markerIcon( &m_markerItem ),
33  m_markerText( &m_markerItem )
34 {
35  if ( !marbleModel ) {
36  return;
37  }
38  setVisible( false );
39  m_markerItem.setCacheMode( MarbleGraphicsItem::ItemCoordinateCache );
40 
41  connect( const_cast<MarbleModel *>( marbleModel )->treeModel(), SIGNAL(added(GeoDataObject*)),
42  this, SLOT(onGeoObjectAdded(GeoDataObject*)) );
43  connect( const_cast<MarbleModel *>( marbleModel )->treeModel(), SIGNAL(removed(GeoDataObject*)),
44  this, SLOT(onGeoObjectRemoved(GeoDataObject*)) );
45 }
46 
47 ElevationProfileMarker::~ElevationProfileMarker()
48 {
49 }
50 
51 QStringList ElevationProfileMarker::backendTypes() const
52 {
53  return QStringList( "elevationprofilemarker" );
54 }
55 
56 QString ElevationProfileMarker::renderPolicy() const
57 {
58  return "ALWAYS";
59 }
60 
61 QStringList ElevationProfileMarker::renderPosition() const
62 {
63  return QStringList() << "HOVERS_ABOVE_SURFACE";
64 }
65 
66 qreal ElevationProfileMarker::zValue() const
67 {
68  return 3.0;
69 }
70 
71 QString ElevationProfileMarker::name() const
72 {
73  return tr( "Elevation Profile Marker" );
74 }
75 
76 QString ElevationProfileMarker::guiString() const
77 {
78  return tr( "&Elevation Profile Marker" );
79 }
80 
81 QString ElevationProfileMarker::nameId() const
82 {
83  return QString( "elevationprofilemarker" );
84 }
85 
86 QString ElevationProfileMarker::version() const
87 {
88  return "1.0";
89 }
90 
91 QString ElevationProfileMarker::description() const
92 {
93  return tr( "Marks the current elevation of the elevation profile on the map." );
94 }
95 
96 QString ElevationProfileMarker::copyrightYears() const
97 {
98  return "2011, 2012";
99 }
100 
101 QList<PluginAuthor> ElevationProfileMarker::pluginAuthors() const
102 {
103  return QList<PluginAuthor>()
104  << PluginAuthor( "Bernhard Beschow", "bbeschow@cs.tu-berlin.de" )
105  << PluginAuthor( QString::fromUtf8 ( "Florian Eßer" ), "f.esser@rwth-aachen.de" );
106 }
107 
108 QIcon ElevationProfileMarker::icon() const
109 {
110  return QIcon(":/icons/elevationprofile.png");
111 }
112 
113 void ElevationProfileMarker::initialize()
114 {
115  m_markerIcon.setImage( QImage( ":/flag-red-mirrored.png" ) );
116 
117  MarbleGraphicsGridLayout *topLayout = new MarbleGraphicsGridLayout( 1, 2 );
118  m_markerItem.setLayout( topLayout );
119  topLayout->addItem( &m_markerIcon, 0, 0 );
120 
121  m_markerText.setFrame( LabelGraphicsItem::RoundedRectFrame );
122  m_markerText.setPadding( 1 );
123  topLayout->addItem( &m_markerText, 0, 1 );
124 }
125 
126 bool ElevationProfileMarker::isInitialized() const
127 {
128  return !m_markerIcon.image().isNull();
129 }
130 
131 bool ElevationProfileMarker::render( GeoPainter* painter, ViewportParams* viewport, const QString& renderPos, GeoSceneLayer* layer )
132 {
133  Q_UNUSED( renderPos )
134  Q_UNUSED( layer )
135 
136  if ( !m_markerPlacemark )
137  return true;
138 
139  if ( m_currentPosition != m_markerPlacemark->coordinate() ) {
140  m_currentPosition = m_markerPlacemark->coordinate();
141 
142  if ( m_currentPosition.isValid() ) {
143  QString unitString = tr( "m" );
144  int displayScale = 1.0;
145  const MarbleLocale::MeasurementSystem measurementSystem =
146  MarbleGlobal::getInstance()->locale()->measurementSystem();
147  switch ( measurementSystem ) {
148  case MarbleLocale::MetricSystem:
149  /* nothing to do */
150  break;
151  case MarbleLocale::ImperialSystem:
152  unitString = tr( "ft" );
153  displayScale = M2FT;
154  break;
155  case MarbleLocale::NauticalSystem:
156  unitString = tr("ft");
157  displayScale = 0.001 * KM2NM * NM2FT;
158  }
159 
160  QString intervalStr;
161  intervalStr.setNum( m_currentPosition.altitude() * displayScale, 'f', 1 );
162  intervalStr += ' ' + unitString;
163  m_markerText.setText( intervalStr );
164  }
165  }
166 
167  if ( m_currentPosition.isValid() ) {
168  qreal x;
169  qreal y;
170  qreal lon;
171  qreal lat;
172  // move the icon by some pixels, so that the pole of the flag sits at the exact point
173  int dx = +3 + m_markerItem.size().width() / 2 - m_markerIcon.contentRect().right();//-4;
174  int dy = -6;
175  viewport->screenCoordinates( m_currentPosition.longitude( GeoDataCoordinates::Radian ),
176  m_currentPosition.latitude ( GeoDataCoordinates::Radian ),
177  x, y );
178  viewport->geoCoordinates( x + dx, y + dy, lon, lat, GeoDataCoordinates::Radian );
179  m_markerItem.setCoordinate( GeoDataCoordinates( lon, lat, m_currentPosition.altitude(),
180  GeoDataCoordinates::Radian ) );
181 
182  painter->save();
183 
184  m_markerItem.paintEvent( painter, viewport );
185 
186  painter->restore();
187  }
188 
189  return true;
190 }
191 
192 void ElevationProfileMarker::onGeoObjectAdded( GeoDataObject *object )
193 {
194  if ( m_markerPlacemark )
195  return;
196 
197  GeoDataDocument *document = dynamic_cast<GeoDataDocument *>( object );
198 
199  if ( !document )
200  return;
201 
202  if ( document->name() != "Elevation Profile" )
203  return;
204 
205  if ( document->size() < 1 )
206  return;
207 
208  m_markerPlacemark = dynamic_cast<GeoDataPlacemark *>( document->child( 0 ) );
209 
210  setVisible( m_markerPlacemark != 0 );
211 }
212 
213 void ElevationProfileMarker::onGeoObjectRemoved( GeoDataObject *object )
214 {
215  GeoDataDocument *const document = dynamic_cast<GeoDataDocument *>( object );
216  if ( !document )
217  return;
218 
219  if ( document->name() != "Elevation Profile" )
220  return;
221 
222  m_markerPlacemark = 0;
223 
224  emit repaintNeeded();
225 }
226 
227 }
228 
229 Q_EXPORT_PLUGIN2(ElevationProfileMarker, Marble::ElevationProfileMarker)
230 
231 #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:131
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
ElevationProfileMarker.h
Marble::ElevationProfileMarker::~ElevationProfileMarker
~ElevationProfileMarker()
Definition: ElevationProfileMarker.cpp:47
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::MarbleLocale::NauticalSystem
Definition: MarbleLocale.h:40
Marble::GeoDataContainer::child
GeoDataFeature * child(int)
returns the requested child item
Definition: GeoDataContainer.cpp:239
Marble::MarbleLocale::measurementSystem
MarbleLocale::MeasurementSystem measurementSystem() const
Definition: MarbleLocale.cpp:45
Marble::ElevationProfileMarker::copyrightYears
QString copyrightYears() const
Definition: ElevationProfileMarker.cpp:96
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:66
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:61
Marble::ElevationProfileMarker::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: ElevationProfileMarker.cpp:101
Marble::PluginAuthor
Definition: PluginInterface.h:28
QPainter::save
void save()
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:172
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
QImage::isNull
bool isNull() const
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::MarbleLocale::MeasurementSystem
MeasurementSystem
Definition: MarbleLocale.h:37
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
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:108
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
QString::fromUtf8
QString fromUtf8(const char *str, int size)
Marble::M2FT
const qreal M2FT
Definition: MarbleGlobal.h:211
Marble::FrameGraphicsItem::RoundedRectFrame
Definition: FrameGraphicsItem.h:31
Marble::LabelGraphicsItem::setText
void setText(const QString &text)
Definition: LabelGraphicsItem.cpp:71
Marble::ElevationProfileMarker::ElevationProfileMarker
ElevationProfileMarker(const MarbleModel *marbleModel=0)
Definition: ElevationProfileMarker.cpp:28
Marble::FrameGraphicsItem::contentRect
QRectF contentRect() const
Returns the rect of the content in item coordinates.
Definition: FrameGraphicsItem.cpp:167
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:286
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:76
Marble::RenderPlugin::setVisible
void setVisible(bool visible)
settting visible
Definition: RenderPlugin.cpp:151
QString
QList
MarbleLocale.h
GeoPainter.h
GeoDataPlacemark.h
GeoDataTreeModel.h
QStringList
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:81
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
QRectF::right
qreal right() const
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:91
MarbleGraphicsGridLayout.h
ViewportParams.h
This file contains the headers for ViewportParams.
QImage
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:71
Marble::NM2FT
const qreal NM2FT
Definition: MarbleGlobal.h:208
QPainter::restore
void restore()
Marble::ElevationProfileMarker::version
QString version() const
Definition: ElevationProfileMarker.cpp:86
Marble::MarbleLocale::MetricSystem
Definition: MarbleLocale.h:38
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:51
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::ElevationProfileMarker::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: ElevationProfileMarker.cpp:56
Marble::MarbleGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
Definition: MarbleGraphicsItem.cpp:159
QString::setNum
QString & setNum(short n, int base)
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:544
Marble::FrameGraphicsItem::setFrame
void setFrame(FrameType type)
Sets the type of the Frame.
Definition: FrameGraphicsItem.cpp:43
Marble::ElevationProfileMarker::initialize
void initialize()
Definition: ElevationProfileMarker.cpp:113
Marble::ElevationProfileMarker::isInitialized
bool isInitialized() const
Definition: ElevationProfileMarker.cpp:126
Marble::MarbleGraphicsItem::paintEvent
bool paintEvent(QPainter *painter, const ViewportParams *viewport)
Paints the item on the screen in view coordinates.
Definition: MarbleGraphicsItem.cpp:38
Marble::MarbleLocale::ImperialSystem
Definition: MarbleLocale.h:39
Marble::KM2NM
const qreal KM2NM
Definition: MarbleGlobal.h:207
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:126
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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
QSizeF::width
qreal width() const
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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
  • 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