File indexing completed on 2024-04-28 15:15:55

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2005-2007 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2010-2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 //
0007 
0008 //
0009 // MarbleModel is the data store and index class for the MarbleWidget.
0010 //
0011 
0012 #ifndef MARBLE_MARBLEMODEL_H
0013 #define MARBLE_MARBLEMODEL_H
0014 
0015 
0016 /** @file
0017  * This file contains the headers for MarbleModel
0018  *
0019  * @author Torsten Rahn <tackat@kde.org>
0020  * @author Inge Wallin  <inge@lysator.liu.se>
0021  */
0022 
0023 
0024 
0025 #include "marble_export.h"
0026 
0027 #include <QObject>
0028 #include <QString>
0029 
0030 #include "MarbleGlobal.h"
0031 
0032 class QItemSelectionModel;
0033 class QAbstractItemModel;
0034 class QTextDocument;
0035 class QDateTime;
0036 
0037 namespace Marble
0038 {
0039 
0040 class GeoDataPlacemark;
0041 class GeoPainter;
0042 class MeasureTool;
0043 class PositionTracking;
0044 class HttpDownloadManager;
0045 class MarbleModelPrivate;
0046 class MarbleClock;
0047 class SunLocator;
0048 class TileCreator;
0049 class PluginManager;
0050 class GeoDataCoordinates;
0051 class GeoDataTreeModel;
0052 class GeoSceneDocument;
0053 class Planet;
0054 class RoutingManager;
0055 class BookmarkManager;
0056 class FileManager;
0057 class ElevationModel;
0058 
0059 /**
0060  * @short The data model (not based on QAbstractModel) for a MarbleWidget.
0061  *
0062  * This class provides a data storage and indexer that can be
0063  * displayed in a MarbleWidget.  It contains 3 different datatypes:
0064  * <b>tiles</b> which provide the background, <b>vectors</b> which
0065  * provide things like country borders and coastlines and
0066  * <b>placemarks</b> which can show points of interest, such as
0067  * cities, mountain tops or the poles.
0068  *
0069  * The <b>tiles</b> provide the background of the image and can be for
0070  * instance height and depth fields, magnetic strength, topographic
0071  * data or anything else that is area based.
0072  *
0073  * The <b>vectors</b> provide things like country borders and
0074  * coastlines.  They are stored in separate files and can be added or
0075  * removed at anytime.
0076  *
0077  * The <b>placemarks</b> contain points of interest, such as cities,
0078  * mountain tops or the poles. These are sorted by size (for cities)
0079  * and category (capitals, other important cities, less important
0080  * cities, etc) and are displayed with different color or shape like
0081  * square or round.
0082  *
0083  * @see MarbleWidget
0084  */
0085 
0086 class MARBLE_EXPORT MarbleModel : public QObject
0087 {
0088     friend class MarbleModelPrivate;
0089 
0090     Q_OBJECT
0091 
0092     Q_PROPERTY( QString mapThemeId READ mapThemeId WRITE setMapThemeId NOTIFY themeChanged )
0093     Q_PROPERTY( bool workOffline READ workOffline WRITE setWorkOffline NOTIFY workOfflineChanged )
0094 
0095  public:
0096     /**
0097      * @brief  Construct a new MarbleModel.
0098      * @param parent the parent widget
0099      */
0100     explicit MarbleModel( QObject *parent = nullptr );
0101     ~MarbleModel() override;
0102 
0103     /**
0104      * @brief Return the list of Placemarks as a QAbstractItemModel *
0105      * @return a list of all Placemarks in the MarbleModel.
0106      */
0107     GeoDataTreeModel *treeModel();
0108     const GeoDataTreeModel *treeModel() const;
0109 
0110     QAbstractItemModel *groundOverlayModel();
0111     const QAbstractItemModel *groundOverlayModel() const;
0112 
0113     QAbstractItemModel *placemarkModel();
0114     const QAbstractItemModel *placemarkModel() const;
0115 
0116     QItemSelectionModel *placemarkSelectionModel();
0117 
0118     /**
0119      * @brief Return the name of the current map theme.
0120      * @return the identifier of the current MapTheme.
0121      * To ensure that a unique identifier is being used the theme does NOT
0122      * get represented by its name but the by relative location of the file
0123      * that specifies the theme:
0124      *
0125      * Example:
0126      *    maptheme = "earth/bluemarble/bluemarble.dgml"
0127      */
0128     QString mapThemeId() const;
0129 
0130     GeoSceneDocument *mapTheme();
0131     const GeoSceneDocument *mapTheme() const;
0132     void setMapTheme( GeoSceneDocument * document );
0133 
0134     /**
0135      * @brief Set a new map theme to use.
0136      * @param mapThemeId  the identifier of the new map theme
0137      *
0138      * This function sets the map theme, i.e. combination of tile set
0139      * and color scheme to use.  If the map theme is not previously
0140      * used, some basic tiles are created and a progress dialog is
0141      * shown.
0142      *
0143      * The ID of the new maptheme. To ensure that a unique
0144      * identifier is being used the theme does NOT get represented by its
0145      * name but the by relative location of the file that specifies the theme:
0146      *
0147      * Example:
0148      *    maptheme = "earth/bluemarble/bluemarble.dgml"
0149      */
0150     void setMapThemeId( const QString &mapThemeId );
0151 
0152     /**
0153      * @brief  get the home point
0154      * @param  lon  the longitude of the home point.
0155      * @param  lat  the latitude of the home point.
0156      * @param  zoom the default zoom level of the home point.
0157      */
0158     void home( qreal &lon, qreal &lat, int& zoom ) const;
0159     /**
0160      * @brief  Set the home point
0161      * @param  lon  the longitude of the new home point.
0162      * @param  lat  the latitude of the new home point.
0163      * @param  zoom the default zoom level for the new home point.
0164      */
0165     void setHome( qreal lon, qreal lat, int zoom = 1050 );
0166     /**
0167      * @brief  Set the home point
0168      * @param  homePoint  the new home point.
0169      * @param  zoom       the default zoom level for the new home point.
0170      */
0171     void setHome( const GeoDataCoordinates& homePoint, int zoom = 1050 );
0172 
0173     /**
0174      * @brief Return the downloadmanager to load missing tiles
0175      * @return the HttpDownloadManager instance.
0176      */
0177     HttpDownloadManager *downloadManager();
0178     const HttpDownloadManager *downloadManager() const;
0179 
0180 
0181     /**
0182      * @brief Handle file loading into the treeModel
0183      * @param filename the file to load
0184      */
0185     void addGeoDataFile( const QString& filename );
0186 
0187     /**
0188      * @brief Handle raw data loading into the treeModel
0189      * @param data the raw data to load
0190      * @param key the name to remove this raw data later
0191      */
0192     void addGeoDataString( const QString& data, const QString& key = QLatin1String("data") );
0193 
0194     /**
0195      * @brief Remove the file or raw data from the treeModel
0196      * @param key either the file name or the key for raw data
0197      */
0198     void removeGeoData( const QString& key );
0199 
0200     FileManager       *fileManager();
0201 
0202     PositionTracking   *positionTracking() const;
0203 
0204     qreal                 planetRadius()   const;
0205     QString               planetName()     const;
0206     QString               planetId()       const;
0207 
0208     MarbleClock *clock();
0209     const MarbleClock *clock() const;
0210 
0211     SunLocator *sunLocator();
0212     const SunLocator *sunLocator() const;
0213 
0214     /**
0215      * @brief  Returns the limit in kilobytes of the persistent (on hard disc) tile cache.
0216      * @return the limit of persistent tile cache in kilobytes.
0217      */
0218     quint64 persistentTileCacheLimit() const;
0219 
0220     /**
0221      * @brief  Returns the limit of the volatile (in RAM) tile cache.
0222      * @return the cache limit in kilobytes
0223      */
0224     quint64 volatileTileCacheLimit() const;
0225 
0226     const PluginManager* pluginManager() const;
0227 
0228     PluginManager* pluginManager();
0229 
0230     /**
0231      * @brief Returns the planet object for the current map.
0232      * @return the planet object for the current map
0233      */
0234     const Planet *planet() const;
0235 
0236     RoutingManager* routingManager();
0237     const RoutingManager* routingManager() const;
0238 
0239     void setClockDateTime( const QDateTime& datetime );
0240 
0241     QDateTime clockDateTime() const;
0242 
0243     int clockSpeed() const;
0244 
0245     void setClockSpeed( int speed );
0246 
0247     void setClockTimezone( int timeInSec );
0248 
0249     int clockTimezone() const;
0250 
0251     /**
0252      * return instance of BookmarkManager
0253     */
0254     BookmarkManager *bookmarkManager();
0255 
0256     QTextDocument * legend();
0257 
0258     /**
0259      * @brief Uses the given text document as the new content of the legend
0260      * Any previous legend content is overwritten. MarbleModel takes ownership
0261      * of the passed document.
0262      */
0263     void setLegend( QTextDocument * document );
0264 
0265     bool workOffline() const;
0266 
0267     void setWorkOffline( bool workOffline );
0268 
0269     ElevationModel* elevationModel();
0270     const ElevationModel* elevationModel() const;
0271 
0272     /**
0273      * Returns the placemark being tracked by this model or 0 if no
0274      * placemark is currently tracked.
0275      * @see setTrackedPlacemark(), trackedPlacemarkChanged()
0276      */
0277     const GeoDataPlacemark *trackedPlacemark() const;
0278 
0279  public Q_SLOTS:
0280     void clearPersistentTileCache();
0281 
0282     /**
0283      * @brief  Set the limit of the persistent (on hard disc) tile cache.
0284      * @param  kiloBytes The limit in kilobytes, 0 means no limit.
0285      */
0286     void setPersistentTileCacheLimit( quint64 kiloBytes );
0287 
0288     /**
0289      * @brief Change the placemark tracked by this model
0290      * @see trackedPlacemark(), trackedPlacemarkChanged()
0291      */
0292     void setTrackedPlacemark( const GeoDataPlacemark *placemark );
0293 
0294     void updateProperty( const QString &property, bool value );
0295 
0296  Q_SIGNALS:
0297 
0298     /**
0299      * @brief Signal that the MarbleModel has started to create a new set of tiles.
0300      * @param name name of the set
0301      * @param description the set description
0302      */
0303     void creatingTilesStart( TileCreator*, const QString& name, const QString& description );
0304 
0305     /**
0306      * @brief Signal that the map theme has changed, and to which theme.
0307      * @param mapTheme the identifier of the new map theme.
0308      * @see  mapTheme
0309      * @see  setMapTheme
0310      */
0311     void themeChanged( const QString &mapTheme );
0312 
0313     void workOfflineChanged();
0314 
0315     /**
0316      * @brief Emitted when the placemark tracked by this model has changed
0317      * @see setTrackedPlacemark(), trackedPlacemark()
0318      */
0319     void trackedPlacemarkChanged( const GeoDataPlacemark *placemark );
0320  
0321     /** @brief Emitted when the home location is changed
0322      * @see home(), setHome()
0323      */
0324     void homeChanged( const GeoDataCoordinates &newHomePoint );
0325 
0326  private:
0327     Q_DISABLE_COPY( MarbleModel )
0328 
0329     Q_PRIVATE_SLOT( d, void assignFillColors( const QString &filePath ) )
0330 
0331     void addDownloadPolicies( const GeoSceneDocument *mapTheme );
0332     MarbleModelPrivate  * const d;
0333 };
0334 
0335 }
0336 
0337 #endif