Browse Source

Protect against empty lists, fix map interaction

QGC4.4
Lorenz Meier 11 years ago
parent
commit
5e95b6d266
  1. 3
      src/ui/WaypointEditableView.cc
  2. 27
      src/ui/WaypointList.cc
  3. 6
      src/ui/WaypointViewOnlyView.cc
  4. 26
      src/ui/map/QGCMapWidget.cc

3
src/ui/WaypointEditableView.cc

@ -39,11 +39,10 @@ @@ -39,11 +39,10 @@
WaypointEditableView::WaypointEditableView(Waypoint* wp, QWidget* parent) :
QWidget(parent),
viewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DEFAULT),
wp(wp),
m_ui(new Ui::WaypointEditableView)
{
m_ui->setupUi(this);
this->wp = wp;
connect(wp, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*)));
// CUSTOM COMMAND WIDGET

27
src/ui/WaypointList.cc

@ -382,13 +382,13 @@ void WaypointList::changeCurrentWaypoint(quint16 seq) @@ -382,13 +382,13 @@ void WaypointList::changeCurrentWaypoint(quint16 seq)
void WaypointList::currentWaypointEditableChanged(quint16 seq)
{
WPM->setCurrentEditable(seq);
const QList<Waypoint *> &waypoints = WPM->getWaypointEditableList();
const QList<Waypoint *> waypoints = WPM->getWaypointEditableList();
if (seq < waypoints.count())
{
for(int i = 0; i < waypoints.count(); i++)
{
WaypointEditableView* widget = wpEditableViews.find(waypoints[i]).value();
WaypointEditableView* widget = wpEditableViews.value(waypoints[i], NULL);
if (widget) {
if (waypoints[i]->getId() == seq)
@ -410,13 +410,13 @@ void WaypointList::currentWaypointViewOnlyChanged(quint16 seq) @@ -410,13 +410,13 @@ void WaypointList::currentWaypointViewOnlyChanged(quint16 seq)
// First update the edit list
currentWaypointEditableChanged(seq);
const QList<Waypoint *> &waypoints = WPM->getWaypointViewOnlyList();
const QList<Waypoint *> waypoints = WPM->getWaypointViewOnlyList();
if (seq < waypoints.count())
{
for(int i = 0; i < waypoints.count(); i++)
{
WaypointViewOnlyView* widget = wpViewOnlyViews.find(waypoints[i]).value();
WaypointViewOnlyView* widget = wpViewOnlyViews.value(waypoints[i], NULL);
if (waypoints[i]->getId() == seq)
{
@ -465,13 +465,15 @@ void WaypointList::waypointViewOnlyListChanged() @@ -465,13 +465,15 @@ void WaypointList::waypointViewOnlyListChanged()
}
}
if (i == waypoints.count()) {
WaypointViewOnlyView* widget = wpViewOnlyViews.find(cur).value();
WaypointViewOnlyView* widget = wpViewOnlyViews.value(cur, NULL);
if (widget) {
widget->hide();
viewOnlyListLayout->removeWidget(widget);
wpViewOnlyViews.remove(cur);
}
}
}
}
// then add/update the views for each waypoint in the list
for(int i = 0; i < waypoints.count(); i++) {
@ -519,13 +521,16 @@ void WaypointList::waypointEditableListChanged() @@ -519,13 +521,16 @@ void WaypointList::waypointEditableListChanged()
}
}
if (i == waypoints.count()) {
WaypointEditableView* widget = wpEditableViews.find(cur).value();
WaypointEditableView* widget = wpEditableViews.value(cur, NULL);
if (widget) {
widget->hide();
editableListLayout->removeWidget(widget);
wpEditableViews.remove(cur);
}
}
}
}
// then add/update the views for each waypoint in the list
for(int i = 0; i < waypoints.count(); i++) {
@ -613,23 +618,27 @@ void WaypointList::on_clearWPListButton_clicked() @@ -613,23 +618,27 @@ void WaypointList::on_clearWPListButton_clicked()
emit clearPathclicked();
const QList<Waypoint *> &waypoints = WPM->getWaypointEditableList();
while(!waypoints.isEmpty()) {
WaypointEditableView* widget = wpEditableViews.find(waypoints[0]).value();
WaypointEditableView* widget = wpEditableViews.value(waypoints[0], NULL);
if (widget) {
widget->remove();
}
}
}
}
void WaypointList::clearWPWidget()
{
// Get list
const QList<Waypoint *> &waypoints = WPM->getWaypointEditableList();
const QList<Waypoint *> waypoints = WPM->getWaypointEditableList();
// XXX delete wps as well
// Clear UI elements
while(!waypoints.isEmpty()) {
WaypointEditableView* widget = wpEditableViews.find(waypoints[0]).value();
WaypointEditableView* widget = wpEditableViews.value(waypoints[0], NULL);
if (widget) {
widget->remove();
}
}
}

