From 581679a8ed81df2541d31d9d0dd47b8223957070 Mon Sep 17 00:00:00 2001 From: goldenhawking Date: Wed, 6 Jan 2016 19:49:58 +0000 Subject: [PATCH] 1.avoiding frequencilly downloading same tile after a doanload failiure. 2.make a copy painting , sloved +180 -180 polygon drawing problem. --- qtviewer_planetosm/osmtiles/urlDownloader.cpp | 4 +- qtvplugin_geomarker/geoitembase.cpp | 13 +++ qtvplugin_geomarker/geoitembase.h | 8 ++ qtvplugin_geomarker/qtvplugin_geomarker.cpp | 61 +++++++++----- qtvplugin_geomarker/qtvplugin_geomarker.h | 18 ++++- qtvplugin_geomarker/qtvplugin_geomarker.ui | 80 +++++++++++++++++-- .../qtvplugin_geomarker_uimethods.cpp | 57 ++++++++++++- 7 files changed, 205 insertions(+), 36 deletions(-) diff --git a/qtviewer_planetosm/osmtiles/urlDownloader.cpp b/qtviewer_planetosm/osmtiles/urlDownloader.cpp index a13d2c8..93f5a8a 100644 --- a/qtviewer_planetosm/osmtiles/urlDownloader.cpp +++ b/qtviewer_planetosm/osmtiles/urlDownloader.cpp @@ -22,6 +22,7 @@ namespace QTVOSM{ { bool needDo = false; bool allFinished = false; + bool succeeded = false; m_mutex_protect.lock(); if (m_map_pendingTasks.contains(rply)==true) { @@ -39,6 +40,7 @@ namespace QTVOSM{ { file.write(rply->readAll()); file.close(); + succeeded = true; } } else @@ -59,7 +61,7 @@ namespace QTVOSM{ m_mutex_protect.unlock(); if (needDo) emit evt_doNextJob(); - if (allFinished == true) + if (allFinished == true && succeeded) emit evt_all_taskFinished(); } diff --git a/qtvplugin_geomarker/geoitembase.cpp b/qtvplugin_geomarker/geoitembase.cpp index 28675d0..7ed760f 100644 --- a/qtvplugin_geomarker/geoitembase.cpp +++ b/qtvplugin_geomarker/geoitembase.cpp @@ -2,6 +2,7 @@ #include "geographicsscene.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include +#include namespace QTVP_GEOMARKER{ geoItemBase::geoItemBase(QString name,geo_item_type tp,QTVOSM::viewer_interface * pVi) :m_pVi(pVi) @@ -68,7 +69,11 @@ namespace QTVP_GEOMARKER{ if (k=="LABEL" && pc) { if (!m_pLabelItem) + { m_pLabelItem = new QGraphicsTextItem(v.toString(),pc); + m_pLabelItem->setDefaultTextColor(m_LabelTextColor); + m_pLabelItem->setFont(m_LabelTextFont); + } else if (m_bPropVisible==false) m_pLabelItem->setPlainText(v.toString()); m_pLabelItem->setPos(this->label_pos()); @@ -109,7 +114,11 @@ namespace QTVP_GEOMARKER{ propValues.pop_front(); } if (!m_pLabelItem) + { m_pLabelItem = new QGraphicsTextItem(str,pc); + m_pLabelItem->setDefaultTextColor(m_LabelTextColor); + m_pLabelItem->setFont(m_LabelTextFont); + } else m_pLabelItem->setPlainText(str); m_pLabelItem->setPos(this->label_pos()); @@ -132,7 +141,11 @@ namespace QTVP_GEOMARKER{ else { if (!m_pLabelItem) + { m_pLabelItem = new QGraphicsTextItem(v.toString(),pc); + m_pLabelItem->setDefaultTextColor(m_LabelTextColor); + m_pLabelItem->setFont(m_LabelTextFont); + } m_pLabelItem->setPlainText(v.toString()); m_pLabelItem->setPos(this->label_pos()); } diff --git a/qtvplugin_geomarker/geoitembase.h b/qtvplugin_geomarker/geoitembase.h index 1514f19..35615b7 100644 --- a/qtvplugin_geomarker/geoitembase.h +++ b/qtvplugin_geomarker/geoitembase.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include namespace QTVOSM{ class viewer_interface; @@ -40,6 +42,8 @@ namespace QTVP_GEOMARKER{ void setViewInterface(QTVOSM::viewer_interface * pVi); private: + QFont m_LabelTextFont; + QColor m_LabelTextColor; bool m_bPropVisible; int m_nCurrentLevel; QGraphicsTextItem * m_pLabelItem; @@ -55,6 +59,10 @@ namespace QTVP_GEOMARKER{ void set_item_type (geo_item_type tp) {m_type = tp;} QString item_name () const {return m_name;} void set_item_name (QString na) {m_name = na;} + void setLabelFont (QFont font) {m_LabelTextFont = font;if (m_pLabelItem) m_pLabelItem->setFont(m_LabelTextFont);} + QFont labelFont () {return m_LabelTextFont;} + void setLabelColor (QColor col) {m_LabelTextColor = col;if (m_pLabelItem) m_pLabelItem->setDefaultTextColor(m_LabelTextColor);} + QColor labelColor () {return m_LabelTextColor;} void adjustLabelPos (); QStringList prop_names(); diff --git a/qtvplugin_geomarker/qtvplugin_geomarker.cpp b/qtvplugin_geomarker/qtvplugin_geomarker.cpp index 7896acb..eb5308a 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker.cpp +++ b/qtvplugin_geomarker/qtvplugin_geomarker.cpp @@ -122,7 +122,7 @@ layer_interface * qtvplugin_geomarker::load_initial_plugin(QString strSLibPath,v assert(ret==instance); return ret; } - + qDebug()<CV_DP2World(0,0,&leftcenx,&topceny); m_pVi->CV_DP2World(rect.width()-1,rect.height()-1,&rightcenx,&bottomceny); - QRectF source( - leftcenx , - topceny, - (rightcenx - leftcenx), - (bottomceny - topceny) - ); + int winsz = 256 * (1<level()); //Warpping 180, -180 - for (int t = -1; t <=1;++t) + for (int p = -1; p<=1 ;++p) { - QRectF destin( - 0 + winsz * t , - 0, - rect.width(), - rect.height() + QRectF source( + leftcenx + p * winsz, + topceny, + (rightcenx - leftcenx), + (bottomceny - topceny) ); - if (destin.right() < 0 || destin.left() >= rect.width()) - continue; - m_pScene->render(pImage,destin,source); + for (int t = -1; t <=1;++t) + { + if (abs(p-t)==2 || (p==t && p !=0)) + continue; + if (abs(p-t)==1 && (p==0 || t ==1)) + continue; + + + QRectF destin( + 0 + winsz * t , + 0, + rect.width(), + rect.height() + ); + if (destin.right() < 0 || destin.left() >= rect.width()) + continue; + m_pScene->render(pImage,destin,source); + } } } @@ -382,8 +392,9 @@ void qtvplugin_geomarker::refreshMarks() m_bNeedRefresh = true; } -void qtvplugin_geomarker::update_line(const QString & name,double lat1, double lon1,double lat2, double lon2, QPen pen) +QTVP_GEOMARKER::geoItemBase * qtvplugin_geomarker::update_line(const QString & name,double lat1, double lon1,double lat2, double lon2, QPen pen) { + QTVP_GEOMARKER::geoItemBase * res = 0; //Get raw Item by name QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); //Get Props @@ -403,7 +414,9 @@ void qtvplugin_geomarker::update_line(const QString & name,double lat1, double l pitem->setPen(pen); - if (false==this->m_pScene->addItem(pitem,0)) + if (base == pitem) + pitem->setGeoLine(lat1,lon1,lat2,lon2); + else if (false==this->m_pScene->addItem(pitem,0)) { if (base != pitem) delete pitem; @@ -417,11 +430,13 @@ void qtvplugin_geomarker::update_line(const QString & name,double lat1, double l propNames.pop_front(); propValues.pop_front(); } + res = pitem; } - + return res; } -void qtvplugin_geomarker::update_region (const QString & name,const QPolygonF latlons, QPen pen, QBrush brush) +QTVP_GEOMARKER::geoItemBase * qtvplugin_geomarker::update_region (const QString & name,const QPolygonF latlons, QPen pen, QBrush brush) { + QTVP_GEOMARKER::geoItemBase * res = 0; //Get raw Item by name QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); //Get Props @@ -441,7 +456,9 @@ void qtvplugin_geomarker::update_region (const QString & name,const QPolygonF l pitem->setPen(pen); pitem->setBrush(brush); - if (false==this->m_pScene->addItem(pitem,0)) + if (base == pitem) + pitem->setGeoPolygon(latlons); + else if (false==this->m_pScene->addItem(pitem,0)) { if (base != pitem) delete pitem; @@ -455,5 +472,7 @@ void qtvplugin_geomarker::update_region (const QString & name,const QPolygonF l propNames.pop_front(); propValues.pop_front(); } + res = pitem; } + return res; } diff --git a/qtvplugin_geomarker/qtvplugin_geomarker.h b/qtvplugin_geomarker/qtvplugin_geomarker.h index 5533946..3d479cd 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker.h +++ b/qtvplugin_geomarker/qtvplugin_geomarker.h @@ -57,9 +57,9 @@ private: QString color2string(const QColor & c); template - void update_point (const QString & name,double lat, double lon, int width, int height, QPen pen, QBrush brush); - void update_line (const QString & name,double lat1, double lon1,double lat2, double lon2, QPen pen); - void update_region (const QString & name,const QPolygonF latlons, QPen pen, QBrush brush); + QTVP_GEOMARKER::geoItemBase * update_point (const QString & name,double lat, double lon, int width, int height, QPen pen, QBrush brush); + QTVP_GEOMARKER::geoItemBase * update_line (const QString & name,double lat1, double lon1,double lat2, double lon2, QPen pen); + QTVP_GEOMARKER::geoItemBase * update_region (const QString & name,const QPolygonF latlons, QPen pen, QBrush brush); protected: layer_interface * load_initial_plugin(QString strSLibPath,viewer_interface * ptrviewer); QWidget * load_prop_window(); @@ -86,6 +86,7 @@ protected slots: void on_radioButton_tool_polygon_toggled(bool); void on_toolButton_selColorPen_clicked(); void on_toolButton_selColorFill_clicked(); + void on_toolButton_selColorText_clicked(); void on_tableView_marks_doubleClicked(const QModelIndex & index); void on_pushButton_prop_update_clicked(); void on_pushButton_prop_delete_clicked(); @@ -96,8 +97,9 @@ protected slots: }; template -void qtvplugin_geomarker::update_point(const QString & name,double lat, double lon, int width, int height, QPen pen, QBrush brush) +QTVP_GEOMARKER::geoItemBase * qtvplugin_geomarker::update_point(const QString & name,double lat, double lon, int width, int height, QPen pen, QBrush brush) { + QTVP_GEOMARKER::geoItemBase * res = 0; //Get raw Item by name QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); //Get Props @@ -118,6 +120,11 @@ void qtvplugin_geomarker::update_point(const QString & name,double lat, double l pitem->setPen(pen); pitem->setBrush(brush); + if (base == pitem) + { + pitem->setCenter(lat,lon); + pitem->setSize(width,height); + } if (false==this->m_pScene->addItem(pitem,0)) { if (base != pitem) @@ -132,8 +139,11 @@ void qtvplugin_geomarker::update_point(const QString & name,double lat, double l propNames.pop_front(); propValues.pop_front(); } + res = pitem; } + return res; + } #endif // QTVPLUGIN_GEOMARKER_H diff --git a/qtvplugin_geomarker/qtvplugin_geomarker.ui b/qtvplugin_geomarker/qtvplugin_geomarker.ui index 93d719b..5555ace 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker.ui +++ b/qtvplugin_geomarker/qtvplugin_geomarker.ui @@ -6,14 +6,14 @@ 0 0 - 612 - 534 + 461 + 497 Grid - + @@ -162,6 +162,9 @@ + + QLayout::SetDefaultConstraint + @@ -361,7 +364,7 @@ - + 0 0 @@ -441,8 +444,53 @@ + + + + + + + + Text Color + + + + + + + + + + ... + + + + + + + weight + + + + + + + 1 + + + 99 + + + 16 + + + + + + + - + Fill Style @@ -451,12 +499,32 @@ + + + + Font Size + + + + + + + 1 + + + 720 + + + 12 + + + - + 0 0 diff --git a/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp b/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp index f6cb406..3382dd2 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp +++ b/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp @@ -96,7 +96,14 @@ void qtvplugin_geomarker::on_toolButton_selColorFill_clicked() if (col.isValid()) ui->lineEdit_FillColor->setText(color2string(col)); } +void qtvplugin_geomarker::on_toolButton_selColorText_clicked() +{ + QString str = ui->lineEdit_TextColor->text(); + QColor col = QColorDialog::getColor(string2color(str),this,tr("Select Color"),QColorDialog::ShowAlphaChannel|QColorDialog::DontUseNativeDialog); + if (col.isValid()) + ui->lineEdit_TextColor->setText(color2string(col)); +} void qtvplugin_geomarker::on_pushButton_pickToLine1_clicked() { ui->lineEdit_lineLat1->setText(ui->lineEdit_point_lat->text()); @@ -134,6 +141,7 @@ void qtvplugin_geomarker::SaveSettingsToIni() settings.setValue("ui/lineEdit_PenColor",ui->lineEdit_PenColor->text()); settings.setValue("ui/lineEdit_FillColor",ui->lineEdit_FillColor->text()); + settings.setValue("ui/lineEdit_TextColor",ui->lineEdit_TextColor->text()); settings.setValue("ui/lineEdit_prop_name",ui->lineEdit_prop_name->text()); settings.setValue("ui/lineEdit_prop_string",ui->lineEdit_prop_string->text()); settings.setValue("ui/lineEdit_lineLat1",ui->lineEdit_lineLat1->text()); @@ -144,6 +152,10 @@ void qtvplugin_geomarker::SaveSettingsToIni() settings.setValue("ui/comboBox_linePad",ui->comboBox_linePad->currentIndex()); settings.setValue("ui/comboBox_fillPad",ui->comboBox_fillPad->currentIndex()); settings.setValue("ui/plainTextEdit_corners",ui->plainTextEdit_corners->toPlainText()); + + settings.setValue("ui/spinBox_textWeight",ui->spinBox_textWeight->value()); + settings.setValue("ui/spinBox_fontSize",ui->spinBox_fontSize->value()); + } void qtvplugin_geomarker::loadSettingsFromIni() @@ -180,6 +192,8 @@ void qtvplugin_geomarker::loadSettingsFromIni() ui->lineEdit_PenColor->setText(lineEdit_PenColor); QString lineEdit_FillColor = settings.value("ui/lineEdit_FillColor",color2string(QColor(255,255,255,128))).toString(); ui->lineEdit_FillColor->setText(lineEdit_FillColor); + QString lineEdit_TextColor = settings.value("ui/lineEdit_TextColor",color2string(QColor(0,0,0))).toString(); + ui->lineEdit_TextColor->setText(lineEdit_TextColor); int radioButton_PointRect = settings.value("ui/radioButton_PointRect",0).toInt(); switch (radioButton_PointRect) { @@ -216,6 +230,11 @@ void qtvplugin_geomarker::loadSettingsFromIni() QString plainTextEdit_corners = settings.value("ui/plainTextEdit_corners","0").toString(); ui->plainTextEdit_corners->setPlainText(plainTextEdit_corners); + int spinBox_fontSize = settings.value("ui/spinBox_fontSize",9).toInt(); + ui->spinBox_fontSize->setValue(spinBox_fontSize); + + int spinBox_textWeight = settings.value("ui/spinBox_textWeight",16).toInt(); + ui->spinBox_textWeight->setValue(spinBox_textWeight); } void qtvplugin_geomarker::on_pushButton_update_clicked() { @@ -271,6 +290,8 @@ void qtvplugin_geomarker::on_pushButton_update_clicked() brush.setColor(brushColor); brush.setStyle(bst[btdd]); + QTVP_GEOMARKER::geoItemBase * newitem = 0; + if (ui->radioButton_tool_point->isChecked()) { double lat = ui->lineEdit_point_lat->text().toDouble(); @@ -279,9 +300,9 @@ void qtvplugin_geomarker::on_pushButton_update_clicked() int width = ui->spinBox_point_width->value(); int height = ui->spinBox_point_size_height->value(); if (tp==0) - update_point(name,lat,lon,width,height,pen,brush); + newitem = update_point(name,lat,lon,width,height,pen,brush); else - update_point(name,lat,lon,width,height,pen,brush); + newitem = update_point(name,lat,lon,width,height,pen,brush); } else if (ui->radioButton_tool_line->isChecked()) { @@ -289,7 +310,7 @@ void qtvplugin_geomarker::on_pushButton_update_clicked() double lat2 = ui->lineEdit_lineLat2->text().toDouble(); double lon1 = ui->lineEdit_lineLon1->text().toDouble(); double lon2 = ui->lineEdit_lineLon2->text().toDouble(); - update_line(name,lat1,lon1,lat2,lon2,pen); + newitem = update_line(name,lat1,lon1,lat2,lon2,pen); } else if (ui->radioButton_tool_polygon->isChecked()) { @@ -313,12 +334,26 @@ void qtvplugin_geomarker::on_pushButton_update_clicked() latlons.push_back(ll); } if (latlons.size()) - update_region(name,latlons,pen,brush); + newitem = update_region(name,latlons,pen,brush); } else return; + if (newitem) + { + int fontSz = ui->spinBox_fontSize->value(); + int fontWeight = ui->spinBox_textWeight->value(); + QColor textColor = string2color( ui->lineEdit_TextColor->text()); + QFont f = newitem->labelFont(); + f.setPointSize(fontSz); + f.setWeight(fontWeight); + newitem->setLabelFont(f); + newitem->setLabelColor(textColor); + + + } refreshMarks(); + m_pVi->UpdateWindow(); } void qtvplugin_geomarker::on_pushButton_del_clicked() @@ -432,6 +467,7 @@ void qtvplugin_geomarker::refreshItemUI(QString markname) ui->radioButton_PointRect->setChecked(true); ui->spinBox_point_width->setValue(pitem->width()); ui->spinBox_point_size_height->setValue(pitem->height()); + ui->radioButton_tool_point->setChecked(true); } break; case QTVP_GEOMARKER::ITEAMTYPE_ELLIPSE_POINT: @@ -446,6 +482,7 @@ void qtvplugin_geomarker::refreshItemUI(QString markname) ui->radioButton_PointRound->setChecked(true); ui->spinBox_point_width->setValue(pitem->width()); ui->spinBox_point_size_height->setValue(pitem->height()); + ui->radioButton_tool_point->setChecked(true); } break; case QTVP_GEOMARKER::ITEAMTYPE_LINE: @@ -458,6 +495,7 @@ void qtvplugin_geomarker::refreshItemUI(QString markname) ui->lineEdit_lineLat2->setText(QString("%1").arg(pitem->lat2(),0,'f',14)); ui->lineEdit_lineLon1->setText(QString("%1").arg(pitem->lon1(),0,'f',14)); ui->lineEdit_lineLon2->setText(QString("%1").arg(pitem->lon2(),0,'f',14)); + ui->radioButton_tool_line->setChecked(true); } break; case QTVP_GEOMARKER::ITEAMTYPE_REGION: @@ -472,6 +510,7 @@ void qtvplugin_geomarker::refreshItemUI(QString markname) foreach (QPointF p, pol) strPlainText += QString("%1,%2\n").arg(p.y(),0,'f',14).arg(p.x(),0,'f',14); ui->plainTextEdit_corners->setPlainText(strPlainText); + ui->radioButton_tool_polygon->setChecked(true); } break; default: @@ -493,6 +532,16 @@ void qtvplugin_geomarker::refreshItemUI(QString markname) int nbs = int(bs); if (nbs >=0 && nbs < ui->comboBox_fillPad->count()) ui->comboBox_fillPad->setCurrentIndex((int)nbs); + + QColor colorText = item->labelColor(); + ui->lineEdit_TextColor->setText(color2string(colorText)); + + int fsize = item->labelFont().pointSize(); + ui->spinBox_fontSize->setValue(fsize); + + int weight = item->labelFont().weight(); + ui->spinBox_textWeight->setValue(weight); + refreshProps(item); }//end if item -- GitLab