事件代码编写
//本次示例主要以地图的状态栏
bool PIEMainWindow::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == m_pMapControl)
{
if (ev->type() == QEvent::MouseMove)
{
QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(ev);
m_pLineEdit_ScreenCoordsInfos->setText(QString("%1,%2").arg(pMouseEvent->x()).arg(pMouseEvent->y()));
double mapX, mapY;
mapX = mapY = 0;
m_pMapControl->GetActiveView()->GetDisplayTransformation()->ToMapPoint(pMouseEvent->x(), pMouseEvent->y(), mapX, mapY);
m_pLineEdit_GeoCoordsInfos->setText(QString("%1,%2").arg(mapX).arg(mapY));
SysGeometry::SpatialReferencePtr ptrSR = m_pMapControl->GetMap()->GetSpatialReference();
if (ptrSR == nullptr) return true;
m_pLabel_SpatialReferenceInfos->setText(ptrSR->GetName());
}
else if (ev->type()==QEvent::MouseButtonPress)
{
QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(ev);
QPoint qPoint;
qPoint.setX(pMouseEvent->x());
qPoint.setY(pMouseEvent->y());
SysGeometry::PointPtr point = new SysGeometry::Point();
point = m_pMapControl->GetActiveView()->GetDisplayTransformation()->ToMapPoint(qPoint);
QString screenPoint = QString("屏幕坐标:%1,%2").arg(pMouseEvent->x()).arg(pMouseEvent->y());
QString mapPoint= QString("屏幕坐标:%1,%2").arg(point->GetX()).arg(point->GetY());
}
else if (ev->type()==QEvent::MouseButtonRelease)
{
qDebug("鼠标释放事件");
}
}
else if (obj == m_pPageLayoutControl)
{
if (ev->type() == QEvent::MouseMove)
{
QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(ev);
m_pLineEdit_ScreenCoordsInfos->setText(QString("%1,%2").arg(pMouseEvent->x()).arg(pMouseEvent->y()));
double mapX, mapY;
mapX = mapY = 0;
m_pPageLayoutControl->GetActiveView()->GetDisplayTransformation()->ToMapPoint(pMouseEvent->x(), pMouseEvent->y(), mapX, mapY);
m_pLineEdit_GeoCoordsInfos->setText(QString("%1,%2").arg(mapX).arg(mapY));
SysGeometry::SpatialReferencePtr ptrSR = m_pPageLayoutControl->GetMap()->GetSpatialReference();
if (ptrSR == nullptr) return true;
m_pLabel_SpatialReferenceInfos->setText(ptrSR->GetName());
}
}
return QMainWindow::eventFilter(obj, ev);
}