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

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