maptoscreen.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /***************************************************************************
  2. maptoscreen.h
  3. ----------------------------------------------------
  4. date : 22.08.2018
  5. copyright : (C) 2018 by Denis Rouzaud
  6. email : denis (at) opengis.ch
  7. ***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #ifndef MAPTOSCREEN_H
  16. #define MAPTOSCREEN_H
  17. #include "qgsquickmapsettings.h"
  18. #include <QObject>
  19. #include <QPointF>
  20. #include <qgspoint.h>
  21. /**
  22. * @brief The MapToScreen class transform a map point to screen coordinates.
  23. * The map point CRS is the one from the map settings.
  24. * Screen point will be automatically updated on map extent changes.
  25. */
  26. class MapToScreen : public QObject
  27. {
  28. Q_OBJECT
  29. //! Map settings is used to define the map canvas CRS and detect any extent change
  30. Q_PROPERTY( QgsQuickMapSettings *mapSettings READ mapSettings WRITE setMapSettings NOTIFY mapSettingsChanged )
  31. //! the point in map coordinates
  32. Q_PROPERTY( QgsPoint mapPoint READ mapPoint WRITE setMapPoint NOTIFY mapPointChanged )
  33. //! the distance in map unit
  34. Q_PROPERTY( double mapDistance READ mapDistance WRITE setMapDistance NOTIFY mapDistanceChanged )
  35. //! the point in screen coordinates (read-only)
  36. Q_PROPERTY( QPointF screenPoint READ screenPoint NOTIFY screenPointChanged )
  37. //! the distance in screen coordinates (read-only)
  38. Q_PROPERTY( double screenDistance READ screenDistance NOTIFY screenDistanceChanged )
  39. public:
  40. explicit MapToScreen( QObject *parent = nullptr );
  41. //! \copydoc mapSettings
  42. void setMapSettings( QgsQuickMapSettings *mapSettings );
  43. //! \copydoc mapSettings
  44. QgsQuickMapSettings *mapSettings() const;
  45. //! \copydoc mapPoint
  46. void setMapPoint( const QgsPoint &point );
  47. //! \copydoc mapPoint
  48. QgsPoint mapPoint() const;
  49. //! \copydoc mapDistance
  50. void setMapDistance( const double distance );
  51. //! \copydoc mapDistance
  52. double mapDistance() const;
  53. //! \copydoc screenPoint
  54. QPointF screenPoint() const;
  55. //! \copydoc screenDistance
  56. double screenDistance() const;
  57. signals:
  58. //! \copydoc mapSettings
  59. void mapSettingsChanged();
  60. //! \copydoc mapPoint
  61. void mapPointChanged();
  62. //! \copydoc mapDistance
  63. void mapDistanceChanged();
  64. //! \copydoc screenPoint
  65. void screenPointChanged();
  66. //! \copydoc screenDistance
  67. void screenDistanceChanged();
  68. private slots:
  69. void transformPoint();
  70. void transformDistance();
  71. private:
  72. QgsQuickMapSettings *mMapSettings = nullptr;
  73. QgsPoint mMapPoint = QgsPoint();
  74. double mMapDistance = 0.0;
  75. QPointF mScreenPoint = QPointF();
  76. double mScreenDistance = 0.0;
  77. };
  78. #endif // MAPTOSCREEN_H