• 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
  • lib
  • marble
  • layers
PlacemarkLayer.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 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007-2008 Inge Wallin <ingwa@kde.org>
10 // Copyright 2011-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
11 //
12 
13 #include "PlacemarkLayer.h"
14 
15 #include <QModelIndex>
16 #include <QPoint>
17 #include <QPainter>
18 
19 #include "MarbleDebug.h"
20 #include "AbstractProjection.h"
21 #include "GeoDataStyle.h"
22 #include "GeoPainter.h"
23 #include "ViewportParams.h"
24 #include "VisiblePlacemark.h"
25 
26 using namespace Marble;
27 
28 bool PlacemarkLayer::m_useXWorkaround = false;
29 
30 PlacemarkLayer::PlacemarkLayer( QAbstractItemModel *placemarkModel,
31  QItemSelectionModel *selectionModel,
32  MarbleClock *clock,
33  QObject *parent ) :
34  QObject( parent ),
35  m_layout( placemarkModel, selectionModel, clock )
36 {
37  m_useXWorkaround = testXBug();
38  mDebug() << "Use workaround: " << ( m_useXWorkaround ? "1" : "0" );
39 
40  connect( &m_layout, SIGNAL(repaintNeeded()), SIGNAL(repaintNeeded()) );
41 }
42 
43 PlacemarkLayer::~PlacemarkLayer()
44 {
45 }
46 
47 QStringList PlacemarkLayer::renderPosition() const
48 {
49  return QStringList() << "HOVERS_ABOVE_SURFACE";
50 }
51 
52 qreal PlacemarkLayer::zValue() const
53 {
54  return 2.0;
55 }
56 
57 bool PlacemarkLayer::render( GeoPainter *geoPainter, ViewportParams *viewport,
58  const QString &renderPos, GeoSceneLayer *layer )
59 {
60  Q_UNUSED( renderPos )
61  Q_UNUSED( layer )
62 
63  QVector<VisiblePlacemark*> visiblePlacemarks = m_layout.generateLayout( viewport );
64  // draw placemarks less important first
65  QVector<VisiblePlacemark*>::const_iterator visit = visiblePlacemarks.constEnd();
66  QVector<VisiblePlacemark*>::const_iterator itEnd = visiblePlacemarks.constBegin();
67 
68  QPainter *const painter = geoPainter;
69 
70  while ( visit != itEnd ) {
71  --visit;
72 
73  VisiblePlacemark *const mark = *visit;
74 
75  QRect labelRect( mark->labelRect().toRect() );
76  QPoint symbolPos( mark->symbolPosition() );
77 
78  // when the map is such zoomed out that a given place
79  // appears many times, we draw one placemark at each
80  if (viewport->currentProjection()->repeatableX() ) {
81  const int symbolX = mark->symbolPosition().x();
82  const int textX = mark->labelRect().x();
83 
84  for ( int i = symbolX % (4 * viewport->radius());
85  i <= viewport->width();
86  i += 4 * viewport->radius() )
87  {
88  labelRect.moveLeft(i - symbolX + textX );
89  symbolPos.setX( i );
90 
91  painter->drawPixmap( symbolPos, mark->symbolPixmap() );
92  painter->drawPixmap( labelRect, mark->labelPixmap() );
93  }
94  } else { // simple case, one draw per placemark
95  painter->drawPixmap( symbolPos, mark->symbolPixmap() );
96  painter->drawPixmap( labelRect, mark->labelPixmap() );
97  }
98  }
99 
100  return true;
101 }
102 
103 RenderState PlacemarkLayer::renderState() const
104 {
105  return RenderState( "Placemarks" );
106 }
107 
108 QString PlacemarkLayer::runtimeTrace() const
109 {
110  return m_layout.runtimeTrace();
111 }
112 
113 QVector<const GeoDataPlacemark *> PlacemarkLayer::whichPlacemarkAt( const QPoint &pos )
114 {
115  return m_layout.whichPlacemarkAt( pos );
116 }
117 
118 void PlacemarkLayer::setShowPlaces( bool show )
119 {
120  m_layout.setShowPlaces( show );
121 }
122 
123 void PlacemarkLayer::setShowCities( bool show )
124 {
125  m_layout.setShowCities( show );
126 }
127 
128 void PlacemarkLayer::setShowTerrain( bool show )
129 {
130  m_layout.setShowTerrain( show );
131 }
132 
133 void PlacemarkLayer::setShowOtherPlaces( bool show )
134 {
135  m_layout.setShowOtherPlaces( show );
136 }
137 
138 void PlacemarkLayer::setShowLandingSites( bool show )
139 {
140  m_layout.setShowLandingSites( show );
141 }
142 
143 void PlacemarkLayer::setShowCraters( bool show )
144 {
145  m_layout.setShowCraters( show );
146 }
147 
148 void PlacemarkLayer::setShowMaria( bool show )
149 {
150  m_layout.setShowMaria( show );
151 }
152 
153 void PlacemarkLayer::requestStyleReset()
154 {
155  m_layout.requestStyleReset();
156 }
157 
158 
159 // Test if there a bug in the X server which makes
160 // text fully transparent if it gets written on
161 // QPixmaps that were initialized by filling them
162 // with Qt::transparent
163 
164 bool PlacemarkLayer::testXBug()
165 {
166  QString testchar( "K" );
167  QFont font( "Sans Serif", 10 );
168 
169  int fontheight = QFontMetrics( font ).height();
170  int fontwidth = QFontMetrics( font ).width(testchar);
171  int fontascent = QFontMetrics( font ).ascent();
172 
173  QPixmap pixmap( fontwidth, fontheight );
174  pixmap.fill( Qt::transparent );
175 
176  QPainter textpainter;
177  textpainter.begin( &pixmap );
178  textpainter.setPen( QColor( 0, 0, 0, 255 ) );
179  textpainter.setFont( font );
180  textpainter.drawText( 0, fontascent, testchar );
181  textpainter.end();
182 
183  QImage image = pixmap.toImage();
184 
185  for ( int x = 0; x < fontwidth; ++x ) {
186  for ( int y = 0; y < fontheight; ++y ) {
187  if ( qAlpha( image.pixel( x, y ) ) > 0 )
188  return false;
189  }
190  }
191 
192  return true;
193 }
194 
195 #include "PlacemarkLayer.moc"
196 
Marble::PlacemarkLayer::setShowOtherPlaces
void setShowOtherPlaces(bool show)
Definition: PlacemarkLayer.cpp:133
Marble::AbstractProjection::repeatableX
virtual bool repeatableX() const
Definition: AbstractProjection.cpp:93
Marble::PlacemarkLayer::setShowTerrain
void setShowTerrain(bool show)
Definition: PlacemarkLayer.cpp:128
Marble::VisiblePlacemark::symbolPixmap
const QPixmap & symbolPixmap() const
Returns the pixmap of the place mark symbol.
Definition: VisiblePlacemark.cpp:38
Marble::VisiblePlacemark
A class which represents the visible place marks on a map.
Definition: VisiblePlacemark.h:38
QFontMetrics::ascent
int ascent() const
Marble::VisiblePlacemark::labelPixmap
const QPixmap & labelPixmap() const
Returns the pixmap of the place mark name label.
Definition: VisiblePlacemark.cpp:105
QRectF::toRect
QRect toRect() const
QPainter::end
bool end()
Marble::PlacemarkLayer::whichPlacemarkAt
QVector< const GeoDataPlacemark * > whichPlacemarkAt(const QPoint &pos)
Returns a list of model indexes that are at position pos.
Definition: PlacemarkLayer.cpp:113
QRectF::x
qreal x() const
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::PlacemarkLayout::setShowOtherPlaces
void setShowOtherPlaces(bool show)
Definition: PlacemarkLayout.cpp:193
Marble::PlacemarkLayer::zValue
qreal zValue() const
Definition: PlacemarkLayer.cpp:52
QFont
Marble::PlacemarkLayer::setShowLandingSites
void setShowLandingSites(bool show)
Definition: PlacemarkLayer.cpp:138
QVector::constEnd
const_iterator constEnd() const
Marble::PlacemarkLayer::runtimeTrace
virtual QString runtimeTrace() const
Returns a debug line for perfo/tracing issues.
Definition: PlacemarkLayer.cpp:108
GeoDataStyle.h
Marble::PlacemarkLayout::setShowCities
void setShowCities(bool show)
Definition: PlacemarkLayout.cpp:183
PlacemarkLayer.h
Marble::VisiblePlacemark::symbolPosition
const QPoint & symbolPosition() const
Returns the position of the place mark symbol on the map.
Definition: VisiblePlacemark.cpp:60
Marble::VisiblePlacemark::labelRect
const QRectF & labelRect() const
Returns the area covered by the place mark name label on the map.
Definition: VisiblePlacemark.cpp:110
Marble::PlacemarkLayer::repaintNeeded
void repaintNeeded()
Marble::PlacemarkLayout::runtimeTrace
QString runtimeTrace() const
Definition: PlacemarkLayout.cpp:532
Marble::PlacemarkLayer::PlacemarkLayer
PlacemarkLayer(QAbstractItemModel *placemarkModel, QItemSelectionModel *selectionModel, MarbleClock *clock, QObject *parent=0)
Definition: PlacemarkLayer.cpp:30
QPoint
QFontMetrics
MarbleDebug.h
AbstractProjection.h
This file contains the headers for AbstractProjection.
QPoint::x
int x() const
QRect
QPainter::setFont
void setFont(const QFont &font)
QImage::pixel
QRgb pixel(int x, int y) const
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::ViewportParams::width
int width() const
Definition: ViewportParams.cpp:250
Marble::PlacemarkLayer::renderState
RenderState renderState() const
Definition: PlacemarkLayer.cpp:103
Marble::PlacemarkLayer::setShowCities
void setShowCities(bool show)
Definition: PlacemarkLayer.cpp:123
QObject
QPainter::setPen
void setPen(const QColor &color)
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
Marble::PlacemarkLayout::setShowPlaces
void setShowPlaces(bool show)
Definition: PlacemarkLayout.cpp:178
QPainter
Marble::PlacemarkLayer::~PlacemarkLayer
~PlacemarkLayer()
Definition: PlacemarkLayer.cpp:43
Marble::PlacemarkLayer::setShowMaria
void setShowMaria(bool show)
Definition: PlacemarkLayer.cpp:148
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
Marble::ViewportParams::currentProjection
const AbstractProjection * currentProjection() const
Definition: ViewportParams.cpp:134
Marble::PlacemarkLayout::generateLayout
QVector< VisiblePlacemark * > generateLayout(const ViewportParams *viewport)
Definition: PlacemarkLayout.cpp:371
QString
QColor
GeoPainter.h
Marble::PlacemarkLayout::whichPlacemarkAt
QVector< const GeoDataPlacemark * > whichPlacemarkAt(const QPoint &pos)
Returns a list of model indexes that are at position pos.
Definition: PlacemarkLayout.cpp:229
Marble::PlacemarkLayer::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos="NONE", GeoSceneLayer *layer=0)
Definition: PlacemarkLayer.cpp:57
Marble::RenderState
Definition: RenderState.h:22
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
VisiblePlacemark.h
QPixmap
Marble::PlacemarkLayer::requestStyleReset
void requestStyleReset()
Definition: PlacemarkLayer.cpp:153
QFontMetrics::width
int width(const QString &text, int len) const
ViewportParams.h
This file contains the headers for ViewportParams.
QImage
QVector::constBegin
const_iterator constBegin() const
Marble::PlacemarkLayout::setShowTerrain
void setShowTerrain(bool show)
Definition: PlacemarkLayout.cpp:188
QVector
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::PlacemarkLayout::setShowCraters
void setShowCraters(bool show)
Definition: PlacemarkLayout.cpp:203
QFontMetrics::height
int height() const
Marble::PlacemarkLayout::setShowMaria
void setShowMaria(bool show)
Definition: PlacemarkLayout.cpp:208
QAbstractItemModel
Marble::PlacemarkLayer::m_useXWorkaround
static bool m_useXWorkaround
Definition: PlacemarkLayer.h:78
Marble::PlacemarkLayout::setShowLandingSites
void setShowLandingSites(bool show)
Definition: PlacemarkLayout.cpp:198
QItemSelectionModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::MarbleClock
Definition: MarbleClock.h:25
Marble::PlacemarkLayer::setShowPlaces
void setShowPlaces(bool show)
Definition: PlacemarkLayer.cpp:118
Marble::PlacemarkLayer::setShowCraters
void setShowCraters(bool show)
Definition: PlacemarkLayer.cpp:143
QPainter::begin
bool begin(QPaintDevice *device)
Marble::PlacemarkLayer::renderPosition
QStringList renderPosition() const
Definition: PlacemarkLayer.cpp:47
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::PlacemarkLayout::requestStyleReset
void requestStyleReset()
Definition: PlacemarkLayout.cpp:213
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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