QGCMapTileSet.h 9.44 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41


/**
 * @file
 *   @brief Map Tile Set
 *
 *   @author Gus Grubba <mavlink@grubba.com>
 *
 */

#ifndef QGC_MAP_TILE_SET_H
#define QGC_MAP_TILE_SET_H

#include <QObject>
#include <QString>
#include <QHash>
#include <QDateTime>
#include <QImage>

#include "QGCLoggingCategory.h"
#include "QGCMapEngineData.h"
#include "QGCMapUrlEngine.h"

Q_DECLARE_LOGGING_CATEGORY(QGCCachedTileSetLog)

class QGCTile;
class QGCMapEngineManager;

//-----------------------------------------------------------------------------
class QGCCachedTileSet : public QObject
{
    Q_OBJECT
public:
dogmaphobic's avatar
dogmaphobic committed
42
    QGCCachedTileSet    (const QString& name);
dogmaphobic's avatar
dogmaphobic committed
43 44
    ~QGCCachedTileSet   ();

dogmaphobic's avatar
dogmaphobic committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    Q_PROPERTY(QString      name                READ    name                CONSTANT)
    Q_PROPERTY(QString      mapTypeStr          READ    mapTypeStr          CONSTANT)
    Q_PROPERTY(double       topleftLon          READ    topleftLon          CONSTANT)
    Q_PROPERTY(double       topleftLat          READ    topleftLat          CONSTANT)
    Q_PROPERTY(double       bottomRightLon      READ    bottomRightLon      CONSTANT)
    Q_PROPERTY(double       bottomRightLat      READ    bottomRightLat      CONSTANT)
    Q_PROPERTY(int          minZoom             READ    minZoom             CONSTANT)
    Q_PROPERTY(int          maxZoom             READ    maxZoom             CONSTANT)
    Q_PROPERTY(quint32      totalTileCount      READ    totalTileCount      NOTIFY totalTileCountChanged)
    Q_PROPERTY(QString      totalTileCountStr   READ    totalTileCountStr   NOTIFY totalTileCountChanged)
    Q_PROPERTY(quint64      totalTilesSize      READ    totalTilesSize      NOTIFY totalTilesSizeChanged)
    Q_PROPERTY(QString      totalTilesSizeStr   READ    totalTilesSizeStr   NOTIFY totalTilesSizeChanged)
    Q_PROPERTY(quint32      uniqueTileCount     READ    uniqueTileCount     NOTIFY uniqueTileCountChanged)
    Q_PROPERTY(QString      uniqueTileCountStr  READ    uniqueTileCountStr  NOTIFY uniqueTileCountChanged)
    Q_PROPERTY(quint64      uniqueTileSize      READ    uniqueTileSize      NOTIFY uniqueTileSizeChanged)
    Q_PROPERTY(QString      uniqueTileSizeStr   READ    uniqueTileSizeStr   NOTIFY uniqueTileSizeChanged)
    Q_PROPERTY(quint32      savedTileCount      READ    savedTileCount      NOTIFY savedTileCountChanged)
    Q_PROPERTY(QString      savedTileCountStr   READ    savedTileCountStr   NOTIFY savedTileCountChanged)
    Q_PROPERTY(quint64      savedTileSize       READ    savedTileSize       NOTIFY savedTileSizeChanged)
    Q_PROPERTY(QString      savedTileSizeStr    READ    savedTileSizeStr    NOTIFY savedTileSizeChanged)
    Q_PROPERTY(QString      downloadStatus      READ    downloadStatus      NOTIFY savedTileSizeChanged)
    Q_PROPERTY(QDateTime    creationDate        READ    creationDate        CONSTANT)
    Q_PROPERTY(bool         complete            READ    complete            NOTIFY completeChanged)
    Q_PROPERTY(bool         defaultSet          READ    defaultSet          CONSTANT)
    Q_PROPERTY(quint64      setID               READ    setID               CONSTANT)
    Q_PROPERTY(bool         deleting            READ    deleting            NOTIFY deletingChanged)
    Q_PROPERTY(bool         downloading         READ    downloading         NOTIFY downloadingChanged)
    Q_PROPERTY(quint32      errorCount          READ    errorCount          NOTIFY errorCountChanged)
    Q_PROPERTY(QString      errorCountStr       READ    errorCountStr       NOTIFY errorCountChanged)
dogmaphobic's avatar
dogmaphobic committed
74 75 76 77 78 79 80 81 82 83 84 85 86

    Q_INVOKABLE void createDownloadTask ();
    Q_INVOKABLE void resumeDownloadTask ();
    Q_INVOKABLE void cancelDownloadTask ();

    void        setManager              (QGCMapEngineManager* mgr);

