QGCMapEngineData.h 10.5 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


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

#ifndef QGC_MAP_ENGINE_DATA_H
#define QGC_MAP_ENGINE_DATA_H

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

#include "QGCMapUrlEngine.h"

class QGCCachedTileSet;

//-----------------------------------------------------------------------------
32
class QGCTile
dogmaphobic's avatar
dogmaphobic committed
33 34 35 36 37 38 39
{
public:
    QGCTile()
        : _x(0)
        , _y(0)
        , _z(0)
        , _set(UINT64_MAX)
40
        , _type("Invalid")
dogmaphobic's avatar
dogmaphobic committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    {
    }

    enum TyleState {
        StatePending = 0,
        StateDownloading,
        StateError,
        StateComplete
    };

    int                 x           () const { return _x; }
    int                 y           () const { return _y; }
    int                 z           () const { return _z; }
    qulonglong          set         () const { return _set;  }
    const QString       hash        () const { return _hash; }
56
    QString type        () const { return _type; }
dogmaphobic's avatar
dogmaphobic committed
57 58 59 60 61 62

    void                setX        (int x) { _x = x; }
    void                setY        (int y) { _y = y; }
    void                setZ        (int z) { _z = z; }
    void                setTileSet  (qulonglong set) { _set = set;  }
    void                setHash     (const QString& hash) { _hash = hash; }
63
    void                setType     (QString type) { _type = type; }
dogmaphobic's avatar
dogmaphobic committed
64 65 66 67 68 69 70

private:
    int         _x;
    int         _y;
    int         _z;
    qulonglong  _set;
    QString     _hash;
71
    QString _type;
dogmaphobic's avatar
dogmaphobic committed
72 73 74 75 76 77 78
};

//-----------------------------------------------------------------------------
class QGCCacheTile : public QObject
{
    Q_OBJECT
public:
79
    QGCCacheTile    (const QString hash, const QByteArray img, const QString format, QString type, qulonglong set = UINT64_MAX)
dogmaphobic's avatar
dogmaphobic committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        : _set(set)
        , _hash(hash)
        , _img(img)
        , _format(format)
        , _type(type)
    {
    }
    QGCCacheTile    (const QString hash, qulonglong set)
        : _set(set)
        , _hash(hash)
    {
    }
    qulonglong          set     () { return _set;   }
    QString             hash    () { return _hash;  }
    QByteArray          img     () { return _img;   }
    QString             format  () { return _format;}
96
    QString type    () { return _type; }
dogmaphobic's avatar
dogmaphobic committed
97 98 99 100 101
private:
    qulonglong  _set;
    QString     _hash;
    QByteArray  _img;
    QString     _format;
102
    QString _type;
dogmaphobic's avatar
dogmaphobic committed
103 104 105 106 107 108 109 110 111 112
};

//-----------------------------------------------------------------------------
class QGCMapTask : public QObject
{
    Q_OBJECT
public:

    enum TaskType {
        taskInit,
113
        taskTestInternet,
dogmaphobic's avatar
dogmaphobic committed
114 115 116 117 118 119 120
        taskCacheTile,
        taskFetchTile,
        taskFetchTileSets,
        taskCreateTileSet,
        taskGetTileDownloadList,
        taskUpdateTileDownloadState,
        taskDeleteTileSet,
Gus Grubba's avatar
Gus Grubba committed
121
        taskRenameTileSet,
dogmaphobic's avatar
dogmaphobic committed
122
        taskPruneCache,
123
        taskReset,
Gus Grubba's avatar
Gus Grubba committed
124 125
        taskExport,
        taskImport
dogmaphobic's avatar
dogmaphobic committed
126 127 128 129 130 131 132 133 134 135
    };

    QGCMapTask(TaskType type)
        : _type(type)
    {}
    virtual ~QGCMapTask()
    {}

    virtual TaskType    type            () { return _type; }

136
    void setError(QString errorString = QString())
dogmaphobic's avatar
dogmaphobic committed
137 138 139 140 141 142 143 144 145 146 147
    {
        emit error(_type, errorString);
    }

signals:
    void error          (QGCMapTask::TaskType type, QString errorString);

private:
    TaskType    _type;
};

148 149 150 151 152 153 154 155 156 157
//-----------------------------------------------------------------------------
class QGCTestInternetTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCTestInternetTask()
        : QGCMapTask(QGCMapTask::taskTestInternet)
    {}
};

dogmaphobic's avatar
dogmaphobic committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
//-----------------------------------------------------------------------------
class QGCFetchTileSetTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCFetchTileSetTask()
        : QGCMapTask(QGCMapTask::taskFetchTileSets)
    {}

    void setTileSetFetched(QGCCachedTileSet* tileSet)
    {
        emit tileSetFetched(tileSet);
    }

signals:
    void            tileSetFetched  (QGCCachedTileSet* tileSet);
};

//-----------------------------------------------------------------------------
class QGCCreateTileSetTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCCreateTileSetTask(QGCCachedTileSet* tileSet)
        : QGCMapTask(QGCMapTask::taskCreateTileSet)
        , _tileSet(tileSet)
        , _saved(false)
    {}

    ~QGCCreateTileSetTask();

    QGCCachedTileSet*   tileSet () { return _tileSet; }

    void setTileSetSaved()
    {
        //-- Flag as saved. Signalee wll maintain it.
        _saved = true;
        emit tileSetSaved(_tileSet);
    }

signals:
    void tileSetSaved   (QGCCachedTileSet* tileSet);

private:
    QGCCachedTileSet* _tileSet;
    bool              _saved;
};

