From a13508b3e6259738237a6977884ef449e7ab8d3c Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 24 May 2013 21:58:39 +0200 Subject: [PATCH] Allowed offline editing of waypoints --- src/ui/QGCWaypointListMulti.cc | 4 +- src/ui/WaypointList.cc | 101 ++++++++++++++++++--------------- src/ui/WaypointList.h | 2 +- 3 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/ui/QGCWaypointListMulti.cc b/src/ui/QGCWaypointListMulti.cc index 9cbe050d7..752e8cdd4 100644 --- a/src/ui/QGCWaypointListMulti.cc +++ b/src/ui/QGCWaypointListMulti.cc @@ -12,7 +12,7 @@ QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) : connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(systemCreated(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(int)), this, SLOT(systemSetActive(int))); - WaypointList* list = new WaypointList(ui->stackedWidget, NULL); + WaypointList* list = new WaypointList(ui->stackedWidget, UASManager::instance()->getActiveUASWaypointManager()); lists.insert(offline_uas_id, list); ui->stackedWidget->addWidget(list); @@ -40,7 +40,7 @@ void QGCWaypointListMulti::systemDeleted(QObject* uas) void QGCWaypointListMulti::systemCreated(UASInterface* uas) { - WaypointList* list = new WaypointList(ui->stackedWidget, uas); + WaypointList* list = new WaypointList(ui->stackedWidget, uas->getWaypointManager()); lists.insert(uas->getUASID(), list); ui->stackedWidget->addWidget(list); // Ensure widget is deleted when system is deleted diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index 639afcae5..fa4efa4b2 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -34,15 +34,17 @@ This file is part of the PIXHAWK project #include "WaypointList.h" #include "ui_WaypointList.h" #include +#include #include #include #include #include #include -WaypointList::WaypointList(QWidget *parent, UASInterface* uas) : +WaypointList::WaypointList(QWidget *parent, UASWaypointManager* wpm) : QWidget(parent), uas(NULL), + WPM(wpm), mavX(0.0), mavY(0.0), mavZ(0.0), @@ -96,28 +98,32 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) : connect(m_ui->refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); + if (WPM) { + // SET UAS AFTER ALL SIGNALS/SLOTS ARE CONNECTED + if (!WPM->getUAS()) + { + // Hide buttons, which don't make sense without valid UAS + m_ui->positionAddButton->hide(); + m_ui->transmitButton->hide(); + m_ui->readButton->hide(); + m_ui->refreshButton->hide(); + //FIXME: The whole "Onboard Waypoints"-tab should be hidden, instead of "refresh" button + UnconnectedUASInfoWidget* inf = new UnconnectedUASInfoWidget(this); + viewOnlyListLayout->insertWidget(0, inf); //insert a "NO UAV" info into the Onboard Tab + showOfflineWarning = true; + } else { + setUAS(static_cast(WPM->getUAS())); + } - // SET UAS AFTER ALL SIGNALS/SLOTS ARE CONNECTED - if (uas) - { - WPM = uas->getWaypointManager(); - } - else - { - // Hide buttons, which don't make sense without valid UAS - m_ui->positionAddButton->hide(); - m_ui->transmitButton->hide(); - m_ui->readButton->hide(); - m_ui->refreshButton->hide(); - //FIXME: The whole "Onboard Waypoints"-tab should be hidden, instead of "refresh" button - UnconnectedUASInfoWidget* inf = new UnconnectedUASInfoWidget(this); - viewOnlyListLayout->insertWidget(0, inf); //insert a "NO UAV" info into the Onboard Tab - showOfflineWarning = true; - WPM = new UASWaypointManager(NULL); + /* connect slots */ + connect(WPM, SIGNAL(updateStatusString(const QString &)), this, SLOT(updateStatusLabel(const QString &))); + connect(WPM, SIGNAL(waypointEditableListChanged(void)), this, SLOT(waypointEditableListChanged(void))); + connect(WPM, SIGNAL(waypointEditableChanged(int,Waypoint*)), this, SLOT(updateWaypointEditable(int,Waypoint*))); + connect(WPM, SIGNAL(waypointViewOnlyListChanged(void)), this, SLOT(waypointViewOnlyListChanged(void))); + connect(WPM, SIGNAL(waypointViewOnlyChanged(int,Waypoint*)), this, SLOT(updateWaypointViewOnly(int,Waypoint*))); + connect(WPM, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointViewOnlyChanged(quint16))); } - setUAS(uas); - // STATUS LABEL updateStatusLabel(""); @@ -154,28 +160,38 @@ void WaypointList::updateAttitude(UASInterface* uas, double roll, double pitch, void WaypointList::setUAS(UASInterface* uas) { - if (this->uas == NULL && uas != NULL) - { - WPM = uas->getWaypointManager(); - } - if (this->uas == NULL) + if (!uas) + return; + + if (this->uas != NULL) { - this->uas = uas; - connect(WPM, SIGNAL(updateStatusString(const QString &)), this, SLOT(updateStatusLabel(const QString &))); - connect(WPM, SIGNAL(waypointEditableListChanged(void)), this, SLOT(waypointEditableListChanged(void))); - connect(WPM, SIGNAL(waypointEditableChanged(int,Waypoint*)), this, SLOT(updateWaypointEditable(int,Waypoint*))); - connect(WPM, SIGNAL(waypointViewOnlyListChanged(void)), this, SLOT(waypointViewOnlyListChanged(void))); - connect(WPM, SIGNAL(waypointViewOnlyChanged(int,Waypoint*)), this, SLOT(updateWaypointViewOnly(int,Waypoint*))); - connect(WPM, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointViewOnlyChanged(quint16))); - if (uas != NULL) - { - connect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updatePosition(UASInterface*,double,double,double,quint64))); - connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64))); - } - //connect(WPM,SIGNAL(loadWPFile()),this,SLOT(setIsLoadFileWP())); - //connect(WPM,SIGNAL(readGlobalWPFromUAS(bool)),this,SLOT(setIsReadGlobalWP(bool))); + // Clear current list + on_clearWPListButton_clicked(); + // Disconnect everything + disconnect(WPM, SIGNAL(updateStatusString(const QString &)), this, SLOT(updateStatusLabel(const QString &))); + disconnect(WPM, SIGNAL(waypointEditableListChanged(void)), this, SLOT(waypointEditableListChanged(void))); + disconnect(WPM, SIGNAL(waypointEditableChanged(int,Waypoint*)), this, SLOT(updateWaypointEditable(int,Waypoint*))); + disconnect(WPM, SIGNAL(waypointViewOnlyListChanged(void)), this, SLOT(waypointViewOnlyListChanged(void))); + disconnect(WPM, SIGNAL(waypointViewOnlyChanged(int,Waypoint*)), this, SLOT(updateWaypointViewOnly(int,Waypoint*))); + disconnect(WPM, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointViewOnlyChanged(quint16))); + disconnect(this->uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updatePosition(UASInterface*,double,double,double,quint64))); + disconnect(this->uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64))); } + WPM = uas->getWaypointManager(); + + this->uas = uas; + connect(WPM, SIGNAL(updateStatusString(const QString &)), this, SLOT(updateStatusLabel(const QString &))); + connect(WPM, SIGNAL(waypointEditableListChanged(void)), this, SLOT(waypointEditableListChanged(void))); + connect(WPM, SIGNAL(waypointEditableChanged(int,Waypoint*)), this, SLOT(updateWaypointEditable(int,Waypoint*))); + connect(WPM, SIGNAL(waypointViewOnlyListChanged(void)), this, SLOT(waypointViewOnlyListChanged(void))); + connect(WPM, SIGNAL(waypointViewOnlyChanged(int,Waypoint*)), this, SLOT(updateWaypointViewOnly(int,Waypoint*))); + connect(WPM, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointViewOnlyChanged(quint16))); + connect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updatePosition(UASInterface*,double,double,double,quint64))); + connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64))); + //connect(WPM,SIGNAL(loadWPFile()),this,SLOT(setIsLoadFileWP())); + //connect(WPM,SIGNAL(readGlobalWPFromUAS(bool)),this,SLOT(setIsReadGlobalWP(bool))); + // Update list read(); } @@ -583,8 +599,6 @@ void WaypointList::changeEvent(QEvent *e) void WaypointList::on_clearWPListButton_clicked() { - - if (uas) { emit clearPathclicked(); const QVector &waypoints = WPM->getWaypointEditableList(); @@ -592,11 +606,6 @@ void WaypointList::on_clearWPListButton_clicked() WaypointEditableView* widget = wpEditableViews.find(waypoints[0]).value(); widget->remove(); } - } else { -// if(isGlobalWP) -// { -// emit clearPathclicked(); -// } } } diff --git a/src/ui/WaypointList.h b/src/ui/WaypointList.h index 41ed84dcc..97f80e2f5 100644 --- a/src/ui/WaypointList.h +++ b/src/ui/WaypointList.h @@ -56,7 +56,7 @@ class WaypointList : public QWidget Q_OBJECT Q_DISABLE_COPY(WaypointList) public: - WaypointList(QWidget* parent = NULL, UASInterface* uas = NULL); + WaypointList(QWidget* parent = NULL, UASWaypointManager* wpm = NULL); virtual ~WaypointList(); public slots: -- 2.22.0