From d55937a1c807f605ac743d850d252d30c5aefd5b Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 26 Aug 2013 17:05:57 +0200 Subject: [PATCH] Another cleanup round --- src/comm/SerialLink.cc | 9 +++++---- src/ui/QGCPX4VehicleConfig.cc | 2 ++ src/ui/QGCToolBar.cc | 12 ++++++++++-- src/ui/uas/UASListWidget.cc | 20 ++++++++++++++++++++ src/ui/uas/UASListWidget.h | 1 + 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index 3af32a6b8..e30f9e3c2 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -28,8 +28,6 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl, m_stopp(false), m_reqReset(false) { - qDebug() << "create SerialLink " << portname << baudRate << hardwareFlowControl - << parity << dataBits << stopBits; // Setup settings m_portName = portname.trimmed(); @@ -38,8 +36,6 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl, m_portName = m_ports.first().trimmed(); } - qDebug() << "m_portName " << m_portName; - // Set unique ID and add link to the list of links m_id = getNextLinkId(); @@ -66,6 +62,11 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl, m_stopBits = stopBits; loadSettings(); + + qDebug() << "create SerialLink " << portname << baudRate << hardwareFlowControl + << parity << dataBits << stopBits; + qDebug() << "m_portName " << m_portName; + LinkManager::instance()->add(this); } void SerialLink::requestReset() diff --git a/src/ui/QGCPX4VehicleConfig.cc b/src/ui/QGCPX4VehicleConfig.cc index cf71c3cdc..5e8edb5b3 100644 --- a/src/ui/QGCPX4VehicleConfig.cc +++ b/src/ui/QGCPX4VehicleConfig.cc @@ -223,6 +223,8 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) : updateTimer.setInterval(150); connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateView())); updateTimer.start(); + + firmwareMenuButtonClicked(); } QGCPX4VehicleConfig::~QGCPX4VehicleConfig() diff --git a/src/ui/QGCToolBar.cc b/src/ui/QGCToolBar.cc index 28c586df5..c75b8554b 100644 --- a/src/ui/QGCToolBar.cc +++ b/src/ui/QGCToolBar.cc @@ -182,8 +182,8 @@ void QGCToolBar::createUI() baudcomboBox->addItem("921600", 921600); baudcomboBox->setCurrentIndex(baudcomboBox->findData(57600)); addWidget(baudcomboBox); - connect(baudcomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(baudSelected(int))); - connect(portComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(portSelected(int))); + connect(baudcomboBox, SIGNAL(activated(int)), this, SLOT(baudSelected(int))); + connect(portComboBox, SIGNAL(activated(int)), this, SLOT(portSelected(int))); connectButton = new QPushButton(tr("Connect"), this); connectButton->setObjectName("connectButton"); @@ -666,6 +666,10 @@ void QGCToolBar::updateComboBox() { if (currentLink) { + // Do not update if not visible + if (!portComboBox->isVisible()) + return; + SerialLink *slink = qobject_cast(currentLink); QList portlist = slink->getCurrentPorts(); foreach (QString port, portlist) @@ -715,6 +719,8 @@ void QGCToolBar::updateLinkState(bool connected) connectButton->blockSignals(true); connectButton->setChecked(true); connectButton->blockSignals(false); + portComboBox->hide(); + baudcomboBox->hide(); } else { @@ -722,6 +728,8 @@ void QGCToolBar::updateLinkState(bool connected) connectButton->blockSignals(true); connectButton->setChecked(false); connectButton->blockSignals(false); + portComboBox->show(); + baudcomboBox->show(); } } diff --git a/src/ui/uas/UASListWidget.cc b/src/ui/uas/UASListWidget.cc index a3fab70aa..bc92aa44e 100644 --- a/src/ui/uas/UASListWidget.cc +++ b/src/ui/uas/UASListWidget.cc @@ -64,6 +64,8 @@ UASListWidget::UASListWidget(QWidget *parent) : QWidget(parent), this->setVisible(false); + connect(LinkManager::instance(), SIGNAL(linkRemoved(LinkInterface*)), this, SLOT(removeLink(LinkInterface*))); + // Listen for when UASes are added or removed. This does not manage the UASView // widgets that are displayed within this widget. connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), @@ -96,12 +98,30 @@ void UASListWidget::changeEvent(QEvent *e) } } +// XXX This is just to prevent +// upfront crashes, will probably need further inspection +void UASListWidget::removeLink(LinkInterface* link) +{ + QGroupBox* box = linkToBoxMapping.value(link, NULL); + + if (box) { + // Just stop updating the status for now - we should + // remove the UAS probably + linkToBoxMapping.remove(link); + } +} + void UASListWidget::updateStatus() { QMapIterator i(linkToBoxMapping); while (i.hasNext()) { i.next(); LinkInterface* link = i.key(); + + // Paranoid sanity check + if (!LinkManager::instance()->getLinks().contains(link)) + continue; + if (!link) continue; diff --git a/src/ui/uas/UASListWidget.h b/src/ui/uas/UASListWidget.h index b14e1e97d..494d16fdb 100644 --- a/src/ui/uas/UASListWidget.h +++ b/src/ui/uas/UASListWidget.h @@ -53,6 +53,7 @@ public slots: void addUAS(UASInterface* uas); void activeUAS(UASInterface* uas); void removeUAS(UASInterface* uas); + void removeLink(LinkInterface* link); protected: // Keep a mapping from UASes to their GroupBox. Useful for determining when groupboxes are empty. -- 2.22.0