Commit 129069d4 authored by Bryant's avatar Bryant

Partway through refactoring of UAS deletion. This is in order to actually...

Partway through refactoring of UAS deletion. This is in order to actually support removing UASes from QGC, which is currently impossible.
parent b3cff5ca
...@@ -684,7 +684,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) ...@@ -684,7 +684,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
if (mavlink_parse_char(this->id, data[i], &msg, &comm)) if (mavlink_parse_char(this->id, data[i], &msg, &comm))
{ {
// MESSAGE RECEIVED! // MESSAGE RECEIVED!
qDebug() << "SIMULATION LINK RECEIVED MESSAGE!"; // qDebug() << "SIMULATION LINK RECEIVED MESSAGE!";
emit messageReceived(msg); emit messageReceived(msg);
switch (msg.msgid) switch (msg.msgid)
...@@ -722,7 +722,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) ...@@ -722,7 +722,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
mavlink_command_long_t action; mavlink_command_long_t action;
mavlink_msg_command_long_decode(&msg, &action); mavlink_msg_command_long_decode(&msg, &action);
qDebug() << "SIM" << "received action" << action.command << "for system" << action.target_system; // qDebug() << "SIM" << "received action" << action.command << "for system" << action.target_system;
// FIXME MAVLINKV10PORTINGNEEDED // FIXME MAVLINKV10PORTINGNEEDED
// switch (action.action) { // switch (action.action) {
...@@ -756,13 +756,13 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) ...@@ -756,13 +756,13 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
case MAVLINK_MSG_ID_MANUAL_CONTROL: { case MAVLINK_MSG_ID_MANUAL_CONTROL: {
mavlink_manual_control_t control; mavlink_manual_control_t control;
mavlink_msg_manual_control_decode(&msg, &control); mavlink_msg_manual_control_decode(&msg, &control);
qDebug() << "\n" << "ROLL:" << control.x << "PITCH:" << control.y; // qDebug() << "\n" << "ROLL:" << control.x << "PITCH:" << control.y;
} }
break; break;
#endif #endif
case MAVLINK_MSG_ID_PARAM_REQUEST_LIST: case MAVLINK_MSG_ID_PARAM_REQUEST_LIST:
{ {
qDebug() << "GCS REQUESTED PARAM LIST FROM SIMULATION"; // qDebug() << "GCS REQUESTED PARAM LIST FROM SIMULATION";
mavlink_param_request_list_t read; mavlink_param_request_list_t read;
mavlink_msg_param_request_list_decode(&msg, &read); mavlink_msg_param_request_list_decode(&msg, &read);
if (read.target_system == systemId) if (read.target_system == systemId)
...@@ -785,7 +785,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) ...@@ -785,7 +785,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
j++; j++;
} }
qDebug() << "SIMULATION SENT PARAMETERS TO GCS"; // qDebug() << "SIMULATION SENT PARAMETERS TO GCS";
} }
} }
break; break;
...@@ -794,7 +794,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) ...@@ -794,7 +794,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
// Drop on even milliseconds // Drop on even milliseconds
if (QGC::groundTimeMilliseconds() % 2 == 0) if (QGC::groundTimeMilliseconds() % 2 == 0)
{ {
qDebug() << "SIMULATION RECEIVED COMMAND TO SET PARAMETER"; // qDebug() << "SIMULATION RECEIVED COMMAND TO SET PARAMETER";
mavlink_param_set_t set; mavlink_param_set_t set;
mavlink_msg_param_set_decode(&msg, &set); mavlink_msg_param_set_decode(&msg, &set);
// if (set.target_system == systemId) // if (set.target_system == systemId)
...@@ -819,7 +819,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) ...@@ -819,7 +819,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
break; break;
case MAVLINK_MSG_ID_PARAM_REQUEST_READ: case MAVLINK_MSG_ID_PARAM_REQUEST_READ:
{ {
qDebug() << "SIMULATION RECEIVED COMMAND TO SEND PARAMETER"; // qDebug() << "SIMULATION RECEIVED COMMAND TO SEND PARAMETER";
mavlink_param_request_read_t read; mavlink_param_request_read_t read;
mavlink_msg_param_request_read_decode(&msg, &read); mavlink_msg_param_request_read_decode(&msg, &read);
QByteArray bytes((char*)read.param_id, MAVLINK_MSG_PARAM_REQUEST_READ_FIELD_PARAM_ID_LEN); QByteArray bytes((char*)read.param_id, MAVLINK_MSG_PARAM_REQUEST_READ_FIELD_PARAM_ID_LEN);
......
...@@ -130,7 +130,7 @@ void MAVLinkSimulationMAV::mainloop() ...@@ -130,7 +130,7 @@ void MAVLinkSimulationMAV::mainloop()
y = nextSPY; y = nextSPY;
z = nextSPZ; z = nextSPZ;
firstWP = false; firstWP = false;
qDebug() << "INIT STEP"; // qDebug() << "INIT STEP";
} }
} }
else else
...@@ -139,7 +139,6 @@ void MAVLinkSimulationMAV::mainloop() ...@@ -139,7 +139,6 @@ void MAVLinkSimulationMAV::mainloop()
} }
// GLOBAL POSITION // GLOBAL POSITION
mavlink_message_t msg; mavlink_message_t msg;
mavlink_global_position_int_t pos; mavlink_global_position_int_t pos;
...@@ -395,7 +394,7 @@ void MAVLinkSimulationMAV::handleMessage(const mavlink_message_t& msg) ...@@ -395,7 +394,7 @@ void MAVLinkSimulationMAV::handleMessage(const mavlink_message_t& msg)
if (msg.sysid != systemid) if (msg.sysid != systemid)
{ {
print_message(&msg); print_message(&msg);
qDebug() << "MAV:" << systemid << "RECEIVED MESSAGE FROM" << msg.sysid << "COMP" << msg.compid; // qDebug() << "MAV:" << systemid << "RECEIVED MESSAGE FROM" << msg.sysid << "COMP" << msg.compid;
} }
switch(msg.msgid) { switch(msg.msgid) {
......
...@@ -394,9 +394,6 @@ signals: ...@@ -394,9 +394,6 @@ signals:
* @param description longer textual description. Should be however limited to a short text, e.g. 200 chars. * @param description longer textual description. Should be however limited to a short text, e.g. 200 chars.
*/ */
void statusChanged(UASInterface* uas, QString status, QString description); void statusChanged(UASInterface* uas, QString status, QString description);
/** @brief System has been removed / disconnected / shutdown cleanly, remove */
void systemRemoved(UASInterface* uas);
void systemRemoved();
/** /**
* @brief Received a plain text message from the robot * @brief Received a plain text message from the robot
* This signal should NOT be used for standard communication, but rather for VERY IMPORTANT * This signal should NOT be used for standard communication, but rather for VERY IMPORTANT
......
...@@ -269,7 +269,6 @@ void UASManager::addUAS(UASInterface* uas) ...@@ -269,7 +269,6 @@ void UASManager::addUAS(UASInterface* uas)
if (!systems.contains(uas)) if (!systems.contains(uas))
{ {
systems.append(uas); systems.append(uas);
connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(removeUAS(QObject*)));
// Set home position on UAV if set in UI // Set home position on UAV if set in UI
// - this is done on a per-UAV basis // - this is done on a per-UAV basis
// Set home position in UI if UAV chooses a new one (caution! if multiple UAVs are connected, take care!) // Set home position in UI if UAV chooses a new one (caution! if multiple UAVs are connected, take care!)
...@@ -300,14 +299,19 @@ void UASManager::addUAS(UASInterface* uas) ...@@ -300,14 +299,19 @@ void UASManager::addUAS(UASInterface* uas)
} }
} }
void UASManager::removeUAS(QObject* uas) /**
* @brief The function that should be used when removing UASes from QGC. emits UASDeletect(UASInterface*) when triggered
* so that UI elements can update accordingly.
* @param uas The UAS to remove
*/
void UASManager::removeUAS(UASInterface* uas)
{ {
UASInterface* mav = qobject_cast<UASInterface*>(uas); if (uas)
{
if (mav) { int listindex = systems.indexOf(uas);
int listindex = systems.indexOf(mav);
if (mav == activeUAS) // If this is the active UAS, select a new one.
if (uas == activeUAS)
{ {
if (systems.count() > 1) if (systems.count() > 1)
{ {
...@@ -334,8 +338,14 @@ void UASManager::removeUAS(QObject* uas) ...@@ -334,8 +338,14 @@ void UASManager::removeUAS(QObject* uas)
// XXX Not emitting the null pointer yet // XXX Not emitting the null pointer yet
} }
} }
// Finally delete a local reference to this UAS
systems.removeAt(listindex); systems.removeAt(listindex);
emit UASDeleted(mav);
// Notify other UI elements that a UAS is being deleted before finally deleting it.
qDebug() << "Deleting UAS object: " << uas->getUASName();
emit UASDeleted(uas);
uas->deleteLater();
} }
} }
......
...@@ -151,8 +151,8 @@ public slots: ...@@ -151,8 +151,8 @@ public slots:
**/ **/
void addUAS(UASInterface* UAS); void addUAS(UASInterface* UAS);
/** @brief Remove a system from the list */ /** @brief Remove a system from the list. Also triggers the UAS to kill itself. */
void removeUAS(QObject* uas); void removeUAS(UASInterface* uas);
/** /**
......
...@@ -184,6 +184,9 @@ HSIDisplay::HSIDisplay(QWidget *parent) : ...@@ -184,6 +184,9 @@ HSIDisplay::HSIDisplay(QWidget *parent) :
setActiveUAS(UASManager::instance()->getActiveUAS()); setActiveUAS(UASManager::instance()->getActiveUAS());
} }
// Listen for the removal of the active UAS.
setActiveUAS(UASManager::instance()->getActiveUAS());
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
} }
...@@ -981,6 +984,12 @@ void HSIDisplay::setActiveUAS(UASInterface* uas) ...@@ -981,6 +984,12 @@ void HSIDisplay::setActiveUAS(UASInterface* uas)
resetMAVState(); resetMAVState();
} }
void HSIDisplay::removeUAS(UASInterface* uas)
{
this->uas = NULL;
resetMAVState();
}
void HSIDisplay::updateSpeed(UASInterface* uas, double vx, double vy, double vz, quint64 time) void HSIDisplay::updateSpeed(UASInterface* uas, double vx, double vy, double vz, quint64 time)
{ {
Q_UNUSED(uas); Q_UNUSED(uas);
......
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
public slots: public slots:
void setActiveUAS(UASInterface* uas); void setActiveUAS(UASInterface* uas);
void removeUAS(UASInterface* uas);
/** @brief Set the width in meters this widget shows from top */ /** @brief Set the width in meters this widget shows from top */
void setMetricWidth(double width); void setMetricWidth(double width);
void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used); void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used);
......
...@@ -1744,7 +1744,6 @@ void MainWindow::UASCreated(UASInterface* uas) ...@@ -1744,7 +1744,6 @@ void MainWindow::UASCreated(UASInterface* uas)
// this code piece might be removed later if this is the final // this code piece might be removed later if this is the final
// conclusion (May 2013) // conclusion (May 2013)
// QAction* uasAction = new QAction(icon, tr("Select %1 for control").arg(uas->getUASName()), ui.menuConnected_Systems); // QAction* uasAction = new QAction(icon, tr("Select %1 for control").arg(uas->getUASName()), ui.menuConnected_Systems);
// connect(uas, SIGNAL(systemRemoved()), uasAction, SLOT(deleteLater()));
// connect(uasAction, SIGNAL(triggered()), uas, SLOT(setSelected())); // connect(uasAction, SIGNAL(triggered()), uas, SLOT(setSelected()));
// ui.menuConnected_Systems->addAction(uasAction); // ui.menuConnected_Systems->addAction(uasAction);
......
...@@ -31,7 +31,6 @@ This file is part of the QGROUNDCONTROL project ...@@ -31,7 +31,6 @@ This file is part of the QGROUNDCONTROL project
QGCToolBar::QGCToolBar(QWidget *parent) : QGCToolBar::QGCToolBar(QWidget *parent) :
QToolBar(parent), QToolBar(parent),
mav(NULL), mav(NULL),
player(NULL),
changed(true), changed(true),
batteryPercent(0), batteryPercent(0),
batteryVoltage(0), batteryVoltage(0),
...@@ -91,28 +90,28 @@ void QGCToolBar::createUI() ...@@ -91,28 +90,28 @@ void QGCToolBar::createUI()
symbolLabel = new QLabel(this); symbolLabel = new QLabel(this);
addWidget(symbolLabel); addWidget(symbolLabel);
toolBarNameLabel = new QLabel("------", this); toolBarNameLabel = new QLabel(this);
toolBarNameLabel->setToolTip(tr("Currently controlled vehicle")); toolBarNameLabel->setToolTip(tr("Currently controlled vehicle"));
toolBarNameLabel->setAlignment(Qt::AlignCenter); toolBarNameLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarNameLabel); addWidget(toolBarNameLabel);
toolBarTimeoutLabel = new QLabel("UNCONNECTED", this); toolBarTimeoutLabel = new QLabel(this);
toolBarTimeoutLabel->setToolTip(tr("System timed out, interval since last message")); toolBarTimeoutLabel->setToolTip(tr("System timed out, interval since last message"));
toolBarTimeoutLabel->setAlignment(Qt::AlignCenter); toolBarTimeoutLabel->setAlignment(Qt::AlignCenter);
toolBarTimeoutLabel->setObjectName("toolBarTimeoutLabel"); toolBarTimeoutLabel->setObjectName("toolBarTimeoutLabel");
addWidget(toolBarTimeoutLabel); addWidget(toolBarTimeoutLabel);
toolBarSafetyLabel = new QLabel("----", this); toolBarSafetyLabel = new QLabel(this);
toolBarSafetyLabel->setToolTip(tr("Vehicle safety state")); toolBarSafetyLabel->setToolTip(tr("Vehicle safety state"));
toolBarSafetyLabel->setAlignment(Qt::AlignCenter); toolBarSafetyLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarSafetyLabel); addWidget(toolBarSafetyLabel);
toolBarModeLabel = new QLabel("------", this); toolBarModeLabel = new QLabel(this);
toolBarModeLabel->setToolTip(tr("Vehicle mode")); toolBarModeLabel->setToolTip(tr("Vehicle mode"));
toolBarModeLabel->setAlignment(Qt::AlignCenter); toolBarModeLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarModeLabel); addWidget(toolBarModeLabel);
toolBarStateLabel = new QLabel("------", this); toolBarStateLabel = new QLabel(this);
toolBarStateLabel->setToolTip(tr("Vehicle state")); toolBarStateLabel->setToolTip(tr("Vehicle state"));
toolBarStateLabel->setAlignment(Qt::AlignCenter); toolBarStateLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarStateLabel); addWidget(toolBarStateLabel);
...@@ -122,28 +121,27 @@ void QGCToolBar::createUI() ...@@ -122,28 +121,27 @@ void QGCToolBar::createUI()
toolBarBatteryBar->setMaximum(100); toolBarBatteryBar->setMaximum(100);
toolBarBatteryBar->setMinimumWidth(20); toolBarBatteryBar->setMinimumWidth(20);
toolBarBatteryBar->setMaximumWidth(100); toolBarBatteryBar->setMaximumWidth(100);
toolBarBatteryBar->setValue(0);
toolBarBatteryBar->setToolTip(tr("Battery charge level")); toolBarBatteryBar->setToolTip(tr("Battery charge level"));
toolBarBatteryBar->setObjectName("toolBarBatteryBar"); toolBarBatteryBar->setObjectName("toolBarBatteryBar");
addWidget(toolBarBatteryBar); addWidget(toolBarBatteryBar);
toolBarBatteryVoltageLabel = new QLabel("xx.x V"); toolBarBatteryVoltageLabel = new QLabel(this);
toolBarBatteryVoltageLabel->setObjectName("toolBarBatteryVoltageLabel"); toolBarBatteryVoltageLabel->setObjectName("toolBarBatteryVoltageLabel");
toolBarBatteryVoltageLabel->setToolTip(tr("Battery voltage")); toolBarBatteryVoltageLabel->setToolTip(tr("Battery voltage"));
toolBarBatteryVoltageLabel->setAlignment(Qt::AlignCenter); toolBarBatteryVoltageLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarBatteryVoltageLabel); addWidget(toolBarBatteryVoltageLabel);
toolBarWpLabel = new QLabel("WP--", this); toolBarWpLabel = new QLabel(this);
toolBarWpLabel->setToolTip(tr("Current waypoint")); toolBarWpLabel->setToolTip(tr("Current waypoint"));
toolBarWpLabel->setAlignment(Qt::AlignCenter); toolBarWpLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarWpLabel); addWidget(toolBarWpLabel);
toolBarDistLabel = new QLabel("--- ---- m", this); toolBarDistLabel = new QLabel(this);
toolBarDistLabel->setToolTip(tr("Distance to current waypoint")); toolBarDistLabel->setToolTip(tr("Distance to current waypoint"));
toolBarDistLabel->setAlignment(Qt::AlignCenter); toolBarDistLabel->setAlignment(Qt::AlignCenter);
addWidget(toolBarDistLabel); addWidget(toolBarDistLabel);
toolBarMessageLabel = new QLabel("", this); toolBarMessageLabel = new QLabel(this);
toolBarMessageLabel->setToolTip(tr("Most recent system message")); toolBarMessageLabel->setToolTip(tr("Most recent system message"));
addWidget(toolBarMessageLabel); addWidget(toolBarMessageLabel);
...@@ -158,11 +156,17 @@ void QGCToolBar::createUI() ...@@ -158,11 +156,17 @@ void QGCToolBar::createUI()
addWidget(connectButton); addWidget(connectButton);
connect(connectButton, SIGNAL(clicked(bool)), this, SLOT(connectLink(bool))); connect(connectButton, SIGNAL(clicked(bool)), this, SLOT(connectLink(bool)));
resetToolbarUI();
// DONE INITIALIZING BUTTONS // DONE INITIALIZING BUTTONS
// Set the toolbar to be updated every 2s
connect(&updateViewTimer, SIGNAL(timeout()), this, SLOT(updateView()));
// Configure the toolbar for the current default UAS // Configure the toolbar for the current default UAS
setActiveUAS(UASManager::instance()->getActiveUAS()); setActiveUAS(UASManager::instance()->getActiveUAS());
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
connect(UASManager::instance(), SIGNAL(UASDeleted(UASInterface*)), this, SLOT(removeUAS(UASInterface*)));
if (LinkManager::instance()->getLinks().count() > 2) if (LinkManager::instance()->getLinks().count() > 2)
addLink(LinkManager::instance()->getLinks().last()); addLink(LinkManager::instance()->getLinks().last());
...@@ -175,15 +179,33 @@ void QGCToolBar::createUI() ...@@ -175,15 +179,33 @@ void QGCToolBar::createUI()
connectButton->setText(tr("New Link")); connectButton->setText(tr("New Link"));
} }
// Set the toolbar to be updated every 2s
connect(&updateViewTimer, SIGNAL(timeout()), this, SLOT(updateView()));
updateViewTimer.start(2000);
loadSettings(); loadSettings();
changed = false; changed = false;
} }
/**
* Reset all the labels and stuff for the toolbar to a pristine state. Done at startup after
* all UI has been created and also when the last UAS has been deleted.
**/
void QGCToolBar::resetToolbarUI()
{
toolBarNameLabel->setText("------");
toolBarNameLabel->setStyleSheet("");
toolBarTimeoutLabel->setText(tr("UNCONNECTED"));
toolBarSafetyLabel->setText("----");
toolBarModeLabel->setText("------");
toolBarStateLabel->setText("------");
toolBarBatteryBar->setValue(0);
toolBarBatteryBar->setDisabled(true);
toolBarBatteryVoltageLabel->setText("xx.x V");
toolBarWpLabel->setText("WP--");
toolBarDistLabel->setText("--- ---- m");
toolBarMessageLabel->clear();
symbolLabel->setStyleSheet("");
symbolLabel->clear();
}
void QGCToolBar::setPerspectiveChangeActions(const QList<QAction*> &actions) void QGCToolBar::setPerspectiveChangeActions(const QList<QAction*> &actions)
{ {
if (actions.count() > 1) if (actions.count() > 1)
...@@ -269,9 +291,9 @@ void QGCToolBar::setActiveUAS(UASInterface* active) ...@@ -269,9 +291,9 @@ void QGCToolBar::setActiveUAS(UASInterface* active)
// Do nothing if system is the same or NULL // Do nothing if system is the same or NULL
if ((active == NULL) || mav == active) return; if ((active == NULL) || mav == active) return;
// If switching UASes, disconnect the only one.
if (mav) if (mav)
{ {
// Disconnect old system
disconnect(mav, SIGNAL(statusChanged(UASInterface*,QString,QString)), this, SLOT(updateState(UASInterface*,QString,QString))); disconnect(mav, SIGNAL(statusChanged(UASInterface*,QString,QString)), this, SLOT(updateState(UASInterface*,QString,QString)));
disconnect(mav, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString))); disconnect(mav, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString)));
disconnect(mav, SIGNAL(nameChanged(QString)), this, SLOT(updateName(QString))); disconnect(mav, SIGNAL(nameChanged(QString)), this, SLOT(updateName(QString)));
...@@ -287,6 +309,11 @@ void QGCToolBar::setActiveUAS(UASInterface* active) ...@@ -287,6 +309,11 @@ void QGCToolBar::setActiveUAS(UASInterface* active)
disconnect(mav->getWaypointManager(), SIGNAL(waypointDistanceChanged(double)), this, SLOT(updateWaypointDistance(double))); disconnect(mav->getWaypointManager(), SIGNAL(waypointDistanceChanged(double)), this, SLOT(updateWaypointDistance(double)));
} }
} }
else
{
// Only update the UI once a UAS has been selected.
updateViewTimer.start(2000);
}
// Connect new system // Connect new system
mav = active; mav = active;
...@@ -315,9 +342,24 @@ void QGCToolBar::setActiveUAS(UASInterface* active) ...@@ -315,9 +342,24 @@ void QGCToolBar::setActiveUAS(UASInterface* active)
toolBarStateLabel->setText(mav->getShortState()); toolBarStateLabel->setText(mav->getShortState());
toolBarTimeoutLabel->setText(""); toolBarTimeoutLabel->setText("");
toolBarDistLabel->setText(""); toolBarDistLabel->setText("");
toolBarBatteryBar->setEnabled(true);
setSystemType(mav, mav->getSystemType()); setSystemType(mav, mav->getSystemType());
} }
/**
* @brief Handle removal of the UAS that is currently being displayed.
* Stop updating the UI periodically, reset the UI, and reset our stored UAS.
* @param uas The UAS to remove.
*/
void QGCToolBar::removeUAS(UASInterface* uas)
{
if (mav == uas) {
updateViewTimer.stop();
resetToolbarUI();
mav = NULL;
}
}
void QGCToolBar::createCustomWidgets() void QGCToolBar::createCustomWidgets()
{ {
......
...@@ -46,6 +46,8 @@ public: ...@@ -46,6 +46,8 @@ public:
public slots: public slots:
/** @brief Set the system that is currently displayed by this widget */ /** @brief Set the system that is currently displayed by this widget */
void setActiveUAS(UASInterface* active); void setActiveUAS(UASInterface* active);
/** @brief Remove the provided UAS if it's currently active from the toolbar */
void removeUAS(UASInterface* uas);
/** @brief Set the link which is currently handled with connecting / disconnecting */ /** @brief Set the link which is currently handled with connecting / disconnecting */
void addLink(LinkInterface* link); void addLink(LinkInterface* link);
/** @brief Remove link which is currently handled */ /** @brief Remove link which is currently handled */
...@@ -88,6 +90,7 @@ protected: ...@@ -88,6 +90,7 @@ protected:
void storeSettings(); void storeSettings();
void loadSettings(); void loadSettings();
void createUI(); void createUI();
void resetToolbarUI();
UASInterface* mav; UASInterface* mav;
QLabel* symbolLabel; QLabel* symbolLabel;
...@@ -102,7 +105,6 @@ protected: ...@@ -102,7 +105,6 @@ protected:
QPushButton* connectButton; QPushButton* connectButton;
QProgressBar* toolBarBatteryBar; QProgressBar* toolBarBatteryBar;
QLabel* toolBarBatteryVoltageLabel; QLabel* toolBarBatteryVoltageLabel;
QGCMAVLinkLogPlayer* player;
bool changed; bool changed;
float batteryPercent; float batteryPercent;
float batteryVoltage; float batteryVoltage;
......
...@@ -146,32 +146,32 @@ void UASListWidget::activeUAS(UASInterface* uas) ...@@ -146,32 +146,32 @@ void UASListWidget::activeUAS(UASInterface* uas)
* If the UAS was removed, check to see if it was the last one in the QGroupBox and delete * If the UAS was removed, check to see if it was the last one in the QGroupBox and delete
* the QGroupBox if so. * the QGroupBox if so.
*/ */
void UASListWidget::removeUASView(QObject* widget) void UASListWidget::removeUAS(UASInterface* uas)
{ {
UASView* view = (UASView*)widget; // Remove the UAS from our data structures and
if (view) { // the global listing.
int views = view->parentWidget()->findChildren<UASView*>().size(); uasViews.remove(uas);
if (views == 0) {
// Delete the groupbox
view->parentWidget()->deleteLater();
// Remove the associated UAS from our list. // Check all groupboxes for all links this uas had and check if they're empty.
UASInterface* uas = uasViews.key(view, NULL); // Delete them if they are.
if (uas) QListIterator<LinkInterface*> i = *uas->getLinks();
while (i.hasNext())
{ {
uasViews.remove(uas); LinkInterface* link = i.next();
}
// And remove this GroupBox from our mapping. QGroupBox* box = linkToBoxMapping[link];
LinkInterface* link = linkToBoxMapping.key((QGroupBox*)view->parentWidget(), NULL); if (box)
if (link)
{ {
// If this was the last UAS in the GroupBox, remove it and its corresponding link.
int views = box->findChildren<UASView*>().size();
if (views == 0) {
box->deleteLater();
linkToBoxMapping.remove(link); linkToBoxMapping.remove(link);
} }
}
}
// And put the initial widget back. // And if no QGroupBoxes are left, put the initial widget back.
uWidget = new QGCUnconnectedInfoWidget(this); uWidget = new QGCUnconnectedInfoWidget(this);
m_ui->verticalLayout->addWidget(uWidget); m_ui->verticalLayout->addWidget(uWidget);
}
}
} }
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
public slots: public slots:
void addUAS(UASInterface* uas); void addUAS(UASInterface* uas);
void activeUAS(UASInterface* uas); void activeUAS(UASInterface* uas);
void removeUASView(QObject* widget); void removeUAS(UASInterface* uas);
protected: protected:
// Keep a mapping from Links to GroupBoxes for adding new links. // Keep a mapping from Links to GroupBoxes for adding new links.
......
...@@ -117,13 +117,12 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : ...@@ -117,13 +117,12 @@ UASView::UASView(UASInterface* uas, QWidget *parent) :
connect(m_ui->shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown())); connect(m_ui->shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown()));
// Allow to delete this widget // Allow to delete this widget
connect(removeAction, SIGNAL(triggered()), this, SLOT(deleteLater())); connect(removeAction, SIGNAL(triggered()), this, SLOT(prepareForDeletion()));
connect(renameAction, SIGNAL(triggered()), this, SLOT(rename())); connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
connect(selectAction, SIGNAL(triggered()), uas, SLOT(setSelected())); connect(selectAction, SIGNAL(triggered()), uas, SLOT(setSelected()));
connect(hilAction, SIGNAL(triggered(bool)), this, SLOT(showHILUi())); connect(hilAction, SIGNAL(triggered(bool)), this, SLOT(showHILUi()));
connect(selectAirframeAction, SIGNAL(triggered()), this, SLOT(selectAirframe())); connect(selectAirframeAction, SIGNAL(triggered()), this, SLOT(selectAirframe()));
connect(setBatterySpecsAction, SIGNAL(triggered()), this, SLOT(setBatterySpecs())); connect(setBatterySpecsAction, SIGNAL(triggered()), this, SLOT(setBatterySpecs()));
connect(uas, SIGNAL(systemRemoved()), this, SLOT(deleteLater()));
// Name changes // Name changes
connect(uas, SIGNAL(nameChanged(QString)), this, SLOT(updateName(QString))); connect(uas, SIGNAL(nameChanged(QString)), this, SLOT(updateName(QString)));
...@@ -563,6 +562,16 @@ void UASView::showHILUi() ...@@ -563,6 +562,16 @@ void UASView::showHILUi()
MainWindow::instance()->showHILConfigurationWidget(uas); MainWindow::instance()->showHILConfigurationWidget(uas);
} }
/**
* @brief Stop updating this UASView, queue it for deletion, and also tell the UASManager to delete the UAS.
*/
void UASView::prepareForDeletion()
{
refreshTimer->stop();
UASManager::instance()->removeUAS(uas);
deleteLater();
}
void UASView::refresh() void UASView::refresh()
{ {
//setUpdatesEnabled(false); //setUpdatesEnabled(false);
...@@ -570,7 +579,6 @@ void UASView::refresh() ...@@ -570,7 +579,6 @@ void UASView::refresh()
//repaint(); //repaint();
//qDebug() << "UPDATING UAS WIDGET!" << uas->getUASName(); //qDebug() << "UPDATING UAS WIDGET!" << uas->getUASName();
if (generalUpdateCount == 4) if (generalUpdateCount == 4)
{ {
#if (QGC_EVENTLOOP_DEBUG) #if (QGC_EVENTLOOP_DEBUG)
......
...@@ -65,6 +65,8 @@ public slots: ...@@ -65,6 +65,8 @@ public slots:
void updateLoad(UASInterface* uas, double load); void updateLoad(UASInterface* uas, double load);
//void receiveValue(int uasid, QString id, double value, quint64 time); //void receiveValue(int uasid, QString id, double value, quint64 time);
void showHILUi(); void showHILUi();
/** @brief Disables the widget from accessing the UAS object in preparation for being deleted */
void prepareForDeletion();
void refresh(); void refresh();
/** @brief Receive new waypoint information */ /** @brief Receive new waypoint information */
void setWaypoint(int uasId, int id, double x, double y, double z, double yaw, bool autocontinue, bool current); void setWaypoint(int uasId, int id, double x, double y, double z, double yaw, bool autocontinue, bool current);
......
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