File indexing completed on 2025-01-05 03:59:25

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2006-2007 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2011 Michael Henning <mikehenning@eclipse.net>
0006 //
0007 
0008 //
0009 // MeasureToolPlugin enables Marble to set and display measure points
0010 //
0011 
0012 #ifndef MARBLE_MEASURE_TOOL_PLUGIN_H
0013 #define MARBLE_MEASURE_TOOL_PLUGIN_H
0014 
0015 #include <QFont>
0016 #include <QPen>
0017 #include <QAction>
0018 #include <QPixmap>
0019 
0020 #include "DialogConfigurationInterface.h"
0021 #include "GeoDataLatLonAltBox.h"
0022 #include "GeoDataLineString.h"
0023 #include "RenderPlugin.h"
0024 #include "MarbleWidget.h"
0025 
0026 namespace Marble
0027 {
0028 
0029 class MeasureConfigDialog;
0030 
0031 class MeasureToolPlugin : public RenderPlugin,
0032                           public DialogConfigurationInterface
0033 {
0034     Q_OBJECT
0035     Q_PLUGIN_METADATA(IID "org.kde.marble.MeasureToolPlugin")
0036     Q_INTERFACES( Marble::RenderPluginInterface )
0037     Q_INTERFACES( Marble::DialogConfigurationInterface )
0038     MARBLE_PLUGIN( MeasureToolPlugin )
0039 
0040 public:
0041 
0042     enum PaintMode
0043     {
0044         Polygon = 0,
0045         Circular
0046     };
0047 
0048 public:
0049 
0050     explicit MeasureToolPlugin( const MarbleModel *marbleModel = nullptr );
0051 
0052     QStringList backendTypes() const override;
0053     QString renderPolicy() const override;
0054     QStringList renderPosition() const override;
0055     QString name() const override;
0056     QString guiString() const override;
0057     QString nameId() const override;
0058 
0059     QString version() const override;
0060 
0061     QString description() const override;
0062 
0063     QString copyrightYears() const override;
0064 
0065     QVector<PluginAuthor> pluginAuthors() const override;
0066 
0067     QIcon icon () const override;
0068 
0069     void initialize () override;
0070 
0071     bool isInitialized () const override;
0072 
0073     bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = nullptr ) override;
0074 
0075     QDialog *configDialog() override;
0076     QHash<QString,QVariant> settings() const override;
0077     void setSettings( const QHash<QString,QVariant> &settings ) override;
0078 
0079 Q_SIGNALS:
0080 
0081     void  numberOfMeasurePointsChanged( int newNumber );
0082 
0083 public Q_SLOTS:
0084 
0085     bool  eventFilter( QObject *object, QEvent *event ) override;
0086 
0087 private:
0088 
0089     void  drawMeasurePoints( GeoPainter *painter );
0090     void  drawInfobox( GeoPainter *painter ) const;
0091     void  drawSegments( GeoPainter *painter );
0092     void  addContextItems();
0093     void  removeContextItems();
0094 
0095 private Q_SLOTS:
0096 
0097     void  setNumberOfMeasurePoints( int number );
0098     void  addMeasurePointEvent();
0099 
0100     void  addMeasurePoint( qreal lon, qreal lat );
0101     void  removeLastMeasurePoint();
0102     void  removeMeasurePoints();
0103 
0104     void writeSettings();
0105 
0106 private:
0107 
0108     Q_DISABLE_COPY( MeasureToolPlugin )
0109 
0110     static QString meterToPreferredUnit(qreal meters, bool isSquare = false);
0111 
0112     // The line strings in the distance path.
0113     GeoDataLineString m_measureLineString;
0114     GeoDataLatLonAltBox m_latLonAltBox;
0115 
0116     QPixmap m_mark;
0117     QFont   m_font_regular;
0118     int     m_fontascent;
0119 
0120     QPen    m_pen;
0121 
0122     QAction *m_addMeasurePointAction;
0123     QAction *m_removeLastMeasurePointAction;
0124     QAction *m_removeMeasurePointsAction;
0125     QAction *m_separator;
0126 
0127     MarbleWidget* m_marbleWidget;
0128 
0129     MeasureConfigDialog *m_configDialog;
0130 
0131     bool m_showDistanceLabel;
0132     bool m_showBearingLabel;
0133     bool m_showBearingChangeLabel;
0134 
0135     bool m_showPolygonArea;
0136     bool m_showCircularArea;
0137     bool m_showRadius;
0138     bool m_showPerimeter;
0139     bool m_showCircumference;
0140 
0141     qreal m_totalDistance;
0142     qreal m_polygonArea;
0143     qreal m_circularArea;
0144     qreal m_radius;
0145     qreal m_perimeter;
0146     qreal m_circumference;
0147 
0148     PaintMode m_paintMode;
0149 };
0150 
0151 } // namespace Marble
0152 
0153 #endif // MARBLE_MEASURE_TOOL_PLUGIN_H