QGCMapEngineManager.h 7.75 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * 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


/// @file
12
///     @author Gus Grubba <gus@auterion.com>
dogmaphobic's avatar
dogmaphobic committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

#ifndef OfflineMapsManager_H
#define OfflineMapsManager_H

#include "QmlObjectListModel.h"
#include "QGCToolbox.h"
#include "QGCLoggingCategory.h"
#include "QGCMapEngine.h"
#include "QGCMapTileSet.h"

Q_DECLARE_LOGGING_CATEGORY(QGCMapEngineManagerLog)

class QGCMapEngineManager : public QGCTool
{
    Q_OBJECT
public:
29
    QGCMapEngineManager(QGCApplication* app, QGCToolbox* toolbox);
dogmaphobic's avatar
dogmaphobic committed
30 31
    ~QGCMapEngineManager();

Gus Grubba's avatar
Gus Grubba committed
32 33 34 35 36 37
    enum ImportAction {
        ActionNone,
        ActionImporting,
        ActionExporting,
        ActionDone,
    };
38
    Q_ENUM(ImportAction)
Gus Grubba's avatar
Gus Grubba committed
39

dogmaphobic's avatar
dogmaphobic committed
40 41 42 43 44 45
    Q_PROPERTY(quint64              tileCount       READ    tileCount       NOTIFY tileCountChanged)
    Q_PROPERTY(QString              tileCountStr    READ    tileCountStr    NOTIFY tileCountChanged)
    Q_PROPERTY(quint64              tileSize        READ    tileSize        NOTIFY tileSizeChanged)
    Q_PROPERTY(QString              tileSizeStr     READ    tileSizeStr     NOTIFY tileSizeChanged)
    Q_PROPERTY(QmlObjectListModel*  tileSets        READ    tileSets        NOTIFY tileSetsChanged)
    Q_PROPERTY(QStringList          mapList         READ    mapList         CONSTANT)
46
    Q_PROPERTY(QStringList          mapProviderList READ    mapProviderList CONSTANT)
dogmaphobic's avatar
dogmaphobic committed
47 48 49
    Q_PROPERTY(quint32              maxMemCache     READ    maxMemCache     WRITE   setMaxMemCache  NOTIFY  maxMemCacheChanged)
    Q_PROPERTY(quint32              maxDiskCache    READ    maxDiskCache    WRITE   setMaxDiskCache NOTIFY  maxDiskCacheChanged)
    Q_PROPERTY(QString              errorMessage    READ    errorMessage    NOTIFY  errorMessageChanged)
50
    Q_PROPERTY(bool                 fetchElevation  READ    fetchElevation  WRITE   setFetchElevation   NOTIFY  fetchElevationChanged)
dogmaphobic's avatar
dogmaphobic committed
51 52 53
    //-- Disk Space in MB
    Q_PROPERTY(quint32              freeDiskSpace   READ    freeDiskSpace   NOTIFY  freeDiskSpaceChanged)
    Q_PROPERTY(quint32              diskSpace       READ    diskSpace       CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
54
    //-- Tile set export
55
    Q_PROPERTY(int                  selectedCount   READ    selectedCount   NOTIFY selectedCountChanged)
Gus Grubba's avatar
Gus Grubba committed
56
    Q_PROPERTY(int                  actionProgress  READ    actionProgress  NOTIFY actionProgressChanged)
57
    Q_PROPERTY(ImportAction         importAction    READ    importAction    WRITE  setImportAction   NOTIFY importActionChanged)
Gus Grubba's avatar
Gus Grubba committed
58 59

    Q_PROPERTY(bool                 importReplace   READ    importReplace   WRITE   setImportReplace   NOTIFY importReplaceChanged)
dogmaphobic's avatar
dogmaphobic committed
60 61 62

    Q_INVOKABLE void                loadTileSets            ();
    Q_INVOKABLE void                updateForCurrentView    (double lon0, double lat0, double lon1, double lat1, int minZoom, int maxZoom, const QString& mapName);
dogmaphobic's avatar
dogmaphobic committed
63
    Q_INVOKABLE void                startDownload           (const QString& name, const QString& mapType);
dogmaphobic's avatar
dogmaphobic committed
64 65 66
    Q_INVOKABLE void                saveSetting             (const QString& key,  const QString& value);
    Q_INVOKABLE QString             loadSetting             (const QString& key,  const QString& defaultValue);
    Q_INVOKABLE void                deleteTileSet           (QGCCachedTileSet* tileSet);
Gus Grubba's avatar
Gus Grubba committed
67
    Q_INVOKABLE void                renameTileSet           (QGCCachedTileSet* tileSet, QString newName);
dogmaphobic's avatar
dogmaphobic committed
68 69
    Q_INVOKABLE QString             getUniqueName           ();
    Q_INVOKABLE bool                findName                (const QString& name);
70 71
    Q_INVOKABLE void                selectAll               ();
    Q_INVOKABLE void                selectNone              ();
Gus Grubba's avatar
Gus Grubba committed
72
    Q_INVOKABLE bool                exportSets              (QString path = QString());
Gus Grubba's avatar
Gus Grubba committed
73
    Q_INVOKABLE bool                importSets              (QString path = QString());
Gus Grubba's avatar
Gus Grubba committed
74
    Q_INVOKABLE void                resetAction             ();
dogmaphobic's avatar
dogmaphobic committed
75

76
    quint64                         tileCount               () { return _imageSet.tileCount + _elevationSet.tileCount; }
dogmaphobic's avatar
dogmaphobic committed
77
    QString                         tileCountStr            ();
78
    quint64                         tileSize                () { return _imageSet.tileSize + _elevationSet.tileSize; }
dogmaphobic's avatar
dogmaphobic committed
79 80
    QString                         tileSizeStr             ();
    QStringList                     mapList                 ();
81 82
    QStringList                     mapProviderList         ();
    Q_INVOKABLE QStringList         mapTypeList             (QString provider);
dogmaphobic's avatar
dogmaphobic committed
83 84 85 86
    QmlObjectListModel*             tileSets                () { return &_tileSets; }
    quint32                         maxMemCache             ();
    quint32                         maxDiskCache            ();
    QString                         errorMessage            () { return _errorMessage; }
87
    bool                            fetchElevation          () { return _fetchElevation; }
dogmaphobic's avatar
dogmaphobic committed
88 89
    quint64                         freeDiskSpace           () { return _freeDiskSpace; }
    quint64                         diskSpace               () { return _diskSpace; }
90
    int                             selectedCount           ();
Gus Grubba's avatar
Gus Grubba committed
91 92 93
    int                             actionProgress          () { return _actionProgress; }
    ImportAction                    importAction            () { return _importAction; }
    bool                            importReplace           () { return _importReplace; }
dogmaphobic's avatar
dogmaphobic committed
94 95 96

    void                            setMaxMemCache          (quint32 size);
    void                            setMaxDiskCache         (quint32 size);
Gus Grubba's avatar
Gus Grubba committed
97
    void                            setImportReplace        (bool replace) { _importReplace = replace; emit importReplaceChanged(); }
98
    void                            setImportAction         (ImportAction action)  {_importAction = action; emit importActionChanged(); }
dogmaphobic's avatar
dogmaphobic committed
99
    void                            setErrorMessage         (const QString& error) { _errorMessage = error; emit errorMessageChanged(); }
100
    void                            setFetchElevation       (bool fetchElevation) { _fetchElevation = fetchElevation; emit fetchElevationChanged(); }
dogmaphobic's avatar
dogmaphobic committed
101 102 103 104 105 106 107 108 109 110 111

    // Override from QGCTool
    void setToolbox(QGCToolbox *toolbox);

signals:
    void tileCountChanged       ();
    void tileSizeChanged        ();
    void tileSetsChanged        ();
    void maxMemCacheChanged     ();
    void maxDiskCacheChanged    ();
    void errorMessageChanged    ();
112
    void fetchElevationChanged  ();
dogmaphobic's avatar
dogmaphobic committed
113
    void freeDiskSpaceChanged   ();
114
    void selectedCountChanged   ();
Gus Grubba's avatar
Gus Grubba committed
115 116 117
    void actionProgressChanged  ();
    void importActionChanged    ();
    void importReplaceChanged   ();
dogmaphobic's avatar
dogmaphobic committed
118 119 120 121 122 123 124 125 126 127

public slots:
    void taskError              (QGCMapTask::TaskType type, QString error);

private slots:
    void _tileSetSaved          (QGCCachedTileSet* set);
    void _tileSetFetched        (QGCCachedTileSet* tileSets);
    void _tileSetDeleted        (quint64 setID);
    void _updateTotals          (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);
    void _resetCompleted        ();
Gus Grubba's avatar
Gus Grubba committed
128 129
    void _actionCompleted       ();
    void _actionProgressHandler (int percentage);
dogmaphobic's avatar
dogmaphobic committed
130 131 132 133 134

private:
    void _updateDiskFreeSpace   ();

private:
135 136
    QGCTileSet  _imageSet;
    QGCTileSet  _elevationSet;
dogmaphobic's avatar
dogmaphobic committed
137 138 139 140 141 142 143 144 145 146 147
    double      _topleftLat;
    double      _topleftLon;
    double      _bottomRightLat;
    double      _bottomRightLon;
    int         _minZoom;
    int         _maxZoom;
    quint64     _setID;
    quint32     _freeDiskSpace;
    quint32     _diskSpace;
    QmlObjectListModel _tileSets;
    QString     _errorMessage;
148
    bool        _fetchElevation;
Gus Grubba's avatar
Gus Grubba committed
149 150 151
    int         _actionProgress;
    ImportAction _importAction;
    bool        _importReplace;
dogmaphobic's avatar
dogmaphobic committed
152 153 154
};

#endif