Files
gcs-nf/opmap/mapwidget/geoFencecircle.cpp
T
2022-05-11 15:12:08 +08:00

101 lines
2.3 KiB
C++

#include "geoFencecircle.h"
#include <QDateTime>
namespace mapcontrol {
geoFencecircle::geoFencecircle(int g, int count, int index, bool inclusion, geoFenceitem *center, double radius, QBrush color, MapGraphicItem *map, bool dashed, int width) :
QGraphicsEllipseItem(map),m_center(center), coord(center->coord), m_brush(color), m_map(map),dashed(dashed),lineWidth(width)
{
this->setZValue(3);
m_inclusion = inclusion;
m_radius = radius;
m_group = g; //2
m_latitude = coord.Lat();//5
m_longitide = coord.Lng();//6
connect(center, SIGNAL(localPositionChanged(QPointF, geoFenceitem *)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(aboutToBeDeleted(geoFenceitem *)), this, SLOT(waypointdeleted()));
refreshLocations();
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
}
int geoFencecircle::type() const
{
return Type;
}
void geoFencecircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setOpacity(0.4);
QPointF p1;
QPointF p2;
p1 = QPointF(line.p1().x(), line.p1().y() + line.length());
p2 = QPointF(line.p1().x(), line.p1().y() - line.length());
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);
}
painter->translate(-line.length(), -line.length());
if(m_inclusion)
{
painter->setBrush(m_brush);
}
else
{
painter->setBrush(Qt::NoBrush);
}
painter->drawEllipse(this->rect());
}
void geoFencecircle::refreshLocations()
{
//qDebug() << my_center->pos();
internals::PointLatLng C;
C = m_map->FromLocalToLatLng(m_center->x(),m_center->y());
C.SetLat(C.Lat() + m_radius/111133.3333f);
line = QLineF(m_center->pos().x(),m_center->pos().y(),m_center->pos().x(),m_map->FromLatLngToLocal(C).Y());
this->setRect(m_center->pos().x(), m_center->pos().y(), 2 * line.length(), 2 * line.length());
this->update();
}
void geoFencecircle::waypointdeleted()
{
this->deleteLater();
}
void geoFencecircle::setOpacitySlot(qreal opacity)
{
setOpacity(opacity);
}
}