Commit 26545b14 authored by Gus Grubba's avatar Gus Grubba

Export to disk complete

parent 1a845a0e
...@@ -389,12 +389,19 @@ public: ...@@ -389,12 +389,19 @@ public:
emit exportCompleted(); emit exportCompleted();
} }
void setProgress(int percentage)
{
emit exportProgress(percentage);
}
private: private:
QVector<QGCCachedTileSet*> _sets; QVector<QGCCachedTileSet*> _sets;
QString _path; QString _path;
signals: signals:
void exportCompleted(); void exportCompleted ();
void exportProgress (int percentage);
}; };
......
...@@ -641,27 +641,40 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask) ...@@ -641,27 +641,40 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask)
if(!_testTask(mtask)) { if(!_testTask(mtask)) {
return; return;
} }
bool res = false;
QGCExportTileTask* task = static_cast<QGCExportTileTask*>(mtask); QGCExportTileTask* task = static_cast<QGCExportTileTask*>(mtask);
//-- Delete target if it exists
QFile file(task->path());
file.remove();
//-- Create exported database //-- Create exported database
QSqlDatabase *dbExport = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", kExportSession)); QSqlDatabase *dbExport = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", kExportSession));
dbExport->setDatabaseName(task->path()); dbExport->setDatabaseName(task->path());
dbExport->setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE"); dbExport->setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE");
if (dbExport->open()) { if (dbExport->open()) {
if(_createDB(dbExport, false)) { if(_createDB(dbExport, false)) {
//-- Prepare progress report
quint64 tileCount = 0;
quint64 currentCount = 0;
for(int i = 0; i < task->sets().count(); i++) {
QGCCachedTileSet* set = task->sets()[i];
//-- Default set has no unique tiles
if(set->defaultSet()) {
tileCount += set->totalTileCount();
} else {
tileCount += set->uniqueTileCount();
}
}
if(!tileCount) {
tileCount = 1;
}
//-- Iterate sets to save //-- Iterate sets to save
for(int i = 0; i < task->sets().count(); i++) { for(int i = 0; i < task->sets().count(); i++) {
QGCCachedTileSet* set = task->sets()[i]; QGCCachedTileSet* set = task->sets()[i];
//-- Create Tile Exported Set //-- Create Tile Exported Set
QSqlQuery exportQuery(*dbExport); QSqlQuery exportQuery(*dbExport);
exportQuery.prepare("INSERT INTO TileSets(" exportQuery.prepare("INSERT INTO TileSets("
"name, typeStr, topleftLat, topleftLon, bottomRightLat, bottomRightLon, minZoom, maxZoom, type, numTiles, date" "name, typeStr, topleftLat, topleftLon, bottomRightLat, bottomRightLon, minZoom, maxZoom, type, numTiles, defaultSet, date"
") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
QString name = set->name(); exportQuery.addBindValue(set->name());
if(set->defaultSet()) {
name = "Exported Default Set";
}
exportQuery.addBindValue(name);
exportQuery.addBindValue(set->mapTypeStr()); exportQuery.addBindValue(set->mapTypeStr());
exportQuery.addBindValue(set->topleftLat()); exportQuery.addBindValue(set->topleftLat());
exportQuery.addBindValue(set->topleftLon()); exportQuery.addBindValue(set->topleftLon());
...@@ -671,6 +684,7 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask) ...@@ -671,6 +684,7 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask)
exportQuery.addBindValue(set->maxZoom()); exportQuery.addBindValue(set->maxZoom());
exportQuery.addBindValue(set->type()); exportQuery.addBindValue(set->type());
exportQuery.addBindValue(set->totalTileCount()); exportQuery.addBindValue(set->totalTileCount());
exportQuery.addBindValue(set->defaultSet());
exportQuery.addBindValue(QDateTime::currentDateTime().toTime_t()); exportQuery.addBindValue(QDateTime::currentDateTime().toTime_t());
if(!exportQuery.exec()) { if(!exportQuery.exec()) {
task->setError("Error adding tile set to exported database"); task->setError("Error adding tile set to exported database");
...@@ -682,6 +696,7 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask) ...@@ -682,6 +696,7 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask)
QString s = QString("SELECT * FROM SetTiles WHERE setID = %1").arg(set->id()); QString s = QString("SELECT * FROM SetTiles WHERE setID = %1").arg(set->id());
QSqlQuery query(*_db); QSqlQuery query(*_db);
if(query.exec(s)) { if(query.exec(s)) {
dbExport->transaction();
while(query.next()) { while(query.next()) {
quint64 tileID = query.value("tileID").toULongLong(); quint64 tileID = query.value("tileID").toULongLong();
//-- Get tile //-- Get tile
...@@ -706,11 +721,14 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask) ...@@ -706,11 +721,14 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask)
QString s = QString("INSERT INTO SetTiles(tileID, setID) VALUES(%1, %2)").arg(exportTileID).arg(exportSetID); QString s = QString("INSERT INTO SetTiles(tileID, setID) VALUES(%1, %2)").arg(exportTileID).arg(exportSetID);
exportQuery.prepare(s); exportQuery.prepare(s);
exportQuery.exec(); exportQuery.exec();
currentCount++;
task->setProgress((int)((double)currentCount / (double)tileCount * 100.0));
} }
} }
} }
} }
} }
dbExport->commit();
} }
} }
} else { } else {
...@@ -721,9 +739,7 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask) ...@@ -721,9 +739,7 @@ QGCCacheWorker::_exportSets(QGCMapTask* mtask)
task->setError("Error opening export database"); task->setError("Error opening export database");
} }
delete dbExport; delete dbExport;
if(res) { task->setExportCompleted();
task->setExportCompleted();
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
...@@ -39,6 +39,7 @@ QGCView { ...@@ -39,6 +39,7 @@ QGCView {
property bool _defaultSet: offlineMapView && offlineMapView._currentSelection && offlineMapView._currentSelection.defaultSet property bool _defaultSet: offlineMapView && offlineMapView._currentSelection && offlineMapView._currentSelection.defaultSet
property real _margins: ScreenTools.defaultFontPixelWidth * 0.5 property real _margins: ScreenTools.defaultFontPixelWidth * 0.5
property real _buttonSize: ScreenTools.defaultFontPixelWidth * 12 property real _buttonSize: ScreenTools.defaultFontPixelWidth * 12
property real _bigButtonSize: ScreenTools.defaultFontPixelWidth * 16
property bool _saveRealEstate: ScreenTools.isTinyScreen || ScreenTools.isShortScreen property bool _saveRealEstate: ScreenTools.isTinyScreen || ScreenTools.isShortScreen
property real _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize property real _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
...@@ -850,8 +851,8 @@ QGCView { ...@@ -850,8 +851,8 @@ QGCView {
visible: _tileSetList.visible visible: _tileSetList.visible
spacing: _margins spacing: _margins
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
QGCButton { QGCButton {
text: qsTr("Import") text: qsTr("Import")
width: _buttonSize width: _buttonSize
...@@ -907,21 +908,31 @@ QGCView { ...@@ -907,21 +908,31 @@ QGCView {
visible: _exporTiles.visible visible: _exporTiles.visible
spacing: _margins spacing: _margins
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
QGCButton { QGCButton {
text: qsTr("All") text: qsTr("Select All")
width: _buttonSize width: _bigButtonSize
onClicked: QGroundControl.mapEngineManager.selectAll() onClicked: QGroundControl.mapEngineManager.selectAll()
} }
QGCButton { QGCButton {
text: qsTr("None") text: qsTr("Select None")
width: _buttonSize width: _bigButtonSize
onClicked: QGroundControl.mapEngineManager.selectNone() onClicked: QGroundControl.mapEngineManager.selectNone()
} }
QGCButton { QGCButton {
text: qsTr("Export") text: qsTr("Export to Disk")
width: _buttonSize width: _bigButtonSize
enabled: QGroundControl.mapEngineManager.selectedCount > 0
onClicked: {
showList();
QGroundControl.mapEngineManager.exportSets()
rootLoader.sourceComponent = exportToDiskProgress
}
}
QGCButton {
text: qsTr("Export to Device")
width: _bigButtonSize
enabled: QGroundControl.mapEngineManager.selectedCount > 0 enabled: QGroundControl.mapEngineManager.selectedCount > 0
onClicked: { onClicked: {
QGroundControl.mapEngineManager.exportSets() QGroundControl.mapEngineManager.exportSets()
...@@ -930,9 +941,64 @@ QGCView { ...@@ -930,9 +941,64 @@ QGCView {
} }
QGCButton { QGCButton {
text: qsTr("Cancel") text: qsTr("Cancel")
width: _buttonSize width: _bigButtonSize
onClicked: showList() onClicked: showList()
} }
} }
} // QGCViewPanel } // QGCViewPanel
Component {
id: exportToDiskProgress
Rectangle {
width: mainWindow.width
height: mainWindow.height
color: "black"
anchors.centerIn: parent
Rectangle {
width: parent.width * 0.5
height: cameraSettingsCol.height * 1.25
radius: ScreenTools.defaultFontPixelWidth
color: qgcPal.windowShadeDark
border.color: qgcPal.text
anchors.centerIn: parent
Column {
id: cameraSettingsCol
spacing: ScreenTools.defaultFontPixelHeight
width: parent.width
anchors.centerIn: parent
QGCLabel {
text: QGroundControl.mapEngineManager.exporting ? qsTr("Tile Set Export Progress") : qsTr("Tile Set Export Completed")
font.family: ScreenTools.demiboldFontFamily
font.pointSize: ScreenTools.mediumFontPointSize
anchors.horizontalCenter: parent.horizontalCenter
}
ProgressBar {
id: progressBar
width: parent.width * 0.45
maximumValue: 100
value: QGroundControl.mapEngineManager.exportProgress
anchors.horizontalCenter: parent.horizontalCenter
}
BusyIndicator {
visible: QGroundControl.mapEngineManager.exporting
running: QGroundControl.mapEngineManager.exporting
width: exportCloseButton.height
height: exportCloseButton.height
anchors.horizontalCenter: parent.horizontalCenter
}
QGCButton {
id: exportCloseButton
text: qsTr("Close")
width: _buttonSize
visible: !QGroundControl.mapEngineManager.exporting
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
rootLoader.sourceComponent = null
}
}
}
}
}
}
} // QGCView } // QGCView
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
/// @file /// @file
/// @author Gus Grubba <mavlink@grubba.com> /// @author Gus Grubba <mavlink@grubba.com>
#if !defined(__mobile__)
#include "QGCFileDialog.h"
#include "MainWindow.h"
#endif
#include "QGCMapEngineManager.h" #include "QGCMapEngineManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCMapTileSet.h" #include "QGCMapTileSet.h"
...@@ -36,6 +41,8 @@ QGCMapEngineManager::QGCMapEngineManager(QGCApplication* app) ...@@ -36,6 +41,8 @@ QGCMapEngineManager::QGCMapEngineManager(QGCApplication* app)
, _setID(UINT64_MAX) , _setID(UINT64_MAX)
, _freeDiskSpace(0) , _freeDiskSpace(0)
, _diskSpace(0) , _diskSpace(0)
, _exportProgress(0)
, _exporting(false)
{ {
} }
...@@ -389,33 +396,59 @@ QGCMapEngineManager::selectedCount() { ...@@ -389,33 +396,59 @@ QGCMapEngineManager::selectedCount() {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void bool
QGCMapEngineManager::exportSets(QString path) { QGCMapEngineManager::exportSets(QString path) {
QString dir = path; QString dir = path;
if(dir.isEmpty()) { if(dir.isEmpty()) {
#if defined(__mobile__)
dir = QDir(QDir::homePath()).filePath(QString("export_%1.db").arg(QDateTime::currentDateTime().toTime_t())); dir = QDir(QDir::homePath()).filePath(QString("export_%1.db").arg(QDateTime::currentDateTime().toTime_t()));
#else
dir = QGCFileDialog::getSaveFileName(
MainWindow::instance(),
"Export Tile Set",
QDir::homePath(),
"Tile Sets (*.qgctiledb)",
"qgctiledb",
true);
#endif
} }
QVector<QGCCachedTileSet*> sets; if(!dir.isEmpty()) {
for(int i = 0; i < _tileSets.count(); i++ ) { QVector<QGCCachedTileSet*> sets;
QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i)); for(int i = 0; i < _tileSets.count(); i++ ) {
Q_ASSERT(set); QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
if(set->selected()) { Q_ASSERT(set);
sets.append(set); if(set->selected()) {
sets.append(set);
}
}
if(sets.count()) {
_exporting = true;
emit exportingChanged();
QGCExportTileTask* task = new QGCExportTileTask(sets, dir);
connect(task, &QGCExportTileTask::exportCompleted, this, &QGCMapEngineManager::_exportCompleted);
connect(task, &QGCExportTileTask::exportProgress, this, &QGCMapEngineManager::_exportProgressHandler);
connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
getQGCMapEngine()->addTask(task);
return true;
} }
} }
if(sets.count()) { return false;
QGCExportTileTask* task = new QGCExportTileTask(sets, dir);
connect(task, &QGCExportTileTask::exportCompleted, this, &QGCMapEngineManager::_exportCompleted);
connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
getQGCMapEngine()->addTask(task);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCMapEngineManager::_exportCompleted() QGCMapEngineManager::_exportProgressHandler(int percentage)
{ {
_exportProgress = percentage;
emit exportProgressChanged();
}
//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_exportCompleted()
{
_exporting = false;
emit exportingChanged();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
...@@ -46,7 +46,10 @@ public: ...@@ -46,7 +46,10 @@ public:
//-- Disk Space in MB //-- Disk Space in MB
Q_PROPERTY(quint32 freeDiskSpace READ freeDiskSpace NOTIFY freeDiskSpaceChanged) Q_PROPERTY(quint32 freeDiskSpace READ freeDiskSpace NOTIFY freeDiskSpaceChanged)
Q_PROPERTY(quint32 diskSpace READ diskSpace CONSTANT) Q_PROPERTY(quint32 diskSpace READ diskSpace CONSTANT)
//-- Tile set export
Q_PROPERTY(int selectedCount READ selectedCount NOTIFY selectedCountChanged) Q_PROPERTY(int selectedCount READ selectedCount NOTIFY selectedCountChanged)
Q_PROPERTY(int exportProgress READ exportProgress NOTIFY exportProgressChanged)
Q_PROPERTY(bool exporting READ exporting NOTIFY exportingChanged)
Q_INVOKABLE void loadTileSets (); 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 updateForCurrentView (double lon0, double lat0, double lon1, double lat1, int minZoom, int maxZoom, const QString& mapName);
...@@ -58,7 +61,7 @@ public: ...@@ -58,7 +61,7 @@ public:
Q_INVOKABLE bool findName (const QString& name); Q_INVOKABLE bool findName (const QString& name);
Q_INVOKABLE void selectAll (); Q_INVOKABLE void selectAll ();
Q_INVOKABLE void selectNone (); Q_INVOKABLE void selectNone ();
Q_INVOKABLE void exportSets (QString path = QString()); Q_INVOKABLE bool exportSets (QString path = QString());
int tileX0 () { return _totalSet.tileX0; } int tileX0 () { return _totalSet.tileX0; }
int tileX1 () { return _totalSet.tileX1; } int tileX1 () { return _totalSet.tileX1; }
...@@ -77,6 +80,8 @@ public: ...@@ -77,6 +80,8 @@ public:
quint64 freeDiskSpace () { return _freeDiskSpace; } quint64 freeDiskSpace () { return _freeDiskSpace; }
quint64 diskSpace () { return _diskSpace; } quint64 diskSpace () { return _diskSpace; }
int selectedCount (); int selectedCount ();
int exportProgress () { return _exportProgress; }
bool exporting () { return _exporting; }
void setMapboxToken (QString token); void setMapboxToken (QString token);
void setMaxMemCache (quint32 size); void setMaxMemCache (quint32 size);
...@@ -101,6 +106,8 @@ signals: ...@@ -101,6 +106,8 @@ signals:
void errorMessageChanged (); void errorMessageChanged ();
void freeDiskSpaceChanged (); void freeDiskSpaceChanged ();
void selectedCountChanged (); void selectedCountChanged ();
void exportProgressChanged ();
void exportingChanged ();
public slots: public slots:
void taskError (QGCMapTask::TaskType type, QString error); void taskError (QGCMapTask::TaskType type, QString error);
...@@ -112,6 +119,7 @@ private slots: ...@@ -112,6 +119,7 @@ private slots:
void _updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize); void _updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);
void _resetCompleted (); void _resetCompleted ();
void _exportCompleted (); void _exportCompleted ();
void _exportProgressHandler (int percentage);
private: private:
void _updateDiskFreeSpace (); void _updateDiskFreeSpace ();
...@@ -129,6 +137,8 @@ private: ...@@ -129,6 +137,8 @@ private:
quint32 _diskSpace; quint32 _diskSpace;
QmlObjectListModel _tileSets; QmlObjectListModel _tileSets;
QString _errorMessage; QString _errorMessage;
int _exportProgress;
bool _exporting;
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment