From 94228d601656ac0acfda9978a3c3e3e7a220199a Mon Sep 17 00:00:00 2001 From: Mariano Lizarraga Date: Thu, 19 Aug 2010 16:04:04 -0500 Subject: [PATCH] Continue the scaffoldinf for the WP click creation. Now the waypoints are graphically shown in the MapControl. Ready to start interacting with the Waypoint widget --- src/ui/MapWidget.cc | 63 ++++++++++++++++++++++++++++++++++++++++----- src/ui/MapWidget.h | 7 ++++- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/ui/MapWidget.cc b/src/ui/MapWidget.cc index 31ed731ed..db0d1bb15 100644 --- a/src/ui/MapWidget.cc +++ b/src/ui/MapWidget.cc @@ -60,9 +60,12 @@ MapWidget::MapWidget(QWidget *parent) : // create a layer with the mapadapter and type MapLayer osmLayer = new Layer("Custom Layer", osmAdapter, Layer::MapLayer); + // create a layer with the mapadapter and type GeometryLayer (for waypoints) + geomLayer = new Layer("Geom Layer", osmAdapter, Layer::GeometryLayer); - // add Layer to the MapControl + // add Layers to the MapControl and set zoom level mc->addLayer(osmLayer); + mc->addLayer(geomLayer); mc->setZoom(3); // display the MapControl in the application @@ -71,7 +74,6 @@ MapWidget::MapWidget(QWidget *parent) : layout->addWidget(mc); setLayout(layout); - // create buttons to control the map (zoom, GPS tracking and WP capture) QPushButton* zoomin = new QPushButton(QIcon(":/images/actions/list-add.svg"), "", this); QPushButton* zoomout = new QPushButton(QIcon(":/images/actions/list-remove.svg"), "", this); @@ -83,15 +85,12 @@ MapWidget::MapWidget(QWidget *parent) : createPath->setMaximumWidth(50); followgps->setMaximumWidth(50); - // Set checkable buttons // TODO: Currently checked buttons are are very difficult to distinguish when checked. // create a style and the slots to change the background so it is easier to distinguish followgps->setCheckable(true); createPath->setCheckable(true); - - // add buttons to control the map (zoom, GPS tracking and WP capture) QVBoxLayout* innerlayout = new QVBoxLayout; innerlayout->addWidget(zoomin); @@ -102,6 +101,12 @@ MapWidget::MapWidget(QWidget *parent) : // Connect the required signals-slots + connect(zoomin, SIGNAL(clicked(bool)), + mc, SLOT(zoomIn())); + + connect(zoomout, SIGNAL(clicked(bool)), + mc, SLOT(zoomOut())); + connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); @@ -111,6 +116,16 @@ MapWidget::MapWidget(QWidget *parent) : connect(createPath, SIGNAL(clicked(bool)), this, SLOT(createPathButtonClicked())); + connect(geomLayer, SIGNAL(geometryClicked(Geometry*,QPoint)), + this, SLOT(captureGeometryClick(Geometry*, QPoint))); + + + // Configure the WP Path's pen + pointPen = new QPen(QColor(0, 255,0)); + pointPen->setWidth(3); + + path = new LineString (wps, "UAV Path", pointPen); + mc->layer("Geom Layer")->addGeometry(path); this->setVisible(false); @@ -136,18 +151,52 @@ MapWidget::MapWidget(QWidget *parent) : } void MapWidget::createPathButtonClicked(){ - this->setCursor(createPath->isChecked()? Qt::PointingHandCursor : Qt::ArrowCursor); + if (createPath->isChecked()){ + // change the cursor shape + this->setCursor(Qt::PointingHandCursor); + + // Clear the previous WP track + // TODO: Move this to an actual clear track button and add a warning dialog + mc->layer("Geom Layer")->clearGeometries(); + wps.clear(); + path->setPoints(wps); + mc->layer("Geom Layer")->addGeometry(path); + } else { + this->setCursor(Qt::ArrowCursor); + } + } void MapWidget::captureMapClick(const QMouseEvent* event, const QPointF coordinate){ + if (QEvent::MouseButtonRelease == event->type() && createPath->isChecked()){ - qDebug()<< "Click Event"; + + // Create waypoint name + QString str; + str = QString("WP%1").arg(path->numberOfPoints()+1); + + + qDebug()<< "Waypoint " << str; qDebug()<< "Lat: " << coordinate.y(); qDebug()<< "Lon: " << coordinate.x(); + + // create the WP and set everything in the LineString to display the path + mc->layer("Geom Layer")->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)); + + mc->updateRequestNew(); } } +void MapWidget::captureGeometryClick(Geometry* geom, QPoint point){ + Q_UNUSED(point); + + qDebug ()<< geom->name(); + qDebug() << geom->GeometryType; +} + MapWidget::~MapWidget() { delete m_ui; diff --git a/src/ui/MapWidget.h b/src/ui/MapWidget.h index 5718cab40..f66fc2dce 100644 --- a/src/ui/MapWidget.h +++ b/src/ui/MapWidget.h @@ -73,6 +73,8 @@ protected: TileMapAdapter* osmAdapter; GoogleSatMapAdapter* gSatAdapter; Layer* osmLayer; + Layer* geomLayer; + //Layer* gSatLayer; QMap uasIcons; @@ -83,9 +85,12 @@ protected: protected slots: void captureMapClick (const QMouseEvent* event, const QPointF coordinate); void createPathButtonClicked(); - + void captureGeometryClick(Geometry*, QPoint); private: Ui::MapWidget *m_ui; + QList wps; + LineString* path; + QPen* pointPen; }; #endif // MAPWIDGET_H -- 2.22.0