Skip to content
Snippets Groups Projects
MainWindow.cc 42 KiB
Newer Older
  • Learn to ignore specific revisions
  • dogmaphobic's avatar
    dogmaphobic committed
        if (settings.contains(_getWindowStateKey())) {
            restoreState(settings.value(_getWindowStateKey()).toByteArray());
    
        // HIL dock widget are dynamic and don't take part in the saved window state, so this
        // need to happen after we restore state
        _showHILConfigurationWidgets();
    
    
        // There is a bug in Qt where a Canvas element inside a QQuickWidget does not
        // receive update requests. Here we emit a signal for them to get repainted.
        emit repaintCanvas();
    
    }
    
    void MainWindow::_hideAllHilDockWidgets(void)
    {
        foreach(QDockWidget* dockWidget, _mapUasId2HilDockWidget) {
            dockWidget->setVisible(false);
        }
    }
    
    void MainWindow::_hideAllDockWidgets(void)
    {
        foreach(QDockWidget* dockWidget, _mapName2DockWidget) {
            dockWidget->setVisible(false);
    
        _hideAllHilDockWidgets();
    
    
    void MainWindow::_showDockWidgetAction(bool show)
    
        QAction* action = dynamic_cast<QAction*>(QObject::sender());
        Q_ASSERT(action);
        _showDockWidget(action->data().toString(), show);
    
    void MainWindow::handleMisconfiguration(UASInterface* uas)
    {
        static QTime lastTime;
        // We have to debounce this signal
        if (!lastTime.isValid()) {
            lastTime.start();
        } else {
            if (lastTime.elapsed() < 10000) {
                lastTime.start();
                return;
            }
        }
    
    dogmaphobic's avatar
    dogmaphobic committed
        // Ask user if they want to handle this now
        QMessageBox::StandardButton button =
            QGCMessageBox::question(
                tr("Missing or Invalid Onboard Configuration"),
                tr("The onboard system configuration is missing or incomplete. Do you want to resolve this now?"),
                QMessageBox::Ok | QMessageBox::Cancel,
                QMessageBox::Ok);
    
    Don Gagne's avatar
    Don Gagne committed
        if (button == QMessageBox::Ok) {
    
    dogmaphobic's avatar
    dogmaphobic committed
            // They want to handle it, make sure this system is selected
    
            UASManager::instance()->setActiveUAS(uas);
            // Flick to config view
    
    void MainWindow::loadAnalyzeView()
    
        if (_currentView != VIEW_ANALYZE)
    
            _storeCurrentViewState();
    
            _currentView = VIEW_ANALYZE;
            _ui.actionAnalyze->setChecked(true);
    
            _loadCurrentViewState();
    
    void MainWindow::loadPlanView()
    
        if (_currentView != VIEW_PLAN)
    
            _storeCurrentViewState();
    
            _currentView = VIEW_PLAN;
            _ui.actionPlan->setChecked(true);
    
            _loadCurrentViewState();
    
    
    void MainWindow::loadOldPlanView()
    {
        if (_currentView != VIEW_EXPERIMENTAL_PLAN)
        {
            _storeCurrentViewState();
            _currentView = VIEW_EXPERIMENTAL_PLAN;
            _ui.actionExperimentalPlanView->setChecked(true);
            _loadCurrentViewState();
        }
    }
    
    
    void MainWindow::loadSetupView()
    
        if (_currentView != VIEW_SETUP)
    
            _storeCurrentViewState();
            _currentView = VIEW_SETUP;
    
    dogmaphobic's avatar
    dogmaphobic committed
            _ui.actionSetup->setChecked(true);
    
            _loadCurrentViewState();
    
    void MainWindow::loadFlightView()
    
        if (_currentView != VIEW_FLIGHT)
    
            _storeCurrentViewState();
            _currentView = VIEW_FLIGHT;
    
            _ui.actionFlight->setChecked(true);
    
            _loadCurrentViewState();
    
    void MainWindow::loadSimulationView()
    {
    
        if (_currentView != VIEW_SIMULATION)
    
            _storeCurrentViewState();
            _currentView = VIEW_SIMULATION;
    
    dogmaphobic's avatar
    dogmaphobic committed
            _ui.actionSimulationView->setChecked(true);
    
            _loadCurrentViewState();
    
    Don Gagne's avatar
    Don Gagne committed
    /// @brief Hides the spash screen if it is currently being shown
    
    void MainWindow::hideSplashScreen(void)
    
    Don Gagne's avatar
    Don Gagne committed
    {
        if (_splashScreen) {
            _splashScreen->hide();
            _splashScreen = NULL;
        }
    }
    
    
    dogmaphobic's avatar
    dogmaphobic committed
    #ifndef __android__
    
        SettingsDialog settings(joystick, this, SettingsDialog::ShowCommLinks);
    
    dogmaphobic's avatar
    dogmaphobic committed
    #else
        SettingsDialog settings(this, SettingsDialog::ShowCommLinks);
    #endif
    
        settings.exec();
    }
    
    /// @brief Saves the last used connection
    void MainWindow::saveLastUsedConnection(const QString connection)
    {
        QSettings settings;
        QString key(MAIN_SETTINGS_GROUP);
        key += "/LAST_CONNECTION";
        settings.setValue(key, connection);
    }
    
    /// @brief Restore (and connects) the last used connection (if any)
    void MainWindow::restoreLastUsedConnection()
    {
        // TODO This should check and see of the port/whatever is present
        // first. That is, if the last connection was to a PX4 on some serial
        // port, it should check and see if the port is present before making
        // the connection.
        QSettings settings;
        QString key(MAIN_SETTINGS_GROUP);
        key += "/LAST_CONNECTION";
        if(settings.contains(key)) {
    
            QString connection = settings.value(key).toString();
    
            LinkManager::instance()->createConnectedLink(connection);
    
    void MainWindow::_linkStateChange(LinkInterface*)
    {
        emit repaintCanvas();
    }
    
    
    void MainWindow::setPixelSizeFactor(double size) {
        if(size < 0.1) {
            size = 0.1;
        }
        _pixelFactor = size;
        emit pixelSizeChanged();
    }
    
    void MainWindow::setFontSizeFactor(double size) {
        if(size < 0.1) {
            size = 0.1;
        }
        _fontFactor = size;
        emit fontSizeChanged();
    }
    
    
    #ifdef QGC_MOUSE_ENABLED_LINUX
    
    bool MainWindow::x11Event(XEvent *event)
    {
        emit x11EventOccured(event);
    
    #endif // QGC_MOUSE_ENABLED_LINUX
    
    
    #ifdef UNITTEST_BUILD
    void MainWindow::_showQmlTestWidget(void)
    {
        new QmlTestWidget();
    }
    #endif