• 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
  • graticule
GraticulePlugin.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 2009 Torsten Rahn <tackat@kde.org>
9 //
10 
11 #include "GraticulePlugin.h"
12 #include "ui_GraticuleConfigWidget.h"
13 
14 #include "MarbleDebug.h"
15 #include "MarbleDirs.h"
16 #include "GeoPainter.h"
17 #include "GeoDataLineString.h"
18 #include "Planet.h"
19 #include "MarbleModel.h"
20 #include "PluginAboutDialog.h"
21 
22 #include "ViewportParams.h"
23 #include "GeoDataLatLonAltBox.h"
24 
25 // Qt
26 #include <QPushButton>
27 #include <QLabel>
28 #include <QRect>
29 #include <QColor>
30 #include <QPixmap>
31 #include <QSvgRenderer>
32 #include <QBrush>
33 #include <QColorDialog>
34 #include <QDebug>
35 
36 
37 
38 namespace Marble
39 {
40 
41 GraticulePlugin::GraticulePlugin()
42  : RenderPlugin( 0 ),
43  m_showPrimaryLabels( true ),
44  m_showSecondaryLabels( true ),
45  m_isInitialized( false ),
46  ui_configWidget( 0 ),
47  m_configDialog( 0 )
48 {
49 }
50 
51 GraticulePlugin::GraticulePlugin( const MarbleModel *marbleModel )
52  : RenderPlugin( marbleModel ),
53  m_equatorCirclePen( Qt::yellow ),
54  m_tropicsCirclePen( Qt::yellow ),
55  m_gridCirclePen( Qt::white ),
56  m_showPrimaryLabels( true ),
57  m_showSecondaryLabels( true ),
58  m_isInitialized( false ),
59  ui_configWidget( 0 ),
60  m_configDialog( 0 )
61 {
62 }
63 
64 QStringList GraticulePlugin::backendTypes() const
65 {
66  return QStringList( "graticule" );
67 }
68 
69 QString GraticulePlugin::renderPolicy() const
70 {
71  return QString( "ALWAYS" );
72 }
73 
74 QStringList GraticulePlugin::renderPosition() const
75 {
76  return QStringList( "SURFACE" );
77 }
78 
79 QString GraticulePlugin::name() const
80 {
81  return tr( "Coordinate Grid" );
82 }
83 
84 QString GraticulePlugin::guiString() const
85 {
86  return tr( "Coordinate &Grid" );
87 }
88 
89 QString GraticulePlugin::nameId() const
90 {
91  return QString( "coordinate-grid" );
92 }
93 
94 QString GraticulePlugin::version() const
95 {
96  return "1.0";
97 }
98 
99 QString GraticulePlugin::description() const
100 {
101  return tr( "A plugin that shows a coordinate grid." );
102 }
103 
104 QString GraticulePlugin::copyrightYears() const
105 {
106  return "2009";
107 }
108 
109 QList<PluginAuthor> GraticulePlugin::pluginAuthors() const
110 {
111  return QList<PluginAuthor>()
112  << PluginAuthor( "Torsten Rahn", "tackat@kde.org" );
113 }
114 
115 QIcon GraticulePlugin::icon () const
116 {
117  return QIcon(":/icons/coordinate.png");
118 }
119 
120 void GraticulePlugin::initialize ()
121 {
122  // Initialize range maps that map the zoom to the number of coordinate grid lines.
123 
124  initLineMaps( GeoDataCoordinates::defaultNotation() );
125 
126  m_isInitialized = true;
127 }
128 
129 bool GraticulePlugin::isInitialized () const
130 {
131  return m_isInitialized;
132 }
133 
134 QDialog *GraticulePlugin::configDialog()
135 {
136  if ( !m_configDialog ) {
137  m_configDialog = new QDialog();
138  ui_configWidget = new Ui::GraticuleConfigWidget;
139  ui_configWidget->setupUi( m_configDialog );
140 
141  connect( ui_configWidget->gridPushButton, SIGNAL(clicked()), this,
142  SLOT(gridGetColor()) );
143  connect( ui_configWidget->tropicsPushButton, SIGNAL(clicked()), this,
144  SLOT(tropicsGetColor()) );
145  connect( ui_configWidget->equatorPushButton, SIGNAL(clicked()), this,
146  SLOT(equatorGetColor()) );
147 
148 
149  connect( ui_configWidget->m_buttonBox, SIGNAL(accepted()), this,
150  SLOT(writeSettings()) );
151  connect( ui_configWidget->m_buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()),
152  SLOT(restoreDefaultSettings()) );
153  QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
154  connect( applyButton, SIGNAL(clicked()),
155  this, SLOT(writeSettings()) );
156  }
157 
158  readSettings();
159 
160  return m_configDialog;
161 }
162 
163 
164 QHash<QString,QVariant> GraticulePlugin::settings() const
165 {
166  QHash<QString, QVariant> settings = RenderPlugin::settings();
167 
168  settings.insert( "gridColor", m_gridCirclePen.color().name() );
169  settings.insert( "tropicsColor", m_tropicsCirclePen.color().name() );
170  settings.insert( "equatorColor", m_equatorCirclePen.color().name() );
171  settings.insert( "primarylabels", m_showPrimaryLabels );
172  settings.insert( "secondaryLabels", m_showSecondaryLabels );
173 
174  return settings;
175 }
176 
177 void GraticulePlugin::setSettings( const QHash<QString,QVariant> &settings )
178 {
179  RenderPlugin::setSettings( settings );
180 
181  const QColor gridColor = settings.value( "gridColor", QColor( Qt::white ) ).value<QColor>();
182  const QColor tropicsColor = settings.value( "tropicsColor", QColor( Qt::yellow ) ).value<QColor>();
183  const QColor equatorColor = settings.value( "equatorColor", QColor( Qt::yellow ) ).value<QColor>();
184  bool primaryLabels = settings.value( "primaryLabels", true ).toBool();
185  bool secondaryLabels = settings.value( "secondaryLabels", true ).toBool();
186 
187  m_gridCirclePen.setColor( gridColor );
188  m_tropicsCirclePen.setColor( tropicsColor );
189  m_equatorCirclePen.setColor( equatorColor );
190 
191  m_showPrimaryLabels = primaryLabels;
192  m_showSecondaryLabels = secondaryLabels;
193 
194  readSettings();
195 }
196 
197 
198 void GraticulePlugin::readSettings()
199 {
200  if ( !m_configDialog )
201  return;
202 
203  QPalette gridPalette;
204  gridPalette.setColor( QPalette::Button, m_gridCirclePen.color() );
205  ui_configWidget->gridPushButton->setPalette( gridPalette );
206 
207  QPalette tropicsPalette;
208  tropicsPalette.setColor( QPalette::Button, m_tropicsCirclePen.color() );
209  ui_configWidget->tropicsPushButton->setPalette( tropicsPalette );
210 
211 
212  QPalette equatorPalette;
213  equatorPalette.setColor( QPalette::Button, m_equatorCirclePen.color() );
214  ui_configWidget->equatorPushButton->setPalette( equatorPalette );
215  ui_configWidget->primaryCheckBox->setChecked( m_showPrimaryLabels );
216  ui_configWidget->secondaryCheckBox->setChecked( m_showSecondaryLabels );
217 }
218 
219 void GraticulePlugin::gridGetColor()
220 {
221  const QColor c = QColorDialog::getColor( m_gridCirclePen.color(), 0, tr("Please choose the color for the coordinate grid.") );
222 
223  if ( c.isValid() ) {
224  QPalette palette = ui_configWidget->gridPushButton->palette();
225  palette.setColor( QPalette::Button, c );
226  ui_configWidget->gridPushButton->setPalette( palette );
227  }
228 }
229 
230 void GraticulePlugin::tropicsGetColor()
231 {
232  const QColor c = QColorDialog::getColor( m_tropicsCirclePen.color(), 0, tr("Please choose the color for the tropic circles.") );
233 
234  if ( c.isValid() ) {
235  QPalette palette = ui_configWidget->tropicsPushButton->palette();
236  palette.setColor( QPalette::Button, c );
237  ui_configWidget->tropicsPushButton->setPalette( palette );
238  }
239 }
240 
241 void GraticulePlugin::equatorGetColor()
242 {
243  const QColor c = QColorDialog::getColor( m_equatorCirclePen.color(), 0, tr("Please choose the color for the equator.") );
244 
245  if ( c.isValid() ) {
246  QPalette palette = ui_configWidget->equatorPushButton->palette();
247  palette.setColor( QPalette::Button, c );
248  ui_configWidget->equatorPushButton->setPalette( palette );
249  }
250 }
251 
252 void GraticulePlugin::writeSettings()
253 {
254  m_equatorCirclePen.setColor( ui_configWidget->equatorPushButton->palette().color( QPalette::Button ) );
255  m_tropicsCirclePen.setColor( ui_configWidget->tropicsPushButton->palette().color( QPalette::Button ) );
256  m_gridCirclePen.setColor( ui_configWidget->gridPushButton->palette().color( QPalette::Button) );
257  m_showPrimaryLabels = ui_configWidget->primaryCheckBox->isChecked();
258  m_showSecondaryLabels = ui_configWidget->secondaryCheckBox->isChecked();
259 
260  emit settingsChanged( nameId() );
261 }
262 
263 bool GraticulePlugin::render( GeoPainter *painter, ViewportParams *viewport,
264  const QString& renderPos,
265  GeoSceneLayer * layer )
266 {
267  Q_UNUSED( layer )
268  Q_UNUSED( renderPos )
269 
270  if ( m_currentNotation != GeoDataCoordinates::defaultNotation() ) {
271  initLineMaps( GeoDataCoordinates::defaultNotation() );
272  }
273 
274  // Setting the label font for the coordinate lines.
275 #ifdef Q_OS_MACX
276  int defaultFontSize = 10;
277 #else
278  int defaultFontSize = 8;
279 #endif
280 
281  QFont gridFont("Sans Serif");
282  gridFont.setPointSize( defaultFontSize );
283  gridFont.setBold( true );
284 
285  painter->save();
286 
287  painter->setFont( gridFont );
288 
289  renderGrid( painter, viewport, m_equatorCirclePen, m_tropicsCirclePen, m_gridCirclePen );
290 
291  painter->restore();
292 
293  return true;
294 }
295 
296 qreal GraticulePlugin::zValue() const
297 {
298  return 1.0;
299 }
300 
301 void GraticulePlugin::renderGrid( GeoPainter *painter, ViewportParams *viewport,
302  const QPen& equatorCirclePen,
303  const QPen& tropicsCirclePen,
304  const QPen& gridCirclePen )
305 {
306  GeoDataLatLonAltBox viewLatLonAltBox = viewport->viewLatLonAltBox();
307 
308  painter->setPen( gridCirclePen );
309  // painter->setPen( QPen( QBrush( Qt::white ), 0.75 ) );
310 
311  // Render UTM grid zones
312  if ( m_currentNotation == GeoDataCoordinates::UTM ) {
313  renderLatitudeLine( painter, 84.0, viewLatLonAltBox );
314 
315  renderLongitudeLines( painter, viewLatLonAltBox,
316  6.0, 18.0, 154.0, LineStart | IgnoreXMargin );
317  renderLongitudeLines( painter, viewLatLonAltBox,
318  6.0, 34.0, 10.0, LineStart | IgnoreXMargin );
319 
320  // Paint longtudes with exceptions
321  renderLongitudeLines( painter, viewLatLonAltBox,
322  6.0, 6.0, 162.0 );
323  renderLongitudeLines( painter, viewLatLonAltBox,
324  6.0, 26.0, 146.0 );
325 
326  renderLatitudeLines( painter, viewLatLonAltBox, 8.0 /*,
327  LineStart | IgnoreYMargin */ );
328 
329  return;
330  }
331 
332  // Render the normal grid
333 
334  // calculate the angular distance between coordinate lines of the normal grid
335  qreal normalDegreeStep = 360.0 / m_normalLineMap.lowerBound(viewport->radius()).value();
336 
337  LabelPositionFlags labelXPosition(NoLabel), labelYPosition(NoLabel);
338  if ( m_showSecondaryLabels ) {
339  labelXPosition = LineStart | IgnoreXMargin;
340  labelYPosition = LineStart | IgnoreYMargin;
341  }
342  renderLongitudeLines( painter, viewLatLonAltBox,
343  normalDegreeStep, normalDegreeStep, normalDegreeStep,
344  labelXPosition );
345  renderLatitudeLines( painter, viewLatLonAltBox, normalDegreeStep,
346  labelYPosition );
347 
348  // Render some non-cut off longitude lines ..
349  renderLongitudeLine( painter, +90.0, viewLatLonAltBox );
350  renderLongitudeLine( painter, -90.0, viewLatLonAltBox );
351 
352  // Render the bold grid
353 
354  if ( painter->mapQuality() == HighQuality
355  || painter->mapQuality() == PrintQuality ) {
356 
357  QPen boldPen = gridCirclePen;
358  boldPen.setWidthF( 1.5 );
359  painter->setPen( boldPen );
360 
361  // calculate the angular distance between coordinate lines of the bold grid
362  qreal boldDegreeStep = 360.0 / m_boldLineMap.lowerBound(viewport->radius()).value();
363 
364  renderLongitudeLines( painter, viewLatLonAltBox,
365  boldDegreeStep, normalDegreeStep, normalDegreeStep,
366  NoLabel
367  );
368  renderLatitudeLines( painter, viewLatLonAltBox, boldDegreeStep,
369  NoLabel );
370  }
371 
372  painter->setPen( equatorCirclePen );
373 
374  LabelPositionFlags mainPosition(NoLabel);
375  if ( m_showPrimaryLabels ) {
376  mainPosition = LineCenter;
377  }
378  // Render the equator
379  renderLatitudeLine( painter, 0.0, viewLatLonAltBox, tr( "Equator" ), mainPosition );
380 
381  // Render the Prime Meridian and Antimeridian
382  GeoDataCoordinates::Notation notation = GeoDataCoordinates::defaultNotation();
383  if (marbleModel()->planet()->id() != "sky" && notation != GeoDataCoordinates::Astro) {
384  renderLongitudeLine( painter, 0.0, viewLatLonAltBox, 0.0, 0.0, tr( "Prime Meridian" ), mainPosition );
385  renderLongitudeLine( painter, 180.0, viewLatLonAltBox, 0.0, 0.0, tr( "Antimeridian" ), mainPosition );
386  }
387 
388  QPen tropicsPen = tropicsCirclePen;
389  if ( painter->mapQuality() != OutlineQuality
390  && painter->mapQuality() != LowQuality ) {
391  tropicsPen.setStyle( Qt::DotLine );
392  }
393  painter->setPen( tropicsPen );
394 
395  // Determine the planet's axial tilt
396  qreal axialTilt = RAD2DEG * marbleModel()->planet()->epsilon();
397 
398  if ( axialTilt > 0 ) {
399  // Render the tropics
400  renderLatitudeLine( painter, +axialTilt, viewLatLonAltBox, tr( "Tropic of Cancer" ), mainPosition );
401  renderLatitudeLine( painter, -axialTilt, viewLatLonAltBox, tr( "Tropic of Capricorn" ), mainPosition );
402 
403  // Render the arctics
404  renderLatitudeLine( painter, +90.0 - axialTilt, viewLatLonAltBox, tr( "Arctic Circle" ), mainPosition );
405  renderLatitudeLine( painter, -90.0 + axialTilt, viewLatLonAltBox, tr( "Antarctic Circle" ), mainPosition );
406  }
407 }
408 
409 void GraticulePlugin::renderLatitudeLine( GeoPainter *painter, qreal latitude,
410  const GeoDataLatLonAltBox& viewLatLonAltBox,
411  const QString& lineLabel,
412  LabelPositionFlags labelPositionFlags )
413 {
414  qreal fromSouthLat = viewLatLonAltBox.south( GeoDataCoordinates::Degree );
415  qreal toNorthLat = viewLatLonAltBox.north( GeoDataCoordinates::Degree );
416 
417  // Coordinate line is not displayed inside the viewport
418  if ( latitude < fromSouthLat || toNorthLat < latitude ) {
419  // mDebug() << "Lat: Out of View";
420  return;
421  }
422 
423  GeoDataLineString line( Tessellate | RespectLatitudeCircle ) ;
424 
425  qreal fromWestLon = viewLatLonAltBox.west( GeoDataCoordinates::Degree );
426  qreal toEastLon = viewLatLonAltBox.east( GeoDataCoordinates::Degree );
427 
428  if ( fromWestLon < toEastLon ) {
429  qreal step = ( toEastLon - fromWestLon ) * 0.25;
430 
431  for ( int i = 0; i < 5; ++i ) {
432  line << GeoDataCoordinates( fromWestLon + i * step, latitude, 0.0, GeoDataCoordinates::Degree );
433  }
434  }
435  else {
436  qreal step = ( +180.0 - toEastLon ) * 0.25;
437 
438  for ( int i = 0; i < 5; ++i ) {
439  line << GeoDataCoordinates( toEastLon + i * step, latitude, 0.0, GeoDataCoordinates::Degree );
440  }
441 
442  step = ( +180 + fromWestLon ) * 0.25;
443 
444  for ( int i = 0; i < 5; ++i ) {
445  line << GeoDataCoordinates( -180 + i * step, latitude, 0.0, GeoDataCoordinates::Degree );
446  }
447  }
448 
449  painter->drawPolyline( line, lineLabel, labelPositionFlags );
450 }
451 
452 void GraticulePlugin::renderLongitudeLine( GeoPainter *painter, qreal longitude,
453  const GeoDataLatLonAltBox& viewLatLonAltBox,
454  qreal northPolarGap, qreal southPolarGap,
455  const QString& lineLabel,
456  LabelPositionFlags labelPositionFlags )
457 {
458  const qreal fromWestLon = viewLatLonAltBox.west();
459  const qreal toEastLon = viewLatLonAltBox.east();
460 
461  // Coordinate line is not displayed inside the viewport
462  if ( ( !viewLatLonAltBox.crossesDateLine()
463  && ( longitude * DEG2RAD < fromWestLon || toEastLon < longitude * DEG2RAD ) ) ||
464  ( viewLatLonAltBox.crossesDateLine() &&
465  longitude * DEG2RAD < toEastLon && fromWestLon < longitude * DEG2RAD &&
466  fromWestLon != -M_PI && toEastLon != +M_PI )
467  ) {
468  // mDebug() << "Lon: Out of View:" << viewLatLonAltBox.toString() << " Crossing: "<< viewLatLonAltBox.crossesDateLine() << "Longitude: " << longitude;
469  return;
470  }
471 
472  qreal fromSouthLat = viewLatLonAltBox.south( GeoDataCoordinates::Degree );
473  qreal toNorthLat = viewLatLonAltBox.north( GeoDataCoordinates::Degree );
474 
475  qreal southLat = ( fromSouthLat < -90.0 + southPolarGap ) ? -90.0 + southPolarGap : fromSouthLat;
476  qreal northLat = ( toNorthLat > +90.0 - northPolarGap ) ? +90.0 - northPolarGap : toNorthLat;
477 
478  GeoDataCoordinates n1( longitude, southLat, 0.0, GeoDataCoordinates::Degree );
479  GeoDataCoordinates n3( longitude, northLat, 0.0, GeoDataCoordinates::Degree );
480 
481  GeoDataLineString line( Tessellate );
482 
483  if ( northLat > 0 && southLat < 0 )
484  {
485  GeoDataCoordinates n2( longitude, 0.0, 0.0, GeoDataCoordinates::Degree );
486  line << n1 << n2 << n3;
487  }
488  else {
489  line << n1 << n3;
490  }
491 
492  painter->drawPolyline( line, lineLabel, labelPositionFlags );
493 }
494 
495 void GraticulePlugin::renderLatitudeLines( GeoPainter *painter,
496  const GeoDataLatLonAltBox& viewLatLonAltBox,
497  qreal step,
498  LabelPositionFlags labelPositionFlags
499  )
500 {
501  if ( step <= 0 ) {
502  return;
503  }
504 
505  // Latitude
506  qreal southLat = viewLatLonAltBox.south( GeoDataCoordinates::Degree );
507  qreal northLat = viewLatLonAltBox.north( GeoDataCoordinates::Degree );
508 
509  qreal southLineLat = step * static_cast<int>( southLat / step );
510  qreal northLineLat = step * ( static_cast<int>( northLat / step ) + 1 );
511 
512  if ( m_currentNotation == GeoDataCoordinates::UTM ) {
513  if ( northLineLat > 84.0 )
514  northLineLat = 76.0;
515 
516  if ( southLineLat < -80.0 )
517  southLineLat = -80.0;
518  }
519 
520  qreal itStep = southLineLat;
521 
522  GeoDataCoordinates::Notation notation = GeoDataCoordinates::defaultNotation();
523 
524  while ( itStep < northLineLat ) {
525  // Create a matching label
526  QString label = GeoDataCoordinates::latToString( itStep, notation,
527  GeoDataCoordinates::Degree, -1, 'g' );
528 
529  // No additional labels for the equator
530  if ( labelPositionFlags.testFlag( LineCenter ) && itStep == 0.0 ) {
531  label.clear();
532  }
533 
534  // Paint all latitude coordinate lines except for the equator
535  if ( itStep != 0.0 ) {
536  renderLatitudeLine( painter, itStep, viewLatLonAltBox, label, labelPositionFlags );
537  }
538 
539  itStep += step;
540  }
541 }
542 
543 
544 void GraticulePlugin::renderUtmExceptions( GeoPainter *painter,
545  const GeoDataLatLonAltBox& viewLatLonAltBox,
546  qreal itStep, qreal northPolarGap, qreal southPolarGap,
547  const QString & label,
548  LabelPositionFlags labelPositionFlags )
549 {
550  // This code renders the so called "exceptions" in the UTM coordinate grid
551  // See: http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system#Exceptions
552  if ( northPolarGap == 6.0 && southPolarGap == 162.0) {
553  if ( label == "31" ) {
554  renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
555  southPolarGap, label, labelPositionFlags );
556  } else if ( label == "33" ) {
557  renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
558  southPolarGap, label, labelPositionFlags );
559  } else if ( label == "35" ) {
560  renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
561  southPolarGap, label, labelPositionFlags );
562  } else if ( label == "37" ) {
563  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
564  southPolarGap, label, labelPositionFlags );
565  } else if ( label == "32" || label == "34" || label == "36" ) {
566  // paint nothing
567  } else {
568  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
569  southPolarGap, label, labelPositionFlags );
570  }
571  }
572  else if ( northPolarGap == 26.0 && southPolarGap == 146.0 ) {
573  if ( label == "31" ) {
574  renderLongitudeLine( painter, itStep-3.0, viewLatLonAltBox, northPolarGap,
575  southPolarGap, label, labelPositionFlags );
576  } else {
577  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
578  southPolarGap, label, labelPositionFlags );
579  }
580  }
581  else {
582  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
583  southPolarGap, label, labelPositionFlags );
584  }
585 }
586 
587 void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
588  const GeoDataLatLonAltBox& viewLatLonAltBox,
589  qreal step, qreal northPolarGap, qreal southPolarGap,
590  LabelPositionFlags labelPositionFlags )
591 {
592  if ( step <= 0 ) {
593  return;
594  }
595 
596  GeoDataCoordinates::Notation notation = marbleModel()->planet()->id() == "sky" ? GeoDataCoordinates::Astro :
597  GeoDataCoordinates::defaultNotation();
598 
599  // Longitude
600  qreal westLon = viewLatLonAltBox.west( GeoDataCoordinates::Degree );
601  qreal eastLon = viewLatLonAltBox.east( GeoDataCoordinates::Degree );
602 
603  qreal westLineLon = step * static_cast<int>( westLon / step );
604  qreal eastLineLon = step * ( static_cast<int>( eastLon / step ) + 1 );
605 
606  if ( !viewLatLonAltBox.crossesDateLine() ||
607  ( westLon == -180.0 && eastLon == +180.0 ) ) {
608  qreal itStep = westLineLon;
609 
610  while ( itStep < eastLineLon ) {
611  // Create a matching label
612  QString label = GeoDataCoordinates::lonToString( itStep,
613  notation, GeoDataCoordinates::Degree,
614  -1, 'g' );
615 
616  // No additional labels for the prime meridian and the antimeridian
617 
618  if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
619  {
620  label.clear();
621  }
622 
623  // Paint all longitude coordinate lines except for the meridians
624  if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
625  // handle exceptions for UTM grid
626  if (notation == GeoDataCoordinates::UTM ) {
627  renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
628  southPolarGap, label, labelPositionFlags );
629  } else {
630  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
631  southPolarGap, label, labelPositionFlags );
632  }
633  }
634  itStep += step;
635  }
636  }
637  else {
638  qreal itStep = eastLineLon;
639 
640  while ( itStep < 180.0 ) {
641 
642  // Create a matching label
643  QString label = GeoDataCoordinates::lonToString( itStep,
644  notation, GeoDataCoordinates::Degree,
645  -1, 'g' );
646 
647  // No additional labels for the prime meridian and the antimeridian
648 
649  if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
650  {
651  label.clear();
652  }
653 
654  // Paint all longitude coordinate lines except for the meridians
655  if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
656  if (notation == GeoDataCoordinates::UTM ) {
657  renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
658  southPolarGap, label, labelPositionFlags );
659  } else {
660  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
661  southPolarGap, label, labelPositionFlags );
662  }
663  }
664  itStep += step;
665  }
666 
667  itStep = -180.0;
668  while ( itStep < westLineLon ) {
669 
670  // Create a matching label
671  QString label = GeoDataCoordinates::lonToString( itStep,
672  notation, GeoDataCoordinates::Degree,
673  -1, 'g' );
674 
675  // No additional labels for the prime meridian and the antimeridian
676  if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
677  {
678  label.clear();
679  }
680 
681  // Paint all longitude coordinate lines except for the meridians
682  if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
683  if (notation == GeoDataCoordinates::UTM ) {
684  renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
685  southPolarGap, label, labelPositionFlags );
686  } else {
687  renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
688  southPolarGap, label, labelPositionFlags );
689  }
690  }
691  itStep += step;
692  }
693  }
694 }
695 
696 void GraticulePlugin::initLineMaps( GeoDataCoordinates::Notation notation)
697 {
698  /* Define Upper Bound keys and associated values:
699  The key number is the globe radius in pixel.
700  The value number is the amount of grid lines for the full range.
701 
702  Example: up to a 100 pixel radius the globe is covered
703  with 4 longitude lines (4 half-circles).
704  */
705 
706  if (marbleModel()->planet()->id() == "sky" || notation == GeoDataCoordinates::Astro) {
707  m_normalLineMap[100] = 4; // 6h
708  m_normalLineMap[1000] = 12; // 2h
709  m_normalLineMap[2000] = 24; // 1h
710  m_normalLineMap[4000] = 48; // 30 min
711  m_normalLineMap[8000] = 96; // 15 min
712  m_normalLineMap[16000] = 288; // 5 min
713  m_normalLineMap[100000] = 24 * 60; // 1 min
714  m_normalLineMap[200000] = 24 * 60 * 2; // 30 sec
715  m_normalLineMap[400000] = 24 * 60 * 4; // 15 sec
716  m_normalLineMap[1200000] = 24 * 60 * 12; // 5 sec
717  m_normalLineMap[6000000] = 24 * 60 * 60; // 1 sec
718  m_normalLineMap[12000000] = 24 * 60 * 60 * 2; // 0.5 sec
719  m_normalLineMap[24000000] = 24 * 60 * 60 * 4; // 0.25 sec
720 
721  m_boldLineMap[1000] = 0; // 0h
722  m_boldLineMap[2000] = 4; // 6h
723  m_boldLineMap[16000] = 24; // 30 deg
724  return;
725  }
726 
727  m_normalLineMap[100] = 4; // 90 deg
728  m_normalLineMap[1000] = 12; // 30 deg
729  m_normalLineMap[4000] = 36; // 10 deg
730  m_normalLineMap[16000] = 72; // 5 deg
731  m_normalLineMap[64000] = 360; // 1 deg
732  m_normalLineMap[128000] = 720; // 0.5 deg
733 
734  m_boldLineMap[1000] = 0; // 0 deg
735  m_boldLineMap[4000] = 12; // 30 deg
736  m_boldLineMap[16000] = 36; // 10 deg
737 
738  switch ( notation )
739  {
740  case GeoDataCoordinates::Decimal :
741 
742  m_normalLineMap[512000] = 360 * 10; // 0.1 deg
743  m_normalLineMap[2048000] = 360 * 20; // 0.05 deg
744  m_normalLineMap[8192000] = 360 * 100; // 0.01 deg
745  m_normalLineMap[16384000] = 360 * 200; // 0.005 deg
746  m_normalLineMap[32768000] = 360 * 1000; // 0.001 deg
747  m_normalLineMap[131072000] = 360 * 2000; // 0.0005 deg
748  m_normalLineMap[524288000] = 360 * 10000; // 0.00001 deg
749 
750  m_boldLineMap[512000] = 360; // 0.1 deg
751  m_boldLineMap[2048000] = 720; // 0.05 deg
752  m_boldLineMap[8192000] = 360 * 10; // 0.01 deg
753  m_boldLineMap[1638400] = 360 * 20; // 0.005 deg
754  m_boldLineMap[32768000] = 360 * 100; // 0.001 deg
755  m_boldLineMap[131072000] = 360 * 200; // 0.0005 deg
756  m_boldLineMap[524288000] = 360 * 1000; // 0.00001 deg
757 
758  break;
759  default:
760  case GeoDataCoordinates::DMS :
761  m_normalLineMap[512000] = 360 * 6; // 10'
762  m_normalLineMap[1024000] = 360 * 12; // 5'
763  m_normalLineMap[4096000] = 360 * 60; // 1'
764  m_normalLineMap[8192000] = 360 * 60 * 2; // 30"
765  m_normalLineMap[16384000] = 360 * 60 * 6; // 10"
766  m_normalLineMap[65535000] = 360 * 60 * 12; // 5"
767  m_normalLineMap[524288000] = 360 * 60 * 60; // 1"
768 
769  m_boldLineMap[512000] = 360; // 10'
770  m_boldLineMap[1024000] = 720; // 5'
771  m_boldLineMap[4096000] = 360 * 6; // 1'
772  m_boldLineMap[8192000] = 360 * 12; // 30"
773  m_boldLineMap[16384000] = 360 * 60; // 10"
774  m_boldLineMap[65535000] = 360 * 60 * 2; // 5"
775  m_boldLineMap[524288000] = 360 * 60 * 6; // 1"
776 
777  break;
778  }
779  m_normalLineMap[999999999] = m_normalLineMap.value(262144000); // last
780  m_boldLineMap[999999999] = m_boldLineMap.value(262144000); // last
781 
782  m_currentNotation = notation;
783 }
784 
785 }
786 
787 Q_EXPORT_PLUGIN2(GraticulePlugin, Marble::GraticulePlugin)
788 
789 #include "GraticulePlugin.moc"
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:220
Marble::GeoDataCoordinates::UTM
Definition: GeoDataCoordinates.h:83
QFont::setPointSize
void setPointSize(int pointSize)
QPen::setStyle
void setStyle(Qt::PenStyle style)
Marble::Planet::id
QString id() const
The internal, nonlocalized name of the planet.
Definition: Planet.cpp:262
QHash::insert
iterator insert(const Key &key, const T &value)
Marble::GraticulePlugin::readSettings
void readSettings()
Definition: GraticulePlugin.cpp:198
Marble::GraticulePlugin::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: GraticulePlugin.cpp:115
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QColor::name
QString name() const
Marble::GraticulePlugin::equatorGetColor
void equatorGetColor()
Definition: GraticulePlugin.cpp:241
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::IgnoreYMargin
Definition: MarbleGlobal.h:116
MarbleModel.h
This file contains the headers for MarbleModel.
QFont
Marble::GraticulePlugin::version
QString version() const
Definition: GraticulePlugin.cpp:94
Marble::PluginAuthor
Definition: PluginInterface.h:28
QPainter::save
void save()
Marble::ViewportParams::viewLatLonAltBox
const GeoDataLatLonAltBox & viewLatLonAltBox() const
Definition: ViewportParams.cpp:305
Marble::GeoDataCoordinates::Decimal
"Decimal" notation (base-10)
Definition: GeoDataCoordinates.h:80
Marble::IgnoreXMargin
Definition: MarbleGlobal.h:115
Marble::RenderPlugin::restoreDefaultSettings
void restoreDefaultSettings()
Passes an empty set of settings to the plugin.
Definition: RenderPlugin.cpp:221
Marble::PrintQuality
Print quality.
Definition: MarbleGlobal.h:87
Marble::GraticulePlugin::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: GraticulePlugin.cpp:164
Planet.h
Marble::MarbleModel::planet
const Planet * planet() const
Returns the planet object for the current map.
Definition: MarbleModel.cpp:644
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::GraticulePlugin::tropicsGetColor
void tropicsGetColor()
Definition: GraticulePlugin.cpp:230
QString::clear
void clear()
Marble::GraticulePlugin::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: GraticulePlugin.cpp:89
Marble::LowQuality
Low resolution (e.g. interlaced)
Definition: MarbleGlobal.h:84
QFont::setBold
void setBold(bool enable)
Marble::GraticulePlugin::gridGetColor
void gridGetColor()
Definition: GraticulePlugin.cpp:219
QPen::color
QColor color() const
Marble::GraticulePlugin::zValue
virtual qreal zValue() const
Returns the z value of the layer (default: 0.0).
Definition: GraticulePlugin.cpp:296
QPainter::setFont
void setFont(const QFont &font)
Marble::GraticulePlugin::initialize
void initialize()
Definition: GraticulePlugin.cpp:120
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
QHash< QString, QVariant >
QPainter::setPen
void setPen(const QColor &color)
Marble::RenderPlugin::settingsChanged
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
Marble::GraticulePlugin::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: GraticulePlugin.cpp:64
MarbleDirs.h
Marble::GraticulePlugin
A plugin that creates a coordinate grid on top of the map.
Definition: GraticulePlugin.h:54
Marble::GraticulePlugin::description
QString description() const
Returns a user description of the plugin.
Definition: GraticulePlugin.cpp:99
Marble::LineCenter
Definition: MarbleGlobal.h:113
GeoDataLineString.h
QPen::setWidthF
void setWidthF(qreal width)
Marble::GraticulePlugin::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: GraticulePlugin.cpp:109
Marble::NoLabel
Definition: MarbleGlobal.h:111
Marble::LineStart
Definition: MarbleGlobal.h:112
Marble::GraticulePlugin::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: GraticulePlugin.cpp:177
QString
QList
QColor
GeoPainter.h
QPen::setColor
void setColor(const QColor &color)
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:219
Marble::GeoDataCoordinates::latToString
QString latToString() const
return a string representation of latitude of the coordinate convenience function that uses the defau...
Definition: GeoDataCoordinates.cpp:1176
QMap::lowerBound
iterator lowerBound(const Key &key)
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::GraticulePlugin::name
QString name() const
Returns the user-visible name of the plugin.
Definition: GraticulePlugin.cpp:79
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::GeoDataCoordinates::lonToString
QString lonToString() const
return a string representation of longitude of the coordinate convenience function that uses the defa...
Definition: GeoDataCoordinates.cpp:1075
QHash::value
const T value(const Key &key) const
QColorDialog::getColor
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::GraticulePlugin::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: GraticulePlugin.cpp:74
QPainter::restore
void restore()
Marble::RespectLatitudeCircle
Definition: MarbleGlobal.h:33
Marble::GraticulePlugin::GraticulePlugin
GraticulePlugin()
Definition: GraticulePlugin.cpp:41
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::GraticulePlugin::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: GraticulePlugin.cpp:69
Marble::GeoDataCoordinates::Notation
Notation
enum used to specify the notation / numerical system
Definition: GeoDataCoordinates.h:79
Marble::OutlineQuality
Only a wire representation is drawn.
Definition: MarbleGlobal.h:83
Marble::GraticulePlugin::render
virtual bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: GraticulePlugin.cpp:263
Marble::GraticulePlugin::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: GraticulePlugin.cpp:84
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::GraticulePlugin::copyrightYears
QString copyrightYears() const
Definition: GraticulePlugin.cpp:104
Marble::HighQuality
High quality (e.g. antialiasing for lines)
Definition: MarbleGlobal.h:86
GeoDataLatLonAltBox.h
GraticulePlugin.h
PluginAboutDialog.h
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
QPen
QDialog
QPushButton
Marble::Planet::epsilon
qreal epsilon() const
obliquity of the ecliptic plane
Definition: Planet.cpp:235
Marble::GeoPainter::mapQuality
MapQuality mapQuality() const
Returns the map quality.
Definition: GeoPainter.cpp:191
Marble::GraticulePlugin::configDialog
QDialog * configDialog()
Returns a pointer to the configuration dialog of the plugin.
Definition: GraticulePlugin.cpp:134
Marble::Tessellate
Definition: MarbleGlobal.h:32
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:83
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::RenderPlugin::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: RenderPlugin.cpp:185
Marble::GeoDataCoordinates::DMS
"Sexagesimal DMS" notation (base-60)
Definition: GeoDataCoordinates.h:81
Marble::GeoDataCoordinates::defaultNotation
static GeoDataCoordinates::Notation defaultNotation()
return Notation of string representation
Definition: GeoDataCoordinates.cpp:764
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GraticulePlugin::isInitialized
bool isInitialized() const
Definition: GraticulePlugin.cpp:129
Marble::RenderPlugin::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: RenderPlugin.cpp:195
QPalette
Marble::GeoDataCoordinates::Astro
< "RA and DEC" notation (used for astronomical sky coordinates)
Definition: GeoDataCoordinates.h:84
QIcon
QColor::isValid
bool isValid() const
QMap::value
const T value(const Key &key) const
Marble::GraticulePlugin::writeSettings
void writeSettings()
Definition: GraticulePlugin.cpp:252
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