Files
gcs-nf/opmap/mapwidget/geoFenceitem.cpp
T

162 lines
3.4 KiB
C++
Raw Normal View History

2022-05-10 21:38:23 +08:00
#include "geoFenceitem.h"
#include <QDateTime>
2022-05-12 15:36:29 +08:00
#include <QGraphicsSceneMouseEvent>
2022-05-10 21:38:23 +08:00
namespace mapcontrol {
2022-05-12 15:36:29 +08:00
geoFenceitem::geoFenceitem(int group, bool inclusion, int version, internals::PointLatLng const & coord, QBrush color, MapGraphicItem *map, bool dashed, int width) :
QGraphicsPolygonItem(map), number(0) , coord(coord), m_brush(color), m_map(map), dashed(dashed), lineWidth(width)
2022-05-10 21:38:23 +08:00
{
this->setZValue(3);
connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
2022-05-11 15:12:08 +08:00
2022-05-12 15:36:29 +08:00
m_version = version;
2022-05-11 15:12:08 +08:00
m_inclusion = inclusion;
2022-05-12 15:36:29 +08:00
//m_Vertex = count;//1
m_group = group; //2
2022-05-11 15:12:08 +08:00
m_latitude = coord.Lat();//5
m_longitide = coord.Lng();//6
2022-05-10 21:38:23 +08:00
RefreshPos();
}
void geoFenceitem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
2022-05-11 15:12:08 +08:00
painter->setOpacity(0.4);
QPen myPen = painter->pen();
myPen.setWidth(lineWidth);
myPen.setColor(m_brush.color());
painter->setPen(myPen);
if (dashed) {
QVector<qreal> dashes;
dashes << 4 << 8;
myPen.setDashPattern(dashes);
}
if(m_inclusion)
{
2022-05-12 17:46:15 +08:00
painter->setBrush(Qt::NoBrush);
2022-05-11 15:12:08 +08:00
}
else
{
2022-05-12 17:46:15 +08:00
painter->setBrush(m_brush);
2022-05-11 15:12:08 +08:00
}
painter->drawPoint(0, 0);
2022-05-12 15:36:29 +08:00
painter->drawPolygon(polygon());
2022-05-17 15:06:08 +08:00
QFont font;
font.setWeight(QFont::ExtraBold);
font.setFamily("Arial");//非衬线
font.setPixelSize(40);
painter->setFont(font);
myPen.setWidth(lineWidth);
myPen.setColor(QColor("#FFFFFF"));
painter->setPen(myPen);
painter->drawText(boundingRect(),Qt::AlignCenter,QString::number(m_group));
2022-05-12 15:36:29 +08:00
}
2022-05-11 15:12:08 +08:00
2022-05-12 15:36:29 +08:00
int geoFenceitem::type() const
{
return Type;
}
2022-05-11 15:12:08 +08:00
2022-05-12 15:36:29 +08:00
void geoFenceitem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
2022-05-11 15:12:08 +08:00
2022-05-12 15:36:29 +08:00
}
}
2022-05-11 15:12:08 +08:00
2022-05-12 15:36:29 +08:00
void geoFenceitem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
isDragging = true;
}
QGraphicsItem::mousePressEvent(event);
update();
}
void geoFenceitem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
isDragging = false;
}
QGraphicsItem::mouseReleaseEvent(event);
update();
}
void geoFenceitem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (isDragging) {
//ElevationTrig();
emit localPositionChanged(this->pos(), this);
}
QGraphicsItem::mouseMoveEvent(event);
update();
}
2022-05-11 15:12:08 +08:00
2022-05-12 15:36:29 +08:00
void geoFenceitem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
2022-05-10 21:38:23 +08:00
}
2022-05-12 15:36:29 +08:00
void geoFenceitem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
2022-05-10 21:38:23 +08:00
{
2022-05-12 15:36:29 +08:00
Q_UNUSED(event)
update();
2022-05-10 21:38:23 +08:00
}
2022-05-12 15:36:29 +08:00
2022-05-10 21:38:23 +08:00
void geoFenceitem::setPosSLOT()
{
//qDebug() << "virtual set pos";
2022-05-11 15:12:08 +08:00
QPolygonF polygon;
for(internals::PointLatLng LatLng:points)
{
QPointF pf;
pf.setX(m_map->FromLatLngToLocal(LatLng).X() - m_map->FromLatLngToLocal(this->coord).X());
pf.setY(m_map->FromLatLngToLocal(LatLng).Y() - m_map->FromLatLngToLocal(this->coord).Y());
polygon.append(pf);
}
setPolygon(polygon);
2022-05-10 21:38:23 +08:00
setPos(m_map->FromLatLngToLocal(this->coord).X(), m_map->FromLatLngToLocal(this->coord).Y());
emit localPositionChanged(this->pos(),this);
2022-05-12 15:36:29 +08:00
update();
2022-05-10 21:38:23 +08:00
}
void geoFenceitem::RefreshPos()
{
setPosSLOT();
}
2022-05-11 15:12:08 +08:00
void geoFenceitem::setPoints(QList<internals::PointLatLng> p)
{
points = p;
2022-05-12 15:36:29 +08:00
m_Vertex = p.size();
RefreshPos();
2022-05-11 15:12:08 +08:00
}
2022-05-10 21:38:23 +08:00
}