地图下载功能调整最多四个线程同时下载

This commit is contained in:
2022-11-05 09:53:35 +08:00
parent 6a50f70fc9
commit e9a0609e91
11 changed files with 387 additions and 200 deletions
+53 -7
View File
@@ -542,9 +542,26 @@ void GlobalSetting::cleanDownloadInfo()
// ui->labMapGrade->setText(QString(u8"地图级别:") );
}
void GlobalSetting::showDownloadImageNum(int total, int actual)
void GlobalSetting::showDownloadImageNum(int total, int actual, quint8 id)
{
ui->lab_image_num->setText(QString(u8"下载图片数:%1/%2").arg(actual).arg(total) );
QProgressBar *bar;
switch(id)
{
case 0: bar = ui->progress_0; break;
case 1: bar = ui->progress_1; break;
case 2: bar = ui->progress_2; break;
case 3: bar = ui->progress_3; break;
}
QString format = QString("%v/%1").arg(total);
bar->setFormat(format);
bar->setMaximum(total);
bar->setValue(actual);
// QString format = QString("%v/%1").arg(total);
// ui->progressBar->setFormat(format);
// ui->progressBar->setMaximum(total);
// ui->progressBar->setValue(actual);
//// ui->lab_image_num->setText(QString(u8"下载图片数:%1/%2").arg(actual).arg(total) );
}
void GlobalSetting::setLngLatRectRange(double lng1, double lat1, double lng2, double lat2)
@@ -557,14 +574,43 @@ void GlobalSetting::setLngLatRectRange(double lng1, double lat1, double lng2, do
void GlobalSetting::setProgressBarValue(int value)
{
ui->progressBar->setValue(value);
// ui->progressBar->setValue(value);
}
void GlobalSetting::setMapSaveGrade(int zoom)
void GlobalSetting::setMapSaveGrade(int zoom, quint8 id)
{
ui->labMapGrade->setText(QString("地图级别:%1").arg(zoom) );
ui->progressBar->setValue(0);
ui->lab_image_num->setText(QString(u8"下载图片数:?") );
QLabel *lab;
QProgressBar *bar;
switch(id)
{
case 0:
{
lab = ui->labMapGrade_0;
bar = ui->progress_0;
break;
}
case 1:
{
lab = ui->labMapGrade_1;
bar = ui->progress_1;
break;
}
case 2:
{
lab = ui->labMapGrade_2;
bar = ui->progress_2;
break;
}
case 3:
{
lab = ui->labMapGrade_3;
bar = ui->progress_3;
break;
}
}
lab->setText(QString("地图级别:%1").arg(zoom) );
bar->setValue(0);
}
void GlobalSetting::on_pushButton_readVirtualMargin_clicked()
+4 -2
View File
@@ -63,8 +63,9 @@ public slots:
* @brief 显示当前已下载的图片数
* @param total 当前级别的图片总数
* @param actual 当前下载的图片数
* @param id 进度条的id
*/
void showDownloadImageNum(int total, int actual);
void showDownloadImageNum(int total, int actual, quint8 id);
/**
* @brief 设置需要缓存的经纬度范围
* @param lng1 左上角经度
@@ -81,8 +82,9 @@ public slots:
/**
* @brief 更改当前正在缓存的地图级别
* @param zoom 当前正在缓存的地图级别
* @param id 进度条的id
*/
void setMapSaveGrade(int zoom);
void setMapSaveGrade(int zoom, quint8 id);
private slots:
+170 -120
View File
@@ -553,8 +553,8 @@
<string>地图设置</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="7" column="0">
<widget class="QLabel" name="labMapGrade">
<item row="8" column="0">
<widget class="QLabel" name="labMapGrade_2">
<property name="text">
<string>地图级别:</string>
</property>
@@ -570,18 +570,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>地图源:</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QProgressBar" name="progressBar">
<item row="8" column="1" colspan="2">
<widget class="QProgressBar" name="progress_2">
<property name="value">
<number>0</number>
</property>
<property name="format">
<string>%v</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
@@ -697,6 +693,159 @@
</layout>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labMapGrade_0">
<property name="text">
<string>地图级别:</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QProgressBar" name="progress_3">
<property name="value">
<number>0</number>
</property>
<property name="format">
<string>%v</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<widget class="QProgressBar" name="progress_0">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="format">
<string>%v</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>开始缓存</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>区域选择</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLng">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>起点经度:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>起点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>终点经度:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="btnRectRange">
<property name="text">
<string>鼠标框选范围</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLat">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>终点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLng">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLat">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labMapGrade_3">
<property name="text">
<string>地图级别:</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labMapGrade_1">
<property name="text">
<string>地图级别:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="groupMapGrade">
<property name="title">
@@ -853,119 +1002,20 @@
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>区域选择</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLng">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>起点经度:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>起点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>终点经度:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="btnRectRange">
<property name="text">
<string>鼠标框选范围</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLat">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>终点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLng">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLat">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QPushButton" name="pushButton">
<item row="1" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>开始缓存</string>
<string>地图源:</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QLabel" name="lab_image_num">
<property name="text">
<string>下载图片数:</string>
<item row="7" column="1" colspan="2">
<widget class="QProgressBar" name="progress_1">
<property name="value">
<number>0</number>
</property>
<property name="format">
<string>%v</string>
</property>
</widget>
</item>
+10 -7
View File
@@ -163,6 +163,13 @@ void ToolsUI::install(ToolsWidget *widget, QString name)
widget->hide();
ToolsList.insert(ToolsList.size(),widget);
connect(widget, &ToolsWidget::toolsWidgetClose,
this, [this]()
{
qDebug() << u8"调整界面";
onTabIndexChanged(this->CurrentIndex);
});
//接收到信号,每个界面自己解析,获取自己想要的信息
// connect(this,&ToolsUI::recieveData,
// widget,&ToolsWidget::recieveData);
@@ -356,14 +363,10 @@ void ToolsUI::onTabIndexChanged(const int &index)//界面选择管理
{
w->show();
}
else
{
w->showNormal();
w->activateWindow();
}
}
else {
if(w->parent())
else
{
if(!w->isPop() )
{
w->hide();
}
+28 -28
View File
@@ -1,8 +1,8 @@
#include "ToolsWidget.h"
#include "ToolsWidget.h"
ToolsWidget::ToolsWidget(QWidget *parent) : QWidget(parent)
ToolsWidget::ToolsWidget(QWidget *parent) : QWidget(parent), ini_size(size() )
{
m_parent = parent;
setWindowFlags(Qt::Widget);
}
ToolsWidget::~ToolsWidget()
@@ -39,36 +39,22 @@ void ToolsWidget::setValue(QCheckBox *w,QString s)
void ToolsWidget::setFloat(void)
{
if(this->parent())
Qt::WindowFlags flags = this->windowFlags();
if(flags != (Qt::Widget | Qt::Window ) )
{
QWidget *m_parent;
m_parent = qobject_cast<QWidget *>(this->parent());
QPoint pos = mapToGlobal(m_parent->pos());
this->setParent(nullptr);
this->resize(this->minimumSize());
this->move(pos.x() + (m_parent->width() - this->width()) * 0.5,
pos.y());
if(Top())
{
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
}
this->show();
}
else
{
if(m_parent)
{
this->setParent(m_parent);
this->setGeometry(m_parent->geometry());
is_pop = true;
this->setWindowFlags(Qt::Widget | Qt::Window );
resize(ini_size);
move(0, 0);
show();
}
this->move(0,0);
this->show();
this->resize(m_parent->size());
update();
}
}
@@ -79,7 +65,21 @@ void ToolsWidget::resizeEvent(QResizeEvent *event)
void ToolsWidget::closeEvent(QCloseEvent *event)
{
setFloat();
QWidget *m_parent;
setWindowFlags(Qt::Widget);
move(0, 0);
m_parent = qobject_cast<QWidget *>(this->parent());
if(m_parent)
{
this->resize(m_parent->size() );
}
show();
is_pop = false;
emit toolsWidgetClose();
event->ignore();
}
+14 -7
View File
@@ -1,4 +1,4 @@
#ifndef TOOLSWIDGET_H
#ifndef TOOLSWIDGET_H
#define TOOLSWIDGET_H
#include <QObject>
@@ -38,7 +38,10 @@ public:
signals:
/**
* @brief 用户点击关闭按钮时发送信号
*/
void toolsWidgetClose();
public slots:
@@ -77,6 +80,11 @@ public slots:
return icon;
}
bool isPop() const
{
return is_pop;
}
protected:
@@ -90,15 +98,14 @@ protected:
private slots:
private:
QWidget *m_parent;
private:
// QWidget *m_parent;
bool isSetTop = false;
bool is_pop = false;
QIcon icon;
QSize ini_size; //初始大小
};
#endif // TOOLSWIDGET_H
+2 -2
View File
@@ -420,8 +420,8 @@ MainWindow::MainWindow(QWidget *parent)
this,&MainWindow::setServoOffset);
connect(map, SIGNAL(rectRange(double, double, double, double) ),
setting->index0->globalsetting, SLOT(setLngLatRectRange(double, double, double, double) ) );
connect(map, SIGNAL(mapSaveGradeChanged(int) ), setting->index0->globalsetting, SLOT(setMapSaveGrade(int) ) );
connect(map, SIGNAL(numberOfTilesChanged(int,int) ), setting->index0->globalsetting, SLOT(showDownloadImageNum(int,int)) );
connect(map, SIGNAL(mapSaveGradeChanged(int, quint8) ), setting->index0->globalsetting, SLOT(setMapSaveGrade(int, quint8) ) );
connect(map, SIGNAL(numberOfTilesChanged(int,int, quint8) ), setting->index0->globalsetting, SLOT(showDownloadImageNum(int,int, quint8)) );
connect(map, SIGNAL(downloadMapFinished() ), setting->index0->globalsetting, SLOT(cleanDownloadInfo() ) );
connect(setting->index0->globalsetting, SIGNAL(cancelSaveMap() ), map, SLOT(cancelSaveMap() ) );
+1 -8
View File
@@ -36,13 +36,6 @@ MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,i
zoom = maxz;
setMaxZoom(maxz);
points = core->Projection()->GetAreaTileList(area, maxz, 0);
this->start();
//progressForm->show();
//connect(this, SIGNAL(percentageChanged(int)), progressForm, SLOT(SetPercentage(int)));
//connect(this, SIGNAL(numberOfTilesChanged(int, int)), progressForm, SLOT(SetNumberOfTiles(int, int)));
//connect(this, SIGNAL(providerChanged(QString, int)), progressForm, SLOT(SetProvider(QString, int)));
connect(this, SIGNAL(finished()), this, SLOT(finish()));
emit numberOfTilesChanged(0, 0);
} else
#ifdef Q_OS_DARWIN
{ QMessageBox::information(new QWidget(), tr("No valid selection"), tr("This pre-caches map data.\n\nPlease first select the area of the map to rip with <COMMAND>+Left mouse click")); }
@@ -108,7 +101,7 @@ void MapRipper::run()
QVector<core::MapType::Types> types = OPMaps::Instance()->GetAllLayersOfType(type);
int all = points.count();
for (int i = 0; i < all; i++) {
emit numberOfTilesChanged(all, i + 1);
emit numberOfTilesChanged(all, i + 1, _id);
qDebug() << u8"cancel: " << cancel;
if (cancel)
{
+11 -1
View File
@@ -45,7 +45,17 @@ class MapRipper : public QThread {
public:
MapRipper(internals::Core *, internals::RectLatLng const &,int const & maxz);
void run();
/**
* @brief 设置缓存地图线程的id
* @param id
*/
void setId(quint8 id) { _id = id; }
/**
* @brief 返回缓存地图线程的id
*/
quint8 id() const {return _id; }
private:
quint8 _id;
QList<core::Point> points;
int zoom;
core::MapType::Types type;
@@ -60,7 +70,7 @@ private:
signals:
void percentageChanged(int const & perc);
void numberOfTilesChanged(int const & total, int const & actual);
void numberOfTilesChanged(int const & total, int const & actual, quint8 id);
void providerChanged(QString const & prov, int const & zoom);
void ripfinished();
+84 -16
View File
@@ -226,11 +226,19 @@ void OPMapWidget::cancelSaveMap()
mapGrades.clear();
}
if(current_ripper)
for(int i = 0; i < rippers.size(); ++i)
{
current_ripper->stopFetching(); //停止缓存
current_ripper = nullptr;
if(rippers[i])
{
qDebug() << "ripper: " << rippers[i];
rippers[i]->stopFetching(); //停止缓存,这里不释放,线程在结束后发出信号会在createNewMapRipper函数中释放掉
}
}
// if(current_ripper)
// {
// current_ripper->stopFetching(); //停止缓存
// current_ripper = nullptr;
// }
}
void OPMapWidget::UAVTip_clicked(bool flag)
@@ -652,6 +660,14 @@ OPMapWidget::~OPMapWidget()
delete i;
}
}
for(int i = 0; i < rippers.size(); ++i)
{
if(rippers[i])
{
rippers[i]->deleteLater();
}
}
}
void OPMapWidget::closeEvent(QCloseEvent *event)
{
@@ -1551,6 +1567,52 @@ void OPMapWidget::ConnectWP(WayPointItem *item)
setSelectedWP(item);
}
void OPMapWidget::createNewMapRipper()
{
// if(mapGrades.empty() )
// {
// emit downloadMapFinished(); //地图下载完成
// rippers.clear(); //清空列表
// return;
// }
MapRipper *old_ripper = qobject_cast<MapRipper*>(sender() );
if(mapGrades.empty() )
{
rippers[old_ripper->id()] = nullptr;
bool is_finished = true;
for(int i = 0; i < rippers.size(); ++i)
{
if(rippers[i] != nullptr)
{
is_finished = false;
}
}
if(is_finished)
{
emit downloadMapFinished(); //地图下载完成
rippers.clear(); //清空列表
}
old_ripper->deleteLater();
return;
}
MapRipper *ripper = new MapRipper(core, mapArea, mapGrades[0]);
ripper->setId(old_ripper->id() ); //设置id
rippers[old_ripper->id()] = ripper;
old_ripper->deleteLater(); //删除原来的线程
connect(ripper, &MapRipper::finished, this, &OPMapWidget::createNewMapRipper);
connect(ripper, &MapRipper::numberOfTilesChanged, this, &OPMapWidget::numberOfTilesChanged);
ripper->start();
emit mapSaveGradeChanged(mapGrades[0], ripper->id() ); //缓存级别发生改变
mapGrades.removeFirst();
}
void OPMapWidget::createMapRipper()
{
if(mapGrades.empty() ) //已经缓存完就退出
@@ -1560,7 +1622,7 @@ void OPMapWidget::createMapRipper()
return;
}
emit mapSaveGradeChanged(mapGrades[0]);
// emit mapSaveGradeChanged(mapGrades[0]);
MapRipper *ripper = new MapRipper(core, mapArea, mapGrades[0]);
current_ripper = ripper;
connect(ripper, SIGNAL(percentageChanged(int)), this, SIGNAL(mapSaveProgressValue(int)) );
@@ -1689,18 +1751,24 @@ void OPMapWidget::RipMap(internals::RectLatLng const &area, QList<int> const &gr
mapGrades = grades;
mapArea = area;
createMapRipper();
// qDebug() << u8"地图开始缓存";
// MapRipper *ripper = new MapRipper(core, area, grades);
// connect(ripper, SIGNAL(zoomChanged(int) ), this, SIGNAL(mapSaveGradeChanged(int) ) );
// connect(ripper, SIGNAL(percentageChanged(int)), this, SIGNAL(mapSaveProgressValue(int)) );
// connect(ripper, &MapRipper::percentageChanged, this,
// [this](int value)
// {
// qDebug() << u8"保存进度百分比:" << value;
// });
// qDebug() << u8"地图开始缓存";
// ripper->start();
//创建最多四个线程缓存地图
for(int i = 0; i < 4; ++i)
{
MapRipper *ripper = new MapRipper(core, mapArea, mapGrades[0]);
ripper->setId(i);
rippers.append(ripper);
connect(ripper, &MapRipper::finished, this, &OPMapWidget::createNewMapRipper);
connect(ripper, &MapRipper::numberOfTilesChanged, this, &OPMapWidget::numberOfTilesChanged);
ripper->start();
emit mapSaveGradeChanged(mapGrades[0], ripper->id() ); //缓存级别发生改变
mapGrades.removeFirst();
if(mapGrades.empty() )
{
break;
}
}
qDebug() << "opmapwidget: RipMap";
}
+10 -2
View File
@@ -471,6 +471,8 @@ public:
private:
//当前正在运行的地图缓存线程
QList<MapRipper *> rippers;
//当前正在运行的地图缓存线程
MapRipper *current_ripper = nullptr;
//保存需要缓存的地图级别
@@ -522,6 +524,10 @@ private:
int fenceCount = 1;
private slots:
/**
* @brief 创建新的地图缓存线程
*/
void createNewMapRipper();
/**
* @brief 创建缓存线程缓存地图
*/
@@ -553,8 +559,9 @@ signals:
* @brief 当前地图级别下载图片进度的信号
* @param total 全部图片数
* @param actual 当前已下载的图片数
* @param id 缓存线程的id号
*/
void numberOfTilesChanged(int const & total, int const & actual);
void numberOfTilesChanged(int const & total, int const & actual, quint8 id);
/**
* @brief 清除航线信息的信号
*/
@@ -566,8 +573,9 @@ signals:
/**
* @brief 地图缓存时更改缓存的地图级别时发出的信号
* @param zoom
* @param id 缓存地图线程的id
*/
void mapSaveGradeChanged(int zoom);
void mapSaveGradeChanged(int zoom, quint8 id);
/**
* @brief 地图缓存进度更改时发出信号
* @param value