Commit d5f038d7 authored by pixhawk's avatar pixhawk

Fixed last nasty wp management bugs, now first time 2D map is fully synced with WPManager

parent 75a1db30
......@@ -119,7 +119,7 @@ namespace qmapcontrol
virtual bool hasClickedPoints() const;
virtual void setPen(QPen* pen);
virtual QList<Geometry*> clickedPoints();
virtual QList<Point*> points()=0;
virtual QList<Point*>& points()=0;
private:
Geometry* myparentGeometry;
......
......@@ -56,7 +56,12 @@ namespace qmapcontrol
vertices.append(point);
}
QList<Point*> LineString::points()
void LineString::clearPoints()
{
vertices.clear();
}
QList<Point*>& LineString::points()
{
return vertices;
}
......
......@@ -56,7 +56,7 @@ namespace qmapcontrol
/*!
* @return a list with the points of the LineString
*/
QList<Point*> points();
QList<Point*>& points();
//! adds a point at the end of the LineString
/*!
......@@ -64,6 +64,9 @@ namespace qmapcontrol
*/
void addPoint ( Point* point );
//! Remove all points from the LineString
void clearPoints();
//! sets the given list as points of the LineString
/*!
* @param points the points which should be set for the LineString
......
......@@ -293,12 +293,11 @@ namespace qmapcontrol
emit(positionChanged(this));
}
QList<Point*> Point::points()
QList<Point*>& Point::points()
{
//TODO: assigning temp?!
QList<Point*> points;
points.append(this);
return points;
// FIXME TODO: THIS IS ABSOLUTELY WRONG IN THE ORIGINAL LIBRARY
// NEEDS AN INHERITANCE REWRITE!!!!
return m_points;
}
QWidget* Point::widget()
......
......@@ -139,7 +139,7 @@ namespace qmapcontrol
*/
QPointF coordinate() const;
virtual QList<Point*> points();
virtual QList<Point*>& points();
/*! \brief returns the widget of the point
@return the widget of the point
......@@ -191,6 +191,7 @@ namespace qmapcontrol
QSize displaysize;
QSize minsize;
QSize maxsize;
QList<Point*> m_points;
void drawWidget(const MapAdapter* mapadapter, const QPoint offset);
......
......@@ -267,6 +267,7 @@ void UASWaypointManager::handleWaypointCurrent(quint8 systemId, quint8 compId, m
void UASWaypointManager::notifyOfChange(Waypoint* wp)
{
qDebug() << "WAYPOINT CHANGED: ID:" << wp->getId();
// If only one waypoint was changed, emit only WP signal
if (wp != NULL)
{
......
......@@ -417,6 +417,7 @@ void MapWidget::captureMapClick(const QMouseEvent* event, const QPointF coordina
{
str = QString("%1").arg(waypointPath->numberOfPoints());
tempCirclePoint = new Waypoint2DIcon(coordinate.x(), coordinate.y(), 20, str, qmapcontrol::Point::Middle);
wpIcons.append(tempCirclePoint);
mc->layer("Waypoints")->addGeometry(tempCirclePoint);
......@@ -435,7 +436,12 @@ void MapWidget::captureMapClick(const QMouseEvent* event, const QPointF coordina
void MapWidget::updateWaypoint(int uas, Waypoint* wp)
{
//qDebug() << "UPDATING WP" << wp->getId() << __FILE__ << __LINE__;
updateWaypoint(uas, wp, true);
}
void MapWidget::updateWaypoint(int uas, Waypoint* wp, bool updateView)
{
qDebug() << "UPDATING WP" << wp->getId() << wp << __FILE__ << __LINE__;
if (uas == this->mav->getUASID())
{
int wpindex = UASManager::instance()->getUASForId(uas)->getWaypointManager()->getIndexOf(wp);
......@@ -448,8 +454,6 @@ void MapWidget::updateWaypoint(int uas, Waypoint* wp)
coordinate.setX(wp->getX());
coordinate.setY(wp->getY());
createWaypointGraphAtMap(wpindex, coordinate);
qDebug() << "Waypoint Index did not contain" << str;
}
else
{
......@@ -478,6 +482,10 @@ void MapWidget::updateWaypoint(int uas, Waypoint* wp)
{
linesegment = waypointPath->points().at(wpindex);
}
else
{
waypointPath->addPoint(waypoint);
}
if (linesegment)
{
......@@ -486,7 +494,7 @@ void MapWidget::updateWaypoint(int uas, Waypoint* wp)
//point2Find = dynamic_cast <Point*> (mc->layer("Waypoints")->get_Geometry(wpindex));
//point2Find->setCoordinate(coordinate);
mc->updateRequest(waypoint->boundingBox().toRect());
if (updateView) mc->updateRequest(waypoint->boundingBox().toRect());
}
}
}
......@@ -642,6 +650,9 @@ void MapWidget::updateWaypointList(int uas)
UASInterface* uasInstance = UASManager::instance()->getUASForId(uas);
if (uasInstance)
{
// Get update rect of old content
QRect updateRect = waypointPath->boundingBox().toRect();
QVector<Waypoint*> wpList = uasInstance->getWaypointManager()->getWaypointList();
// Clear if necessary
......@@ -654,28 +665,26 @@ void MapWidget::updateWaypointList(int uas)
// Load all existing waypoints into map view
foreach (Waypoint* wp, wpList)
{
updateWaypoint(mav->getUASID(), wp);
// Block updates, since we update everything in the next step
updateWaypoint(mav->getUASID(), wp, false);
}
// Delete now unused wps
if (wps.count() > wpList.count())
{
mc->layer("Waypoints")->removeGeometry(waypointPath);
for (int i = wpList.count(); i < wps.count(); ++i)
{
QRect updateRect = wps.at(i)->boundingBox().toRect();
wps.removeAt(i);
mc->layer("Waypoints")->removeGeometry(wpIcons.at(i));
waypointPath->points().removeAt(i);
//Point* linesegment = waypointPath->points().at(mav->getWaypointManager()->getWaypointList().indexOf(wp));
mc->updateRequest(updateRect);
}
mc->layer("Waypoints")->addGeometry(waypointPath);
}
// Clear and rebuild linestring
// Update view
mc->updateRequest(updateRect);
}
}
......@@ -703,7 +712,7 @@ void MapWidget::activeUASSet(UASInterface* uas)
{
// Disconnect the waypoint manager / data storage from the UI
disconnect(mav->getWaypointManager(), SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
disconnect(mav->getWaypointManager(), SIGNAL(waypointUpdated(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
disconnect(mav->getWaypointManager(), SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
disconnect(this, SIGNAL(waypointCreated(Waypoint*)), mav->getWaypointManager(), SLOT(addWaypoint(Waypoint*)));
}
......@@ -723,7 +732,7 @@ void MapWidget::activeUASSet(UASInterface* uas)
// Connect the waypoint manager / data storage to the UI
connect(mav->getWaypointManager(), SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(mav->getWaypointManager(), SIGNAL(waypointUpdated(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
connect(mav->getWaypointManager(), SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
connect(this, SIGNAL(waypointCreated(Waypoint*)), mav->getWaypointManager(), SLOT(addWaypoint(Waypoint*)));
}
}
......@@ -925,12 +934,23 @@ void MapWidget::clearWaypoints(int uas)
//mc->layer("Waypoints")->clearGeometries();
wps.clear();
foreach (Point* p, wpIcons)
{
mc->layer("Waypoints")->removeGeometry(p);
}
wpIcons.clear();
// Get bounding box of this object BEFORE deleting the content
QRect box = waypointPath->boundingBox().toRect();
// Delete the content
waypointPath->points().clear();
//delete waypointPath;
//waypointPath = new
mc->layer("Waypoints")->addGeometry(waypointPath);
//mc->layer("Waypoints")->addGeometry(waypointPath);
//wpIndex.clear();
mc->updateRequestNew();//(waypointPath->boundingBox().toRect());
mc->updateRequest(box);//(waypointPath->boundingBox().toRect());
if(createPath->isChecked())
{
......
......@@ -87,6 +87,7 @@ public slots:
/** @brief Update waypoint */
void updateWaypoint(int uas, Waypoint* wp);
void updateWaypoint(int uas, Waypoint* wp, bool updateView);
void drawBorderCamAtMap(bool status);
/** @brief Bring up dialog to go to a specific location */
......
......@@ -336,6 +336,9 @@ QProgressBar::chunk#thrustBar {
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000010000000000</double>
</property>
</widget>
</item>
<item>
......@@ -361,6 +364,9 @@ QProgressBar::chunk#thrustBar {
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000010000000000</double>
</property>
</widget>
</item>
<item>
......
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