Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
a681941a
Commit
a681941a
authored
Jul 12, 2016
by
dogmaphobic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes to Offline Map Cache
parent
6920c117
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
391 additions
and
502 deletions
+391
-502
OfflineMapButton.qml
src/QmlControls/OfflineMapButton.qml
+3
-1
QGCMapEngine.cpp
src/QtLocationPlugin/QGCMapEngine.cpp
+21
-7
QGCMapEngine.h
src/QtLocationPlugin/QGCMapEngine.h
+3
-2
QGCMapTileSet.cpp
src/QtLocationPlugin/QGCMapTileSet.cpp
+67
-39
QGCMapTileSet.h
src/QtLocationPlugin/QGCMapTileSet.h
+62
-55
QGCTileCacheWorker.cpp
src/QtLocationPlugin/QGCTileCacheWorker.cpp
+74
-68
QGCTileCacheWorker.h
src/QtLocationPlugin/QGCTileCacheWorker.h
+1
-1
OfflineMap.qml
src/QtLocationPlugin/QMLControl/OfflineMap.qml
+151
-318
QGCMapEngineManager.cc
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc
+8
-10
QGCMapEngineManager.h
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h
+1
-1
No files found.
src/QmlControls/OfflineMapButton.qml
View file @
a681941a
...
...
@@ -20,7 +20,8 @@ Rectangle
property
bool
checked
:
false
property
bool
complete
:
false
property
alias
text
:
nameLabel
.
text
property
alias
size
:
sizeLabel
.
text
property
int
tiles
:
0
property
string
size
:
""
signal
clicked
()
...
...
@@ -40,6 +41,7 @@ Rectangle
horizontalAlignment
:
Text
.
AlignRight
anchors.verticalCenter
:
parent
.
verticalCenter
color
:
__showHighlight
?
__qgcPal
.
buttonHighlightText
:
__qgcPal
.
buttonText
text
:
__mapButton
.
size
+
(
tiles
>
0
?
"
(
"
+
tiles
+
"
tiles)
"
:
""
)
}
Item
{
width
:
ScreenTools
.
defaultFontPixelWidth
*
2
...
...
src/QtLocationPlugin/QGCMapEngine.cpp
View file @
a681941a
...
...
@@ -32,7 +32,7 @@ Q_DECLARE_METATYPE(QList<QGCTile*>)
static
const
char
*
kDbFileName
=
"qgcMapCache.db"
;
static
QLocale
kLocale
;
#define CACHE_PATH_VERSION "
1
00"
#define CACHE_PATH_VERSION "
3
00"
struct
stQGeoTileCacheQGCMapTypes
{
const
char
*
name
;
...
...
@@ -144,15 +144,29 @@ QGCMapEngine::~QGCMapEngine()
//-----------------------------------------------------------------------------
void
QGCMapEngine
::
init
()
QGCMapEngine
::
_wipeOldCaches
()
{
//-- Delete old style cache (if present)
QString
oldCacheDir
;
#ifdef __mobile__
oldCacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
AppDataLocation
)
+
QLatin1String
(
"/QGCMapCache55"
);
#else
oldCacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericCacheLocation
)
+
QLatin1String
(
"/QGCMapCache55"
);
#endif
_wipeDirectory
(
oldCacheDir
);
#ifdef __mobile__
QString
oldCacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
AppDataLocation
)
+
QLatin1String
(
"/QGCMapCache55
"
);
oldCacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
AppDataLocation
)
+
QLatin1String
(
"/QGCMapCache100
"
);
#else
QString
oldCacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericCacheLocation
)
+
QLatin1String
(
"/QGCMapCache55
"
);
oldCacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericCacheLocation
)
+
QLatin1String
(
"/QGCMapCache100
"
);
#endif
_wipeDirectory
(
oldCacheDir
);
}
//-----------------------------------------------------------------------------
void
QGCMapEngine
::
init
()
{
//-- Delete old style caches (if present)
_wipeOldCaches
();
//-- Figure out cache path
#ifdef __mobile__
QString
cacheDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
AppDataLocation
)
+
QLatin1String
(
"/QGCMapCache"
CACHE_PATH_VERSION
);
...
...
@@ -398,7 +412,7 @@ QGCMapEngine::bigSizeToString(quint64 size)
//-----------------------------------------------------------------------------
QString
QGCMapEngine
::
numberToString
(
quint
32
number
)
QGCMapEngine
::
numberToString
(
quint
64
number
)
{
return
kLocale
.
toString
(
number
);
}
...
...
@@ -408,7 +422,7 @@ void
QGCMapEngine
::
_updateTotals
(
quint32
totaltiles
,
quint64
totalsize
,
quint32
defaulttiles
,
quint64
defaultsize
)
{
emit
updateTotals
(
totaltiles
,
totalsize
,
defaulttiles
,
defaultsize
);
quint64
maxSize
=
getMaxDiskCache
()
*
1024
*
1024
;
quint64
maxSize
=
(
quint64
)
getMaxDiskCache
()
*
1024L
*
1024L
;
if
(
!
_prunning
&&
defaultsize
>
maxSize
)
{
//-- Prune Disk Cache
_prunning
=
true
;
...
...
src/QtLocationPlugin/QGCMapEngine.h
View file @
a681941a
...
...
@@ -96,7 +96,7 @@ public:
static
QString
getTileHash
(
UrlFactory
::
MapType
type
,
int
x
,
int
y
,
int
z
);
static
UrlFactory
::
MapType
getTypeFromName
(
const
QString
&
name
);
static
QString
bigSizeToString
(
quint64
size
);
static
QString
numberToString
(
quint
32
number
);
static
QString
numberToString
(
quint
64
number
);
static
int
concurrentDownloads
(
UrlFactory
::
MapType
type
);
private
slots
:
...
...
@@ -107,7 +107,8 @@ signals:
void
updateTotals
(
quint32
totaltiles
,
quint64
totalsize
,
quint32
defaulttiles
,
quint64
defaultsize
);
private:
bool
_wipeDirectory
(
const
QString
&
dirPath
);
void
_wipeOldCaches
();
bool
_wipeDirectory
(
const
QString
&
dirPath
);
private:
QGCCacheWorker
_worker
;
...
...
src/QtLocationPlugin/QGCMapTileSet.cpp
View file @
a681941a
...
...
@@ -28,17 +28,18 @@ QGC_LOGGING_CATEGORY(QGCCachedTileSetLog, "QGCCachedTileSetLog")
#define TILE_BATCH_SIZE 256
//-----------------------------------------------------------------------------
QGCCachedTileSet
::
QGCCachedTileSet
(
const
QString
&
name
,
const
QString
&
description
)
QGCCachedTileSet
::
QGCCachedTileSet
(
const
QString
&
name
)
:
_name
(
name
)
,
_description
(
description
)
,
_topleftLat
(
0.0
)
,
_topleftLon
(
0.0
)
,
_bottomRightLat
(
0.0
)
,
_bottomRightLon
(
0.0
)
,
_numTiles
(
0
)
,
_tilesSize
(
0
)
,
_savedTiles
(
0
)
,
_savedSize
(
0
)
,
_totalTileCount
(
0
)
,
_totalTileSize
(
0
)
,
_uniqueTileCount
(
0
)
,
_uniqueTileSize
(
0
)
,
_savedTileCount
(
0
)
,
_savedTileSize
(
0
)
,
_minZoom
(
3
)
,
_maxZoom
(
3
)
,
_defaultSet
(
false
)
...
...
@@ -72,30 +73,44 @@ QGCCachedTileSet::errorCountStr()
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet
::
numTiles
Str
()
QGCCachedTileSet
::
totalTileCount
Str
()
{
return
QGCMapEngine
::
numberToString
(
_
numTiles
);
return
QGCMapEngine
::
numberToString
(
_
totalTileCount
);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet
::
tilesSizeStr
()
QGCCachedTileSet
::
t
otalT
ilesSizeStr
()
{
return
QGCMapEngine
::
bigSizeToString
(
_t
iles
Size
);
return
QGCMapEngine
::
bigSizeToString
(
_t
otalTile
Size
);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet
::
savedTiles
Str
()
QGCCachedTileSet
::
uniqueTileSize
Str
()
{
return
QGCMapEngine
::
numberToString
(
_savedTiles
);
return
QGCMapEngine
::
bigSizeToString
(
_uniqueTileSize
);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet
::
savedSize
Str
()
QGCCachedTileSet
::
uniqueTileCount
Str
()
{
return
QGCMapEngine
::
bigSizeToString
(
_savedSize
);
return
QGCMapEngine
::
numberToString
(
_uniqueTileCount
);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet
::
savedTileCountStr
()
{
return
QGCMapEngine
::
numberToString
(
_savedTileCount
);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet
::
savedTileSizeStr
()
{
return
QGCMapEngine
::
bigSizeToString
(
_savedTileSize
);
}
//-----------------------------------------------------------------------------
...
...
@@ -103,12 +118,12 @@ QString
QGCCachedTileSet
::
downloadStatus
()
{
if
(
_defaultSet
)
{
return
tilesSizeStr
();
return
t
otalT
ilesSizeStr
();
}
if
(
_
numTiles
==
_savedTiles
)
{
return
savedSizeStr
();
if
(
_
totalTileCount
<=
_savedTileCount
)
{
return
saved
Tile
SizeStr
();
}
else
{
return
saved
SizeStr
()
+
" / "
+
t
ilesSizeStr
();
return
saved
TileSizeStr
()
+
" / "
+
totalT
ilesSizeStr
();
}
}
...
...
@@ -128,8 +143,8 @@ QGCCachedTileSet::createDownloadTask()
if
(
_manager
)
connect
(
task
,
&
QGCMapTask
::
error
,
_manager
,
&
QGCMapEngineManager
::
taskError
);
getQGCMapEngine
()
->
addTask
(
task
);
emit
numTiles
Changed
();
emit
tilesSizeChanged
();
emit
totalTileCount
Changed
();
emit
t
otalT
ilesSizeChanged
();
_batchRequested
=
true
;
}
...
...
@@ -164,6 +179,7 @@ QGCCachedTileSet::_tileListFetched(QList<QGCTile *> tiles)
_noMoreTiles
=
true
;
}
if
(
!
tiles
.
size
())
{
_doneWithDownload
();
return
;
}
//-- If this is the first time, create Network Manager
...
...
@@ -176,23 +192,33 @@ QGCCachedTileSet::_tileListFetched(QList<QGCTile *> tiles)
_prepareDownload
();
}
//-----------------------------------------------------------------------------
void
QGCCachedTileSet
::
_doneWithDownload
()
{
if
(
!
_errorCount
)
{
_totalTileCount
=
_savedTileCount
;
_totalTileSize
=
_savedTileSize
;
//-- Too expensive to compute the real size now. Estimate it for the time being.
quint32
avg
=
_savedTileSize
/
_savedTileCount
;
_uniqueTileSize
=
_uniqueTileCount
*
avg
;
}
emit
totalTileCountChanged
();
emit
totalTilesSizeChanged
();
emit
savedTileSizeChanged
();
emit
savedTileCountChanged
();
emit
uniqueTileSizeChanged
();
_downloading
=
false
;
emit
downloadingChanged
();
emit
completeChanged
();
}
//-----------------------------------------------------------------------------
void
QGCCachedTileSet
::
_prepareDownload
()
{
if
(
!
_tilesToDownload
.
count
())
{
//-- Are we done?
if
(
_noMoreTiles
)
{
if
(
!
_errorCount
)
{
_numTiles
=
_savedTiles
;
_tilesSize
=
_savedSize
;
}
emit
numTilesChanged
();
emit
tilesSizeChanged
();
emit
savedSizeChanged
();
emit
savedTilesChanged
();
_downloading
=
false
;
emit
downloadingChanged
();
emit
completeChanged
();
_doneWithDownload
();
}
else
{
if
(
!
_batchRequested
)
createDownloadTask
();
...
...
@@ -253,15 +279,17 @@ QGCCachedTileSet::_networkReplyFinished()
QGCUpdateTileDownloadStateTask
*
task
=
new
QGCUpdateTileDownloadStateTask
(
_id
,
QGCTile
::
StateComplete
,
hash
);
getQGCMapEngine
()
->
addTask
(
task
);
//-- Updated cached (downloaded) data
_savedSize
+=
image
.
size
();
_savedTile
s
++
;
emit
savedSizeChanged
();
emit
savedTile
s
Changed
();
_saved
Tile
Size
+=
image
.
size
();
_savedTile
Count
++
;
emit
saved
Tile
SizeChanged
();
emit
savedTile
Count
Changed
();
//-- Update estimate
if
(
_savedTiles
%
10
==
0
)
{
quint32
avg
=
_savedSize
/
_savedTiles
;
_tilesSize
=
avg
*
_numTiles
;
emit
tilesSizeChanged
();
if
(
_savedTileCount
%
10
==
0
)
{
quint32
avg
=
_savedTileSize
/
_savedTileCount
;
_totalTileSize
=
avg
*
_totalTileCount
;
_uniqueTileSize
=
avg
*
_uniqueTileCount
;
emit
totalTilesSizeChanged
();
emit
uniqueTileSizeChanged
();
}
}
//-- Setup a new download
...
...
src/QtLocationPlugin/QGCMapTileSet.h
View file @
a681941a
This diff is collapsed.
Click to expand it.
src/QtLocationPlugin/QGCTileCacheWorker.cpp
View file @
a681941a
This diff is collapsed.
Click to expand it.
src/QtLocationPlugin/QGCTileCacheWorker.h
View file @
a681941a
...
...
@@ -60,7 +60,7 @@ private:
void
_resetCacheDatabase
(
QGCMapTask
*
mtask
);
void
_pruneCache
(
QGCMapTask
*
mtask
);
bool
_findTile
(
const
QString
hash
);
quint64
_findTile
(
const
QString
hash
);
bool
_findTileSetID
(
const
QString
name
,
quint64
&
setID
);
void
_updateSetTotals
(
QGCCachedTileSet
*
set
);
bool
_init
();
...
...
src/QtLocationPlugin/QMLControl/OfflineMap.qml
View file @
a681941a
This diff is collapsed.
Click to expand it.
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc
View file @
a681941a
...
...
@@ -127,10 +127,10 @@ QGCMapEngineManager::_tileSetFetched(QGCCachedTileSet* tileSet)
//-----------------------------------------------------------------------------
void
QGCMapEngineManager
::
startDownload
(
const
QString
&
name
,
const
QString
&
description
,
const
QString
&
mapType
,
const
QImage
&
imag
e
)
QGCMapEngineManager
::
startDownload
(
const
QString
&
name
,
const
QString
&
mapTyp
e
)
{
if
(
_totalSet
.
tileSize
)
{
QGCCachedTileSet
*
set
=
new
QGCCachedTileSet
(
name
,
description
);
QGCCachedTileSet
*
set
=
new
QGCCachedTileSet
(
name
);
set
->
setMapTypeStr
(
mapType
);
set
->
setTopleftLat
(
_topleftLat
);
set
->
setTopleftLon
(
_topleftLon
);
...
...
@@ -138,11 +138,9 @@ QGCMapEngineManager::startDownload(const QString& name, const QString& descripti
set
->
setBottomRightLon
(
_bottomRightLon
);
set
->
setMinZoom
(
_minZoom
);
set
->
setMaxZoom
(
_maxZoom
);
set
->
setT
iles
Size
(
_totalSet
.
tileSize
);
set
->
set
NumTiles
(
_totalSet
.
tileCount
);
set
->
setT
otalTile
Size
(
_totalSet
.
tileSize
);
set
->
set
TotalTileCount
(
_totalSet
.
tileCount
);
set
->
setType
(
QGCMapEngine
::
getTypeFromName
(
mapType
));
if
(
!
image
.
isNull
())
set
->
setThumbNail
(
image
);
QGCCreateTileSetTask
*
task
=
new
QGCCreateTileSetTask
(
set
);
//-- Create Tile Set (it will also create a list of tiles to download)
connect
(
task
,
&
QGCCreateTileSetTask
::
tileSetSaved
,
this
,
&
QGCMapEngineManager
::
_tileSetSaved
);
...
...
@@ -329,10 +327,10 @@ QGCMapEngineManager::_updateTotals(quint32 totaltiles, quint64 totalsize, quint3
QGCCachedTileSet
*
set
=
qobject_cast
<
QGCCachedTileSet
*>
(
_tileSets
.
get
(
i
));
Q_ASSERT
(
set
);
if
(
set
->
defaultSet
())
{
set
->
setSavedSize
(
totalsize
);
set
->
setSavedTile
s
(
totaltiles
);
set
->
set
NumTiles
(
defaulttiles
);
set
->
setT
iles
Size
(
defaultsize
);
set
->
setSaved
Tile
Size
(
totalsize
);
set
->
setSavedTile
Count
(
totaltiles
);
set
->
set
TotalTileCount
(
defaulttiles
);
set
->
setT
otalTile
Size
(
defaultsize
);
return
;
}
}
...
...
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h
View file @
a681941a
...
...
@@ -49,7 +49,7 @@ public:
Q_INVOKABLE
void
loadTileSets
();
Q_INVOKABLE
void
updateForCurrentView
(
double
lon0
,
double
lat0
,
double
lon1
,
double
lat1
,
int
minZoom
,
int
maxZoom
,
const
QString
&
mapName
);
Q_INVOKABLE
void
startDownload
(
const
QString
&
name
,
const
QString
&
description
,
const
QString
&
mapType
,
const
QImage
&
image
=
QImage
()
);
Q_INVOKABLE
void
startDownload
(
const
QString
&
name
,
const
QString
&
mapType
);
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment