File indexing completed on 2024-05-05 03:49:47

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 // SPDX-FileCopyrightText: 2009 Andrew Manson <g.real.ate@gmail.com>
0005 //
0006 
0007 #ifndef MARBLE_GEOGRAPHICSITEM_H
0008 #define MARBLE_GEOGRAPHICSITEM_H
0009 
0010 // Marble
0011 #include "marble_export.h"
0012 #include "GeoDataStyle.h"
0013 
0014 class QString;
0015 
0016 namespace Marble
0017 {
0018 
0019 class GeoDataFeature;
0020 class GeoDataLatLonAltBox;
0021 class GeoDataCoordinates;
0022 class GeoGraphicsItemPrivate;
0023 class GeoPainter;
0024 class StyleBuilder;
0025 class ViewportParams;
0026 class GeoDataRelation;
0027 
0028 class RenderContext
0029 {
0030 public:
0031     bool operator==(const RenderContext &other) const;
0032     bool operator!=(const RenderContext &other) const;
0033 
0034     explicit RenderContext(int tileLevel = -1);
0035     int tileLevel() const;
0036 
0037 private:
0038     int m_tileLevel;
0039 };
0040 
0041 class MARBLE_EXPORT GeoGraphicsItem
0042 {
0043  public:
0044     explicit GeoGraphicsItem( const GeoDataFeature *feature );
0045     virtual ~GeoGraphicsItem();
0046 
0047     enum GeoGraphicsItemFlag {
0048         NoOptions = 0x0,
0049         ItemIsMovable = 0x1,
0050         ItemIsSelectable = 0x2,
0051         ItemIsVisible = 0x4
0052     };
0053 
0054     Q_DECLARE_FLAGS(GeoGraphicsItemFlags, GeoGraphicsItemFlag)
0055 
0056     bool visible() const;
0057 
0058     void setVisible( bool visible );
0059 
0060     /**
0061      * Get the GeoGraphicItemFlags value that describes which flags are set on
0062      * this item. @see QFlags
0063      */
0064     GeoGraphicsItemFlags flags() const;
0065 
0066     /**
0067      * Set or unset a single flag
0068      * @param flag the flag
0069      * @param enabled sets if the flag is to be set or unset
0070      */
0071     void setFlag( GeoGraphicsItemFlag flag, bool enabled = true );
0072 
0073     /**
0074      * Replace all of the current flags.
0075      * @param flags is the new value for this item's flags.
0076      */
0077     void setFlags( GeoGraphicsItemFlags flags );
0078 
0079     /**
0080      * Returns the minim zoom level on which item will be active.
0081      */
0082     int minZoomLevel() const;
0083 
0084     /**
0085      * Sets the minimum zoom level
0086      */
0087     void setMinZoomLevel( int zoomLevel );
0088 
0089     /**
0090      * Returns the placemark for that item.
0091      */
0092     const GeoDataFeature* feature() const;
0093 
0094     /**
0095      * Returns the bounding box covered by the item.
0096      */
0097     virtual const GeoDataLatLonAltBox &latLonAltBox() const = 0;
0098 
0099     /**
0100      * Returns the style of item.
0101      */
0102     GeoDataStyle::ConstPtr style() const;
0103 
0104     /**
0105      * Set the style for the item.
0106      */
0107     void setStyleBuilder(const StyleBuilder *styleBuilder);
0108 
0109     void resetStyle();
0110 
0111     /**
0112      * Set the style which will be used when
0113      * placemark is highlighted.
0114      * GeoGraphicsItem takes ownership of the
0115      * passed style and deletes it when appropriate.
0116      */
0117     void setHighlightStyle( const GeoDataStyle::ConstPtr &highlightStyle );
0118 
0119     /**
0120      * Returns the z value of the item
0121      */
0122     qreal zValue() const;
0123 
0124     /**
0125      * Set the z value of the item
0126      */
0127     void setZValue( qreal z );
0128 
0129     static bool zValueLessThan(GeoGraphicsItem* one, GeoGraphicsItem* two);
0130     static bool styleLessThan(GeoGraphicsItem* one, GeoGraphicsItem* two);
0131     static bool zValueAndStyleLessThan(GeoGraphicsItem* one, GeoGraphicsItem* two);
0132 
0133     /**
0134      * Paints the item using the given GeoPainter.
0135      *
0136      * Note that depending on the projection and zoom level, the item may be visible more than once,
0137      * which is taken care of by GeoPainter.
0138      */
0139     virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel) = 0;
0140 
0141     void setHighlighted( bool highlight );
0142 
0143     bool isHighlighted() const;
0144 
0145     QStringList paintLayers() const;
0146 
0147     void setPaintLayers(const QStringList &paintLayers);
0148 
0149     void setRenderContext(const RenderContext &renderContext);
0150 
0151     /**
0152      * @brief contains Returns true if the item contains the given coordinates
0153      * @param screenPosition
0154      * @param viewport
0155      * @return
0156      */
0157     virtual bool contains(const QPoint &screenPosition, const ViewportParams *viewport) const;
0158 
0159     void setRelations(const QSet<const GeoDataRelation *> &relations);
0160 
0161  protected:
0162     virtual void handleRelationUpdate(const QVector<const GeoDataRelation *> &relations);
0163 
0164     GeoGraphicsItemPrivate *const d;
0165 };
0166 
0167 } // Namespace Marble
0168 Q_DECLARE_OPERATORS_FOR_FLAGS(Marble::GeoGraphicsItem::GeoGraphicsItemFlags)
0169 
0170 #endif