Commit c81927fa authored by Don Gagne's avatar Don Gagne

Rework Connect toolbar button usage

Now works for more than Serial links
parent cf777949
...@@ -252,8 +252,6 @@ bool QGCApplication::_initForNormalAppBoot(void) ...@@ -252,8 +252,6 @@ bool QGCApplication::_initForNormalAppBoot(void)
_createSingletons(); _createSingletons();
enum MainWindow::CUSTOM_MODE mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_PX4).toInt();
// Show splash screen // Show splash screen
QPixmap splashImage(":/files/images/splash.png"); QPixmap splashImage(":/files/images/splash.png");
QSplashScreen* splashScreen = new QSplashScreen(splashImage); QSplashScreen* splashScreen = new QSplashScreen(splashImage);
...@@ -268,7 +266,7 @@ bool QGCApplication::_initForNormalAppBoot(void) ...@@ -268,7 +266,7 @@ bool QGCApplication::_initForNormalAppBoot(void)
// Start the user interface // Start the user interface
splashScreen->showMessage(tr("Starting user interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141)); splashScreen->showMessage(tr("Starting user interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
MainWindow* mainWindow = MainWindow::_create(splashScreen, mode); MainWindow* mainWindow = MainWindow::_create(splashScreen);
Q_CHECK_PTR(mainWindow); Q_CHECK_PTR(mainWindow);
// If we made it this far and we still don't have a location. Either the specfied location was invalid // If we made it this far and we still don't have a location. Either the specfied location was invalid
...@@ -281,47 +279,10 @@ bool QGCApplication::_initForNormalAppBoot(void) ...@@ -281,47 +279,10 @@ bool QGCApplication::_initForNormalAppBoot(void)
mainWindow->showSettings(); mainWindow->showSettings();
} }
UDPLink* udpLink = NULL;
if (mainWindow->getCustomMode() == MainWindow::CUSTOM_MODE_WIFI)
{
// Connect links
// to make sure that all components are initialized when the
// first messages arrive
udpLink = new UDPLink(QHostAddress::Any, 14550);
LinkManager::instance()->addLink(udpLink);
} else {
// We want to have a default serial link available for "quick" connecting.
SerialLink *slink = new SerialLink();
LinkManager::instance()->addLink(slink);
}
#ifdef QGC_RTLAB_ENABLED
// Add OpalRT Link, but do not connect
OpalLink* opalLink = new OpalLink();
_mainWindow->addLink(opalLink);
#endif
// Remove splash screen // Remove splash screen
splashScreen->finish(mainWindow); splashScreen->finish(mainWindow);
mainWindow->splashScreenFinished(); mainWindow->splashScreenFinished();
// Check if link could be connected
if (udpLink && LinkManager::instance()->connectLink(udpLink))
{
QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Could not connect UDP port. Is an instance of %1 already running?").arg(qAppName()),
tr("It is recommended to close the application and stop all instances. Click Yes to close."),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
// Exit application
if (button == QMessageBox::Yes)
{
//mainWindow->close();
QTimer::singleShot(200, mainWindow, SLOT(close()));
}
}
// Now that main window is upcheck for lost log files // Now that main window is upcheck for lost log files
connect(this, &QGCApplication::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles); connect(this, &QGCApplication::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles(); emit checkForLostLogFiles();
......
...@@ -84,6 +84,9 @@ void LinkManager::addLink(LinkInterface* link) ...@@ -84,6 +84,9 @@ void LinkManager::addLink(LinkInterface* link)
connect(link, &LinkInterface::connected, mavlink, &MAVLinkProtocol::linkConnected); connect(link, &LinkInterface::connected, mavlink, &MAVLinkProtocol::linkConnected);
connect(link, &LinkInterface::disconnected, mavlink, &MAVLinkProtocol::linkDisconnected); connect(link, &LinkInterface::disconnected, mavlink, &MAVLinkProtocol::linkDisconnected);
mavlink->resetMetadataForLink(link); mavlink->resetMetadataForLink(link);
connect(link, &LinkInterface::connected, this, &LinkManager::_linkConnected);
connect(link, &LinkInterface::disconnected, this, &LinkManager::_linkDisconnected);
} }
bool LinkManager::connectAll() bool LinkManager::connectAll()
...@@ -131,13 +134,22 @@ bool LinkManager::connectLink(LinkInterface* link) ...@@ -131,13 +134,22 @@ bool LinkManager::connectLink(LinkInterface* link)
return false; return false;
} }
return link->_connect(); if (link->_connect()) {
return true;
} else {
return false;
}
} }
bool LinkManager::disconnectLink(LinkInterface* link) bool LinkManager::disconnectLink(LinkInterface* link)
{ {
Q_ASSERT(link); Q_ASSERT(link);
return link->_disconnect();
if (link->_disconnect()) {
return true;
} else {
return false;
}
} }
void LinkManager::deleteLink(LinkInterface* link) void LinkManager::deleteLink(LinkInterface* link)
...@@ -218,3 +230,13 @@ void LinkManager::_shutdown(void) ...@@ -218,3 +230,13 @@ void LinkManager::_shutdown(void)
deleteLink(link); deleteLink(link);
} }
} }
void LinkManager::_linkConnected(void)
{
emit linkConnected((LinkInterface*)sender());
}
void LinkManager::_linkDisconnected(void)
{
emit linkDisconnected((LinkInterface*)sender());
}
...@@ -91,6 +91,12 @@ public: ...@@ -91,6 +91,12 @@ public:
signals: signals:
void newLink(LinkInterface* link); void newLink(LinkInterface* link);
void linkDeleted(LinkInterface* link); void linkDeleted(LinkInterface* link);
void linkConnected(LinkInterface* link);
void linkDisconnected(LinkInterface* link);
private slots:
void _linkConnected(void);
void _linkDisconnected(void);
private: private:
/// All access to LinkManager is through LinkManager::instance /// All access to LinkManager is through LinkManager::instance
......
...@@ -277,16 +277,15 @@ bool UDPLink::_disconnect(void) ...@@ -277,16 +277,15 @@ bool UDPLink::_disconnect(void)
this->quit(); this->quit();
this->wait(); this->wait();
if(socket) if (socket) {
{
// Make sure delete happen on correct thread // Make sure delete happen on correct thread
socket->deleteLater(); socket->deleteLater();
socket = NULL; socket = NULL;
emit disconnected();
} }
connectState = false; connectState = false;
emit disconnected();
return !connectState; return !connectState;
} }
......
...@@ -42,7 +42,7 @@ void MainWindowTest::init(void) ...@@ -42,7 +42,7 @@ void MainWindowTest::init(void)
{ {
UnitTest::init(); UnitTest::init();
_mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); _mainWindow = MainWindow::_create(NULL);
Q_CHECK_PTR(_mainWindow); Q_CHECK_PTR(_mainWindow);
} }
......
...@@ -368,7 +368,6 @@ void CommConfigurationWindow::remove() ...@@ -368,7 +368,6 @@ void CommConfigurationWindow::remove()
action=NULL; action=NULL;
if(link) { if(link) {
LinkManager::instance()->disconnectLink(link); // disconnect connection
link->deleteLater(); link->deleteLater();
} }
link=NULL; link=NULL;
......
...@@ -80,11 +80,11 @@ This file is part of the QGROUNDCONTROL project ...@@ -80,11 +80,11 @@ This file is part of the QGROUNDCONTROL project
static MainWindow* _instance = NULL; ///< @brief MainWindow singleton static MainWindow* _instance = NULL; ///< @brief MainWindow singleton
MainWindow* MainWindow::_create(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode) MainWindow* MainWindow::_create(QSplashScreen* splashScreen)
{ {
Q_ASSERT(_instance == NULL); Q_ASSERT(_instance == NULL);
new MainWindow(splashScreen, mode); new MainWindow(splashScreen);
// _instance is set in constructor // _instance is set in constructor
Q_ASSERT(_instance); Q_ASSERT(_instance);
...@@ -105,13 +105,12 @@ void MainWindow::deleteInstance(void) ...@@ -105,13 +105,12 @@ void MainWindow::deleteInstance(void)
/// @brief Private constructor for MainWindow. MainWindow singleton is only ever created /// @brief Private constructor for MainWindow. MainWindow singleton is only ever created
/// by MainWindow::_create method. Hence no other code should have access to /// by MainWindow::_create method. Hence no other code should have access to
/// constructor. /// constructor.
MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode) : MainWindow::MainWindow(QSplashScreen* splashScreen) :
currentView(VIEW_FLIGHT), currentView(VIEW_FLIGHT),
centerStackActionGroup(new QActionGroup(this)), centerStackActionGroup(new QActionGroup(this)),
autoReconnect(false), autoReconnect(false),
simulationLink(NULL), simulationLink(NULL),
lowPowerMode(false), lowPowerMode(false),
customMode(mode),
menuActionHelper(new MenuActionHelper()), menuActionHelper(new MenuActionHelper()),
_splashScreen(splashScreen) _splashScreen(splashScreen)
{ {
...@@ -405,10 +404,10 @@ QString MainWindow::getWindowStateKey() ...@@ -405,10 +404,10 @@ QString MainWindow::getWindowStateKey()
{ {
if (UASManager::instance()->getActiveUAS()) if (UASManager::instance()->getActiveUAS())
{ {
return QString::number(currentView)+"_windowstate_" + QString::number(getCustomMode()) + "_" + UASManager::instance()->getActiveUAS()->getAutopilotTypeName(); return QString::number(currentView)+"_windowstate_" + UASManager::instance()->getActiveUAS()->getAutopilotTypeName();
} }
else else
return QString::number(currentView)+"_windowstate_" + QString::number(getCustomMode()); return QString::number(currentView)+"_windowstate_";
} }
QString MainWindow::getWindowGeometryKey() QString MainWindow::getWindowGeometryKey()
...@@ -938,8 +937,6 @@ void MainWindow::loadSettings() ...@@ -938,8 +937,6 @@ void MainWindow::loadSettings()
{ {
QSettings settings; QSettings settings;
customMode = static_cast<enum MainWindow::CUSTOM_MODE>(settings.value("QGC_CUSTOM_MODE", (unsigned int)MainWindow::CUSTOM_MODE_NONE).toInt());
settings.beginGroup("QGC_MAINWINDOW"); settings.beginGroup("QGC_MAINWINDOW");
autoReconnect = settings.value("AUTO_RECONNECT", autoReconnect).toBool(); autoReconnect = settings.value("AUTO_RECONNECT", autoReconnect).toBool();
lowPowerMode = settings.value("LOW_POWER_MODE", lowPowerMode).toBool(); lowPowerMode = settings.value("LOW_POWER_MODE", lowPowerMode).toBool();
...@@ -953,8 +950,6 @@ void MainWindow::storeSettings() ...@@ -953,8 +950,6 @@ void MainWindow::storeSettings()
{ {
QSettings settings; QSettings settings;
settings.setValue("QGC_CUSTOM_MODE", (int)customMode);
settings.beginGroup("QGC_MAINWINDOW"); settings.beginGroup("QGC_MAINWINDOW");
settings.setValue("AUTO_RECONNECT", autoReconnect); settings.setValue("AUTO_RECONNECT", autoReconnect);
settings.setValue("LOW_POWER_MODE", lowPowerMode); settings.setValue("LOW_POWER_MODE", lowPowerMode);
......
...@@ -88,14 +88,6 @@ class MainWindow : public QMainWindow ...@@ -88,14 +88,6 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
enum CUSTOM_MODE {
CUSTOM_MODE_UNCHANGED = 0,
CUSTOM_MODE_NONE,
CUSTOM_MODE_PX4,
CUSTOM_MODE_WIFI
};
/// @brief Returns the MainWindow singleton. Will not create the MainWindow if it has not already /// @brief Returns the MainWindow singleton. Will not create the MainWindow if it has not already
/// been created. /// been created.
static MainWindow* instance(void); static MainWindow* instance(void);
...@@ -104,7 +96,7 @@ public: ...@@ -104,7 +96,7 @@ public:
void deleteInstance(void); void deleteInstance(void);
/// @brief Creates the MainWindow singleton. Should only be called once by QGCApplication. /// @brief Creates the MainWindow singleton. Should only be called once by QGCApplication.
static MainWindow* _create(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode); static MainWindow* _create(QSplashScreen* splashScreen);
/// @brief Called to indicate that splash screen is no longer being displayed. /// @brief Called to indicate that splash screen is no longer being displayed.
void splashScreenFinished(void) { _splashScreen = NULL; } void splashScreenFinished(void) { _splashScreen = NULL; }
...@@ -127,19 +119,6 @@ public: ...@@ -127,19 +119,6 @@ public:
return lowPowerMode; return lowPowerMode;
} }
void setCustomMode(MainWindow::CUSTOM_MODE mode)
{
if (mode != CUSTOM_MODE_UNCHANGED)
{
customMode = mode;
}
}
MainWindow::CUSTOM_MODE getCustomMode() const
{
return customMode;
}
QList<QAction*> listLinkMenuActions(); QList<QAction*> listLinkMenuActions();
void hideSplashScreen(void); void hideSplashScreen(void);
...@@ -420,14 +399,13 @@ protected: ...@@ -420,14 +399,13 @@ protected:
bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets
QGCFlightGearLink* fgLink; QGCFlightGearLink* fgLink;
QTimer windowNameUpdateTimer; QTimer windowNameUpdateTimer;
CUSTOM_MODE customMode;
private slots: private slots:
void _addLinkMenu(LinkInterface* link); void _addLinkMenu(LinkInterface* link);
private: private:
/// Constructor is private since all creation should be through MainWindow::_create /// Constructor is private since all creation should be through MainWindow::_create
MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode); MainWindow(QSplashScreen* splashScreen);
void _openUrl(const QString& url, const QString& errorMessage); void _openUrl(const QString& url, const QString& errorMessage);
......
This diff is collapsed.
...@@ -32,8 +32,10 @@ This file is part of the QGROUNDCONTROL project ...@@ -32,8 +32,10 @@ This file is part of the QGROUNDCONTROL project
#include <QProgressBar> #include <QProgressBar>
#include <QComboBox> #include <QComboBox>
#include <QTimer> #include <QTimer>
#include "UASInterface.h" #include "UASInterface.h"
#include "SerialLink.h" #include "SerialLink.h"
#include "LinkManager.h"
class QGCToolBar : public QToolBar class QGCToolBar : public QToolBar
{ {
...@@ -43,15 +45,10 @@ public: ...@@ -43,15 +45,10 @@ public:
explicit QGCToolBar(QWidget* parent = 0); explicit QGCToolBar(QWidget* parent = 0);
void setPerspectiveChangeActions(const QList<QAction*> &action); void setPerspectiveChangeActions(const QList<QAction*> &action);
void setPerspectiveChangeAdvancedActions(const QList<QAction*> &action); void setPerspectiveChangeAdvancedActions(const QList<QAction*> &action);
~QGCToolBar();
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 Set the link which is currently handled with connecting / disconnecting */
void addLink(LinkInterface* link);
/** @brief Remove link which is currently handled */
void removeLink(LinkInterface* link);
/** @brief Set the system state */ /** @brief Set the system state */
void updateState(UASInterface* system, QString name, QString description); void updateState(UASInterface* system, QString name, QString description);
/** @brief Set the system mode */ /** @brief Set the system mode */
...@@ -74,31 +71,12 @@ public slots: ...@@ -74,31 +71,12 @@ public slots:
void updateView(); void updateView();
/** @brief Update connection timeout time */ /** @brief Update connection timeout time */
void heartbeatTimeout(bool timeout, unsigned int ms); void heartbeatTimeout(bool timeout, unsigned int ms);
/** @brief Update global position */
void globalPositionChanged(UASInterface* uas, double lat, double lon, double altAMSL, double altWGS84, quint64 usec);
/** @brief Create or connect link */
void connectLink(bool connect);
/** @brief Clear status string */ /** @brief Clear status string */
void clearStatusString(); void clearStatusString();
/** @brief Set an activity action as checked in menu */ /** @brief Set an activity action as checked in menu */
void advancedActivityTriggered(QAction* action); void advancedActivityTriggered(QAction* action);
void updateComboBox();
/**
* @brief User selected baud rate
* @param index The current index of the combo box
*/
void baudSelected(int index);
/**
* @brief User selected port
* @param index The current index of the combo box
*/
void portSelected(int index);
protected: protected:
void storeSettings();
void loadSettings();
void createUI(); void createUI();
void resetToolbarUI(); void resetToolbarUI();
UASInterface* mav; UASInterface* mav;
...@@ -107,8 +85,6 @@ protected: ...@@ -107,8 +85,6 @@ protected:
QLabel* toolBarTimeoutLabel; QLabel* toolBarTimeoutLabel;
QAction* toolBarTimeoutAction; ///< Needed to set label (in)visible. QAction* toolBarTimeoutAction; ///< Needed to set label (in)visible.
QAction* toolBarMessageAction; QAction* toolBarMessageAction;
QAction* toolBarPortAction;
QAction* toolBarBaudAction;
QAction* toolBarWpAction; QAction* toolBarWpAction;
QAction* toolBarBatteryBarAction; QAction* toolBarBatteryBarAction;
QAction* toolBarBatteryVoltageAction; QAction* toolBarBatteryVoltageAction;
...@@ -117,21 +93,14 @@ protected: ...@@ -117,21 +93,14 @@ protected:
QLabel* toolBarStateLabel; QLabel* toolBarStateLabel;
QLabel* toolBarWpLabel; QLabel* toolBarWpLabel;
QLabel* toolBarMessageLabel; QLabel* toolBarMessageLabel;
QPushButton* connectButton;
QProgressBar* toolBarBatteryBar; QProgressBar* toolBarBatteryBar;
QLabel* toolBarBatteryVoltageLabel; QLabel* toolBarBatteryVoltageLabel;
QComboBox *portComboBox;
QComboBox *baudcomboBox;
QTimer portBoxTimer;
bool userBaudChoice;
bool userPortChoice;
bool changed; bool changed;
float batteryPercent; float batteryPercent;
float batteryVoltage; float batteryVoltage;
int wpId; int wpId;
double wpDistance; double wpDistance;
float altitudeMSL;
float altitudeRel; float altitudeRel;
QString state; QString state;
QString mode; QString mode;
...@@ -146,12 +115,28 @@ protected: ...@@ -146,12 +115,28 @@ protected:
QButtonGroup *group; QButtonGroup *group;
private slots: private slots:
void _linkConnected(void); void _linkConnected(LinkInterface* link);
void _linkDisconnected(void); void _linkDisconnected(LinkInterface* link);
void _disconnectFromMenu(bool checked);
void _connectButtonClicked(bool checked);
void _linkComboActivated(int index);
private: private:
/** @brief Update the link state */ void _updateConnectButton(void);
void _updateLinkState(bool connected); void _updatePortList(void);
LinkManager* _linkMgr;
QComboBox* _linkCombo;
QAction* _linkComboAction;
bool _linkSelectedOnce;
QTimer _portListTimer;
QComboBox* _baudCombo;
QAction* _baudComboAction;
QPushButton* _connectButton;
bool _linksConnected;
}; };
#endif // QGCTOOLBAR_H #endif // QGCTOOLBAR_H
...@@ -76,15 +76,6 @@ _ui(new Ui::SettingsDialog) ...@@ -76,15 +76,6 @@ _ui(new Ui::SettingsDialog)
connect(_ui->deleteSettings, &QAbstractButton::toggled, this, &SettingsDialog::_deleteSettingsToggled); connect(_ui->deleteSettings, &QAbstractButton::toggled, this, &SettingsDialog::_deleteSettingsToggled);
// Custom mode
_ui->customModeComboBox->addItem(tr("Default: Generic MAVLink and serial links"), MainWindow::CUSTOM_MODE_NONE);
_ui->customModeComboBox->addItem(tr("Wifi: Generic MAVLink, wifi or serial links"), MainWindow::CUSTOM_MODE_WIFI);
_ui->customModeComboBox->addItem(tr("PX4: Optimized for PX4 Autopilot Users"), MainWindow::CUSTOM_MODE_PX4);
_ui->customModeComboBox->setCurrentIndex(_ui->customModeComboBox->findData(_mainWindow->getCustomMode()));
connect(_ui->customModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectCustomMode(int)));
// Application color style // Application color style
_ui->styleChooser->setCurrentIndex(qgcApp()->styleIsDark() ? 0 : 1); _ui->styleChooser->setCurrentIndex(qgcApp()->styleIsDark() ? 0 : 1);
...@@ -107,11 +98,6 @@ void SettingsDialog::styleChanged(int index) ...@@ -107,11 +98,6 @@ void SettingsDialog::styleChanged(int index)
qgcApp()->setStyle(index == 0); qgcApp()->setStyle(index == 0);
} }
void SettingsDialog::selectCustomMode(int mode)
{
_mainWindow->setCustomMode(static_cast<enum MainWindow::CUSTOM_MODE>(_ui->customModeComboBox->itemData(mode).toInt()));
}
void SettingsDialog::_deleteSettingsToggled(bool checked) void SettingsDialog::_deleteSettingsToggled(bool checked)
{ {
if (checked){ if (checked){
......
...@@ -40,11 +40,10 @@ public: ...@@ -40,11 +40,10 @@ public:
SettingsDialog(JoystickInput *joystick, QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet); SettingsDialog(JoystickInput *joystick, QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet);
~SettingsDialog(); ~SettingsDialog();
public slots: public slots:
void styleChanged(int index); void styleChanged(int index);
void selectCustomMode(int mode);
private slots: private slots:
void _deleteSettingsToggled(bool checked); void _deleteSettingsToggled(bool checked);
void _selectSavedFilesDirectory(void); void _selectSavedFilesDirectory(void);
void _validateBeforeClose(void); void _validateBeforeClose(void);
......
This diff is collapsed.
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