QGCMapTileSet.h 9.76 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   ();

Gus Grubba's avatar
Gus Grubba committed
45
    Q_PROPERTY(QString      name                READ    name                NOTIFY nameChanged)
dogmaphobic's avatar
dogmaphobic committed
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      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
    Q_PROPERTY(bool         selected            READ    selected            WRITE  setSelected  NOTIFY selectedChanged)

dogmaphobic's avatar
dogmaphobic committed
77 78 79 80 81 82 83 84 85 86 87 88
    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
89 90 91 92 93 94 95 96 97 98 99 100
    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
101 102 103 104 105
    QString     downloadStatus          ();
    int         minZoom                 () { return _minZoom; }
    int         maxZoom                 () { return _maxZoom; }
    QDateTime   creationDate            () { return _creationDate; }
    quint64     id                      () { return _id; }
106
    QString type            () { return _type; }
dogmaphobic's avatar
dogmaphobic committed
107
    bool        complete                () { return _defaultSet || (_totalTileCount <= _savedTileCount); }
dogmaphobic's avatar
dogmaphobic committed
108 109 110 111 112 113
    bool        defaultSet              () { return _defaultSet; }
    quint64     setID                   () { return _id; }
    bool        deleting                () { return _deleting; }
    bool        downloading             () { return _downloading; }
    quint32     errorCount              () { return _errorCount; }
    QString     errorCountStr           ();
114
    bool        selected                () { return _selected; }
dogmaphobic's avatar
dogmaphobic committed
115

116
    void        setSelected             (bool sel);
dogmaphobic's avatar
dogmaphobic committed
117 118 119 120 121 122
    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
123 124 125 126 127 128
    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
129 130 131 132
    void        setMinZoom              (int zoom)                  { _minZoom = zoom; }
    void        setMaxZoom              (int zoom)                  { _maxZoom = zoom; }
    void        setCreationDate         (QDateTime date)            { _creationDate = date; }
    void        setId                   (quint64 id)                { _id = id; }
133
    void        setType                 (QString type)  { _type = type; }
dogmaphobic's avatar
dogmaphobic committed
134 135 136 137 138 139 140
    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
141 142 143 144 145 146
    void        totalTileCountChanged   ();
    void        uniqueTileCountChanged  ();
    void        uniqueTileSizeChanged   ();
    void        totalTilesSizeChanged   ();
    void        savedTileCountChanged   ();
    void        savedTileSizeChanged    ();
dogmaphobic's avatar
dogmaphobic committed
147 148
    void        completeChanged         ();
    void        errorCountChanged       ();
149
    void        selectedChanged         ();
Gus Grubba's avatar
Gus Grubba committed
150
    void        nameChanged             ();
dogmaphobic's avatar
dogmaphobic committed
151 152 153 154 155 156 157 158

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

private:
    void        _prepareDownload        ();
dogmaphobic's avatar
dogmaphobic committed
159
    void        _doneWithDownload       ();
dogmaphobic's avatar
dogmaphobic committed
160 161 162 163 164 165 166 167

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

#endif // QGC_MAP_TILE_SET_H