12 #include "ui_GraticuleConfigWidget.h" 
   26 #include <QPushButton> 
   31 #include <QSvgRenderer> 
   33 #include <QColorDialog> 
   43       m_showPrimaryLabels( true ),
 
   44       m_showSecondaryLabels( true ),
 
   45       m_isInitialized( false ),
 
   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 ),
 
   81     return tr( 
"Coordinate Grid" );
 
   86     return tr( 
"Coordinate &Grid" );
 
   91     return QString( 
"coordinate-grid" );
 
  101     return tr( 
"A plugin that shows a coordinate grid." );
 
  117     return QIcon(
":/icons/coordinate.png");
 
  126     m_isInitialized = 
true;
 
  131     return m_isInitialized;
 
  136     if ( !m_configDialog ) {
 
  137         m_configDialog = 
new QDialog();
 
  138         ui_configWidget = 
new Ui::GraticuleConfigWidget;
 
  139         ui_configWidget->setupUi( m_configDialog );
 
  141         connect( ui_configWidget->gridPushButton, SIGNAL(clicked()), 
this,
 
  143         connect( ui_configWidget->tropicsPushButton, SIGNAL(clicked()), 
this,
 
  145         connect( ui_configWidget->equatorPushButton, SIGNAL(clicked()), 
this,
 
  149         connect( ui_configWidget->m_buttonBox, SIGNAL(accepted()), 
this, 
 
  151         connect( ui_configWidget->m_buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()),
 
  153         QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
 
  154         connect( applyButton, SIGNAL(clicked()),
 
  160     return m_configDialog;
 
  171     settings.
insert( 
"primarylabels", m_showPrimaryLabels );
 
  172     settings.
insert( 
"secondaryLabels", m_showSecondaryLabels );
 
  184     bool primaryLabels = settings.
value( 
"primaryLabels", 
true ).toBool();
 
  185     bool secondaryLabels = settings.
value( 
"secondaryLabels", 
true ).toBool();
 
  187     m_gridCirclePen.
setColor( gridColor );
 
  188     m_tropicsCirclePen.
setColor( tropicsColor );
 
  189     m_equatorCirclePen.
setColor( equatorColor );
 
  191     m_showPrimaryLabels = primaryLabels;
 
  192     m_showSecondaryLabels = secondaryLabels;
 
  200     if ( !m_configDialog )
 
  204     gridPalette.
setColor( QPalette::Button, m_gridCirclePen.
color() );
 
  205     ui_configWidget->gridPushButton->setPalette( gridPalette );
 
  208     tropicsPalette.
setColor( QPalette::Button, m_tropicsCirclePen.
color() );
 
  209     ui_configWidget->tropicsPushButton->setPalette( tropicsPalette );
 
  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 );
 
  224         QPalette palette = ui_configWidget->gridPushButton->palette();
 
  225         palette.
setColor( QPalette::Button, c );
 
  226         ui_configWidget->gridPushButton->setPalette( palette );
 
  235         QPalette palette = ui_configWidget->tropicsPushButton->palette();
 
  236         palette.
setColor( QPalette::Button, c );
 
  237         ui_configWidget->tropicsPushButton->setPalette( palette );
 
  246         QPalette palette = ui_configWidget->equatorPushButton->palette();
 
  247         palette.
setColor( QPalette::Button, c );
 
  248         ui_configWidget->equatorPushButton->setPalette( palette );
 
  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();
 
  268     Q_UNUSED( renderPos )
 
  276     int defaultFontSize = 10;
 
  278     int defaultFontSize = 8;
 
  281     QFont gridFont(
"Sans Serif");
 
  289     renderGrid( painter, viewport, m_equatorCirclePen, m_tropicsCirclePen, m_gridCirclePen );
 
  302                                   const QPen& equatorCirclePen,
 
  303                                   const QPen& tropicsCirclePen,
 
  304                                   const QPen& gridCirclePen )
 
  308     painter->
setPen( gridCirclePen );
 
  313         renderLatitudeLine( painter, 84.0, viewLatLonAltBox );
 
  315         renderLongitudeLines( painter, viewLatLonAltBox,
 
  317         renderLongitudeLines( painter, viewLatLonAltBox,
 
  321         renderLongitudeLines( painter, viewLatLonAltBox,
 
  323         renderLongitudeLines( painter, viewLatLonAltBox,
 
  326         renderLatitudeLines( painter, viewLatLonAltBox, 8.0 
 
  335     qreal normalDegreeStep = 360.0 / m_normalLineMap.
lowerBound(viewport->
radius()).value();
 
  337     LabelPositionFlags labelXPosition(
NoLabel), labelYPosition(
NoLabel);
 
  338     if ( m_showSecondaryLabels ) {
 
  342     renderLongitudeLines( painter, viewLatLonAltBox,
 
  343                           normalDegreeStep, normalDegreeStep, normalDegreeStep,
 
  345     renderLatitudeLines(  painter, viewLatLonAltBox, normalDegreeStep,
 
  349     renderLongitudeLine( painter, +90.0, viewLatLonAltBox );
 
  350     renderLongitudeLine( painter, -90.0, viewLatLonAltBox );
 
  357         QPen boldPen = gridCirclePen;
 
  359         painter->
setPen( boldPen );
 
  362         qreal boldDegreeStep = 360.0 / m_boldLineMap.
lowerBound(viewport->
radius()).value();
 
  364         renderLongitudeLines( painter, viewLatLonAltBox,
 
  365                             boldDegreeStep, normalDegreeStep, normalDegreeStep,
 
  368         renderLatitudeLines(  painter, viewLatLonAltBox, boldDegreeStep,
 
  372     painter->
setPen( equatorCirclePen );
 
  374     LabelPositionFlags mainPosition(
NoLabel);
 
  375     if ( m_showPrimaryLabels ) {
 
  379     renderLatitudeLine( painter, 0.0, viewLatLonAltBox, 
tr( 
"Equator" ), mainPosition );
 
  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 );
 
  388     QPen tropicsPen = tropicsCirclePen;
 
  393     painter->
setPen( tropicsPen );
 
  398     if ( axialTilt > 0 ) {
 
  400         renderLatitudeLine( painter, +axialTilt, viewLatLonAltBox, 
tr( 
"Tropic of Cancer" ), mainPosition  );
 
  401         renderLatitudeLine( painter, -axialTilt, viewLatLonAltBox, 
tr( 
"Tropic of Capricorn" ), mainPosition );
 
  404         renderLatitudeLine( painter, +90.0 - axialTilt, viewLatLonAltBox, 
tr( 
"Arctic Circle" ), mainPosition );
 
  405         renderLatitudeLine( painter, -90.0 + axialTilt, viewLatLonAltBox, 
tr( 
"Antarctic Circle" ), mainPosition );
 
  409 void GraticulePlugin::renderLatitudeLine( GeoPainter *painter, qreal latitude,
 
  410                                           const GeoDataLatLonAltBox& viewLatLonAltBox,
 
  412                                           LabelPositionFlags labelPositionFlags )
 
  418     if ( latitude < fromSouthLat || toNorthLat < latitude ) {
 
  428     if ( fromWestLon < toEastLon ) {
 
  429         qreal step = ( toEastLon - fromWestLon ) * 0.25;
 
  431         for ( 
int i = 0; i < 5; ++i ) {
 
  436         qreal step = ( +180.0 - toEastLon ) * 0.25;
 
  438         for ( 
int i = 0; i < 5; ++i ) {
 
  442         step = ( +180 + fromWestLon ) * 0.25;
 
  444         for ( 
int i = 0; i < 5; ++i ) {
 
  449     painter->drawPolyline( line, lineLabel, labelPositionFlags );     
 
  452 void GraticulePlugin::renderLongitudeLine( GeoPainter *painter, qreal longitude,
 
  453                                            const GeoDataLatLonAltBox& viewLatLonAltBox, 
 
  454                                            qreal northPolarGap, qreal southPolarGap,
 
  456                                            LabelPositionFlags labelPositionFlags )
 
  458     const qreal fromWestLon = viewLatLonAltBox.west();
 
  459     const qreal toEastLon   = viewLatLonAltBox.east();
 
  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 )
 
  475     qreal southLat = ( fromSouthLat < -90.0 + southPolarGap ) ? -90.0 + southPolarGap : fromSouthLat;
 
  476     qreal northLat = ( toNorthLat   > +90.0 - northPolarGap ) ? +90.0 - northPolarGap : toNorthLat;
 
  483     if ( northLat > 0 && southLat < 0 )
 
  486         line << n1 << n2 << n3;
 
  492     painter->drawPolyline( line, lineLabel, labelPositionFlags );     
 
  495 void GraticulePlugin::renderLatitudeLines( GeoPainter *painter,
 
  496                                            const GeoDataLatLonAltBox& viewLatLonAltBox,
 
  498                                            LabelPositionFlags labelPositionFlags
 
  509     qreal southLineLat = step * 
static_cast<int>( southLat / step ); 
 
  510     qreal northLineLat = step * ( 
static_cast<int>( northLat / step ) + 1 );
 
  513         if ( northLineLat > 84.0 )
 
  516         if ( southLineLat < -80.0 )
 
  517             southLineLat = -80.0;
 
  520     qreal itStep = southLineLat;
 
  524     while ( itStep < northLineLat ) {
 
  530         if ( labelPositionFlags.testFlag( 
LineCenter ) && itStep == 0.0 ) {
 
  535         if ( itStep != 0.0 ) {
 
  536             renderLatitudeLine( painter, itStep, viewLatLonAltBox, label, labelPositionFlags );
 
  544 void GraticulePlugin::renderUtmExceptions( GeoPainter *painter,
 
  545                                             const GeoDataLatLonAltBox& viewLatLonAltBox,
 
  546                                             qreal itStep, qreal northPolarGap, qreal southPolarGap,
 
  548                                             LabelPositionFlags labelPositionFlags )
 
  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" ) {
 
  568             renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
 
  569             southPolarGap, label, labelPositionFlags );
 
  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 );
 
  577             renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
 
  578             southPolarGap, label, labelPositionFlags );
 
  582         renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
 
  583         southPolarGap, label, labelPositionFlags );
 
  587 void GraticulePlugin::renderLongitudeLines( GeoPainter *painter, 
 
  588                                             const GeoDataLatLonAltBox& viewLatLonAltBox, 
 
  589                                             qreal step, qreal northPolarGap, qreal southPolarGap,
 
  590                                             LabelPositionFlags labelPositionFlags )
 
  603     qreal westLineLon = step * 
static_cast<int>( westLon / step );
 
  604     qreal eastLineLon = step * ( 
static_cast<int>( eastLon / step ) + 1 );
 
  606     if ( !viewLatLonAltBox.crossesDateLine() ||
 
  607          ( westLon == -180.0 && eastLon == +180.0 ) ) {
 
  608         qreal itStep = westLineLon;
 
  610         while ( itStep < eastLineLon ) {
 
  618             if ( labelPositionFlags.testFlag( 
LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
 
  624             if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
 
  627                     renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
 
  628                     southPolarGap, label, labelPositionFlags );
 
  630                     renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
 
  631                     southPolarGap, label, labelPositionFlags );
 
  638         qreal itStep = eastLineLon;
 
  640         while ( itStep < 180.0 ) {
 
  649             if ( labelPositionFlags.testFlag( 
LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
 
  655             if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
 
  657                     renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
 
  658                     southPolarGap, label, labelPositionFlags );
 
  660                     renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
 
  661                     southPolarGap, label, labelPositionFlags );
 
  668         while ( itStep < westLineLon ) {
 
  676             if ( labelPositionFlags.testFlag( 
LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )
 
  682             if ( itStep != 0.0 && itStep != 180.0 && itStep != -180.0 ) {
 
  684                     renderUtmExceptions( painter, viewLatLonAltBox, itStep, northPolarGap,
 
  685                     southPolarGap, label, labelPositionFlags );
 
  687                     renderLongitudeLine( painter, itStep, viewLatLonAltBox, northPolarGap,
 
  688                     southPolarGap, label, labelPositionFlags );
 
  707         m_normalLineMap[100]     = 4;          
 
  708         m_normalLineMap[1000]    = 12;          
 
  709         m_normalLineMap[2000]   = 24;         
 
  710         m_normalLineMap[4000]   = 48;         
 
  711         m_normalLineMap[8000]   = 96;         
 
  712         m_normalLineMap[16000]  = 288;        
 
  713         m_normalLineMap[100000]  = 24 * 60;     
 
  714         m_normalLineMap[200000]  = 24 * 60 * 2; 
 
  715         m_normalLineMap[400000]  = 24 * 60 * 4; 
 
  716         m_normalLineMap[1200000] = 24 * 60 * 12; 
 
  717         m_normalLineMap[6000000] = 24 * 60 * 60; 
 
  718         m_normalLineMap[12000000] = 24 * 60 * 60 * 2; 
 
  719         m_normalLineMap[24000000] = 24 * 60 * 60 * 4; 
 
  721         m_boldLineMap[1000]     = 0;        
 
  722         m_boldLineMap[2000]    = 4;         
 
  723         m_boldLineMap[16000]    = 24;       
 
  727     m_normalLineMap[100]     = 4;          
 
  728     m_normalLineMap[1000]    = 12;          
 
  729     m_normalLineMap[4000]   = 36;         
 
  730     m_normalLineMap[16000]   = 72;         
 
  731     m_normalLineMap[64000]  = 360;         
 
  732     m_normalLineMap[128000] = 720;        
 
  734     m_boldLineMap[1000]     = 0;         
 
  735     m_boldLineMap[4000]    = 12;         
 
  736     m_boldLineMap[16000]   = 36;         
 
  742             m_normalLineMap[512000]  = 360 * 10;       
 
  743             m_normalLineMap[2048000] = 360 * 20;       
 
  744             m_normalLineMap[8192000] = 360 * 100;      
 
  745             m_normalLineMap[16384000] = 360 * 200;      
 
  746             m_normalLineMap[32768000] = 360 * 1000;    
 
  747             m_normalLineMap[131072000] = 360 * 2000;    
 
  748             m_normalLineMap[524288000] = 360 * 10000;  
 
  750             m_boldLineMap[512000]     = 360;          
 
  751             m_boldLineMap[2048000]    = 720;          
 
  752             m_boldLineMap[8192000]   = 360 * 10;     
 
  753             m_boldLineMap[1638400]   = 360 * 20;     
 
  754             m_boldLineMap[32768000]  = 360 * 100;    
 
  755             m_boldLineMap[131072000]  = 360 * 200;    
 
  756             m_boldLineMap[524288000] = 360 * 1000;   
 
  761             m_normalLineMap[512000]  = 360 * 6;         
 
  762             m_normalLineMap[1024000] = 360 * 12;        
 
  763             m_normalLineMap[4096000] = 360 * 60;        
 
  764             m_normalLineMap[8192000] = 360 * 60 * 2;    
 
  765             m_normalLineMap[16384000] = 360 * 60 * 6;   
 
  766             m_normalLineMap[65535000] = 360 * 60 * 12;  
 
  767             m_normalLineMap[524288000] = 360 * 60 * 60; 
 
  769             m_boldLineMap[512000]     = 360;          
 
  770             m_boldLineMap[1024000]    = 720;          
 
  771             m_boldLineMap[4096000]   = 360 * 6;      
 
  772             m_boldLineMap[8192000]   = 360 * 12;     
 
  773             m_boldLineMap[16384000]  = 360 * 60;     
 
  774             m_boldLineMap[65535000]  = 360 * 60 * 2; 
 
  775             m_boldLineMap[524288000] = 360 * 60 * 6; 
 
  779     m_normalLineMap[999999999] = m_normalLineMap.
value(262144000);     
 
  780     m_boldLineMap[999999999]   = m_boldLineMap.
value(262144000);     
 
  782     m_currentNotation = notation;
 
  789 #include "GraticulePlugin.moc" 
void setPointSize(int pointSize)
void setStyle(Qt::PenStyle style)
QString id() const 
The internal, nonlocalized name of the planet. 
iterator insert(const Key &key, const T &value)
QIcon icon() const 
Returns an icon for the plugin. 
void setColor(ColorGroup group, ColorRole role, const QColor &color)
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 tr(const char *sourceText, const char *disambiguation, int n)
QString nameId() const 
Returns the unique name of the plugin. 
Low resolution (e.g. interlaced) 
void setBold(bool enable)
virtual qreal zValue() const 
Returns the z value of the layer (default: 0.0). 
void setFont(const QFont &font)
Layer of a GeoScene document. 
void setPen(const QColor &color)
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. 
void setWidthF(qreal width)
QList< PluginAuthor > pluginAuthors() const 
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin. 
void setColor(const QColor &color)
QString latToString() const 
return a string representation of latitude of the coordinate convenience function that uses the defau...
iterator lowerBound(const Key &key)
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...
const T value(const Key &key) const
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
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. 
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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) 
const T value(const Key &key) const