//-----------------------------------------------------------------------------
class QGCFetchTileTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCFetchTileTask(const QString hash)
        : QGCMapTask(QGCMapTask::taskFetchTile)
        , _hash(hash)
    {}

    ~QGCFetchTileTask()
    {
    }

    void setTileFetched(QGCCacheTile* tile)
    {
        emit tileFetched(tile);
    }

    QString         hash() { return _hash; }

signals:
    void            tileFetched     (QGCCacheTile* tile);

private:
    QString         _hash;
};

//-----------------------------------------------------------------------------
class QGCSaveTileTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCSaveTileTask(QGCCacheTile* tile)
        : QGCMapTask(QGCMapTask::taskCacheTile)
        , _tile(tile)
    {}

    ~QGCSaveTileTask()
    {
        if(_tile)
            delete _tile;
    }

    QGCCacheTile*   tile() { return _tile; }

private:
    QGCCacheTile*   _tile;
};

//-----------------------------------------------------------------------------
class QGCGetTileDownloadListTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCGetTileDownloadListTask(qulonglong setID, int count)
        : QGCMapTask(QGCMapTask::taskGetTileDownloadList)
        , _setID(setID)
        , _count(count)
    {}

    qulonglong  setID() { return _setID; }
    int         count() { return _count; }

    void setTileListFetched(QList<QGCTile*> tiles)
    {
        emit tileListFetched(tiles);
    }

signals:
    void            tileListFetched  (QList<QGCTile*> tiles);

private:
    qulonglong  _setID;
    int         _count;
};

//-----------------------------------------------------------------------------
class QGCUpdateTileDownloadStateTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCUpdateTileDownloadStateTask(qulonglong setID, QGCTile::TyleState state, const QString& hash)
        : QGCMapTask(QGCMapTask::taskUpdateTileDownloadState)
        , _setID(setID)
        , _state(state)
        , _hash(hash)
    {}

    QString             hash    () { return _hash; }
    qulonglong          setID   () { return _setID; }
    QGCTile::TyleState  state   () { return _state; }

private:
    qulonglong          _setID;
    QGCTile::TyleState  _state;
    QString             _hash;
};

//-----------------------------------------------------------------------------
class QGCDeleteTileSetTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCDeleteTileSetTask(qulonglong setID)
        : QGCMapTask(QGCMapTask::taskDeleteTileSet)
        , _setID(setID)
    {}

    qulonglong  setID() { return _setID; }

    void setTileSetDeleted()
    {
        emit tileSetDeleted(_setID);
    }

signals:
    void tileSetDeleted(qulonglong setID);

private:
    qulonglong  _setID;
};

Gus Grubba's avatar
Gus Grubba committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
//-----------------------------------------------------------------------------
class QGCRenameTileSetTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCRenameTileSetTask(qulonglong setID, QString newName)
        : QGCMapTask(QGCMapTask::taskRenameTileSet)
        , _setID(setID)
        , _newName(newName)
    {}

    qulonglong  setID   () { return _setID; }
    QString     newName () { return _newName; }

private:
    qulonglong  _setID;
    QString     _newName;
};

dogmaphobic's avatar
dogmaphobic committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
//-----------------------------------------------------------------------------
class QGCPruneCacheTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCPruneCacheTask(quint64 amount)
        : QGCMapTask(QGCMapTask::taskPruneCache)
        , _amount(amount)
    {}

    quint64  amount() { return _amount; }

    void setPruned()
    {
        emit pruned();
    }

signals:
    void pruned();

private:
    quint64  _amount;
};

//-----------------------------------------------------------------------------
class QGCResetTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCResetTask()
        : QGCMapTask(QGCMapTask::taskReset)
    {}

    void setResetCompleted()
    {
        emit resetCompleted();
    }

signals:
    void resetCompleted();
};

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
//-----------------------------------------------------------------------------
class QGCExportTileTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCExportTileTask(QVector<QGCCachedTileSet*> sets, QString path)
        : QGCMapTask(QGCMapTask::taskExport)
        , _sets(sets)
        , _path(path)
    {}

    ~QGCExportTileTask()
    {
    }

    QVector<QGCCachedTileSet*> sets() { return _sets; }
    QString                    path() { return _path; }

    void setExportCompleted()
    {
Gus Grubba's avatar
Gus Grubba committed
410
        emit actionCompleted();
411 412
    }

Gus Grubba's avatar
Gus Grubba committed
413 414
    void setProgress(int percentage)
    {
Gus Grubba's avatar
Gus Grubba committed
415
        emit actionProgress(percentage);
Gus Grubba's avatar
Gus Grubba committed
416 417
    }

418 419 420 421 422
private:
    QVector<QGCCachedTileSet*>  _sets;
    QString                     _path;

signals:
Gus Grubba's avatar
Gus Grubba committed
423 424
    void actionCompleted        ();
    void actionProgress         (int percentage);
Gus Grubba's avatar
Gus Grubba committed
425

426 427
};

Gus Grubba's avatar
Gus Grubba committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
//-----------------------------------------------------------------------------
class QGCImportTileTask : public QGCMapTask
{
    Q_OBJECT
public:
    QGCImportTileTask(QString path, bool replace)
        : QGCMapTask(QGCMapTask::taskImport)
        , _path(path)
        , _replace(replace)
    {}

    ~QGCImportTileTask()
    {
    }

    QString                    path     () { return _path; }
    bool                       replace  () { return _replace; }

    void setImportCompleted()
    {
        emit actionCompleted();
    }

    void setProgress(int percentage)
    {
        emit actionProgress(percentage);
    }

private:
    QString                     _path;
    bool                        _replace;

signals:
    void actionCompleted        ();
    void actionProgress         (int percentage);

};
dogmaphobic's avatar
dogmaphobic committed
465 466

#endif // QGC_MAP_ENGINE_DATA_H