File indexing completed on 2024-04-14 03:47:59

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: 2010-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 //
0007 
0008 //
0009 // PlacemarkLayout is responsible for drawing the Placemarks on the map
0010 //
0011 
0012 #ifndef MARBLE_PLACEMARKLAYOUT_H
0013 #define MARBLE_PLACEMARKLAYOUT_H
0014 
0015 #include <QHash>
0016 #include <QRect>
0017 #include <QSet>
0018 #include <QMap>
0019 #include <QVector>
0020 #include <QPointer>
0021 
0022 #include "GeoDataPlacemark.h"
0023 #include <GeoDataStyle.h>
0024 
0025 class QAbstractItemModel;
0026 class QItemSelectionModel;
0027 class QPoint;
0028 class QModelIndex;
0029 
0030 
0031 namespace Marble
0032 {
0033 
0034 class GeoDataCoordinates;
0035 class GeoPainter;
0036 class MarbleClock;
0037 class PlacemarkPainter;
0038 class TileId;
0039 class VisiblePlacemark;
0040 class ViewportParams;
0041 class StyleBuilder;
0042 
0043 /**
0044  * Layouts the place marks with a passed QPainter.
0045  */
0046 
0047 
0048 
0049 class PlacemarkLayout : public QObject
0050 {
0051     Q_OBJECT
0052 
0053  public:
0054     /**
0055      * Creates a new place mark layout.
0056      */
0057     PlacemarkLayout( QAbstractItemModel  *placemarkModel,
0058                      QItemSelectionModel *selectionModel,
0059                      MarbleClock *clock,
0060                      const StyleBuilder* styleBuilder,
0061                      QObject *parent = nullptr );
0062 
0063     /**
0064      * Destroys the place mark painter.
0065      */
0066     ~PlacemarkLayout() override;
0067 
0068     /**
0069      * @reimp
0070      */
0071     QVector<VisiblePlacemark *> generateLayout(const ViewportParams *viewport , int tileLevel);
0072 
0073     /**
0074      * Returns a list of model indexes that are at position @p pos.
0075      */
0076     QVector<const GeoDataFeature *> whichPlacemarkAt( const QPoint &pos );
0077 
0078     QString runtimeTrace() const;
0079 
0080     QList<VisiblePlacemark *> visiblePlacemarks() const;
0081 
0082     bool hasPlacemarkAt(const QPoint &pos);
0083 
0084  public Q_SLOTS:
0085     // earth
0086     void setShowPlaces( bool show );
0087     void setShowCities( bool show );
0088     void setShowTerrain( bool show );
0089     void setShowOtherPlaces( bool show );
0090 
0091     // other planets
0092     void setShowLandingSites( bool show );
0093     void setShowCraters( bool show );
0094     void setShowMaria( bool show );
0095 
0096     void requestStyleReset();
0097     void addPlacemarks( const QModelIndex& index, int first, int last );
0098     void removePlacemarks( const QModelIndex& index, int first, int last );
0099     void resetCacheData();
0100 
0101  Q_SIGNALS:
0102     void repaintNeeded();
0103 
0104  private:
0105     /**
0106      * Returns a the maximum height of all possible labels.
0107      * WARNING: This is a really slow method as it traverses all placemarks
0108      * to check the labelheight.
0109      * FIXME: Once a StyleManager that manages all styles has been implemented
0110      * just traverse all existing styles.
0111      */
0112     static int maxLabelHeight();
0113 
0114     void styleReset();
0115     void clearCache();
0116 
0117     static QSet<TileId> visibleTiles(const ViewportParams &viewport, int tileLevel);
0118     bool layoutPlacemark(const GeoDataPlacemark *placemark, const GeoDataCoordinates &coordinates, qreal x, qreal y, bool selected );
0119 
0120     /**
0121      * Returns the coordinates at which an icon should be drawn for the @p placemark.
0122      * @p ok is set to true if the coordinates are valid and should be used for drawing,
0123      * it is set to false otherwise.
0124      */
0125     GeoDataCoordinates placemarkIconCoordinates( const GeoDataPlacemark *placemark ) const;
0126 
0127     QRectF  roomForLabel(const GeoDataStyle::ConstPtr &style,
0128                          const qreal x, const qreal y,
0129                          const QString &labelText , const VisiblePlacemark *placemark) const;
0130     bool    hasRoomForPixmap(const qreal y, const VisiblePlacemark *placemark) const;
0131 
0132     bool    placemarksOnScreenLimit( const QSize &screenSize ) const;
0133 
0134  private:
0135     Q_DISABLE_COPY( PlacemarkLayout )
0136     QAbstractItemModel*  m_placemarkModel;
0137     QItemSelectionModel *const m_selectionModel;
0138     MarbleClock *const m_clock;
0139 
0140     QVector<VisiblePlacemark*> m_paintOrder;
0141     QString m_runtimeTrace;
0142     int m_labelArea;
0143     QHash<const GeoDataPlacemark*, VisiblePlacemark*> m_visiblePlacemarks;
0144     QVector< QVector< VisiblePlacemark* > >  m_rowsection;
0145 
0146     /// map providing the list of placemark belonging in TileId as key
0147     QMap<TileId, QList<const GeoDataPlacemark*> > m_placemarkCache;
0148     QSet<qint64> m_osmIds;
0149 
0150     const QSet<GeoDataPlacemark::GeoDataVisualCategory> m_acceptedVisualCategories;
0151 
0152     // earth
0153     bool m_showPlaces;
0154     bool m_showCities;
0155     bool m_showTerrain;
0156     bool m_showOtherPlaces;
0157 
0158     // other planets
0159     bool m_showLandingSites;
0160     bool m_showCraters;
0161     bool m_showMaria;
0162 
0163     int     m_maxLabelHeight;
0164     bool    m_styleResetRequested;
0165     const StyleBuilder* m_styleBuilder;
0166     // Referencing these properties by value
0167     // instead of using a more fragile pointer
0168     bool m_lastPlacemarkAvailable;
0169     QRectF m_lastPlacemarkLabelRect;
0170     QRectF m_lastPlacemarkSymbolRect;
0171 };
0172 
0173 }
0174 
0175 #endif