From 51d263738664e3c69fc41ed6e2b59ac7676e2cbb Mon Sep 17 00:00:00 2001 From: goldenhawking Date: Mon, 20 Apr 2020 22:44:35 +0800 Subject: [PATCH] Major improvement of geomarker. --- qplanetosm.pro | 7 +- .../geographicsellipseitem.cpp | 31 +- qtvplugin_geomarker/geographicsellipseitem.h | 17 +- qtvplugin_geomarker/geographicslineitem.cpp | 30 +- qtvplugin_geomarker/geographicslineitem.h | 17 +- .../geographicsmultilineitem.cpp | 31 +- .../geographicsmultilineitem.h | 21 +- qtvplugin_geomarker/geographicspixmapitem.cpp | 31 +- qtvplugin_geomarker/geographicspixmapitem.h | 17 +- .../geographicspolygonitem.cpp | 31 +- qtvplugin_geomarker/geographicspolygonitem.h | 17 +- qtvplugin_geomarker/geographicsrectitem.cpp | 32 +- qtvplugin_geomarker/geographicsrectitem.h | 17 +- qtvplugin_geomarker/geographicsscene.cpp | 49 +- qtvplugin_geomarker/geographicsscene.h | 8 +- qtvplugin_geomarker/geoitembase.h | 10 +- qtvplugin_geomarker/qtvplugin_geomarker.cpp | 1816 ++++++++--------- qtvplugin_geomarker/qtvplugin_geomarker.h | 1 - .../qtvplugin_geomarker_uimethods.cpp | 67 +- test_container/test_container.pro | 2 + test_container/testcontainer.cpp | 27 +- test_container/testcontainer.h | 4 +- test_container/testcontainer.ui | 177 +- test_container/testcontainer_linux.cpp | 28 +- test_container/testcontainer_linux.ui | 177 +- 25 files changed, 1404 insertions(+), 1261 deletions(-) diff --git a/qplanetosm.pro b/qplanetosm.pro index 3e346e4..9491613 100644 --- a/qplanetosm.pro +++ b/qplanetosm.pro @@ -11,10 +11,11 @@ SUBDIRS += \ qtwidget_planetosm.file = qtviewer_planetosm/qtwidget_planetosm.pro -win32:{ -contains(DEFINES,BUILD_ACTIVEX_OSM){ +win32: contains(DEFINES,BUILD_ACTIVEX_OSM){ + message ("Build ActiveX!") SUBDIRS +=\ qtaxviewer_planetosm qtaxviewer_planetosm.file = qtviewer_planetosm/qtaxviewer_planetosm.pro -} +}else{ + message ("Do NOT Build ActiveX!") } diff --git a/qtvplugin_geomarker/geographicsellipseitem.cpp b/qtvplugin_geomarker/geographicsellipseitem.cpp index ce2fd1c..290ca7e 100644 --- a/qtvplugin_geomarker/geographicsellipseitem.cpp +++ b/qtvplugin_geomarker/geographicsellipseitem.cpp @@ -1,4 +1,4 @@ -#include "geographicsellipseitem.h" +#include "geographicsellipseitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include @@ -43,6 +43,35 @@ namespace QTVP_GEOMARKER{ } } + void geoGraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) + { + if (vi()) + { + const int cv = vi()->level(); + if (cv!=level()) + { + adjust_coords(cv); + setLevel(cv); + } + } + + QGraphicsEllipseItem::paint(painter,option,widget); + } + QRectF geoGraphicsEllipseItem::boundingRect() const + { + QRectF rect = QGraphicsEllipseItem::boundingRect(); + auto v = vi(); + if (v && v->level()!=level()) + { + double ratio = pow(2.0,(v->level() - level())); + QPointF center = rect.center(); + rect.setRect(center.x() * ratio - rect.width()/2, + center.y() * ratio - rect.height()/2, + rect.width(), + rect.height()); + } + return rect; + } void geoGraphicsEllipseItem::setSize(qreal pxwidth,qreal pxheight) { double px,py; diff --git a/qtvplugin_geomarker/geographicsellipseitem.h b/qtvplugin_geomarker/geographicsellipseitem.h index 6965180..c9fa5d3 100644 --- a/qtvplugin_geomarker/geographicsellipseitem.h +++ b/qtvplugin_geomarker/geographicsellipseitem.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSELLIPSEITEM_H +#ifndef GEOGRAPHICSELLIPSEITEM_H #define GEOGRAPHICSELLIPSEITEM_H #include @@ -12,16 +12,20 @@ namespace QTVP_GEOMARKER{ qreal m_width; qreal m_height; protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent * event); + void mousePressEvent(QGraphicsSceneMouseEvent * event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)override; + void hoverEnterEvent(QGraphicsSceneHoverEvent * event)override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent * event)override; + void adjust_coords(int nNewLevel) override; + QPointF label_pos() override; public: explicit geoGraphicsEllipseItem(QString name,QTVOSM::viewer_interface * pVi, qreal cent_lat = 90, qreal cent_lon = 0, qreal pxwidth = 8, qreal pxheight = 8); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; public: qreal lat() const {return m_lat;} qreal lon() const {return m_lon;} @@ -29,9 +33,6 @@ namespace QTVP_GEOMARKER{ qreal height() const {return m_height;} void setSize(qreal pxwidth,qreal pxheight); void setGeo(qreal cent_lat,qreal cent_lon); - void adjust_coords(int nNewLevel); - QPointF label_pos(); - QPointF center_pos(){return rect().center();} }; } #endif // GEOGRAPHICSELLIPSEITEM_H diff --git a/qtvplugin_geomarker/geographicslineitem.cpp b/qtvplugin_geomarker/geographicslineitem.cpp index e9682f6..64fe699 100644 --- a/qtvplugin_geomarker/geographicslineitem.cpp +++ b/qtvplugin_geomarker/geographicslineitem.cpp @@ -1,4 +1,4 @@ -#include "geographicslineitem.h" +#include "geographicslineitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include @@ -60,7 +60,35 @@ namespace QTVP_GEOMARKER{ setLine(l1.x1() * ratio,l1.y1() * ratio,l1.x2() * ratio,l1.y2() * ratio); } } + void geoGraphicsLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) + { + if (vi()) + { + const int cv = vi()->level(); + if (cv!=level()) + { + adjust_coords(cv); + setLevel(cv); + } + } + QGraphicsLineItem::paint(painter,option,widget); + } + QRectF geoGraphicsLineItem::boundingRect() const + { + QRectF rect = QGraphicsLineItem::boundingRect(); + auto v = vi(); + if (v && v->level()!=level()) + { + double ratio = pow(2.0,(v->level() - level())); + QPointF center = rect.center(); + rect.setRect(center.x() * ratio - rect.width()/2, + center.y() * ratio - rect.height()/2, + rect.width(), + rect.height()); + } + return rect; + } void geoGraphicsLineItem::mousePressEvent(QGraphicsSceneMouseEvent * event) { QGraphicsLineItem::mousePressEvent(event); diff --git a/qtvplugin_geomarker/geographicslineitem.h b/qtvplugin_geomarker/geographicslineitem.h index 2118993..1b353df 100644 --- a/qtvplugin_geomarker/geographicslineitem.h +++ b/qtvplugin_geomarker/geographicslineitem.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSLINEITEM_H +#ifndef GEOGRAPHICSLINEITEM_H #define GEOGRAPHICSLINEITEM_H #include @@ -13,10 +13,12 @@ namespace QTVP_GEOMARKER{ qreal m_lon2; void unwarrp(); protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent * event); + void mousePressEvent(QGraphicsSceneMouseEvent * event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override; + void adjust_coords(int nNewLevel) override; + QPointF label_pos() override; public: explicit geoGraphicsLineItem(QString name,QTVOSM::viewer_interface * pVi, qreal lat1 = 90, @@ -24,15 +26,14 @@ namespace QTVP_GEOMARKER{ qreal lat2 = 90, qreal lon2 = 0 ); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; public: qreal lat1() const {return m_lat1;} qreal lon1() const {return m_lon1;} qreal lat2() const {return m_lat2;} qreal lon2() const {return m_lon2;} void setGeo(qreal lat1, qreal lon1, qreal lat2, qreal lon2); - void adjust_coords(int nNewLevel); - QPointF label_pos(); - QPointF center_pos(){return this->line().pointAt(0.5);} }; } #endif // GEOGRAPHICSLINEITEM_H diff --git a/qtvplugin_geomarker/geographicsmultilineitem.cpp b/qtvplugin_geomarker/geographicsmultilineitem.cpp index 3a01937..c27b80d 100644 --- a/qtvplugin_geomarker/geographicsmultilineitem.cpp +++ b/qtvplugin_geomarker/geographicsmultilineitem.cpp @@ -1,4 +1,4 @@ -#include "geographicsmultilineitem.h" +#include "geographicsmultilineitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include @@ -68,6 +68,35 @@ namespace QTVP_GEOMARKER{ this->setPath(p); } } + void geoGraphicsMultilineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) + { + if (vi()) + { + const int cv = vi()->level(); + if (cv!=level()) + { + adjust_coords(cv); + setLevel(cv); + } + } + + QGraphicsPathItem::paint(painter,option,widget); + } + QRectF geoGraphicsMultilineItem::boundingRect() const + { + QRectF rect = QGraphicsPathItem::boundingRect(); + auto v = vi(); + if (v && v->level()!=level()) + { + double ratio = pow(2.0,(v->level() - level())); + QPointF center = rect.center(); + rect.setRect(center.x() * ratio - rect.width()/2, + center.y() * ratio - rect.height()/2, + rect.width(), + rect.height()); + } + return rect; + } void geoGraphicsMultilineItem::mousePressEvent(QGraphicsSceneMouseEvent * event) { diff --git a/qtvplugin_geomarker/geographicsmultilineitem.h b/qtvplugin_geomarker/geographicsmultilineitem.h index 6cf847a..9e0b0eb 100644 --- a/qtvplugin_geomarker/geographicsmultilineitem.h +++ b/qtvplugin_geomarker/geographicsmultilineitem.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSMULTILINEITEM_H +#ifndef GEOGRAPHICSMULTILINEITEM_H #define GEOGRAPHICSMULTILINEITEM_H #include @@ -11,24 +11,21 @@ namespace QTVP_GEOMARKER{ QPolygonF m_llap; void unwarrp(); protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent * event); + void mousePressEvent(QGraphicsSceneMouseEvent * event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override; + void adjust_coords(int nNewLevel) override; + QPointF label_pos() override; public: explicit geoGraphicsMultilineItem(QString name,QTVOSM::viewer_interface * pVi, const QPolygonF & lla_polygon ); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; public: QPolygonF llas() const {return m_llap;} void setGeo(const QPolygonF & lla_polygon); - void adjust_coords(int nNewLevel); - QPointF label_pos(); - QPointF center_pos(){ - qreal x = path().elementAt(0).x; - qreal y = path().elementAt(0).y; - return QPointF(x,y); - } }; } #endif // geoGraphicsMultilineItem_H diff --git a/qtvplugin_geomarker/geographicspixmapitem.cpp b/qtvplugin_geomarker/geographicspixmapitem.cpp index 2d6fd30..f61144f 100644 --- a/qtvplugin_geomarker/geographicspixmapitem.cpp +++ b/qtvplugin_geomarker/geographicspixmapitem.cpp @@ -1,4 +1,4 @@ -#include "geographicspixmapitem.h" +#include "geographicspixmapitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include @@ -43,6 +43,35 @@ namespace QTVP_GEOMARKER{ QGraphicsPixmapItem::setTransformOriginPoint(oldlefttop_x*ratio, oldlefttop_y*ratio ); } } + void geoGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) + { + if (vi()) + { + const int cv = vi()->level(); + if (cv!=level()) + { + adjust_coords(cv); + setLevel(cv); + } + } + + QGraphicsPixmapItem::paint(painter,option,widget); + } + QRectF geoGraphicsPixmapItem::boundingRect() const + { + QRectF rect = QGraphicsPixmapItem::boundingRect(); + auto v = vi(); + if (v && v->level()!=level()) + { + double ratio = pow(2.0,(v->level() - level())); + QPointF center = rect.center(); + rect.setRect(center.x() * ratio - rect.width()/2, + center.y() * ratio - rect.height()/2, + rect.width(), + rect.height()); + } + return rect; + } void geoGraphicsPixmapItem::setPixmap(const tag_icon &icon) { diff --git a/qtvplugin_geomarker/geographicspixmapitem.h b/qtvplugin_geomarker/geographicspixmapitem.h index 178e387..cb3bae8 100644 --- a/qtvplugin_geomarker/geographicspixmapitem.h +++ b/qtvplugin_geomarker/geographicspixmapitem.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSPIXMAPITEM_H +#ifndef GEOGRAPHICSPIXMAPITEM_H #define GEOGRAPHICSPIXMAPITEM_H #include @@ -19,24 +19,25 @@ namespace QTVP_GEOMARKER{ qreal m_lon; const tag_icon * m_pIcon; protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent * event); + void mousePressEvent(QGraphicsSceneMouseEvent * event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override; + void adjust_coords(int ncurrLevel) override; + QPointF label_pos() override; public: explicit geoGraphicsPixmapItem(QString name,QTVOSM::viewer_interface * pVi ,const tag_icon * pIcon, qreal cent_lat = 90, qreal cent_lon = 0); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; public: const tag_icon * icon(){return m_pIcon;} qreal lat() const {return m_lat;} qreal lon() const {return m_lon;} void setGeo(qreal cent_lat,qreal cent_lon); void setPixmap(const tag_icon &icon); - void adjust_coords(int ncurrLevel); - QPointF label_pos(); - QPointF center_pos(){return offset();} }; } #endif // GEOGRAPHICSELLIPSEITEM_H diff --git a/qtvplugin_geomarker/geographicspolygonitem.cpp b/qtvplugin_geomarker/geographicspolygonitem.cpp index a19ec7a..34245c8 100644 --- a/qtvplugin_geomarker/geographicspolygonitem.cpp +++ b/qtvplugin_geomarker/geographicspolygonitem.cpp @@ -1,4 +1,4 @@ -#include "geographicspolygonitem.h" +#include "geographicspolygonitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include @@ -68,6 +68,35 @@ namespace QTVP_GEOMARKER{ this->setPolygon(p); } } + void geoGraphicsPolygonItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) + { + if (vi()) + { + const int cv = vi()->level(); + if (cv!=level()) + { + adjust_coords(cv); + setLevel(cv); + } + } + + QGraphicsPolygonItem::paint(painter,option,widget); + } + QRectF geoGraphicsPolygonItem::boundingRect() const + { + QRectF rect = QGraphicsPolygonItem::boundingRect(); + auto v = vi(); + if (v && v->level()!=level()) + { + double ratio = pow(2.0,(v->level() - level())); + QPointF center = rect.center(); + rect.setRect(center.x() * ratio - rect.width()/2, + center.y() * ratio - rect.height()/2, + rect.width(), + rect.height()); + } + return rect; + } void geoGraphicsPolygonItem::mousePressEvent(QGraphicsSceneMouseEvent * event) { diff --git a/qtvplugin_geomarker/geographicspolygonitem.h b/qtvplugin_geomarker/geographicspolygonitem.h index d50ee2a..6cc9efe 100644 --- a/qtvplugin_geomarker/geographicspolygonitem.h +++ b/qtvplugin_geomarker/geographicspolygonitem.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSPOLYGONITEM_H +#ifndef GEOGRAPHICSPOLYGONITEM_H #define GEOGRAPHICSPOLYGONITEM_H #include @@ -11,20 +11,21 @@ namespace QTVP_GEOMARKER{ QPolygonF m_llap; void unwarrp(); protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent * event); + void mousePressEvent(QGraphicsSceneMouseEvent * event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override; + void adjust_coords(int nNewLevel) override; + QPointF label_pos() override; public: explicit geoGraphicsPolygonItem(QString name,QTVOSM::viewer_interface * pVi, const QPolygonF & lla_polygon ); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; public: QPolygonF llas() const {return m_llap;} void setGeo(const QPolygonF & lla_polygon); - void adjust_coords(int nNewLevel); - QPointF label_pos(); - QPointF center_pos(){return this->polygon().first();} }; } #endif // GEOGRAPHICSPOLYGONITEM_H diff --git a/qtvplugin_geomarker/geographicsrectitem.cpp b/qtvplugin_geomarker/geographicsrectitem.cpp index 87e82d8..62a661f 100644 --- a/qtvplugin_geomarker/geographicsrectitem.cpp +++ b/qtvplugin_geomarker/geographicsrectitem.cpp @@ -1,4 +1,4 @@ -#include "geographicsrectitem.h" +#include "geographicsrectitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include @@ -44,6 +44,36 @@ namespace QTVP_GEOMARKER{ rect.height()); } } + void geoGraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) + { + if (vi()) + { + const int cv = vi()->level(); + if (cv!=level()) + { + adjust_coords(cv); + setLevel(cv); + } + } + + QGraphicsRectItem::paint(painter,option,widget); + } + + QRectF geoGraphicsRectItem::boundingRect() const + { + QRectF rect = QGraphicsRectItem::boundingRect(); + auto v = vi(); + if (v && v->level()!=level()) + { + double ratio = pow(2.0,(v->level() - level())); + QPointF center = rect.center(); + rect.setRect(center.x() * ratio - rect.width()/2, + center.y() * ratio - rect.height()/2, + rect.width(), + rect.height()); + } + return rect; + } void geoGraphicsRectItem::setSize(qreal pxwidth,qreal pxheight) { diff --git a/qtvplugin_geomarker/geographicsrectitem.h b/qtvplugin_geomarker/geographicsrectitem.h index 9b932fc..40128f1 100644 --- a/qtvplugin_geomarker/geographicsrectitem.h +++ b/qtvplugin_geomarker/geographicsrectitem.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSRECTITEM_H +#ifndef GEOGRAPHICSRECTITEM_H #define GEOGRAPHICSRECTITEM_H #include @@ -12,16 +12,19 @@ namespace QTVP_GEOMARKER{ qreal m_width; qreal m_height; protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent * event); + void mousePressEvent(QGraphicsSceneMouseEvent * event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override; + void adjust_coords(int ncurrLevel) override; public: explicit geoGraphicsRectItem(QString name,QTVOSM::viewer_interface * pVi, qreal cent_lat = 90, qreal cent_lon = 0, qreal pxwidth = 8, qreal pxheight = 8); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + QRectF boundingRect() const override; public: qreal lat() const {return m_lat;} qreal lon() const {return m_lon;} @@ -29,9 +32,7 @@ namespace QTVP_GEOMARKER{ qreal height() const {return m_height;} void setSize(qreal pxwidth,qreal pxheight); void setGeo(qreal cent_lat,qreal cent_lon); - void adjust_coords(int ncurrLevel); - QPointF label_pos(); - QPointF center_pos(){return rect().center();} + QPointF label_pos() override; }; } #endif // GEOGRAPHICSELLIPSEITEM_H diff --git a/qtvplugin_geomarker/geographicsscene.cpp b/qtvplugin_geomarker/geographicsscene.cpp index bbbdcda..13f889d 100644 --- a/qtvplugin_geomarker/geographicsscene.cpp +++ b/qtvplugin_geomarker/geographicsscene.cpp @@ -1,4 +1,4 @@ -#include "geographicsscene.h" +#include "geographicsscene.h" #include "geoitembase.h" #include #include @@ -64,53 +64,6 @@ namespace QTVP_GEOMARKER{ } - /** - * @brief sequentially call virtual function geoItemBase::adjust_coords for every geoItemBase object. - * - * Since the scene coord will be zoomed in / out together with level change, all graphics items' coords should - * be recalculated in time. the method adjust_item_coords will do this automatically, - * @param newLevel the level to which current map is zoomed. - */ - void geoGraphicsScene::adjust_item_coords(int newLevel) - { - currentNewLevel = newLevel; - if (total_items()<1024) - { - for (QMap::iterator p = m_map_items.begin();p!=m_map_items.end();++p) - { - geoItemBase * base = p.value(); - //when this function is called, base->level() is the old level from which - // current map is zoomed. - base->adjust_coords(newLevel); - //After adjust_coords above, the item "base" is considered to - // have a valid coord corresponds to current newLevel - base->setLevel(newLevel); - } - } - else - m_queue_level_change = geo_items(); - - - } - bool geoGraphicsScene::deal_level_queue() - { - int bneedref = 0; - for (int i=0;i<1024 && m_queue_level_change.empty()==false;++i) - { - ++bneedref; - geoItemBase * base = m_queue_level_change.first(); - m_queue_level_change.pop_front(); - //when this function is called, base->level() is the old level from which - // current map is zoomed. - base->adjust_coords(currentNewLevel); - //After adjust_coords above, the item "base" is considered to - // have a valid coord corresponds to current newLevel - base->setLevel(currentNewLevel); - } - if (m_queue_level_change.empty()==true && bneedref) - return true; - return false; - } geoItemBase * geoGraphicsScene::geoitem_by_name(const QString & name) { diff --git a/qtvplugin_geomarker/geographicsscene.h b/qtvplugin_geomarker/geographicsscene.h index a403179..0c9cbe4 100644 --- a/qtvplugin_geomarker/geographicsscene.h +++ b/qtvplugin_geomarker/geographicsscene.h @@ -1,4 +1,4 @@ -#ifndef GEOGRAPHICSSCENE_H +#ifndef GEOGRAPHICSSCENE_H #define GEOGRAPHICSSCENE_H #include @@ -26,10 +26,10 @@ namespace QTVP_GEOMARKER{ geoGraphicsScene(QObject *parent = 0); geoGraphicsScene(const QRectF &sceneRect, QObject *parent = 0); geoGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0); + int currentLevel() const {return currentNewLevel;} private: QMap m_map_items; int currentNewLevel; - QList m_queue_level_change; //Overload public functions to provate. QGraphicsEllipseItem * addEllipse(const QRectF & rect, const QPen & pen = QPen(), const QBrush & brush = QBrush()) {return QGraphicsScene::addEllipse(rect,pen,brush);} @@ -58,14 +58,10 @@ namespace QTVP_GEOMARKER{ void addItem(QGraphicsItem *item){return QGraphicsScene::addItem(item);} void removeItem(QGraphicsItem * item){return QGraphicsScene::removeItem(item);} public : - //for many items, we just change level coords in timer, batch mode. - bool deal_level_queue(); - double progress_queue() {return 1-m_queue_level_change.size()*1.0 / m_map_items.size();} //For mutithread opertaions, you should call lock_scene first, and call unlock scene when over bool addItem(geoItemBase *item,int /*reserved*/); void removeItem(geoItemBase * item, int /*reserved*/); geoItemBase * geoitem_by_name(const QString & name); - void adjust_item_coords(int currentLevel); QList geo_items(); QList geo_item_names(); int total_items() {return m_map_items.count();} diff --git a/qtvplugin_geomarker/geoitembase.h b/qtvplugin_geomarker/geoitembase.h index 4269243..3c290c3 100644 --- a/qtvplugin_geomarker/geoitembase.h +++ b/qtvplugin_geomarker/geoitembase.h @@ -1,4 +1,4 @@ -#ifndef GEOITEMBASE_H +#ifndef GEOITEMBASE_H #define GEOITEMBASE_H #include #include @@ -69,8 +69,10 @@ namespace QTVP_GEOMARKER{ protected: void setLevel (int currlevel); QTVOSM::viewer_interface * vi(){return m_pVi;} + virtual void adjust_coords(int nNewLevel) = 0; + virtual QPointF label_pos() = 0; public: - int level () {return m_nCurrentLevel;} + int level () const {return m_nCurrentLevel;} geo_item_type item_type () const {return m_type;} void set_item_type (geo_item_type tp) {m_type = tp;} QString item_name () const {return m_name;} @@ -93,10 +95,6 @@ namespace QTVP_GEOMARKER{ bool props_visible (); bool is_selected (); void set_selected (bool bsel); - public: - virtual void adjust_coords(int nNewLevel) = 0; - virtual QPointF label_pos() = 0; - virtual QPointF center_pos() = 0; }; } #endif // GEOITEMBASE_H diff --git a/qtvplugin_geomarker/qtvplugin_geomarker.cpp b/qtvplugin_geomarker/qtvplugin_geomarker.cpp index 1656c80..587076f 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker.cpp +++ b/qtvplugin_geomarker/qtvplugin_geomarker.cpp @@ -23,99 +23,97 @@ QMutex mutex_instances; QMap map_instances; QMap count_instances; qtvplugin_geomarker::qtvplugin_geomarker(QWidget *parent) : - QWidget(parent), - ui(new Ui::qtvplugin_geomarker), - m_currentTools(qtvplugin_geomarker::TOOLS_DISPLAY_ONLY), - m_sel_ptStart_World(0,0), - m_sel_ptEnd_World(0,0) + QWidget(parent), + ui(new Ui::qtvplugin_geomarker), + m_currentTools(qtvplugin_geomarker::TOOLS_DISPLAY_ONLY), + m_sel_ptStart_World(0,0), + m_sel_ptEnd_World(0,0) { - m_nInstance = 0; - ui->setupUi(this); - m_pVi = 0; - m_nDivideTimer = 0; - m_bVisible = true; - m_pScene = new QTVP_GEOMARKER::geoGraphicsScene(this); - m_pScene->setBackgroundBrush(Qt::NoBrush); - //senece is 256 * 2^level - m_pScene->setSceneRect(0,0,256,256); - - m_pGeoItemModel = new QStandardItemModel(this); - m_pGeoItemModel->setColumnCount(3); - m_pGeoItemModel->setHeaderData(0,Qt::Horizontal,tr("Name")); - m_pGeoItemModel->setHeaderData(1,Qt::Horizontal,tr("Type")); - m_pGeoItemModel->setHeaderData(2,Qt::Horizontal,tr("Props")); - ui->tableView_QTV_marks->setModel(m_pGeoItemModel); - - m_pSelItemNameModel = new QStandardItemModel(this); - m_pSelItemNameModel->setColumnCount(1); - m_pSelItemNameModel->setHeaderData(0,Qt::Horizontal,tr("Name")); - ui->tableView_QTV_marks_sel->setModel(m_pSelItemNameModel); - - - m_pGeoPropModel = new QStandardItemModel(this); - m_pGeoPropModel->setColumnCount(2); - m_pGeoPropModel->setHeaderData(0,Qt::Horizontal,tr("Name")); - m_pGeoPropModel->setHeaderData(1,Qt::Horizontal,tr("Value")); - ui->tableView_QTV_props->setModel(m_pGeoPropModel); - - m_pLineStyleModel = new QStandardItemModel(this); - m_pLineStyleModel->appendRow(new QStandardItem("NoPen")); - m_pLineStyleModel->appendRow(new QStandardItem("SolidLine")); - m_pLineStyleModel->appendRow(new QStandardItem("DashLine")); - m_pLineStyleModel->appendRow(new QStandardItem("DotLine")); - m_pLineStyleModel->appendRow(new QStandardItem("DashDotLine")); - m_pLineStyleModel->appendRow(new QStandardItem("DashDotDotLine")); - m_pLineStyleModel->appendRow(new QStandardItem("CustomDashLine")); - ui->comboBox_QTV_linePad->setModel(m_pLineStyleModel); - - m_pFillStyleModel = new QStandardItemModel(this); - m_pFillStyleModel->appendRow(new QStandardItem("NoBrush")); - m_pFillStyleModel->appendRow(new QStandardItem("SolidPattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense1Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense2Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense3Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense4Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense5Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense6Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("Dense7Pattern")); - m_pFillStyleModel->appendRow(new QStandardItem("HorPattern")); - m_pFillStyleModel->appendRow(new QStandardItem("VerPattern")); - m_pFillStyleModel->appendRow(new QStandardItem("CrossPattern")); - m_pFillStyleModel->appendRow(new QStandardItem("BDiagPattern")); - m_pFillStyleModel->appendRow(new QStandardItem("FDiagPattern")); - m_pFillStyleModel->appendRow(new QStandardItem("DiagCrossPattern")); - ui->comboBox_QTV_fillPad->setModel(m_pFillStyleModel); - - //insert 1 icons - QTVP_GEOMARKER::tag_icon icon; - icon.name = "default"; - icon.filename = "://icons/default.png"; - icon.centerx = 8; - icon.centery = 8; - if (icon.icon.load(icon.filename)) - m_map_icons[icon.name] = icon; - - - m_pIconsModel = new QStandardItemModel(this); - refreshIconModel(); - ui->comboBox_QTV_icons->setModel(m_pIconsModel); - - m_bNeedRefresh = false; - m_bNeedUpdateView = false; - m_nTimerID_refreshUI = startTimer(2000); - m_nTimerID_refreshMap = startTimer(100); - m_nTimerID_levelQueue = startTimer(100); - - ui->radioButton_QTV_display->setChecked(true); + m_nInstance = 0; + ui->setupUi(this); + m_pVi = 0; + m_nDivideTimer = 0; + m_bVisible = true; + m_pScene = new QTVP_GEOMARKER::geoGraphicsScene(this); + m_pScene->setBackgroundBrush(Qt::NoBrush); + //senece is 256 * 2^level + m_pScene->setSceneRect(0,0,256,256); + + m_pGeoItemModel = new QStandardItemModel(this); + m_pGeoItemModel->setColumnCount(3); + m_pGeoItemModel->setHeaderData(0,Qt::Horizontal,tr("Name")); + m_pGeoItemModel->setHeaderData(1,Qt::Horizontal,tr("Type")); + m_pGeoItemModel->setHeaderData(2,Qt::Horizontal,tr("Props")); + ui->tableView_QTV_marks->setModel(m_pGeoItemModel); + + m_pSelItemNameModel = new QStandardItemModel(this); + m_pSelItemNameModel->setColumnCount(1); + m_pSelItemNameModel->setHeaderData(0,Qt::Horizontal,tr("Name")); + ui->tableView_QTV_marks_sel->setModel(m_pSelItemNameModel); + + + m_pGeoPropModel = new QStandardItemModel(this); + m_pGeoPropModel->setColumnCount(2); + m_pGeoPropModel->setHeaderData(0,Qt::Horizontal,tr("Name")); + m_pGeoPropModel->setHeaderData(1,Qt::Horizontal,tr("Value")); + ui->tableView_QTV_props->setModel(m_pGeoPropModel); + + m_pLineStyleModel = new QStandardItemModel(this); + m_pLineStyleModel->appendRow(new QStandardItem("NoPen")); + m_pLineStyleModel->appendRow(new QStandardItem("SolidLine")); + m_pLineStyleModel->appendRow(new QStandardItem("DashLine")); + m_pLineStyleModel->appendRow(new QStandardItem("DotLine")); + m_pLineStyleModel->appendRow(new QStandardItem("DashDotLine")); + m_pLineStyleModel->appendRow(new QStandardItem("DashDotDotLine")); + m_pLineStyleModel->appendRow(new QStandardItem("CustomDashLine")); + ui->comboBox_QTV_linePad->setModel(m_pLineStyleModel); + + m_pFillStyleModel = new QStandardItemModel(this); + m_pFillStyleModel->appendRow(new QStandardItem("NoBrush")); + m_pFillStyleModel->appendRow(new QStandardItem("SolidPattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense1Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense2Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense3Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense4Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense5Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense6Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("Dense7Pattern")); + m_pFillStyleModel->appendRow(new QStandardItem("HorPattern")); + m_pFillStyleModel->appendRow(new QStandardItem("VerPattern")); + m_pFillStyleModel->appendRow(new QStandardItem("CrossPattern")); + m_pFillStyleModel->appendRow(new QStandardItem("BDiagPattern")); + m_pFillStyleModel->appendRow(new QStandardItem("FDiagPattern")); + m_pFillStyleModel->appendRow(new QStandardItem("DiagCrossPattern")); + ui->comboBox_QTV_fillPad->setModel(m_pFillStyleModel); + + //insert 1 icons + QTVP_GEOMARKER::tag_icon icon; + icon.name = "default"; + icon.filename = "://icons/default.png"; + icon.centerx = 8; + icon.centery = 8; + if (icon.icon.load(icon.filename)) + m_map_icons[icon.name] = icon; + + + m_pIconsModel = new QStandardItemModel(this); + refreshIconModel(); + ui->comboBox_QTV_icons->setModel(m_pIconsModel); + + m_bNeedRefresh = false; + m_bNeedUpdateView = false; + m_nTimerID_refreshUI = startTimer(2000); + m_nTimerID_refreshMap = startTimer(100); + ui->radioButton_QTV_display->setChecked(true); } qtvplugin_geomarker::~qtvplugin_geomarker() { - delete ui; + delete ui; } void qtvplugin_geomarker::load_retranslate_UI() { - ui->retranslateUi(this); + ui->retranslateUi(this); } /*! load_initial_plugin will be called when this plug in being loaded. * Please notice that a global parament "map_instances" is introduced, for multi-instance situation @@ -127,385 +125,353 @@ void qtvplugin_geomarker::load_retranslate_UI() */ layer_interface * qtvplugin_geomarker::load_initial_plugin(QString strSLibPath,viewer_interface * ptrviewer) { - //!In this instance, we will see how to create a new instance for each ptrviewer - qtvplugin_geomarker * instance = 0; - //!1.Check whether there is already a instance for ptrviewer( viewer_interface) - mutex_instances.lock(); - //!1.1 situation 1: map_instances is empty, which means no instance exists. We just save this pointer to map_instances - if (map_instances.empty()==true) - { - map_instances[ptrviewer] = this; - instance = this; - } - /*! 1.2 situation 2: map_instances dose not contain ptrviewer, which is the normal situation when a second ocx ctrl is initializing. + //!In this instance, we will see how to create a new instance for each ptrviewer + qtvplugin_geomarker * instance = 0; + //!1.Check whether there is already a instance for ptrviewer( viewer_interface) + mutex_instances.lock(); + //!1.1 situation 1: map_instances is empty, which means no instance exists. We just save this pointer to map_instances + if (map_instances.empty()==true) + { + map_instances[ptrviewer] = this; + instance = this; + } + /*! 1.2 situation 2: map_instances dose not contain ptrviewer, which is the normal situation when a second ocx ctrl is initializing. * we just allocate a new qtvplugin_geomarker, and save key-value in map_instances. */ - else if (map_instances.contains(ptrviewer)==false) - { - instance = new qtvplugin_geomarker; - map_instances[ptrviewer] = instance; - } - //! 1.3 situation 3: a ABNORMAL situation. load_initial_plugin is called again. - else - instance = map_instances[ptrviewer]; + else if (map_instances.contains(ptrviewer)==false) + { + instance = new qtvplugin_geomarker; + map_instances[ptrviewer] = instance; + } + //! 1.3 situation 3: a ABNORMAL situation. load_initial_plugin is called again. + else + instance = map_instances[ptrviewer]; + mutex_instances.unlock(); + //2. if the instance is just this object, we do real init code. + if (instance==this) + { + QFileInfo info(strSLibPath); + m_SLLibPath = strSLibPath; + m_SLLibName = info.completeBaseName(); + m_pVi = ptrviewer; + + mutex_instances.lock(); + m_nInstance = ++count_instances[m_SLLibName]; mutex_instances.unlock(); - //2. if the instance is just this object, we do real init code. - if (instance==this) - { - QFileInfo info(strSLibPath); - m_SLLibPath = strSLibPath; - m_SLLibName = info.completeBaseName(); - m_pVi = ptrviewer; - - mutex_instances.lock(); - m_nInstance = ++count_instances[m_SLLibName]; - mutex_instances.unlock(); - - loadTranslations(); - ini_load(); - style_load(); - initialBindPluginFuntions(); - } - //3. elseif, we call the instance's load_initial_plugin method instead - else - { - layer_interface * ret = instance->load_initial_plugin(strSLibPath,ptrviewer); - assert(ret==instance); - return ret; - } - qDebug()<load_initial_plugin(strSLibPath,ptrviewer); + assert(ret==instance); + return ret; + } + qDebug()<installTranslator(&pluginTranslator); - ui->retranslateUi(this); - } - else - QTVOSM_WARNING("Load translationfile")<<"\n\t"<installTranslator(&pluginTranslator); + ui->retranslateUi(this); } + else + QTVOSM_WARNING("Load translationfile")<<"\n\t"<level(); - if (currentLevel <=7) - { - //skip painting when there are too many marks on map - int reduce_limit = (1<m_pScene->total_items()>=reduce_limit) - res = true; - } + bool res = false; + if (!m_pVi || m_bVisible==false) return res; + int currentLevel = m_pVi->level(); + if (currentLevel <=7) + { + //skip painting when there are too many marks on map + int reduce_limit = (1<m_pScene->total_items()>=reduce_limit) + res = true; + } + return res; } void qtvplugin_geomarker::cb_paintEvent( QPainter * pImage ) { - if (!m_pVi || m_bVisible==false) - return ; - QRect rect = m_pVi->windowRect(); - // Calc current viewport in world - double leftcenx, topceny, rightcenx, bottomceny; - m_pVi->CV_DP2World(0,0,&leftcenx,&topceny); - m_pVi->CV_DP2World(rect.width()-1,rect.height()-1,&rightcenx,&bottomceny); - - int winsz = 256 * (1<level()); - - QRectF destin( - 0, - 0, - rect.width(), - rect.height() - ); - if (too_many_items()==false) + if (!m_pVi || m_bVisible==false) + return ; + QRect rect = m_pVi->windowRect(); + // Calc current viewport in world + double leftcenx, topceny, rightcenx, bottomceny; + m_pVi->CV_DP2World(0,0,&leftcenx,&topceny); + m_pVi->CV_DP2World(rect.width()-1,rect.height()-1,&rightcenx,&bottomceny); + + int winsz = 256 * (1<level()); + + QRectF destin( + 0, + 0, + rect.width(), + rect.height() + ); + //Warpping 180, -180. because longitude +180 and -180 is the same point, + // but the map is plat, -180 and + 180 is quite different positions, we + // should draw 3 times, to slove cross 180 drawing problems. + for (int p = -1; p<=1 ;++p) + { + QRectF source( + leftcenx + p * winsz, + topceny, + (rightcenx - leftcenx), + (bottomceny - topceny) + ); + + m_pScene->render(pImage,destin,source); + + } + + + //draw current tools + switch (m_currentTools) + { + case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + { + QPen pen_sel(QColor(128,64,0,128)); + pen_sel.setWidth(3); + pen_sel.setStyle(Qt::DashLine); + pImage->setPen(pen_sel); + pImage->drawText(32,32,"GEO MARKER Rect-Selection Tools Actived."); + QRectF wrct = current_sel_RectWorld(); + if (wrct.isValid()) { - //Warpping 180, -180. because longitude +180 and -180 is the same point, - // but the map is plat, -180 and + 180 is quite different positions, we - // should draw 3 times, to slove cross 180 drawing problems. - for (int p = -1; p<=1 ;++p) - { - QRectF source( - leftcenx + p * winsz, - topceny, - (rightcenx - leftcenx), - (bottomceny - topceny) - ); - - m_pScene->render(pImage,destin,source); - - } - } - else - { - QPen pen(QColor(255,0,0,128)); - pen.setWidth(m_pVi->level()/2+1); - pImage->setPen(pen); - QList items - = m_pScene->geo_items(); - foreach (QTVP_GEOMARKER::geoItemBase * pitem, items) - { - QPointF pt = pitem->center_pos(); - qint32 x,y; - m_pVi->CV_World2DP(pt.x(),pt.y(),&x,&y); - pImage->drawPoint(x,y); - } - } - //draw progres - double pc = m_pScene->progress_queue(); - if (pc<0.999) - { - QBrush br1(QColor(255,0,0,128)); - QBrush br2(QColor(0,255,0,128)); - pImage->setBrush(br1); - int left = rect.center().x()-128; - int top = rect.center().y()-16; - pImage->drawRect(left,top,256,32); - pImage->setBrush(br2); - pImage->drawRect(left,top,256*pc,32); - QString strmsg= tr("Level Re-Coord %1 %%").arg(pc*100); - pImage->drawText(left+32,top+16,strmsg); - } - //draw current tools - switch (m_currentTools) - { - case qtvplugin_geomarker::TOOLS_RECT_SELECTION: - { - QPen pen_sel(QColor(128,64,0,128)); - pen_sel.setWidth(3); - pen_sel.setStyle(Qt::DashLine); - pImage->setPen(pen_sel); - pImage->drawText(32,32,"GEO MARKER Rect-Selection Tools Actived."); - QRectF wrct = current_sel_RectWorld(); - if (wrct.isValid()) - { - double x1 = wrct.left(); - double y1 = wrct.top(); - double x2 = wrct.right(); - double y2 = wrct.bottom(); - qint32 nx1,ny1,nx2,ny2; - m_pVi->CV_World2DP(x1,y1,&nx1,&ny1); - m_pVi->CV_World2DP(x2,y2,&nx2,&ny2); - for (int i = -1;i<=1;++i) - { - pImage->drawLine(nx1 + i * winsz,ny1,nx1 + i * winsz,ny2); - pImage->drawLine(nx1 + i * winsz,ny2,nx2 + i * winsz,ny2); - pImage->drawLine(nx2 + i * winsz,ny2,nx2 + i * winsz,ny1); - pImage->drawLine(nx2 + i * winsz,ny1,nx1 + i * winsz,ny1); - } - } - } - break; - default: - break; + double x1 = wrct.left(); + double y1 = wrct.top(); + double x2 = wrct.right(); + double y2 = wrct.bottom(); + qint32 nx1,ny1,nx2,ny2; + m_pVi->CV_World2DP(x1,y1,&nx1,&ny1); + m_pVi->CV_World2DP(x2,y2,&nx2,&ny2); + for (int i = -1;i<=1;++i) + { + pImage->drawLine(nx1 + i * winsz,ny1,nx1 + i * winsz,ny2); + pImage->drawLine(nx1 + i * winsz,ny2,nx2 + i * winsz,ny2); + pImage->drawLine(nx2 + i * winsz,ny2,nx2 + i * winsz,ny1); + pImage->drawLine(nx2 + i * winsz,ny1,nx1 + i * winsz,ny1); + } } + } + break; + default: + break; + } } void qtvplugin_geomarker::cb_levelChanged(int level) { - if (!m_pVi) - return ; - m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(); - //Adjust new Scene rect - QRectF rect(0,0,256*(1<set_visible(false); - m_pScene->adjust_item_coords(level); - m_pScene->setSceneRect(rect); - this->set_visible(true); + if (!m_pVi) + return ; + m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(); + //Adjust new Scene rect + QRectF rect(0,0,256*(1<set_visible(false); + m_pScene->setSceneRect(rect); + this->set_visible(true); } bool qtvplugin_geomarker::is_visible() { - return m_bVisible; + return m_bVisible; } void qtvplugin_geomarker::set_visible(bool vb) { - m_bVisible = vb; + m_bVisible = vb; } void qtvplugin_geomarker::set_active(bool ab) { - if (ab==true) - { - if (m_currentTools==qtvplugin_geomarker::TOOLS_DISPLAY_ONLY) - { - ui->radioButton_QTV_rect_selection->setChecked(true); - m_currentTools = qtvplugin_geomarker::TOOLS_RECT_SELECTION; - } - } - else + if (ab==true) + { + if (m_currentTools==qtvplugin_geomarker::TOOLS_DISPLAY_ONLY) { - m_currentTools = qtvplugin_geomarker::TOOLS_DISPLAY_ONLY; - ui->radioButton_QTV_display->setChecked(true); + ui->radioButton_QTV_rect_selection->setChecked(true); + m_currentTools = qtvplugin_geomarker::TOOLS_RECT_SELECTION; } + } + else + { + m_currentTools = qtvplugin_geomarker::TOOLS_DISPLAY_ONLY; + ui->radioButton_QTV_display->setChecked(true); + } } QString qtvplugin_geomarker::get_name() { - QString strName = m_SLLibName.mid(10); - if (m_SLLibName.left(3)=="lib") - strName = m_SLLibName.mid(13); - if (strName.length()) - return strName/* + QString("%1").arg(m_nInstance)*/; - else - return "geomarker"; + QString strName = m_SLLibName.mid(10); + if (m_SLLibName.left(3)=="lib") + strName = m_SLLibName.mid(13); + if (strName.length()) + return strName/* + QString("%1").arg(m_nInstance)*/; + else + return "geomarker"; } void qtvplugin_geomarker::set_name(QString /*vb*/) { - if (!m_pVi) - return ; + if (!m_pVi) + return ; } QRectF qtvplugin_geomarker::CV_RectWrold2Mkt(QRectF world) { - if (!m_pVi) return QRectF(); - double mx1,my1,mx2,my2; - m_pVi->CV_World2MK(world.left(),world.top(),&mx1,&my1); - m_pVi->CV_World2MK(world.right(),world.bottom(),&mx2,&my2); - return QRectF(QPointF(mx1,my1),QPointF(mx2,my2)); + if (!m_pVi) return QRectF(); + double mx1,my1,mx2,my2; + m_pVi->CV_World2MK(world.left(),world.top(),&mx1,&my1); + m_pVi->CV_World2MK(world.right(),world.bottom(),&mx2,&my2); + return QRectF(QPointF(mx1,my1),QPointF(mx2,my2)); } QRectF qtvplugin_geomarker::current_sel_RectWorld() { - if (!m_pVi) return QRectF(); - if (m_currentTools!=qtvplugin_geomarker::TOOLS_RECT_SELECTION) - return QRectF(); - if (m_sel_ptEnd_World.isNull() || m_sel_ptStart_World.isNull()) - return QRectF(); - qint32 wsz = 256*(1<level()); - int wx1 = m_sel_ptStart_World.x(),wx2 = m_sel_ptEnd_World.x(), - wy1 = m_sel_ptStart_World.y(), wy2 = m_sel_ptEnd_World.y(); - while (wx2 - wx1 > wsz/2) - wx1+=wsz; - while (wx2 - wx1 < -wsz/2) - wx2+=wsz; - if (wx1 > wx2) - { - float tp = wx1; - wx1 = wx2; - wx2 = tp; - } - if (wy1 > wy2) - { - float tp = wy1; - wy1 = wy2; - wy2 = tp; - } - - return QRectF(QPointF(wx1,wy1),QPointF(wx2,wy2)); + if (!m_pVi) return QRectF(); + if (m_currentTools!=qtvplugin_geomarker::TOOLS_RECT_SELECTION) + return QRectF(); + if (m_sel_ptEnd_World.isNull() || m_sel_ptStart_World.isNull()) + return QRectF(); + qint32 wsz = 256*(1<level()); + int wx1 = m_sel_ptStart_World.x(),wx2 = m_sel_ptEnd_World.x(), + wy1 = m_sel_ptStart_World.y(), wy2 = m_sel_ptEnd_World.y(); + while (wx2 - wx1 > wsz/2) + wx1+=wsz; + while (wx2 - wx1 < -wsz/2) + wx2+=wsz; + if (wx1 > wx2) + { + float tp = wx1; + wx1 = wx2; + wx2 = tp; + } + if (wy1 > wy2) + { + float tp = wy1; + wy1 = wy2; + wy2 = tp; + } + + return QRectF(QPointF(wx1,wy1),QPointF(wx2,wy2)); } void qtvplugin_geomarker::clearSelection() { - if (!m_pVi) - return ; - foreach (QString name, m_set_itemNameSelected) - { - QTVP_GEOMARKER::geoItemBase * it = m_pScene->geoitem_by_name(name); - if (it) - it->set_selected(false); - } - - m_set_itemNameSelected.clear(); - refresh_selection_listview(); - m_pVi->UpdateWindow(); + if (!m_pVi) + return ; + foreach (QString name, m_set_itemNameSelected) + { + QTVP_GEOMARKER::geoItemBase * it = m_pScene->geoitem_by_name(name); + if (it) + it->set_selected(false); + } + + m_set_itemNameSelected.clear(); + refresh_selection_listview(); + m_pVi->UpdateWindow(); } void qtvplugin_geomarker::addSelection(QRectF rectWorld) { - qint32 wsz = 256*(1<level()); - bool changed = false; - for (int i=-1;i<=1;++i) + qint32 wsz = 256*(1<level()); + bool changed = false; + for (int i=-1;i<=1;++i) + { + double x1 = rectWorld.left()+i * wsz, + y1 = rectWorld.top(), + x2 = rectWorld.right()+i * wsz, + y2 = rectWorld.bottom(); + + QList itmesel = m_pScene->items(QRectF(QPointF(x1,y1),QPointF(x2,y2))); + foreach (QGraphicsItem * it, itmesel) { - double x1 = rectWorld.left()+i * wsz, - y1 = rectWorld.top(), - x2 = rectWorld.right()+i * wsz, - y2 = rectWorld.bottom(); - - QList itmesel = m_pScene->items(QRectF(QPointF(x1,y1),QPointF(x2,y2))); - foreach (QGraphicsItem * it, itmesel) + QTVP_GEOMARKER::geoItemBase * + gi = dynamic_cast(it); + if (gi) + { + changed = true; + QString nm = gi->item_name(); + if (m_set_itemNameSelected.contains(nm)) { - QTVP_GEOMARKER::geoItemBase * - gi = dynamic_cast(it); - if (gi) - { - changed = true; - QString nm = gi->item_name(); - if (m_set_itemNameSelected.contains(nm)) - { - m_set_itemNameSelected.remove(nm); - gi->set_selected(false); - } - else - { - m_set_itemNameSelected.insert(nm); - gi->set_selected(true); - } - - } + m_set_itemNameSelected.remove(nm); + gi->set_selected(false); } + else + { + m_set_itemNameSelected.insert(nm); + gi->set_selected(true); + } + + } } - if (changed) - { - refresh_selection_listview(); - scheduleUpdateMap(); - } + } + if (changed) + { + refresh_selection_listview(); + scheduleUpdateMap(); + } } bool qtvplugin_geomarker::cb_event(const QMap para) { - if (para["source"]==this->get_name() && para["name"]=="ITEM_MOUSE_ENTER") + if (para["source"]==this->get_name() && para["name"]=="ITEM_MOUSE_ENTER") + { + if (ui->checkBox_QTV_hoverEvt_AutoLabel->isChecked()) { - if (ui->checkBox_QTV_hoverEvt_AutoLabel->isChecked()) + const QString key = para["id"].toString(); + if (key.length()) + { + QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(key); + if (base) { - const QString key = para["id"].toString(); - if (key.length()) - { - QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(key); - if (base) - { - base->show_props(true); - scheduleUpdateMap(); - } - } + base->show_props(true); + scheduleUpdateMap(); } + } } - if (para["source"]==this->get_name() && para["name"]=="ITEM_MOUSE_LEAVE") + } + if (para["source"]==this->get_name() && para["name"]=="ITEM_MOUSE_LEAVE") + { + if (ui->checkBox_QTV_hoverEvt_AutoLabel->isChecked()) { - if (ui->checkBox_QTV_hoverEvt_AutoLabel->isChecked()) + const QString key = para["id"].toString(); + if (key.length()) + { + QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(key); + if (base) { - const QString key = para["id"].toString(); - if (key.length()) - { - QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(key); - if (base) - { - base->show_props(false); - scheduleUpdateMap(); - } - } + base->show_props(false); + scheduleUpdateMap(); } - } return false; + } + } + } return false; } /*! qtvplugin_geomarker::cb_mouseXXXEvent tranfer mouse events from main view to @@ -519,51 +485,51 @@ bool qtvplugin_geomarker::cb_event(const QMap para) */ bool qtvplugin_geomarker::cb_mouseDoubleClickEvent(QMouseEvent * e) { - if (!m_pVi) - return false; - if (m_bVisible==false) - return false; - QPoint mouse_view_pt = e->pos(); - int winsz = 256 * (1<level()); - double wx,wy; - double mlat, mlon; - m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); - m_pVi->CV_DP2LLA(mouse_view_pt.x(),mouse_view_pt.y(),&mlat,&mlon); - if (e->button()==Qt::RightButton) - { - ui->lineEdit_QTV_point_lat->setText(QString("%1").arg(mlat,0,'f',7)); - ui->lineEdit_QTV_point_lon->setText(QString("%1").arg(mlon,0,'f',7)); - ui->lineEdit_QTV_icon_lat->setText(QString("%1").arg(mlat,0,'f',7)); - ui->lineEdit_QTV_icon_lon->setText(QString("%1").arg(mlon,0,'f',7)); - } - //Warp - while (wx < 0) wx += winsz; - while (wx > winsz-1) wx -= winsz; - - QPointF mouse_scene_pt(wx,wy); - QPoint mouse_screen_pt = e->globalPos(); - Qt::MouseButton mouse_button = e->button(); - QWidget * pwig = dynamic_cast (m_pVi); - if (m_bVisible && pwig && too_many_items()==false) - { - // Convert and deliver the mouse event to the scene. - QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseDoubleClick); - QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent; - mouseEvent.setWidget(pwig); - mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt); - mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt); - mouseEvent.setScenePos(mouse_scene_pt); - mouseEvent.setScreenPos(mouse_screen_pt); - mouseEvent.setLastScenePos(mouse_scene_pt); - mouseEvent.setLastScreenPos(mouse_screen_pt); - mouseEvent.setButtons(e->buttons()); - mouseEvent.setButton(e->button()); - mouseEvent.setModifiers(e->modifiers()); - mouseEvent.setAccepted(false); - QApplication::postEvent(m_pScene, &mouseEvent); - scheduleUpdateMap(); - } + if (!m_pVi) return false; + if (m_bVisible==false) + return false; + QPoint mouse_view_pt = e->pos(); + int winsz = 256 * (1<level()); + double wx,wy; + double mlat, mlon; + m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); + m_pVi->CV_DP2LLA(mouse_view_pt.x(),mouse_view_pt.y(),&mlat,&mlon); + if (e->button()==Qt::RightButton) + { + ui->lineEdit_QTV_point_lat->setText(QString("%1").arg(mlat,0,'f',7)); + ui->lineEdit_QTV_point_lon->setText(QString("%1").arg(mlon,0,'f',7)); + ui->lineEdit_QTV_icon_lat->setText(QString("%1").arg(mlat,0,'f',7)); + ui->lineEdit_QTV_icon_lon->setText(QString("%1").arg(mlon,0,'f',7)); + } + //Warp + while (wx < 0) wx += winsz; + while (wx > winsz-1) wx -= winsz; + + QPointF mouse_scene_pt(wx,wy); + QPoint mouse_screen_pt = e->globalPos(); + Qt::MouseButton mouse_button = e->button(); + QWidget * pwig = dynamic_cast (m_pVi); + if (m_bVisible && pwig && too_many_items()==false) + { + // Convert and deliver the mouse event to the scene. + QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseDoubleClick); + QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent; + mouseEvent.setWidget(pwig); + mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt); + mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt); + mouseEvent.setScenePos(mouse_scene_pt); + mouseEvent.setScreenPos(mouse_screen_pt); + mouseEvent.setLastScenePos(mouse_scene_pt); + mouseEvent.setLastScreenPos(mouse_screen_pt); + mouseEvent.setButtons(e->buttons()); + mouseEvent.setButton(e->button()); + mouseEvent.setModifiers(e->modifiers()); + mouseEvent.setAccepted(false); + QApplication::postEvent(m_pScene, &mouseEvent); + scheduleUpdateMap(); + } + return false; } /*! qtvplugin_geomarker::cb_mouseXXXEvent tranfer mouse events from main view to * QGraphicsItem based classes, so that these items will recieve mouse events. @@ -576,151 +542,151 @@ bool qtvplugin_geomarker::cb_mouseDoubleClickEvent(QMouseEvent * e) */ bool qtvplugin_geomarker::cb_mousePressEvent(QMouseEvent * e) { - if (!m_pVi) - return false; - if (m_bVisible==false) - return false; - QPoint mouse_view_pt = e->pos(); - int winsz = 256 * (1<level()); - double wx,wy; - m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); - //Warp - while (wx < 0) wx += winsz; - while (wx > winsz-1) wx -= winsz; - - QPointF mouse_scene_pt(wx,wy); - QPoint mouse_screen_pt = e->globalPos(); - Qt::MouseButton mouse_button = e->button(); - QWidget * pwig = dynamic_cast (m_pVi); - if (m_bVisible && pwig && too_many_items()==false) - { - // Convert and deliver the mouse event to the scene. - QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress); - QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent; - mouseEvent.setWidget(pwig); - mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt); - mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt); - mouseEvent.setScenePos(mouse_scene_pt); - mouseEvent.setScreenPos(mouse_screen_pt); - mouseEvent.setLastScenePos(mouse_scene_pt); - mouseEvent.setLastScreenPos(mouse_screen_pt); - mouseEvent.setButtons(e->buttons()); - mouseEvent.setButton(e->button()); - mouseEvent.setModifiers(e->modifiers()); - mouseEvent.setAccepted(false); - QApplication::postEvent(m_pScene, &mouseEvent); - scheduleUpdateMap(); - } - //tools - switch (m_currentTools) - { - case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + if (!m_pVi) + return false; + if (m_bVisible==false) + return false; + QPoint mouse_view_pt = e->pos(); + int winsz = 256 * (1<level()); + double wx,wy; + m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); + //Warp + while (wx < 0) wx += winsz; + while (wx > winsz-1) wx -= winsz; + + QPointF mouse_scene_pt(wx,wy); + QPoint mouse_screen_pt = e->globalPos(); + Qt::MouseButton mouse_button = e->button(); + QWidget * pwig = dynamic_cast (m_pVi); + if (m_bVisible && pwig && too_many_items()==false) + { + // Convert and deliver the mouse event to the scene. + QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress); + QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent; + mouseEvent.setWidget(pwig); + mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt); + mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt); + mouseEvent.setScenePos(mouse_scene_pt); + mouseEvent.setScreenPos(mouse_screen_pt); + mouseEvent.setLastScenePos(mouse_scene_pt); + mouseEvent.setLastScreenPos(mouse_screen_pt); + mouseEvent.setButtons(e->buttons()); + mouseEvent.setButton(e->button()); + mouseEvent.setModifiers(e->modifiers()); + mouseEvent.setAccepted(false); + QApplication::postEvent(m_pScene, &mouseEvent); + scheduleUpdateMap(); + } + //tools + switch (m_currentTools) + { + case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + { + if (e->button()==Qt::LeftButton) { - if (e->button()==Qt::LeftButton) - { - m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(wx,wy); - } - } - break; - default: - break; + m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(wx,wy); } + } + break; + default: + break; + } - return false; + return false; } bool qtvplugin_geomarker::cb_mouseMoveEvent ( QMouseEvent * e ) { - if (!m_pVi) - return false; - if (m_bVisible==false) - return false; - QPoint mouse_view_pt = e->pos(); - int winsz = 256 * (1<level()); - double wx,wy; - m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); - //Warp - while (wx < 0) wx += winsz; - while (wx > winsz-1) wx -= winsz; - QPointF mouse_scene_pt(wx,wy); - QPoint mouse_screen_pt = e->globalPos(); - Qt::MouseButton mouse_button = e->button(); - QWidget * pwig = dynamic_cast (m_pVi); - if (m_bVisible && pwig && too_many_items()==false) - { - // Convert and deliver the mouse event to the scene. - QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove); - QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent; - mouseEvent.setWidget(pwig); - mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt); - mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt); - mouseEvent.setScenePos(mouse_scene_pt); - mouseEvent.setScreenPos(mouse_screen_pt); - mouseEvent.setLastScenePos(mouse_scene_pt); - mouseEvent.setLastScreenPos(mouse_screen_pt); - mouseEvent.setButtons(e->buttons()); - mouseEvent.setButton(e->button()); - mouseEvent.setModifiers(e->modifiers()); - mouseEvent.setAccepted(false); - QApplication::postEvent(m_pScene, &mouseEvent); - } - //tools - switch (m_currentTools) - { - case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + if (!m_pVi) + return false; + if (m_bVisible==false) + return false; + QPoint mouse_view_pt = e->pos(); + int winsz = 256 * (1<level()); + double wx,wy; + m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); + //Warp + while (wx < 0) wx += winsz; + while (wx > winsz-1) wx -= winsz; + QPointF mouse_scene_pt(wx,wy); + QPoint mouse_screen_pt = e->globalPos(); + Qt::MouseButton mouse_button = e->button(); + QWidget * pwig = dynamic_cast (m_pVi); + if (m_bVisible && pwig && too_many_items()==false) + { + // Convert and deliver the mouse event to the scene. + QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove); + QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent; + mouseEvent.setWidget(pwig); + mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt); + mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt); + mouseEvent.setScenePos(mouse_scene_pt); + mouseEvent.setScreenPos(mouse_screen_pt); + mouseEvent.setLastScenePos(mouse_scene_pt); + mouseEvent.setLastScreenPos(mouse_screen_pt); + mouseEvent.setButtons(e->buttons()); + mouseEvent.setButton(e->button()); + mouseEvent.setModifiers(e->modifiers()); + mouseEvent.setAccepted(false); + QApplication::postEvent(m_pScene, &mouseEvent); + } + //tools + switch (m_currentTools) + { + case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + { + if (e->buttons()==Qt::LeftButton) { - if (e->buttons()==Qt::LeftButton) - { - m_sel_ptEnd_World = QPointF(wx,wy); - scheduleUpdateMap(); - } - } - break; - default: - break; + m_sel_ptEnd_World = QPointF(wx,wy); + scheduleUpdateMap(); } + } + break; + default: + break; + } - return false; + return false; } bool qtvplugin_geomarker::cb_mouseReleaseEvent ( QMouseEvent * e ) { - if (!m_pVi) - return false; - if (m_bVisible==false) - return false; - QPoint mouse_view_pt = e->pos(); - int winsz = 256 * (1<level()); - double wx,wy; - m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); - //Warp - while (wx < 0) wx += winsz; - while (wx > winsz-1) wx -= winsz; - - //tools - switch (m_currentTools) - { - case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + if (!m_pVi) + return false; + if (m_bVisible==false) + return false; + QPoint mouse_view_pt = e->pos(); + int winsz = 256 * (1<level()); + double wx,wy; + m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy); + //Warp + while (wx < 0) wx += winsz; + while (wx > winsz-1) wx -= winsz; + + //tools + switch (m_currentTools) + { + case qtvplugin_geomarker::TOOLS_RECT_SELECTION: + { + if (e->button()==Qt::LeftButton) { - if (e->button()==Qt::LeftButton) - { - m_sel_ptEnd_World = QPointF(wx,wy); - QRectF rectSel = current_sel_RectWorld(); - m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(); - addSelection(rectSel); - scheduleUpdateMap(); - } - } - break; - default: - break; + m_sel_ptEnd_World = QPointF(wx,wy); + QRectF rectSel = current_sel_RectWorld(); + m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(); + addSelection(rectSel); + scheduleUpdateMap(); } + } + break; + default: + break; + } - return false; + return false; } @@ -733,13 +699,13 @@ bool qtvplugin_geomarker::cb_mouseReleaseEvent ( QMouseEvent * e ) */ QColor qtvplugin_geomarker::string2color(const QString & s) { - QStringList lst = s.split(",",QString::SkipEmptyParts); - int r = 255,g = 255, b = 255, a= 128; - if (lst.empty()==false) {r = lst.first().toInt(); lst.pop_front();} - if (lst.empty()==false) {g = lst.first().toInt(); lst.pop_front();} - if (lst.empty()==false) {b = lst.first().toInt(); lst.pop_front();} - if (lst.empty()==false) {a = lst.first().toInt(); lst.pop_front();} - return QColor(r,g,b,a); + QStringList lst = s.split(",",QString::SkipEmptyParts); + int r = 255,g = 255, b = 255, a= 128; + if (lst.empty()==false) {r = lst.first().toInt(); lst.pop_front();} + if (lst.empty()==false) {g = lst.first().toInt(); lst.pop_front();} + if (lst.empty()==false) {b = lst.first().toInt(); lst.pop_front();} + if (lst.empty()==false) {a = lst.first().toInt(); lst.pop_front();} + return QColor(r,g,b,a); } /*! for convenience, color is stored in plain text in XML and UI. * the plain text color is 4 sub value , which stands for r,g,b,alpha. @@ -750,442 +716,442 @@ QColor qtvplugin_geomarker::string2color(const QString & s) */ QString qtvplugin_geomarker::color2string(const QColor & col) { - QString str = QString("%1,%2,%3,%4").arg(col.red()).arg(col.green()).arg(col.blue()).arg(col.alpha()); - return str; + QString str = QString("%1,%2,%3,%4").arg(col.red()).arg(col.green()).arg(col.blue()).arg(col.alpha()); + return str; } QString qtvplugin_geomarker::ini_file() { - if (m_SLLibPath.size()) - return m_SLLibPath + QString("%1").arg(m_nInstance) + ".ini"; - else - return QCoreApplication::applicationFilePath() + QString("/geomarker%1.ini").arg(m_nInstance); + if (m_SLLibPath.size()) + return m_SLLibPath + QString("%1").arg(m_nInstance) + ".ini"; + else + return QCoreApplication::applicationFilePath() + QString("/geomarker%1.ini").arg(m_nInstance); } void qtvplugin_geomarker::scheduleRefreshMarks() { - if (!m_pVi || !m_pScene) - return; - //We do not refresh UI immediately after each mark-insert, for these inserts is very dense , - //BAD performence will arise if so. - //We will set a flag and refresh the ui in timerEvent Instead. - m_bNeedRefresh = true; - m_items_to_insert.clear(); + if (!m_pVi || !m_pScene) + return; + //We do not refresh UI immediately after each mark-insert, for these inserts is very dense , + //BAD performence will arise if so. + //We will set a flag and refresh the ui in timerEvent Instead. + m_bNeedRefresh = true; + m_items_to_insert.clear(); } void qtvplugin_geomarker::scheduleUpdateMap() { - if (!m_pVi || !m_pScene) - return; - //We do not refresh MAP immediately after each mark-insert, for these inserts is very dense , - //BAD performence will arise if so. - //We will set a flag and refresh the ui in timerEvent Instead. - m_bNeedUpdateView = true; + if (!m_pVi || !m_pScene) + return; + //We do not refresh MAP immediately after each mark-insert, for these inserts is very dense , + //BAD performence will arise if so. + //We will set a flag and refresh the ui in timerEvent Instead. + m_bNeedUpdateView = true; } void qtvplugin_geomarker::refresh_selection_listview() { - if (!m_pVi || !m_pScene) - return; - //refersh - this->m_pSelItemNameModel->removeRows(0,this->m_pSelItemNameModel->rowCount()); - foreach (QString name, m_set_itemNameSelected) - { - m_pSelItemNameModel->appendRow(new QStandardItem(name)); - } + if (!m_pVi || !m_pScene) + return; + //refersh + this->m_pSelItemNameModel->removeRows(0,this->m_pSelItemNameModel->rowCount()); + foreach (QString name, m_set_itemNameSelected) + { + m_pSelItemNameModel->appendRow(new QStandardItem(name)); + } } 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 - QStringList propNames; - QVariantList propValues; - if (base) + QTVP_GEOMARKER::geoItemBase * res = 0; + //Get raw Item by name + QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); + //Get Props + QStringList propNames; + QVariantList propValues; + if (base) + { + propNames = base->prop_names(); + propValues = base->prop_values(); + } + //type convertion to T + QTVP_GEOMARKER::geoGraphicsLineItem * pitem = base?dynamic_cast(base):0; + if (!pitem) + pitem = new QTVP_GEOMARKER::geoGraphicsLineItem(name, + this->m_pVi, + lat1,lon1,lat2,lon2); + + pitem->setPen(pen); + + if (base == pitem) + { + pitem->setGeo(lat1,lon1,lat2,lon2); + res = pitem; + } + else if (false==this->m_pScene->addItem(pitem,0)) + { + if (base != pitem) + delete pitem; + } + else + { + int cs = propNames.size(); + for (int i=0;iprop_names(); - propValues = base->prop_values(); + pitem->set_prop_data(propNames.first(), propValues.first()); + propNames.pop_front(); + propValues.pop_front(); } + res = pitem; + } + return res; +} + + +QTVP_GEOMARKER::geoItemBase * qtvplugin_geomarker::update_polygon (const QString & name,const QPolygonF latlons, QPen pen, QBrush brush, bool tp) +{ + QTVP_GEOMARKER::geoItemBase * res = 0; + //Get raw Item by name + QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); + //Get Props + QStringList propNames; + QVariantList propValues; + if (base) + { + propNames = base->prop_names(); + propValues = base->prop_values(); + } + if (tp==false) + { //type convertion to T - QTVP_GEOMARKER::geoGraphicsLineItem * pitem = base?dynamic_cast(base):0; + QTVP_GEOMARKER::geoGraphicsPolygonItem * pitem = base?dynamic_cast(base):0; if (!pitem) - pitem = new QTVP_GEOMARKER::geoGraphicsLineItem(name, - this->m_pVi, - lat1,lon1,lat2,lon2); - + pitem = new QTVP_GEOMARKER::geoGraphicsPolygonItem(name, + this->m_pVi, + latlons); pitem->setPen(pen); - + pitem->setBrush(brush); if (base == pitem) { - pitem->setGeo(lat1,lon1,lat2,lon2); - res = pitem; + pitem->setGeo(latlons); + res = pitem; } else if (false==this->m_pScene->addItem(pitem,0)) { - if (base != pitem) - delete pitem; + if (base != pitem) + delete pitem; } else { - int cs = propNames.size(); - for (int i=0;iset_prop_data(propNames.first(), propValues.first()); - propNames.pop_front(); - propValues.pop_front(); - } - res = pitem; + int cs = propNames.size(); + for (int i=0;iset_prop_data(propNames.first(), propValues.first()); + propNames.pop_front(); + propValues.pop_front(); + } + res = pitem; } - return res; -} - - -QTVP_GEOMARKER::geoItemBase * qtvplugin_geomarker::update_polygon (const QString & name,const QPolygonF latlons, QPen pen, QBrush brush, bool tp) -{ - QTVP_GEOMARKER::geoItemBase * res = 0; - //Get raw Item by name - QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); - //Get Props - QStringList propNames; - QVariantList propValues; - if (base) + } + else + { + //type convertion to T + QTVP_GEOMARKER::geoGraphicsMultilineItem * pitem = base?dynamic_cast(base):0; + if (!pitem) + pitem = new QTVP_GEOMARKER::geoGraphicsMultilineItem(name, + this->m_pVi, + latlons); + pitem->setPen(pen); + //pitem->setBrush(QBrush(Qt::NoBrush)); + if (base == pitem) { - propNames = base->prop_names(); - propValues = base->prop_values(); + pitem->setGeo(latlons); + res = pitem; } - if (tp==false) + else if (false==this->m_pScene->addItem(pitem,0)) { - //type convertion to T - QTVP_GEOMARKER::geoGraphicsPolygonItem * pitem = base?dynamic_cast(base):0; - if (!pitem) - pitem = new QTVP_GEOMARKER::geoGraphicsPolygonItem(name, - this->m_pVi, - latlons); - pitem->setPen(pen); - pitem->setBrush(brush); - if (base == pitem) - { - pitem->setGeo(latlons); - res = pitem; - } - else if (false==this->m_pScene->addItem(pitem,0)) - { - if (base != pitem) - delete pitem; - } - else - { - int cs = propNames.size(); - for (int i=0;iset_prop_data(propNames.first(), propValues.first()); - propNames.pop_front(); - propValues.pop_front(); - } - res = pitem; - } + if (base != pitem) + delete pitem; } else { - //type convertion to T - QTVP_GEOMARKER::geoGraphicsMultilineItem * pitem = base?dynamic_cast(base):0; - if (!pitem) - pitem = new QTVP_GEOMARKER::geoGraphicsMultilineItem(name, - this->m_pVi, - latlons); - pitem->setPen(pen); - //pitem->setBrush(QBrush(Qt::NoBrush)); - if (base == pitem) - { - pitem->setGeo(latlons); - res = pitem; - } - else if (false==this->m_pScene->addItem(pitem,0)) - { - if (base != pitem) - delete pitem; - } - else - { - int cs = propNames.size(); - for (int i=0;iset_prop_data(propNames.first(), propValues.first()); - propNames.pop_front(); - propValues.pop_front(); - } - res = pitem; - } + int cs = propNames.size(); + for (int i=0;iset_prop_data(propNames.first(), propValues.first()); + propNames.pop_front(); + propValues.pop_front(); + } + res = pitem; } + } - return res; + return res; } QTVP_GEOMARKER::geoItemBase * qtvplugin_geomarker::update_icon(const QString & name,double lat, double lon,qreal scale, qreal rotate,int smooth, QString id) { - QTVP_GEOMARKER::geoItemBase * res = 0; - //Get raw Item by name - QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); - //Get Props - QStringList propNames; - QVariantList propValues; - if (base) + QTVP_GEOMARKER::geoItemBase * res = 0; + //Get raw Item by name + QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); + //Get Props + QStringList propNames; + QVariantList propValues; + if (base) + { + propNames = base->prop_names(); + propValues = base->prop_values(); + } + //type convertion to T + QTVP_GEOMARKER::geoGraphicsPixmapItem * pitem = base?dynamic_cast(base):0; + if (!pitem) + { + const QTVP_GEOMARKER::tag_icon * iconp = 0; + if (m_map_icons.contains(id)) + iconp = &m_map_icons[id]; + else + iconp = &m_map_icons["default"]; + + pitem = new QTVP_GEOMARKER::geoGraphicsPixmapItem(name,this->m_pVi, + iconp, + lat,lon + ); + } + if (base == pitem) + { + pitem->setGeo(lat,lon); + if (m_map_icons.contains(id)) + pitem->setPixmap(m_map_icons[id]); + else + pitem->setPixmap(m_map_icons["default"]); + res = pitem; + } + else if (false==this->m_pScene->addItem(pitem,0)) + { + if (base != pitem) { - propNames = base->prop_names(); - propValues = base->prop_values(); + delete pitem; + pitem = 0; } - //type convertion to T - QTVP_GEOMARKER::geoGraphicsPixmapItem * pitem = base?dynamic_cast(base):0; - if (!pitem) + } + else + { + int cs = propNames.size(); + for (int i=0;im_pVi, - iconp, - lat,lon - ); + pitem->set_prop_data(propNames.first(), propValues.first()); + propNames.pop_front(); + propValues.pop_front(); } - if (base == pitem) + res = pitem; + } + if (pitem) + { + pitem->setScale(scale); + pitem->setRotation(rotate); + if (smooth) + pitem->setTransformationMode(Qt::SmoothTransformation); + else + pitem->setTransformationMode(Qt::FastTransformation); + pitem->adjustLabelPos(); + } + return res; +} +bool qtvplugin_geomarker::cmd_save (QString cmdFile) +{ + QFile fp(cmdFile); + if (fp.open(QIODevice::WriteOnly)==false) + return false; + QTextStream stream_out(&fp); + //1. for each mark, write a root element + QList items = m_pScene->geo_items(); + foreach (QTVP_GEOMARKER::geoItemBase * item, items) + { + QString cmd_str; + QTVP_GEOMARKER::geo_item_type x_tp = item->item_type(); + QString x_name = item->item_name(); + + //1.1. Mark + switch (x_tp) { - pitem->setGeo(lat,lon); - if (m_map_icons.contains(id)) - pitem->setPixmap(m_map_icons[id]); - else - pitem->setPixmap(m_map_icons["default"]); - res = pitem; + case QTVP_GEOMARKER::ITEAMTYPE_RECT_POINT: + { + QTVP_GEOMARKER::geoGraphicsRectItem * pU = dynamic_cast(item); + if (pU) + { + cmd_str += "function=update_point;name="+x_name+QString(";type=%1;").arg(x_tp); + cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7); + //1.2 style + cmd_str += "width="+ QString("%1;").arg(pU->width()); + cmd_str += "height="+ QString("%1;").arg(pU->height()); + cmd_str += "color_pen="+ color2string(pU->pen().color())+";"; + cmd_str += "style_pen="+ QString("%1;").arg(int(pU->pen().style())); + cmd_str += "width_pen="+ QString("%1;").arg(int(pU->pen().width())); + cmd_str += "color_brush="+ color2string(pU->brush().color())+";"; + cmd_str += "style_brush="+ QString("%1;").arg(int(pU->brush().style())); + } } - else if (false==this->m_pScene->addItem(pitem,0)) + break; + case QTVP_GEOMARKER::ITEAMTYPE_ELLIPSE_POINT: { - if (base != pitem) - { - delete pitem; - pitem = 0; - } + QTVP_GEOMARKER::geoGraphicsEllipseItem * pU = dynamic_cast(item); + if (pU) + { + cmd_str += "function=update_point;name="+x_name+QString(";type=%1;").arg(x_tp); + cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7); + //1.2 style + cmd_str += "width="+ QString("%1;").arg(pU->width()); + cmd_str += "height="+ QString("%1;").arg(pU->height()); + cmd_str += "color_pen="+ color2string(pU->pen().color())+";"; + cmd_str += "style_pen="+ QString("%1;").arg(int(pU->pen().style())); + cmd_str += "width_pen="+ QString("%1;").arg(int(pU->pen().width())); + cmd_str += "color_brush="+ color2string(pU->brush().color())+";"; + cmd_str += "style_brush="+ QString("%1;").arg(int(pU->brush().style())); + } } - else + break; + case QTVP_GEOMARKER::ITEAMTYPE_LINE: { - int cs = propNames.size(); - for (int i=0;i(item); + if (pU) + { + cmd_str += "function=update_line;name="+x_name+QString(";type=%1;").arg(x_tp); + cmd_str += QString("lat0=%1;lon0=%2;").arg(pU->lat1(),0,'f',7).arg(pU->lon1(),0,'f',7); + cmd_str += QString("lat1=%1;lon1=%2;").arg(pU->lat2(),0,'f',7).arg(pU->lon2(),0,'f',7); + //1.2 style + cmd_str += "color_pen=" + color2string(pU->pen().color())+";"; + cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style())); + cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width())); + } + } + break; + case QTVP_GEOMARKER::ITEAMTYPE_POLYGON: + { + QTVP_GEOMARKER::geoGraphicsPolygonItem * pU = dynamic_cast(item); + if (pU) + { + cmd_str += "function=update_polygon;name="+x_name+QString(";type=%1;").arg(x_tp); + QPolygonF pl = pU->llas(); + int nPl = pl.size(); + int ct_pg = 0; + foreach (QPointF pf, pl) { - pitem->set_prop_data(propNames.first(), propValues.first()); - propNames.pop_front(); - propValues.pop_front(); + cmd_str += QString("lat%3=%1;lon%3=%2;").arg(pf.y(),0,'f',7).arg(pf.x(),0,'f',7).arg(ct_pg); + ++ct_pg; } - res = pitem; + cmd_str += "color_pen=" + color2string(pU->pen().color())+";"; + cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style())); + cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width())); + cmd_str += "color_brush=" + color2string(pU->brush().color())+";"; + cmd_str += "style_brush=" + QString("%1;").arg(int(pU->brush().style())); + } } - if (pitem) + break; + case QTVP_GEOMARKER::ITEAMTYPE_PIXMAP: { - pitem->setScale(scale); - pitem->setRotation(rotate); - if (smooth) - pitem->setTransformationMode(Qt::SmoothTransformation); - else - pitem->setTransformationMode(Qt::FastTransformation); - pitem->adjustLabelPos(); + QTVP_GEOMARKER::geoGraphicsPixmapItem * pU = dynamic_cast(item); + if (pU) + { + cmd_str += "function=update_icon;name="+x_name+QString(";type=%1;").arg(x_tp); + //1.2. geo + cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7); + //1.2 style + cmd_str += "icon=" +QString("%1;").arg(pU->icon()->name); + cmd_str += "scale=" +QString("%1;").arg(pU->scale()); + cmd_str += "rotate=" +QString("%1;").arg(pU->rotation()); + cmd_str += "smooth=" +QString("%1;").arg(pU->transformationMode()==Qt::SmoothTransformation?1:0); + } } - return res; -} -bool qtvplugin_geomarker::cmd_save (QString cmdFile) -{ - QFile fp(cmdFile); - if (fp.open(QIODevice::WriteOnly)==false) - return false; - QTextStream stream_out(&fp); - //1. for each mark, write a root element - QList items = m_pScene->geo_items(); - foreach (QTVP_GEOMARKER::geoItemBase * item, items) + break; + case QTVP_GEOMARKER::ITEAMTYPE_MULTILINE: { - QString cmd_str; - QTVP_GEOMARKER::geo_item_type x_tp = item->item_type(); - QString x_name = item->item_name(); - - //1.1. Mark - switch (x_tp) + QTVP_GEOMARKER::geoGraphicsMultilineItem * pU = dynamic_cast(item); + if (pU) + { + cmd_str += "function=update_polygon;name="+x_name+QString(";type=%1;").arg(x_tp); + QPolygonF pl = pU->llas(); + int nPl = pl.size(); + int ct_pg = 0; + foreach (QPointF pf, pl) { - case QTVP_GEOMARKER::ITEAMTYPE_RECT_POINT: - { - QTVP_GEOMARKER::geoGraphicsRectItem * pU = dynamic_cast(item); - if (pU) - { - cmd_str += "function=update_point;name="+x_name+QString(";type=%1;").arg(x_tp); - cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7); - //1.2 style - cmd_str += "width="+ QString("%1;").arg(pU->width()); - cmd_str += "height="+ QString("%1;").arg(pU->height()); - cmd_str += "color_pen="+ color2string(pU->pen().color())+";"; - cmd_str += "style_pen="+ QString("%1;").arg(int(pU->pen().style())); - cmd_str += "width_pen="+ QString("%1;").arg(int(pU->pen().width())); - cmd_str += "color_brush="+ color2string(pU->brush().color())+";"; - cmd_str += "style_brush="+ QString("%1;").arg(int(pU->brush().style())); - } - } - break; - case QTVP_GEOMARKER::ITEAMTYPE_ELLIPSE_POINT: - { - QTVP_GEOMARKER::geoGraphicsEllipseItem * pU = dynamic_cast(item); - if (pU) - { - cmd_str += "function=update_point;name="+x_name+QString(";type=%1;").arg(x_tp); - cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7); - //1.2 style - cmd_str += "width="+ QString("%1;").arg(pU->width()); - cmd_str += "height="+ QString("%1;").arg(pU->height()); - cmd_str += "color_pen="+ color2string(pU->pen().color())+";"; - cmd_str += "style_pen="+ QString("%1;").arg(int(pU->pen().style())); - cmd_str += "width_pen="+ QString("%1;").arg(int(pU->pen().width())); - cmd_str += "color_brush="+ color2string(pU->brush().color())+";"; - cmd_str += "style_brush="+ QString("%1;").arg(int(pU->brush().style())); - } - } - break; - case QTVP_GEOMARKER::ITEAMTYPE_LINE: - { - QTVP_GEOMARKER::geoGraphicsLineItem * pU = dynamic_cast(item); - if (pU) - { - cmd_str += "function=update_line;name="+x_name+QString(";type=%1;").arg(x_tp); - cmd_str += QString("lat0=%1;lon0=%2;").arg(pU->lat1(),0,'f',7).arg(pU->lon1(),0,'f',7); - cmd_str += QString("lat1=%1;lon1=%2;").arg(pU->lat2(),0,'f',7).arg(pU->lon2(),0,'f',7); - //1.2 style - cmd_str += "color_pen=" + color2string(pU->pen().color())+";"; - cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style())); - cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width())); - } - } - break; - case QTVP_GEOMARKER::ITEAMTYPE_POLYGON: - { - QTVP_GEOMARKER::geoGraphicsPolygonItem * pU = dynamic_cast(item); - if (pU) - { - cmd_str += "function=update_polygon;name="+x_name+QString(";type=%1;").arg(x_tp); - QPolygonF pl = pU->llas(); - int nPl = pl.size(); - int ct_pg = 0; - foreach (QPointF pf, pl) - { - cmd_str += QString("lat%3=%1;lon%3=%2;").arg(pf.y(),0,'f',7).arg(pf.x(),0,'f',7).arg(ct_pg); - ++ct_pg; - } - cmd_str += "color_pen=" + color2string(pU->pen().color())+";"; - cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style())); - cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width())); - cmd_str += "color_brush=" + color2string(pU->brush().color())+";"; - cmd_str += "style_brush=" + QString("%1;").arg(int(pU->brush().style())); - } - } - break; - case QTVP_GEOMARKER::ITEAMTYPE_PIXMAP: - { - QTVP_GEOMARKER::geoGraphicsPixmapItem * pU = dynamic_cast(item); - if (pU) - { - cmd_str += "function=update_icon;name="+x_name+QString(";type=%1;").arg(x_tp); - //1.2. geo - cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7); - //1.2 style - cmd_str += "icon=" +QString("%1;").arg(pU->icon()->name); - cmd_str += "scale=" +QString("%1;").arg(pU->scale()); - cmd_str += "rotate=" +QString("%1;").arg(pU->rotation()); - cmd_str += "smooth=" +QString("%1;").arg(pU->transformationMode()==Qt::SmoothTransformation?1:0); - } - } - break; - case QTVP_GEOMARKER::ITEAMTYPE_MULTILINE: - { - QTVP_GEOMARKER::geoGraphicsMultilineItem * pU = dynamic_cast(item); - if (pU) - { - cmd_str += "function=update_polygon;name="+x_name+QString(";type=%1;").arg(x_tp); - QPolygonF pl = pU->llas(); - int nPl = pl.size(); - int ct_pg = 0; - foreach (QPointF pf, pl) - { - cmd_str += QString("lat%3=%1;lon%3=%2;").arg(pf.y(),0,'f',7).arg(pf.x(),0,'f',7).arg(ct_pg); - ++ct_pg; - } - cmd_str += "color_pen=" + color2string(pU->pen().color())+";"; - cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style())); - cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width())); - cmd_str += "color_brush=" + color2string(pU->brush().color())+";"; - cmd_str += "style_brush=" + QString("%1;").arg(int(pU->brush().style())); - } - } - break; - default: - break; + cmd_str += QString("lat%3=%1;lon%3=%2;").arg(pf.y(),0,'f',7).arg(pf.x(),0,'f',7).arg(ct_pg); + ++ct_pg; } + cmd_str += "color_pen=" + color2string(pU->pen().color())+";"; + cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style())); + cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width())); + cmd_str += "color_brush=" + color2string(pU->brush().color())+";"; + cmd_str += "style_brush=" + QString("%1;").arg(int(pU->brush().style())); + } + } + break; + default: + break; + } - QColor colorText = item->labelColor(); - cmd_str += "color_label="+color2string(colorText)+";"; + QColor colorText = item->labelColor(); + cmd_str += "color_label="+color2string(colorText)+";"; - int fsize = item->labelFont().pointSize(); - cmd_str += "size_label="+QString("%1;").arg(fsize); + int fsize = item->labelFont().pointSize(); + cmd_str += "size_label="+QString("%1;").arg(fsize); - int weight = item->labelFont().weight(); - cmd_str += "weight_label="+QString("%1;").arg(weight); - cmd_str += "want_hover="+QString("%1;\015\012").arg(item->wantMouseHoverEvent()==true?1:0); + int weight = item->labelFont().weight(); + cmd_str += "weight_label="+QString("%1;").arg(weight); + cmd_str += "want_hover="+QString("%1;\015\012").arg(item->wantMouseHoverEvent()==true?1:0); - cmd_str += "function=update_props;name="+x_name+";"; - //1.2 properties - int props = item->prop_counts(); - QStringList lstNames = item->prop_names(); - QVariantList lstValues = item->prop_values(); - for (int i=0;iprop_counts(); + QStringList lstNames = item->prop_names(); + QVariantList lstValues = item->prop_values(); + for (int i=0;i res; + QStringList lst = linered.split(";"); + foreach (QString s, lst) + { + int t = s.indexOf("="); + if (t>0 && t< s.size()) { - QMap res; - QStringList lst = linered.split(";"); - foreach (QString s, lst) - { - int t = s.indexOf("="); - if (t>0 && t< s.size()) - { - QString name = s.left(t).trimmed(); - QString value = s.mid(t+1).trimmed(); - res[name] = value; - } - } - this->call_func(res); + QString name = s.left(t).trimmed(); + QString value = s.mid(t+1).trimmed(); + res[name] = value; } + } + this->call_func(res); } - fp.close(); - if (res==false) - { - QMap evt_error; - evt_error["source"] = get_name(); - evt_error["destin"] = "ALL"; - evt_error["name"] = "error"; - evt_error["class"] = "cmd reader"; - evt_error["file"] = cmdFile; - evt_error["detail"] = errMessage; - m_pVi->post_event(evt_error); - - } - return res; + } + fp.close(); + if (res==false) + { + QMap evt_error; + evt_error["source"] = get_name(); + evt_error["destin"] = "ALL"; + evt_error["name"] = "error"; + evt_error["class"] = "cmd reader"; + evt_error["file"] = cmdFile; + evt_error["detail"] = errMessage; + m_pVi->post_event(evt_error); + + } + return res; } diff --git a/qtvplugin_geomarker/qtvplugin_geomarker.h b/qtvplugin_geomarker/qtvplugin_geomarker.h index 2d1553c..bc6accb 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker.h +++ b/qtvplugin_geomarker/qtvplugin_geomarker.h @@ -112,7 +112,6 @@ private: */ int m_nTimerID_refreshUI; int m_nTimerID_refreshMap; - int m_nTimerID_levelQueue; quint64 m_nDivideTimer; bool m_bNeedRefresh; bool m_bNeedUpdateView; diff --git a/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp b/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp index d5cfeef..c61d602 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp +++ b/qtvplugin_geomarker/qtvplugin_geomarker_uimethods.cpp @@ -1,4 +1,4 @@ -#include "qtvplugin_geomarker.h" +#include "qtvplugin_geomarker.h" #include "ui_qtvplugin_geomarker.h" #include #include @@ -60,19 +60,6 @@ void qtvplugin_geomarker::timerEvent(QTimerEvent * e) m_pVi->UpdateWindow(); m_nTimerID_refreshMap = startTimer(97); } - else if (m_nTimerID_levelQueue == e->timerId()) - { - killTimer(m_nTimerID_levelQueue); - ++m_nDivideTimer; - if (true==m_pScene->deal_level_queue()) - m_pVi->UpdateWindow(); - else if (m_nDivideTimer % 20 == 0) - { - if (m_pScene->progress_queue()<0.999) - m_pVi->UpdateWindow(); - } - m_nTimerID_levelQueue = startTimer(119); - } } @@ -814,18 +801,18 @@ void qtvplugin_geomarker::on_pushButton_QTV_save_clicked() ); if (newfm.size()>2) { - if (newfm.right(3).toUpper()=="XML") - { - if (true==xml_save(newfm)) - { - settings.setValue("history/last_save_xml_dir",newfm); - //QMessageBox::information(this,tr("succeed"),tr("Successfully saved XML file") + newfm); - } - else - QMessageBox::warning(this,tr("failed"),tr("Save XML file") + newfm + tr(" Failed")); - } - else - { + if (newfm.right(3).toUpper()=="XML") + { + if (true==xml_save(newfm)) + { + settings.setValue("history/last_save_xml_dir",newfm); + //QMessageBox::information(this,tr("succeed"),tr("Successfully saved XML file") + newfm); + } + else + QMessageBox::warning(this,tr("failed"),tr("Save XML file") + newfm + tr(" Failed")); + } + else + { if (true==cmd_save(newfm)) { settings.setValue("history/last_save_xml_dir",newfm); @@ -833,7 +820,7 @@ void qtvplugin_geomarker::on_pushButton_QTV_save_clicked() } else QMessageBox::warning(this,tr("failed"),tr("Save CMD file") + newfm + tr(" Failed")); - } + } } } @@ -846,18 +833,18 @@ void qtvplugin_geomarker::on_pushButton_QTV_load_clicked() ); if (newfm.size()>2) { - if (newfm.right(3).toUpper()=="XML") - { - if (true==xml_load(newfm)) - { - settings.setValue("history/last_open_xml_dir",newfm); - //QMessageBox::information(this,tr("succeed"),tr("Successfully load XML file") + newfm); - } - else - QMessageBox::warning(this,tr("failed"),tr("Load XML file") + newfm + tr(" Failed")); - } - else - { + if (newfm.right(3).toUpper()=="XML") + { + if (true==xml_load(newfm)) + { + settings.setValue("history/last_open_xml_dir",newfm); + //QMessageBox::information(this,tr("succeed"),tr("Successfully load XML file") + newfm); + } + else + QMessageBox::warning(this,tr("failed"),tr("Load XML file") + newfm + tr(" Failed")); + } + else + { if (true==cmd_load(newfm)) { settings.setValue("history/last_open_xml_dir",newfm); @@ -865,7 +852,7 @@ void qtvplugin_geomarker::on_pushButton_QTV_load_clicked() } else QMessageBox::warning(this,tr("failed"),tr("Load CMD file") + newfm + tr(" Failed")); - } + } } scheduleRefreshMarks(); m_pVi->UpdateWindow(); diff --git a/test_container/test_container.pro b/test_container/test_container.pro index 2ec3aef..db3feab 100644 --- a/test_container/test_container.pro +++ b/test_container/test_container.pro @@ -23,12 +23,14 @@ HEADERS += testcontainer.h DEFINES += BUILD_ACTIVEX_OSM win32:contains(DEFINES,BUILD_ACTIVEX_OSM){ + message ("Invoke ActiveX!"); FORMS += testcontainer.ui SOURCES += testcontainer.cpp win32-g++{ QMAKE_CXXFLAGS += -std=c++11 } } else { + message ("Not Invoke ActiveX!"); FORMS += testcontainer_linux.ui SOURCES += testcontainer_linux.cpp } diff --git a/test_container/testcontainer.cpp b/test_container/testcontainer.cpp index 8eb3b2b..a43c413 100644 --- a/test_container/testcontainer.cpp +++ b/test_container/testcontainer.cpp @@ -1,4 +1,4 @@ -#include "testcontainer.h" +#include "testcontainer.h" #include "ui_testcontainer.h" #include #include @@ -584,3 +584,28 @@ void testcontainer::on_pushButton_QTV_default_style_clicked() QMessageBox::information(this,"geomarker::selection_delete",res); } +void testcontainer::on_pushButton_QTV_test_10000_clicked() +{ + + for (int i=0;i<10000;++i) + { + ui->osmmap->osm_layer_call_function("geomarker", + QString( + "function=update_point;name=ID%1;type=%2;" + "lat=%3;lon=%4;" + "style_pen=1;color_pen=%5,%6,%7,128;" + "width_pen=1;style_brush=1;color_brush=%7,%6,%5,128;" + "width=%8;height=%9;") + .arg(i+10) + .arg(rand()%2+1) + .arg((rand()%17000-8500)/100.0) + .arg((rand()%18000-9000)/50.0) + .arg(rand()%255) + .arg(rand()%255) + .arg(rand()%255) + .arg(rand()%16+4) + .arg(rand()%16+4) + ); + + } +} diff --git a/test_container/testcontainer.h b/test_container/testcontainer.h index 94a3231..119b150 100644 --- a/test_container/testcontainer.h +++ b/test_container/testcontainer.h @@ -1,4 +1,4 @@ -#ifndef TESTCONTAINER_H +#ifndef TESTCONTAINER_H #define TESTCONTAINER_H #include @@ -45,7 +45,7 @@ protected slots: void on_pushButton_QTV_test_geo_del_sel_clicked(); void on_pushButton_QTV_default_style_clicked(); void on_osmmap_map_event(QMap p); - + void on_pushButton_QTV_test_10000_clicked(); }; #endif // TESTCONTAINER_H diff --git a/test_container/testcontainer.ui b/test_container/testcontainer.ui index 3c3e9a9..582a24e 100644 --- a/test_container/testcontainer.ui +++ b/test_container/testcontainer.ui @@ -16,17 +16,37 @@ - - + + - cache Folder + order a layer - - + + + + Qt::Vertical + + + + 20 + 40 + + + + + + - add a polygon + get info + + + + + + + Grid measure @@ -37,73 +57,73 @@ - - + + - measure on/off + enum layers - - + + - Grid measure + connect - - + + - Layer control + display mod - - + + - add a line + address - - + + - navigate + add a line - - + + - get info + default_style - - + + - Plugin test: + res save/load - - + + - connect + add a polygon - - + + - res save/load + measure on/off - - + + - display mod + Plugin test: @@ -114,79 +134,66 @@ - - + + - geo marker + Navigate - - + + - order a layer + delete selection - - + + - Plugin test: + marks save/load - - + + - address + navigate - - + + - Navigate + geo marker - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + - get polygon + cache Folder - - + + - enum layers + Layer control - - + + - clear selection + get polygon - - + + - add marks + Plugin test: @@ -197,24 +204,24 @@ - - + + - marks save/load + clear selection - - + + - delete selection + add marks - - + + - default_style + 10000 marks diff --git a/test_container/testcontainer_linux.cpp b/test_container/testcontainer_linux.cpp index b261652..cf14c8b 100644 --- a/test_container/testcontainer_linux.cpp +++ b/test_container/testcontainer_linux.cpp @@ -1,4 +1,4 @@ -#include "testcontainer.h" +#include "testcontainer.h" #include "ui_testcontainer_linux.h" #include #include @@ -550,3 +550,29 @@ void testcontainer::on_pushButton_QTV_default_style_clicked() QMessageBox::information(this,"geomarker::selection_delete",res); } + +void testcontainer::on_pushButton_QTV_test_10000_clicked() +{ + + for (int i=0;i<10000;++i) + { + ui->osmmap->osm_layer_call_function("geomarker", + QString( + "function=update_point;name=ID%1;type=%2;" + "lat=%3;lon=%4;" + "style_pen=1;color_pen=%5,%6,%7,128;" + "width_pen=1;style_brush=1;color_brush=%7,%6,%5,128;" + "width=%8;height=%9;") + .arg(i+10) + .arg(rand()%2+1) + .arg((rand()%17000-8500)/100.0) + .arg((rand()%18000-9000)/50.0) + .arg(rand()%255) + .arg(rand()%255) + .arg(rand()%255) + .arg(rand()%16+4) + .arg(rand()%16+4) + ); + + } +} diff --git a/test_container/testcontainer_linux.ui b/test_container/testcontainer_linux.ui index b36dc3f..f7d0b1a 100644 --- a/test_container/testcontainer_linux.ui +++ b/test_container/testcontainer_linux.ui @@ -16,73 +16,73 @@ - - + + - Layer control + get info - - + + - navigate + Layer control - - + + - cache Folder + clear selection - - + + - add marks + res save/load - - + + - Plugin test: + selection mod - - + + - background osm conn + connect - - + + - connect + Grid measure - - + + - get polygon + geo marker - - + + - res save/load + Plugin test: - - + + - measure on/off + order a layer @@ -100,54 +100,41 @@ - - + + - geo marker + marks save/load - - + + - order a layer + add a line - - + + - Grid measure + navigate - - + + - Plugin test: + get polygon - - + + - Navigate + measure on/off - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -155,66 +142,86 @@ - - + + - get info + add marks - - + + - add a line + display mod - - + + - selected_marks + Plugin test: - - + + - marks save/load + Navigate - - + + - selection mod + delete selection - - + + - display mod + background osm conn - - + + + + Qt::Vertical + + + + 20 + 40 + + + + + + - clear selection + default_style - - + + - delete selection + selected_marks - - + + - default_style + cache Folder + + + + + + + 10000 makrs -- GitLab