Merge remote-tracking branch 'origin/aj500b_5' into aj500b

This commit is contained in:
hm
2022-11-04 14:18:29 +08:00
13 changed files with 474 additions and 314 deletions
+25 -88
View File
@@ -32,12 +32,11 @@ MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,i
type = core->GetMapType();
//progressForm = new MapRipForm;
//connect(progressForm, SIGNAL(cancelRequest()), this, SLOT(stopFetching()));
_area = rect;
zoom = core->Zoom();
area = rect;
zoom = maxz;
setMaxZoom(maxz);
points = core->Projection()->GetAreaTileList(_area, zoom, 0);
points = core->Projection()->GetAreaTileList(area, maxz, 0);
this->start();
cancel = false;
//progressForm->show();
//connect(this, SIGNAL(percentageChanged(int)), progressForm, SLOT(SetPercentage(int)));
//connect(this, SIGNAL(numberOfTilesChanged(int, int)), progressForm, SLOT(SetNumberOfTiles(int, int)));
@@ -51,91 +50,50 @@ MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,i
{ 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 <CTRL>+Left mouse click")); }
#endif
}
MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng &area, const QList<int> &grades):
sleep(0), cancel(false), core(core), yesToAll(true), _area(area), zoom(0), _grades(grades)
{
qDebug() << "缓存级别:";
foreach(int v, _grades)
{
qDebug() << v;
}
if(!_grades.isEmpty() )
{
qDebug() << u8"开始获取1";
type = core->GetMapType();
qDebug() << u8"开始获取2";
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
qDebug() << u8"获取完成";
cancel = false;
connect(this, SIGNAL(finished()), this, SLOT(finish()));
emit numberOfTilesChanged(0, 0);
}
}
MapRipper::~MapRipper()
{
qDebug() << u8"MapRipper: 析构函数";
}
void MapRipper::finish()
{
if (zoom < (_grades.size() -1) && !cancel)
{
if (zoom < maxzoom && !cancel) {
++zoom;
int ret = QMessageBox::Yes;
if (!yesToAll)
{
if (!yesToAll) {
QMessageBox msgBox;
msgBox.setText(QString(tr("Continue Ripping at zoom level %1?")).arg(_grades[zoom]) );
msgBox.setText(QString(tr("Continue Ripping at zoom level %1?")).arg(zoom));
// msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::YesAll);
msgBox.setDefaultButton(QMessageBox::Yes);
ret = msgBox.exec();
}
else
{
} else {
ret = QMessageBox::Yes;
}
if (ret == QMessageBox::Yes)
{
if (ret == QMessageBox::Yes) {
points.clear();
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
points = core->Projection()->GetAreaTileList(area, zoom, 0);
//qDebug() << zoom << maxzoom << ret;
this->start();
}
else if (ret == QMessageBox::YesAll)
{
} else if (ret == QMessageBox::YesAll) {
yesToAll = true;
points.clear();
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
points = core->Projection()->GetAreaTileList(area, zoom, 0);
this->start();
}
else
{
} else {
//progressForm->close();
//delete progressForm;
emit ripfinished();
this->deleteLater();
}
}
else
{
} else {
//yesToAll = false;
//progressForm->close();
//delete progressForm;
qDebug() << u8"当前缓存线程已完成";
emit ripfinished();
this->quit();
this->deleteLater();
}
}
@@ -143,70 +101,49 @@ void MapRipper::finish()
void MapRipper::run()
{
qDebug() << u8"mapripper: running";
int countOk = 0;
bool goodtile = false;
// Stuff.Shuffle<Point>(ref list);
QVector<core::MapType::Types> types = OPMaps::Instance()->GetAllLayersOfType(type);
int all = points.count();
emit zoomChanged(_grades[zoom]);
qDebug() << "mapripper: run的次数: " << zoom;
for (int i = 0; i < all; i++)
{
qDebug() << u8"mappripperrunning" ;
for (int i = 0; i < all; i++) {
emit numberOfTilesChanged(all, i + 1);
qDebug() << u8"cancel: " << cancel;
if (cancel)
{
break;
break;
}
core::Point p = points[i];
{
//qDebug()<<"offline fetching:"<<p.ToString();
foreach(core::MapType::Types type, types)
{
foreach(core::MapType::Types type, types) {
emit providerChanged(core::MapType::StrByType(type), zoom);
QByteArray img = OPMaps::Instance()->GetImageFrom(type, p, zoom);
emit providerChanged(core::MapType::StrByType(type), _grades[zoom]);
//qDebug() << img;
QByteArray img = OPMaps::Instance()->GetImageFrom(type, p, _grades[zoom]);
qDebug() << u8"img" << img;
if (img.length() != 0)
{
if (img.length() != 0) {
goodtile = true;
img = NULL;
}
else
{
} else {
goodtile = false;
}
}
if (goodtile)
{
if (goodtile) {
countOk++;
}
else
{
} else {
i--;
QThread::msleep(1);
continue;
}
}
qDebug() << u8"mapripper:发出信号";
emit percentageChanged((int)((i + 1) * 100 / all)); // , i+1);
// worker.ReportProgress((int) ((i+1)*100/all), i+1);
QThread::msleep(sleep);
}
}
void MapRipper::stopFetching()
+2 -7
View File
@@ -44,29 +44,24 @@ class MapRipper : public QThread {
Q_OBJECT
public:
MapRipper(internals::Core *, internals::RectLatLng const &,int const & maxz);
MapRipper(internals::Core *core, internals::RectLatLng const &area, QList<int> const &grades);
~MapRipper();
void run() override;
void run();
private:
QList<core::Point> points;
int zoom;
int gradeIndex;
core::MapType::Types type;
int sleep;
internals::RectLatLng _area;
internals::RectLatLng area;
bool cancel;
MapRipForm *progressForm;
int maxzoom;
internals::Core *core;
bool yesToAll;
QMutex mutex;
QList<int> _grades; //需要缓存的地图级别
signals:
void percentageChanged(int const & perc);
void numberOfTilesChanged(int const & total, int const & actual);
void providerChanged(QString const & prov, int const & zoom);
void zoomChanged(int zoom);
void ripfinished();
+3 -1
View File
@@ -51,9 +51,10 @@ SOURCES += $$PWD/mapgraphicitem.cpp \
$$PWD/AltitudeItem.cpp \
$$PWD/waypointbutton.cpp \
$$PWD/waypointsetting.cpp \
$$PWD/mapripper.cpp \
geoFencecircle.cpp \
geoFenceitem.cpp \
geoFenceitemline.cpp \
geoFenceitemline.cpp \
measureline.cpp
HEADERS += $$PWD/mapgraphicitem.h \
@@ -75,6 +76,7 @@ HEADERS += $$PWD/mapgraphicitem.h \
$$PWD/AltitudeItem.h \
$$PWD/waypointbutton.h \
$$PWD/waypointsetting.h \
$$PWD/mapripper.h \
geoFencecircle.h \
geoFenceitem.h \
geoFenceitemline.h \
+62 -12
View File
@@ -219,6 +219,20 @@ void OPMapWidget::dropEvent(QDropEvent *event)
}
}
void OPMapWidget::cancelSaveMap()
{
if(!mapGrades.empty() )
{
mapGrades.clear();
}
if(current_ripper)
{
current_ripper->stopFetching(); //停止缓存
current_ripper = nullptr;
}
}
void OPMapWidget::UAVTip_clicked(bool flag)
{
foreach(QGraphicsItem * i, map->childItems()) {
@@ -1537,6 +1551,33 @@ void OPMapWidget::ConnectWP(WayPointItem *item)
setSelectedWP(item);
}
void OPMapWidget::createMapRipper()
{
if(mapGrades.empty() ) //已经缓存完就退出
{
current_ripper = nullptr;
emit downloadMapFinished();
return;
}
emit mapSaveGradeChanged(mapGrades[0]);
MapRipper *ripper = new MapRipper(core, mapArea, mapGrades[0]);
current_ripper = ripper;
connect(ripper, SIGNAL(percentageChanged(int)), this, SIGNAL(mapSaveProgressValue(int)) );
connect(ripper, &MapRipper::numberOfTilesChanged, this, &OPMapWidget::numberOfTilesChanged);
connect(ripper, &MapRipper::finished, this,
[this]()
{
if(!mapGrades.empty() )
{
mapGrades.removeFirst();
}
createMapRipper();
});
}
@@ -1639,18 +1680,27 @@ void OPMapWidget::userRipMap(bool start, qreal lat_l, qreal lng_l, qreal lat_r,
void OPMapWidget::RipMap(internals::RectLatLng const &area, QList<int> const &grades)
{
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();
{
if(grades.empty() ) //如果没有选择级别,直接return
{
return;
}
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();
qDebug() << "opmapwidget: RipMap";
}
+25 -1
View File
@@ -471,6 +471,12 @@ public:
private:
//当前正在运行的地图缓存线程
MapRipper *current_ripper = nullptr;
//保存需要缓存的地图级别
QList<int> mapGrades;
//需要缓存的范围
internals::RectLatLng mapArea;
internals::Core *core;
MapGraphicItem *map;
QGraphicsScene mscene;
@@ -516,6 +522,10 @@ private:
int fenceCount = 1;
private slots:
/**
* @brief 创建缓存线程缓存地图
*/
void createMapRipper();
void diagRefresh();
// WayPointItem* item;//apagar
@@ -535,6 +545,16 @@ protected:
// private slots:
signals:
/**
* @brief 所有选择的地图级别下载完成后发出信号
*/
void downloadMapFinished();
/**
* @brief 当前地图级别下载图片进度的信号
* @param total 全部图片数
* @param actual 当前已下载的图片数
*/
void numberOfTilesChanged(int const & total, int const & actual);
/**
* @brief 清除航线信息的信号
*/
@@ -556,7 +576,7 @@ signals:
void rectRange(double lng1, double lat1, double lng2, double lat2);
void cancelRequest();
void percentageChanged(int const & perc);
void numberOfTilesChanged(int const & total, int const & actual);
// void numberOfTilesChanged(int const & total, int const & actual);
void providerChanged(QString const & prov, int const & zoom);
void ripfinished();
@@ -711,6 +731,10 @@ signals:
public slots:
/**
* @brief 取消缓存地图
*/
void cancelSaveMap();
void getAllPoints(int group);
void groupchanged(int value);