6
src/ui/WaypointViewOnlyView.cc

@ -6,10 +6,10 @@ @@ -6,10 +6,10 @@
WaypointViewOnlyView::WaypointViewOnlyView(Waypoint* wp, QWidget *parent) :
QWidget(parent),
wp(wp),
m_ui(new Ui::WaypointViewOnlyView)
{
m_ui->setupUi(this);
this->wp = wp;
updateValues();
connect(m_ui->current, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
@ -60,6 +60,10 @@ void WaypointViewOnlyView::changedCurrent(int state) @@ -60,6 +60,10 @@ void WaypointViewOnlyView::changedCurrent(int state)
void WaypointViewOnlyView::setCurrent(bool state)
//This is a slot receiving signals from UASWaypointManager. The state given here is the true representation of what the "current" waypoint on UAV is.
{
if (!wp) {
return;
}
m_ui->current->blockSignals(true);
if (state == true)
{

26
src/ui/map/QGCMapWidget.cc

@ -169,6 +169,12 @@ void QGCMapWidget::mouseReleaseEvent(QMouseEvent *event) @@ -169,6 +169,12 @@ void QGCMapWidget::mouseReleaseEvent(QMouseEvent *event)
{
mousePressPos = event->pos();
mapcontrol::OPMapWidget::mouseReleaseEvent(event);
// If the mouse is released, we can't be dragging
if (firingWaypointChange) {
firingWaypointChange = NULL;
}
qDebug() << "MOUSE RELEASED";
}
QGCMapWidget::~QGCMapWidget()
@ -620,10 +626,11 @@ void QGCMapWidget::handleMapWaypointEdit(mapcontrol::WayPointItem* waypoint) @@ -620,10 +626,11 @@ void QGCMapWidget::handleMapWaypointEdit(mapcontrol::WayPointItem* waypoint)
WPDelete(waypoint);
// Protect from vicious double update cycle
if (firingWaypointChange == wp) return;
if (firingWaypointChange == wp) {
return;
}
// Not in cycle, block now from entering it
firingWaypointChange = wp;
// // qDebug() << "UPDATING WP FROM MAP";
// Update WP values
internals::PointLatLng pos = waypoint->Coord();
@ -632,19 +639,14 @@ void QGCMapWidget::handleMapWaypointEdit(mapcontrol::WayPointItem* waypoint) @@ -632,19 +639,14 @@ void QGCMapWidget::handleMapWaypointEdit(mapcontrol::WayPointItem* waypoint)
wp->blockSignals(true);
wp->setLatitude(pos.Lat());
wp->setLongitude(pos.Lng());
// XXX Magic values
// wp->setAltitude(homeAltitude + 50.0f);
// wp->setAcceptanceRadius(10.0f);
wp->blockSignals(false);
internals::PointLatLng coord = waypoint->Coord();
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
// // qDebug() << "MAP WP COORD (MAP):" << coord_str << __FILE__ << __LINE__;
QString wp_str = QString::number(wp->getLatitude(), 'f', 6) + " " + QString::number(wp->getLongitude(), 'f', 6);
// // qDebug() << "MAP WP COORD (WP):" << wp_str << __FILE__ << __LINE__;
firingWaypointChange = NULL;
// internals::PointLatLng coord = waypoint->Coord();
// QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
// qDebug() << "MAP WP COORD (MAP):" << coord_str << __FILE__ << __LINE__;
// QString wp_str = QString::number(wp->getLatitude(), 'f', 6) + " " + QString::number(wp->getLongitude(), 'f', 6);
// qDebug() << "MAP WP COORD (WP):" << wp_str << __FILE__ << __LINE__;
emit waypointChanged(wp);
}

Loading…
Cancel
Save