    QString     name                    () { return _name; }
    QString     mapTypeStr              () { return _mapTypeStr; }
    double      topleftLat              () { return _topleftLat; }
    double      topleftLon              () { return _topleftLon; }
    double      bottomRightLat          () { return _bottomRightLat; }
    double      bottomRightLon          () { return _bottomRightLon; }
dogmaphobic's avatar
dogmaphobic committed
87 88 89 90 91 92 93 94 95 96 97 98
    quint32     totalTileCount          () { return (quint32)_totalTileCount; }
    QString     totalTileCountStr       ();
    quint64     totalTilesSize          () { return (quint64)_totalTileSize; }
    QString     totalTilesSizeStr       ();
    quint32     uniqueTileCount         () { return _uniqueTileCount; }
    QString     uniqueTileCountStr      ();
    quint64     uniqueTileSize          () { return _uniqueTileSize; }
    QString     uniqueTileSizeStr       ();
    quint32     savedTileCount          () { return (quint32)_savedTileCount; }
    QString     savedTileCountStr       ();
    quint64     savedTileSize           () { return (quint64)_savedTileSize; }
    QString     savedTileSizeStr        ();
dogmaphobic's avatar
dogmaphobic committed
99 100 101 102 103 104
    QString     downloadStatus          ();
    int         minZoom                 () { return _minZoom; }
    int         maxZoom                 () { return _maxZoom; }
    QDateTime   creationDate            () { return _creationDate; }
    quint64     id                      () { return _id; }
    UrlFactory::MapType type            () { return _type; }
dogmaphobic's avatar
dogmaphobic committed
105
    bool        complete                () { return _defaultSet || (_totalTileCount <= _savedTileCount); }
dogmaphobic's avatar
dogmaphobic committed
106 107 108 109 110 111 112 113 114 115 116 117 118
    bool        defaultSet              () { return _defaultSet; }
    quint64     setID                   () { return _id; }
    bool        deleting                () { return _deleting; }
    bool        downloading             () { return _downloading; }
    quint32     errorCount              () { return _errorCount; }
    QString     errorCountStr           ();

    void        setName                 (QString name)              { _name = name; }
    void        setMapTypeStr           (QString typeStr)           { _mapTypeStr = typeStr; }
    void        setTopleftLat           (double lat)                { _topleftLat = lat; }
    void        setTopleftLon           (double lon)                { _topleftLon = lon; }
    void        setBottomRightLat       (double lat)                { _bottomRightLat = lat; }
    void        setBottomRightLon       (double lon)                { _bottomRightLon = lon; }
dogmaphobic's avatar
dogmaphobic committed
119 120 121 122 123 124
    void        setTotalTileCount       (quint32 num)               { _totalTileCount = num; emit totalTileCountChanged(); }
    void        setUniqueTileCount      (quint32 num)               { _uniqueTileCount = num; }
    void        setUniqueTileSize       (quint64 size)              { _uniqueTileSize  = size; }
    void        setTotalTileSize        (quint64 size)              { _totalTileSize  = size; emit totalTilesSizeChanged(); }
    void        setSavedTileCount       (quint32 num)               { _savedTileCount = num; emit savedTileCountChanged(); }
    void        setSavedTileSize        (quint64 size)              { _savedTileSize  = size; emit savedTileSizeChanged();  }
dogmaphobic's avatar
dogmaphobic committed
125 126 127 128 129 130 131 132 133 134 135 136
    void        setMinZoom              (int zoom)                  { _minZoom = zoom; }
    void        setMaxZoom              (int zoom)                  { _maxZoom = zoom; }
    void        setCreationDate         (QDateTime date)            { _creationDate = date; }
    void        setId                   (quint64 id)                { _id = id; }
    void        setType                 (UrlFactory::MapType type)  { _type = type; }
    void        setDefaultSet           (bool def)                  { _defaultSet = def; }
    void        setDeleting             (bool del)                  { _deleting = del; emit deletingChanged(); }
    void        setDownloading          (bool down)                 { _downloading = down; }

signals:
    void        deletingChanged         ();
    void        downloadingChanged      ();
dogmaphobic's avatar
dogmaphobic committed
137 138 139 140 141 142
    void        totalTileCountChanged   ();
    void        uniqueTileCountChanged  ();
    void        uniqueTileSizeChanged   ();
    void        totalTilesSizeChanged   ();
    void        savedTileCountChanged   ();
    void        savedTileSizeChanged    ();
dogmaphobic's avatar
dogmaphobic committed
143 144 145 146 147 148 149 150 151 152
    void        completeChanged         ();
    void        errorCountChanged       ();

private slots:
    void _tileListFetched               (QList<QGCTile*> tiles);
    void _networkReplyFinished          ();
    void _networkReplyError             (QNetworkReply::NetworkError error);

private:
    void        _prepareDownload        ();
dogmaphobic's avatar
dogmaphobic committed
153
    void        _doneWithDownload       ();
dogmaphobic's avatar
dogmaphobic committed
154 155 156 157 158 159 160 161

private:
    QString     _name;
    QString     _mapTypeStr;
    double      _topleftLat;
    double      _topleftLon;
    double      _bottomRightLat;
    double      _bottomRightLon;
dogmaphobic's avatar
dogmaphobic committed
162 163 164 165 166 167
    quint32     _totalTileCount;
    quint64     _totalTileSize;
    quint32     _uniqueTileCount;
    quint64     _uniqueTileSize;
    quint32     _savedTileCount;
    quint64     _savedTileSize;
dogmaphobic's avatar
dogmaphobic committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    int         _minZoom;
    int         _maxZoom;
    bool        _defaultSet;
    bool        _deleting;
    bool        _downloading;
    QDateTime   _creationDate;
    quint64     _id;
    UrlFactory::MapType _type;
    QNetworkAccessManager*  _networkManager;
    QHash<QString, QNetworkReply*> _replies;
    quint32     _errorCount;
    //-- Tile download
    QList<QGCTile *> _tilesToDownload;
    bool        _noMoreTiles;
    bool        _batchRequested;
    QGCMapEngineManager* _manager;
};

#endif // QGC_MAP_TILE_SET_H