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