File indexing completed on 2024-04-28 03:50:17

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Torsten Rahn <tackat@kde.org>
0004 //
0005 
0006 //
0007 // This class is a graticule plugin.
0008 //
0009 
0010 #ifndef MARBLEGRATICULEPLUGIN_H
0011 #define MARBLEGRATICULEPLUGIN_H
0012 
0013 #include <QMap>
0014 #include <QHash>
0015 #include <QPen>
0016 #include <QIcon>
0017 #include <QColorDialog>
0018 
0019 
0020 #include "DialogConfigurationInterface.h"
0021 #include "RenderPlugin.h"
0022 
0023 #include "GeoDataCoordinates.h"
0024 #include "GeoDataLatLonAltBox.h"
0025 
0026 
0027 namespace Ui 
0028 {
0029     class GraticuleConfigWidget;
0030 }
0031 
0032 namespace Marble
0033 {
0034 
0035 class GeoDataLatLonAltBox;
0036 
0037 /**
0038  * @brief A plugin that creates a coordinate grid on top of the map.
0039  * Unlike in all other classes we are using degree by default in this class.
0040  * This choice was made due to the fact that all common coordinate grids focus fully 
0041  * on the degree system. 
0042  */
0043 
0044 class GraticulePlugin : public RenderPlugin, public DialogConfigurationInterface
0045 {
0046     Q_OBJECT
0047     Q_PLUGIN_METADATA(IID "org.kde.marble.GraticulePlugin")
0048     Q_INTERFACES( Marble::RenderPluginInterface )
0049     Q_INTERFACES( Marble::DialogConfigurationInterface )
0050     MARBLE_PLUGIN( GraticulePlugin )
0051 
0052  public:
0053     GraticulePlugin();
0054 
0055     explicit GraticulePlugin( const MarbleModel *marbleModel );
0056 
0057     QStringList backendTypes() const override;
0058 
0059     QString renderPolicy() const override;
0060 
0061     QStringList renderPosition() const override;
0062 
0063     QString name() const override;
0064 
0065     QString guiString() const override;
0066 
0067     QString nameId() const override;
0068 
0069     QString version() const override;
0070 
0071     QString description() const override;
0072 
0073     QString copyrightYears() const override;
0074 
0075     QVector<PluginAuthor> pluginAuthors() const override;
0076 
0077     QIcon icon () const override;
0078 
0079     QDialog *configDialog() override;
0080 
0081     void initialize () override;
0082 
0083     bool isInitialized () const override;
0084 
0085     bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = nullptr ) override;
0086 
0087     qreal zValue() const override;
0088 
0089     QHash<QString,QVariant> settings() const override;
0090 
0091     void setSettings( const QHash<QString,QVariant> &settings ) override;
0092 
0093 
0094 
0095  public Q_SLOTS:
0096     void readSettings();
0097     void writeSettings();
0098 
0099     void gridGetColor();
0100     void tropicsGetColor();
0101     void equatorGetColor();
0102 
0103 
0104  private:
0105      /**
0106      * @brief Renders the coordinate grid within the defined view bounding box.
0107      * @param painter the painter used to draw the grid
0108      * @param viewport the viewport
0109      */
0110     void renderGrid( GeoPainter *painter, ViewportParams *viewport,
0111                      const QPen& equatorCirclePen,    
0112                      const QPen& tropicsCirclePen,
0113                      const QPen& gridCirclePen );
0114 
0115      /**
0116      * @brief Renders a latitude line within the defined view bounding box.
0117      * @param painter the painter used to draw the latitude line
0118      * @param latitude the latitude of the coordinate line measured in degree .
0119      * @param viewLatLonAltBox the latitude longitude bounding box that is covered by the view.
0120      */
0121     static void renderLatitudeLine( GeoPainter *painter, qreal latitude,
0122                                     const GeoDataLatLonAltBox& viewLatLonAltBox = GeoDataLatLonAltBox(),
0123                                     const QString& lineLabel = QString(),
0124                                     LabelPositionFlags labelPositionFlags = LineCenter );
0125 
0126     /**
0127      * @brief Renders a longitude line within the defined view bounding box.
0128      * @param painter the painter used to draw the latitude line
0129      * @param longitude the longitude of the coordinate line measured in degree .
0130      * @param viewLatLonAltBox the latitude longitude bounding box that is covered by the view.
0131      * @param polarGap the area around the poles in which most longitude lines are not drawn
0132      *        for reasons of aesthetics and clarity of the map. The polarGap avoids narrow
0133      *        concurring lines around the poles which obstruct the view onto the surface.
0134      *        The radius of the polarGap area is measured in degrees. 
0135      * @param lineLabel draws a label using the font and color properties set for the painter.
0136      */
0137     static void renderLongitudeLine( GeoPainter *painter, qreal longitude,
0138                                      const GeoDataLatLonAltBox& viewLatLonAltBox = GeoDataLatLonAltBox(),
0139                                      qreal northPolarGap = 0.0, qreal southPolarGap = 0.0,
0140                                      const QString& lineLabel = QString(),
0141                                      LabelPositionFlags labelPositionFlags = LineCenter );
0142 
0143     /**
0144      * @brief Renders the latitude lines that are visible within the defined view bounding box.
0145      * @param painter the painter used to draw the latitude lines
0146      * @param viewLatLonAltBox the latitude longitude bounding box that is covered by the view.
0147      * @param step the angular distance between the lines measured in degrees .
0148      */
0149     void renderLatitudeLines( GeoPainter *painter, 
0150                               const GeoDataLatLonAltBox& viewLatLonAltBox,
0151                               qreal step, qreal skipStep,
0152                               LabelPositionFlags labelPositionFlags = LineCenter
0153                             );
0154 
0155     /**
0156      * @brief Renders the longitude lines that are visible within the defined view bounding box.
0157      * @param painter the painter used to draw the latitude lines
0158      * @param viewLatLonAltBox the latitude longitude bounding box that is covered by the view.
0159      * @param step the angular distance between the lines measured in degrees .
0160      * @param northPolarGap the area around the north pole in which most longitude lines are not drawn
0161      *        for reasons of aesthetics and clarity of the map. The polarGap avoids narrow
0162      *        concurring lines around the poles which obstruct the view onto the surface.
0163      *        The radius of the polarGap area is measured in degrees.
0164      * @param southPolarGap the area around the south pole in which most longitude lines are not drawn
0165      *        for reasons of aesthetics and clarity of the map. The polarGap avoids narrow
0166      *        concurring lines around the poles which obstruct the view onto the surface.
0167      *        The radius of the polarGap area is measured in degrees. 
0168      */
0169     void renderLongitudeLines( GeoPainter *painter, 
0170                               const GeoDataLatLonAltBox& viewLatLonAltBox, 
0171                               qreal step, qreal skipStep,
0172                               qreal northPolarGap = 0.0, qreal southPolarGap = 0.0,
0173                               LabelPositionFlags labelPositionFlags = LineCenter
0174                              ) const;
0175 
0176     /**
0177      * @brief Renders UTM exceptions that are visible within the defined view bounding box.
0178      * @param painter the painter used to draw the latitude lines
0179      * @param viewLatLonAltBox the latitude longitude bounding box that is covered by the view.
0180      * @param step the angular distance between the lines measured in degrees .
0181      * @param northPolarGap the area around the north pole in which most longitude lines are not drawn
0182      *        for reasons of aesthetics and clarity of the map. The polarGap avoids narrow
0183      *        concurring lines around the poles which obstruct the view onto the surface.
0184      *        The radius of the polarGap area is measured in degrees.
0185      * @param southPolarGap the area around the south pole in which most longitude lines are not drawn
0186      *        for reasons of aesthetics and clarity of the map. The polarGap avoids narrow
0187      *        concurring lines around the poles which obstruct the view onto the surface.
0188      *        The radius of the polarGap area is measured in degrees.
0189      */
0190     static void renderUtmExceptions( GeoPainter *painter,
0191                                      const GeoDataLatLonAltBox& viewLatLonAltBox,
0192                                      qreal step,
0193                                      qreal northPolarGap, qreal southPolarGap,
0194                                      const QString & label,
0195                                      LabelPositionFlags labelPositionFlags );
0196 
0197     /**
0198      * @brief Maps the number of coordinate lines per 360 deg against the globe radius on the screen.
0199      * @param notation Determines whether the graticule is according to the DMS or Decimal system.
0200      */
0201     void initLineMaps( GeoDataCoordinates::Notation notation );
0202 
0203     GeoDataCoordinates::Notation m_currentNotation;
0204 
0205     // Maps the zoom factor to the amount of lines per 360 deg
0206     QMap<qreal,qreal> m_boldLineMap;
0207     QMap<qreal,qreal> m_normalLineMap;
0208 
0209     QPen m_equatorCirclePen;
0210     QPen m_tropicsCirclePen;
0211     QPen m_gridCirclePen;
0212     bool m_showPrimaryLabels;
0213     bool m_showSecondaryLabels;
0214 
0215     bool m_isInitialized;
0216 
0217     QIcon m_icon;
0218 
0219     Ui::GraticuleConfigWidget *ui_configWidget;
0220     QDialog *m_configDialog;
0221 };
0222 
0223 }
0224 
0225 #endif // MARBLEGRATICULEPLUGIN_H