12 #include "ui_GraticuleConfigWidget.h"
26 #include <QPushButton>
31 #include <QSvgRenderer>
33 #include <QColorDialog>
50 m_equatorCirclePen( Qt::yellow ),
51 m_tropicsCirclePen( Qt::yellow ),
52 m_gridCirclePen( Qt::white ),
53 m_showPrimaryLabels( true ),
54 m_showSecondaryLabels( true ),
55 m_isInitialized( false ),
63 return QStringList(
"graticule" );
68 return QString(
"ALWAYS" );
73 return QStringList(
"SURFACE" );
78 return tr(
"Coordinate Grid" );
83 return tr(
"Coordinate &Grid" );
88 return QString(
"coordinate-grid" );
98 return tr(
"A plugin that shows a coordinate grid." );
108 return QList<PluginAuthor>()
114 return QIcon(
":/icons/coordinate.png");
123 m_isInitialized =
true;
128 return m_isInitialized;
133 if ( !m_configDialog ) {
134 m_configDialog =
new QDialog();
135 ui_configWidget =
new Ui::GraticuleConfigWidget;
136 ui_configWidget->setupUi( m_configDialog );
138 connect( ui_configWidget->gridPushButton, SIGNAL(clicked()),
this,
140 connect( ui_configWidget->tropicsPushButton, SIGNAL(clicked()),
this,
142 connect( ui_configWidget->equatorPushButton, SIGNAL(clicked()),
this,
146 connect( ui_configWidget->m_buttonBox, SIGNAL(accepted()),
this,
148 connect( ui_configWidget->m_buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()),
150 QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
151 connect( applyButton, SIGNAL(clicked()),
157 return m_configDialog;
165 settings.insert(
"gridColor", m_gridCirclePen.color().name() );
166 settings.insert(
"tropicsColor", m_tropicsCirclePen.color().name() );
167 settings.insert(
"equatorColor", m_equatorCirclePen.color().name() );
168 settings.insert(
"primarylabels", m_showPrimaryLabels );
169 settings.insert(
"secondaryLabels", m_showSecondaryLabels );
178 const QColor gridColor = settings.value(
"gridColor", QColor( Qt::white ) ).value<QColor>();
179 const QColor tropicsColor = settings.value(
"tropicsColor", QColor( Qt::yellow ) ).value<QColor>();
180 const QColor equatorColor = settings.value(
"equatorColor", QColor( Qt::yellow ) ).value<QColor>();
181 bool primaryLabels = settings.value(
"primaryLabels",
true ).toBool();
182 bool secondaryLabels = settings.value(
"secondaryLabels",
true ).toBool();
184 m_gridCirclePen.setColor( gridColor );
185 m_tropicsCirclePen.setColor( tropicsColor );
186 m_equatorCirclePen.setColor( equatorColor );
188 m_showPrimaryLabels = primaryLabels;
189 m_showSecondaryLabels = secondaryLabels;
197 if ( !m_configDialog )
200 QPalette gridPalette;
201 gridPalette.setColor( QPalette::Button, m_gridCirclePen.color() );
202 ui_configWidget->gridPushButton->setPalette( gridPalette );
204 QPalette tropicsPalette;
205 tropicsPalette.setColor( QPalette::Button, m_tropicsCirclePen.color() );
206 ui_configWidget->tropicsPushButton->setPalette( tropicsPalette );
209 QPalette equatorPalette;
210 equatorPalette.setColor( QPalette::Button, m_equatorCirclePen.color() );
211 ui_configWidget->equatorPushButton->setPalette( equatorPalette );
212 ui_configWidget->primaryCheckBox->setChecked( m_showPrimaryLabels );
213 ui_configWidget->secondaryCheckBox->setChecked( m_showSecondaryLabels );
218 const QColor c = QColorDialog::getColor( m_gridCirclePen.color(), 0, tr(
"Please choose the color for the coordinate grid.") );
221 QPalette palette = ui_configWidget->gridPushButton->palette();
222 palette.setColor( QPalette::Button, c );
223 ui_configWidget->gridPushButton->setPalette( palette );
229 const QColor c = QColorDialog::getColor( m_tropicsCirclePen.color(), 0, tr(
"Please choose the color for the tropic circles.") );
232 QPalette palette = ui_configWidget->tropicsPushButton->palette();
233 palette.setColor( QPalette::Button, c );
234 ui_configWidget->tropicsPushButton->setPalette( palette );
240 const QColor c = QColorDialog::getColor( m_equatorCirclePen.color(), 0, tr(
"Please choose the color for the equator.") );
243 QPalette palette = ui_configWidget->equatorPushButton->palette();
244 palette.setColor( QPalette::Button, c );
245 ui_configWidget->equatorPushButton->setPalette( palette );
251 m_equatorCirclePen.setColor( ui_configWidget->equatorPushButton->palette().color( QPalette::Button ) );
252 m_tropicsCirclePen.setColor( ui_configWidget->tropicsPushButton->palette().color( QPalette::Button ) );
253 m_gridCirclePen.setColor( ui_configWidget->gridPushButton->palette().color( QPalette::Button) );
254 m_showPrimaryLabels = ui_configWidget->primaryCheckBox->isChecked();
255 m_showSecondaryLabels = ui_configWidget->secondaryCheckBox->isChecked();
261 const QString& renderPos,
265 Q_UNUSED( renderPos )
273 int defaultFontSize = 10;
275 int defaultFontSize = 8;
278 QFont gridFont(
"Sans Serif");
279 gridFont.setPointSize( defaultFontSize );
280 gridFont.setBold(
true );
284 painter->setFont( gridFont );
286 renderGrid( painter, viewport, m_equatorCirclePen, m_tropicsCirclePen, m_gridCirclePen );
299 const QPen& equatorCirclePen,
300 const QPen& tropicsCirclePen,
301 const QPen& gridCirclePen )
305 painter->setPen( gridCirclePen );
310 renderLatitudeLine( painter, 84.0, viewLatLonAltBox );
312 renderLongitudeLines( painter, viewLatLonAltBox,
314 renderLongitudeLines( painter, viewLatLonAltBox,
318 renderLongitudeLines( painter, viewLatLonAltBox,
320 renderLongitudeLines( painter, viewLatLonAltBox,
323 renderLatitudeLines( painter, viewLatLonAltBox, 8.0
332 qreal normalDegreeStep = 360.0 / m_normalLineMap.lowerBound(viewport->
radius()).value();
334 LabelPositionFlags labelXPosition(
NoLabel), labelYPosition(
NoLabel);
335 if ( m_showSecondaryLabels ) {
339 renderLongitudeLines( painter, viewLatLonAltBox,
340 normalDegreeStep, normalDegreeStep, normalDegreeStep,
342 renderLatitudeLines( painter, viewLatLonAltBox, normalDegreeStep,
346 renderLongitudeLine( painter, +90.0, viewLatLonAltBox );
347 renderLongitudeLine( painter, -90.0, viewLatLonAltBox );
354 QPen boldPen = gridCirclePen;
355 boldPen.setWidthF( 1.5 );
356 painter->setPen( boldPen );
359 qreal boldDegreeStep = 360.0 / m_boldLineMap.lowerBound(viewport->
radius()).value();
361 renderLongitudeLines( painter, viewLatLonAltBox,
362 boldDegreeStep, normalDegreeStep, normalDegreeStep,
365 renderLatitudeLines( painter, viewLatLonAltBox, boldDegreeStep,
369 painter->setPen( equatorCirclePen );
371 LabelPositionFlags mainPosition(
NoLabel);
372 if ( m_showPrimaryLabels ) {
376 renderLatitudeLine( painter, 0.0, viewLatLonAltBox, tr(
"Equator" ), mainPosition );
381 renderLongitudeLine( painter, 0.0, viewLatLonAltBox, 0.0, 0.0, tr(
"Prime Meridian" ), mainPosition );
382 renderLongitudeLine( painter, 180.0, viewLatLonAltBox, 0.0, 0.0, tr(
"Antimeridian" ), mainPosition );
385 QPen tropicsPen = tropicsCirclePen;
388 tropicsPen.setStyle( Qt::DotLine );
390 painter->setPen( tropicsPen );
395 if ( axialTilt > 0 ) {
397 renderLatitudeLine( painter, +axialTilt, viewLatLonAltBox, tr(
"Tropic of Cancer" ), mainPosition );
398 renderLatitudeLine( painter, -axialTilt, viewLatLonAltBox, tr(
"Tropic of Capricorn" ), mainPosition );
401 renderLatitudeLine( painter, +90.0 - axialTilt, viewLatLonAltBox, tr(
"Arctic Circle" ), mainPosition );
402 renderLatitudeLine( painter, -90.0 + axialTilt, viewLatLonAltBox, tr(
"Antarctic Circle" ), mainPosition );
406 void GraticulePlugin::renderLatitudeLine( GeoPainter *painter, qreal latitude,
407 const GeoDataLatLonAltBox& viewLatLonAltBox,
408 const QString& lineLabel,
409 LabelPositionFlags labelPositionFlags )
415 if ( latitude < fromSouthLat || toNorthLat < latitude ) {
425 if ( fromWestLon < toEastLon ) {
426 qreal step = ( toEastLon - fromWestLon ) * 0.25;
428 for (
int i = 0; i < 5; ++i ) {
433 qreal step = ( +180.0 - toEastLon ) * 0.25;
435 for (
int i = 0; i < 5; ++i ) {
439 step = ( +180 + fromWestLon ) * 0.25;
441 for (
int i = 0; i < 5; ++i ) {
446 painter->drawPolyline( line, lineLabel, labelPositionFlags );
449 void GraticulePlugin::renderLongitudeLine( GeoPainter *painter, qreal longitude,
450 const GeoDataLatLonAltBox& viewLatLonAltBox,
451 qreal northPolarGap, qreal southPolarGap,
452 const QString& lineLabel,
453 LabelPositionFlags labelPositionFlags )
455 const qreal fromWestLon = viewLatLonAltBox.west();
456 const qreal toEastLon = viewLatLonAltBox.east();
459 if ( ( !viewLatLonAltBox.crossesDateLine()
460 && ( longitude *
DEG2RAD < fromWestLon || toEastLon < longitude *
DEG2RAD ) ) ||
461 ( viewLatLonAltBox.crossesDateLine() &&
462 longitude *
DEG2RAD < toEastLon && fromWestLon < longitude *
DEG2RAD &&
463 fromWestLon != -
M_PI && toEastLon != +
M_PI )
472 qreal southLat = ( fromSouthLat < -90.0 + southPolarGap ) ? -90.0 + southPolarGap : fromSouthLat;
473 qreal northLat = ( toNorthLat > +90.0 - northPolarGap ) ? +90.0 - northPolarGap : toNorthLat;
480 if ( northLat > 0 && southLat < 0 )
483 line << n1 << n2 << n3;
489 painter->drawPolyline( line, lineLabel, labelPositionFlags );
492 void GraticulePlugin::renderLatitudeLines( GeoPainter *painter,
493 const GeoDataLatLonAltBox& viewLatLonAltBox,
495 LabelPositionFlags labelPositionFlags
506 qreal southLineLat = step *
static_cast<int>( southLat / step );
507 qreal northLineLat = step * (
static_cast<int>( northLat / step ) + 1 );
510 if ( northLineLat > 84.0 )
513 if ( southLineLat < -80.0 )
514 southLineLat = -80.0;
517 qreal itStep = southLineLat;
521 while ( itStep < northLineLat ) {
527 if ( labelPositionFlags.testFlag(
LineCenter ) && itStep == 0.0 ) {
532 if ( itStep != 0.0 ) {
533 renderLatitudeLine( painter, itStep, viewLatLonAltBox, label, labelPositionFlags );
541 void GraticulePlugin::renderUtmExceptions( GeoPainter *painter,
542 const GeoDataLatLonAltBox& viewLatLonAltBox,
543 qreal itStep, qreal northPolarGap, qreal southPolarGap,
544 const QString & label,
545 LabelPositionFlags labelPositionFlags )
549 if ( northPolarGap == 6.0 && southPolarGap == 162.0) {
550 if ( label ==
"31" ) {
551 renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
552 southPolarGap, label, labelPositionFlags );
553 }
else if ( label ==
"33" ) {
554 renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
555 southPolarGap, label, labelPositionFlags );
556 }
else if ( label ==
"35" ) {
557 renderLongitudeLine( painter, itStep+3.0, viewLatLonAltBox, northPolarGap,
558 southPolarGap, label, labelPositionFlags );
559 }
else if ( label ==
"37" ) {
560 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
561 southPolarGap, label, labelPositionFlags );
562 }
else if ( label ==
"32" || label ==
"34" || label ==
"36" ) {
565 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
566 southPolarGap, label, labelPositionFlags );
569 else if ( northPolarGap == 26.0 && southPolarGap == 146.0 ) {
570 if ( label ==
"31" ) {
571 renderLongitudeLine( painter, itStep-3.0, viewLatLonAltBox, northPolarGap,
572 southPolarGap, label, labelPositionFlags );
574 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
575 southPolarGap, label, labelPositionFlags );
579 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
580 southPolarGap, label, labelPositionFlags );
584 void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
585 const GeoDataLatLonAltBox& viewLatLonAltBox,
586 qreal step, qreal northPolarGap, qreal southPolarGap,
587 LabelPositionFlags labelPositionFlags )
600 qreal westLineLon = step *
static_cast<int>( westLon / step );
601 qreal eastLineLon = step * (
static_cast<int>( eastLon / step ) + 1 );
603 if ( !viewLatLonAltBox.crossesDateLine() ||
604 ( westLon == -180.0 && eastLon == +180.0 ) ) {
605 qreal itStep = westLineLon;
607 while ( itStep < eastLineLon ) {
615 if ( labelPositionFlags.testFlag(
LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
621 if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
624 renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
625 southPolarGap, label, labelPositionFlags );
627 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
628 southPolarGap, label, labelPositionFlags );
635 qreal itStep = eastLineLon;
637 while ( itStep < 180.0 ) {
646 if ( labelPositionFlags.testFlag(
LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
652 if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
654 renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
655 southPolarGap, label, labelPositionFlags );
657 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
658 southPolarGap, label, labelPositionFlags );
665 while ( itStep < westLineLon ) {
673 if ( labelPositionFlags.testFlag(
LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
679 if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
681 renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
682 southPolarGap, label, labelPositionFlags );
684 renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
685 southPolarGap, label, labelPositionFlags );
704 m_normalLineMap[100] = 4;
705 m_normalLineMap[1000] = 12;
706 m_normalLineMap[2000] = 24;
707 m_normalLineMap[4000] = 48;
708 m_normalLineMap[8000] = 96;
709 m_normalLineMap[16000] = 288;
710 m_normalLineMap[100000] = 24 * 60;
711 m_normalLineMap[200000] = 24 * 60 * 2;
712 m_normalLineMap[400000] = 24 * 60 * 4;
713 m_normalLineMap[1200000] = 24 * 60 * 12;
714 m_normalLineMap[6000000] = 24 * 60 * 60;
715 m_normalLineMap[12000000] = 24 * 60 * 60 * 2;
716 m_normalLineMap[24000000] = 24 * 60 * 60 * 4;
718 m_boldLineMap[1000] = 0;
719 m_boldLineMap[2000] = 4;
720 m_boldLineMap[16000] = 24;
724 m_normalLineMap[100] = 4;
725 m_normalLineMap[1000] = 12;
726 m_normalLineMap[4000] = 36;
727 m_normalLineMap[16000] = 72;
728 m_normalLineMap[64000] = 360;
729 m_normalLineMap[128000] = 720;
731 m_boldLineMap[1000] = 0;
732 m_boldLineMap[4000] = 12;
733 m_boldLineMap[16000] = 36;
739 m_normalLineMap[512000] = 360 * 10;
740 m_normalLineMap[2048000] = 360 * 20;
741 m_normalLineMap[8192000] = 360 * 100;
742 m_normalLineMap[16384000] = 360 * 200;
743 m_normalLineMap[32768000] = 360 * 1000;
744 m_normalLineMap[131072000] = 360 * 2000;
745 m_normalLineMap[524288000] = 360 * 10000;
747 m_boldLineMap[512000] = 360;
748 m_boldLineMap[2048000] = 720;
749 m_boldLineMap[8192000] = 360 * 10;
750 m_boldLineMap[1638400] = 360 * 20;
751 m_boldLineMap[32768000] = 360 * 100;
752 m_boldLineMap[131072000] = 360 * 200;
753 m_boldLineMap[524288000] = 360 * 1000;
758 m_normalLineMap[512000] = 360 * 6;
759 m_normalLineMap[1024000] = 360 * 12;
760 m_normalLineMap[4096000] = 360 * 60;
761 m_normalLineMap[8192000] = 360 * 60 * 2;
762 m_normalLineMap[16384000] = 360 * 60 * 6;
763 m_normalLineMap[65535000] = 360 * 60 * 12;
764 m_normalLineMap[524288000] = 360 * 60 * 60;
766 m_boldLineMap[512000] = 360;
767 m_boldLineMap[1024000] = 720;
768 m_boldLineMap[4096000] = 360 * 6;
769 m_boldLineMap[8192000] = 360 * 12;
770 m_boldLineMap[16384000] = 360 * 60;
771 m_boldLineMap[65535000] = 360 * 60 * 2;
772 m_boldLineMap[524288000] = 360 * 60 * 6;
776 m_normalLineMap[999999999] = m_normalLineMap.value(262144000);
777 m_boldLineMap[999999999] = m_boldLineMap.value(262144000);
779 m_currentNotation = notation;
786 #include "GraticulePlugin.moc"
QString id() const
The internal, nonlocalized name of the planet.
QIcon icon() const
Returns an icon for the plugin.
A painter that allows to draw geometric primitives on the map.
This file contains the headers for MarbleModel.
const GeoDataLatLonAltBox & viewLatLonAltBox() const
"Decimal" notation (base-10)
void restoreDefaultSettings()
Passes an empty set of settings to the plugin.
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
const Planet * planet() const
Returns the planet object for the current map.
QString nameId() const
Returns the unique name of the plugin.
Low resolution (e.g. interlaced)
virtual qreal zValue() const
Returns the z value of the layer (default: 0.0).
Layer of a GeoScene document.
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
A plugin that creates a coordinate grid on top of the map.
QString description() const
Returns a user description of the plugin.
QList< PluginAuthor > pluginAuthors() const
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
QString latToString() const
return a string representation of latitude of the coordinate convenience function that uses the defau...
A public class that controls what is visible in the viewport of a Marble map.
QString name() const
Returns the user-visible name of the plugin.
#define Q_EXPORT_PLUGIN2(a, b)
QString lonToString() const
return a string representation of longitude of the coordinate convenience function that uses the defa...
This file contains the headers for ViewportParams.
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
The data model (not based on QAbstractModel) for a MarbleWidget.
QString renderPolicy() const
Return how the plugin settings should be used.
Notation
enum used to specify the notation / numerical system
Only a wire representation is drawn.
virtual bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
QString guiString() const
String that should be displayed in GUI.
QString copyrightYears() const
High quality (e.g. antialiasing for lines)
qreal epsilon() const
obliquity of the ecliptic plane
MapQuality mapQuality() const
Returns the map quality.
QDialog * configDialog()
Returns a pointer to the configuration dialog of the plugin.
const MarbleModel * marbleModel() const
Access to the MarbleModel.
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
"Sexagesimal DMS" notation (base-60)
static GeoDataCoordinates::Notation defaultNotation()
return Notation of string representation
The abstract class that creates a renderable item.
A class that defines a 3D bounding box for geographic data.
bool isInitialized() const
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
< "RA and DEC" notation (used for astronomical sky coordinates)