Commit b95fd4cb authored by Mariano Lizarraga's avatar Mariano Lizarraga

Dragging of waypoints now working in the map control

parent 42386f6f
......@@ -110,28 +110,45 @@ namespace qmapcontrol
}
void Layer::mouseEvent(const QMouseEvent* evnt, const QPoint mapmiddle_px)
{
if (takesMouseEvents())
{
if (evnt->button() == Qt::LeftButton && evnt->type() == QEvent::MouseButtonPress)
if (takesMouseEvents())
{
// check for collision
QPointF c = mapAdapter->displayToCoordinate(QPoint(evnt->x()-screenmiddle.x()+mapmiddle_px.x(),
evnt->y()-screenmiddle.y()+mapmiddle_px.y()));
Point* tmppoint = new Point(c.x(), c.y());
for (int i=0; i<geometries.count(); i++)
if (evnt->button() == Qt::LeftButton && evnt->type() == QEvent::MouseButtonPress)
{
if (geometries.at(i)->isVisible() && geometries.at(i)->Touches(tmppoint, mapAdapter))
//if (geometries.at(i)->Touches(c, mapAdapter))
// check for collision
QPointF c = mapAdapter->displayToCoordinate(QPoint(evnt->x()-screenmiddle.x()+mapmiddle_px.x(),
evnt->y()-screenmiddle.y()+mapmiddle_px.y()));
Point* tmppoint = new Point(c.x(), c.y());
for (int i=0; i<geometries.count(); i++)
{
emit(geometryClicked(geometries.at(i), QPoint(evnt->x(), evnt->y())));
if (geometries.at(i)->isVisible() && geometries.at(i)->Touches(tmppoint, mapAdapter))
//if (geometries.at(i)->Touches(c, mapAdapter))
{
emit(geometryClicked(geometries.at(i), QPoint(evnt->x(), evnt->y())));
draggingGeometry = true;
geometrySelected = geometries.at(i);
}
}
delete tmppoint;
}
if (evnt->type() == QEvent::MouseButtonRelease){
QPointF c = mapAdapter->displayToCoordinate(QPoint(evnt->x()-screenmiddle.x()+mapmiddle_px.x(),
evnt->y()-screenmiddle.y()+mapmiddle_px.y()));
draggingGeometry = false;
emit (geometryEndDrag(geometrySelected, c));
geometrySelected = 0;
}
if ( evnt->type() == QEvent::MouseMove && draggingGeometry){
QPointF c = mapAdapter->displayToCoordinate(QPoint(evnt->x()-screenmiddle.x()+mapmiddle_px.x(),
evnt->y()-screenmiddle.y()+mapmiddle_px.y()));
emit(geometryDragged(geometrySelected, c));
}
delete tmppoint;
}
}
}
bool Layer::takesMouseEvents() const
{
......
......@@ -63,6 +63,7 @@ namespace qmapcontrol
public:
friend class LayerManager;
//! sets the type of a layer, see Layer class doc for further information
enum LayerType
{
......@@ -157,6 +158,9 @@ namespace qmapcontrol
bool takeevents;
mutable QRect myoffscreenViewport;
Geometry* geometrySelected;
bool draggingGeometry;
signals:
//! This signal is emitted when a Geometry is clicked
/*!
......@@ -167,6 +171,25 @@ namespace qmapcontrol
*/
void geometryClicked(Geometry* geometry, QPoint point);
//! This signal is emitted while a Geometry is being dragged
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The layer emits a signal as it is dragged
* @param geometry The selected Geometry
* @param coordinate The new coordinate (in world coordinates)
*/
void geometryDragged(Geometry* geometrySelected, QPointF coordinate);
//! This signal is emitted when a User releases the button after selecting a Geometry
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The layer emits a signal when it is released
* @param geometry The selected Geometry
* @param coordinate The new coordinate (in world coordinates)
*/
void geometryEndDrag(Geometry* geometrySelected, QPointF coordinate);
void updateRequest(QRectF rect);
void updateRequest();
......
......@@ -255,6 +255,7 @@ namespace qmapcontrol
void MapControl::mouseReleaseEvent(QMouseEvent* evnt)
{
layermanager->mouseEvent(evnt);
mousepressed = false;
if (mymousemode == Dragging)
{
......@@ -271,6 +272,7 @@ namespace qmapcontrol
void MapControl::mouseMoveEvent(QMouseEvent* evnt)
{
layermanager->mouseEvent(evnt);
emit(mouseEvent(evnt));
......
......@@ -190,11 +190,16 @@ MapWidget::MapWidget(QWidget *parent) :
this, SLOT(captureMapClick(const QMouseEvent*, const QPointF)));
connect(createPath, SIGNAL(clicked(bool)),
this, SLOT(createPathButtonClicked()));
this, SLOT(createPathButtonClicked(bool)));
connect(geomLayer, SIGNAL(geometryClicked(Geometry*,QPoint)),
this, SLOT(captureGeometryClick(Geometry*, QPoint)));
connect(geomLayer, SIGNAL(geometryDragged(Geometry*, QPointF)),
this, SLOT(captureGeometryDrag(Geometry*, QPointF)));
connect(geomLayer, SIGNAL(geometryEndDrag(Geometry*, QPointF)),
this, SLOT(captureGeometryEndDrag(Geometry*, QPointF)));
// Configure the WP Path's pen
pointPen = new QPen(QColor(0, 255,0));
......@@ -290,12 +295,15 @@ void MapWidget::mapproviderSelected(QAction* action)
}
void MapWidget::createPathButtonClicked()
void MapWidget::createPathButtonClicked(bool checked)
{
Q_UNUSED(checked);
if (createPath->isChecked())
{
// change the cursor shape
this->setCursor(Qt::PointingHandCursor);
mc->setMouseMode(qmapcontrol::MapControl::None);
// Clear the previous WP track
// TODO: Move this to an actual clear track button and add a warning dialog
......@@ -303,8 +311,12 @@ void MapWidget::createPathButtonClicked()
wps.clear();
path->setPoints(wps);
mc->layer("Waypoints")->addGeometry(path);
wpIndex.clear();
} else {
this->setCursor(Qt::ArrowCursor);
mc->setMouseMode(qmapcontrol::MapControl::Panning);
}
}
......@@ -313,37 +325,55 @@ void MapWidget::createPathButtonClicked()
void MapWidget::captureMapClick(const QMouseEvent* event, const QPointF coordinate){
if (QEvent::MouseButtonRelease == event->type() && createPath->isChecked()){
// Create waypoint name
QString str;
str = QString("WP%1").arg(path->numberOfPoints()+1);
qDebug()<< "Waypoint " << str;
qDebug()<< "Lat: " << coordinate.y();
qDebug()<< "Lon: " << coordinate.x();
str = QString("WP%1").arg(path->numberOfPoints());
// create the WP and set everything in the LineString to display the path
mc->layer("Waypoints")->addGeometry(new CirclePoint(coordinate.x(), coordinate.y(), 10, str));
wps.append(new Point(coordinate.x(), coordinate.y(),str));
path->addPoint(new Point(coordinate.x(), coordinate.y(),str));
CirclePoint* tempCirclePoint = new CirclePoint(coordinate.x(), coordinate.y(), 10, str);
mc->layer("Waypoints")->addGeometry(tempCirclePoint);
Point* tempPoint = new Point(coordinate.x(), coordinate.y(),str);
wps.append(tempPoint);
path->addPoint(tempPoint);
wpIndex.insert(str,tempPoint);
// Refresh the screen
mc->updateRequestNew();
}
}
void MapWidget::captureGeometryClick(Geometry* geom, QPoint point){
Q_UNUSED(geom);
Q_UNUSED(point);
mc->setMouseMode(qmapcontrol::MapControl::None);
qDebug() << geom->name();
qDebug() << geom->GeometryType;
qDebug() << point;
}
void MapWidget::captureGeometryDrag(Geometry* geom, QPointF coordinate){
Q_UNUSED(coordinate);
Point* point2Find;
point2Find = wpIndex[geom->name()];
point2Find->setCoordinate(coordinate);
point2Find = dynamic_cast <Point*> (geom);
point2Find->setCoordinate(coordinate);
// Refresh the screen
mc->updateRequestNew();
}
void MapWidget::captureGeometryEndDrag(Geometry* geom, QPointF coordinate){
mc->setMouseMode(qmapcontrol::MapControl::Panning);
qDebug() << geom->name();
qDebug() << geom->GeometryType;
qDebug() << coordinate;
// qDebug() << geom->name();
// qDebug() << geom->GeometryType;
// qDebug() << point;
}
MapWidget::~MapWidget()
......
......@@ -102,14 +102,19 @@ protected:
protected slots:
void captureMapClick (const QMouseEvent* event, const QPointF coordinate);
void createPathButtonClicked();
void createPathButtonClicked(bool checked);
void captureGeometryClick(Geometry*, QPoint);
void mapproviderSelected(QAction* action);
void captureGeometryDrag(Geometry* geom, QPointF coordinate);
void captureGeometryEndDrag(Geometry* geom, QPointF coordinate);
signals:
void movePoint(QPointF newCoord);
private:
Ui::MapWidget *m_ui;
QList<Point*> wps;
QHash <QString, Point*> wpIndex;
LineString* path;
QPen* pointPen;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment