From b6a405209523d8b8a669f6eb7e8d93972c3b6cf2 Mon Sep 17 00:00:00 2001 From: pixhawk Date: Thu, 17 Feb 2011 18:09:11 +0100 Subject: [PATCH] removed unnecessary list element operations when updating waypoint list view. There is still some crazy updating going on - most probably in the wp widgets --- src/ui/WaypointList.cc | 81 +++++++++++++++++++++++++++----------------------- src/ui/WaypointView.cc | 2 +- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index ee69e6b..7f07eaf 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -278,56 +278,61 @@ void WaypointList::waypointListChanged() this->setUpdatesEnabled(false); const QVector &waypoints = uas->getWaypointManager()->getWaypointList(); - if (!wpViews.empty()) + if (!wpViews.empty()) + { + QMapIterator viewIt(wpViews); + viewIt.toFront(); + while(viewIt.hasNext()) { - QMapIterator viewIt(wpViews); - viewIt.toFront(); - while(viewIt.hasNext()) + viewIt.next(); + Waypoint *cur = viewIt.key(); + int i; + for (i = 0; i < waypoints.size(); i++) { - viewIt.next(); - Waypoint *cur = viewIt.key(); - int i; - for (i = 0; i < waypoints.size(); i++) - { - if (waypoints[i] == cur) - { - break; - } - } - if (i == waypoints.size()) + if (waypoints[i] == cur) { - WaypointView* widget = wpViews.find(cur).value(); - widget->hide(); - listLayout->removeWidget(widget); - wpViews.remove(cur); + break; } } - } - - // then add/update the views for each waypoint in the list - for(int i = 0; i < waypoints.size(); i++) - { - Waypoint *wp = waypoints[i]; - if (!wpViews.contains(wp)) + if (i == waypoints.size()) { - WaypointView* wpview = new WaypointView(wp, this); - wpViews.insert(wp, wpview); - connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*))); - connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*))); - connect(wpview, SIGNAL(removeWaypoint(Waypoint*)), this, SLOT(removeWaypoint(Waypoint*))); - connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16))); - connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16))); + WaypointView* widget = wpViews.find(cur).value(); + widget->hide(); + listLayout->removeWidget(widget); + wpViews.remove(cur); } - WaypointView *wpv = wpViews.value(wp); - wpv->updateValues(); // update the values of the ui elements in the view - listLayout->addWidget(wpv); - } - this->setUpdatesEnabled(true); } + // then add/update the views for each waypoint in the list + for(int i = 0; i < waypoints.size(); i++) + { + Waypoint *wp = waypoints[i]; + if (!wpViews.contains(wp)) + { + WaypointView* wpview = new WaypointView(wp, this); + wpViews.insert(wp, wpview); + connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*))); + connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*))); + connect(wpview, SIGNAL(removeWaypoint(Waypoint*)), this, SLOT(removeWaypoint(Waypoint*))); + connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16))); + connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16))); + listLayout->insertWidget(i, wpview); + } + WaypointView *wpv = wpViews.value(wp); + + //check if ordering has changed + if(listLayout->itemAt(i)->widget() != wpv) + { + listLayout->removeWidget(wpv); + listLayout->insertWidget(i, wpv); + } + wpv->updateValues(); // update the values of the ui elements in the view + } + this->setUpdatesEnabled(true); loadFileGlobalWP = false; + } } //void WaypointList::waypointListChanged() diff --git a/src/ui/WaypointView.cc b/src/ui/WaypointView.cc index d8ecc15..81fe574 100644 --- a/src/ui/WaypointView.cc +++ b/src/ui/WaypointView.cc @@ -530,7 +530,7 @@ void WaypointView::updateValues() void WaypointView::setCurrent(bool state) { m_ui->selectedBox->blockSignals(true); - m_ui->selectedBox->setChecked(state);; + m_ui->selectedBox->setChecked(state); m_ui->selectedBox->blockSignals(false); }