From dc3b21fb29d532ce2d2049af334444a80b7f40c1 Mon Sep 17 00:00:00 2001 From: LM Date: Wed, 21 Sep 2011 10:46:34 +0200 Subject: [PATCH] Fixed and thoroughly tested custom widgets --- src/ui/MainWindow.cc | 136 +++++++++++++++++++------------ src/ui/QGCWaypointListMulti.cc | 1 + src/ui/WaypointList.ui | 72 ++++++++-------- src/ui/designer/QGCToolWidget.cc | 87 +++++++++++++------- src/ui/designer/QGCToolWidget.h | 2 +- 5 files changed, 178 insertions(+), 120 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 72b3161d4..c2d7f2a49 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -126,6 +126,9 @@ MainWindow::MainWindow(QWidget *parent): configureWindowName(); + // Setup corners + setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); + // Setup UI state machines centerStackActionGroup.setExclusive(true); @@ -146,28 +149,6 @@ MainWindow::MainWindow(QWidget *parent): // Create actions connectCommonActions(); - buildCustomWidget(); - - - - // Restore the window setup - if (settings.contains(getWindowStateKey())) - { - loadViewState(); - } - - // Restore the window position and size - if (settings.contains(getWindowGeometryKey())) - { - // Restore the window geometry - restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray()); - } - else - { - // Adjust the size - adjustSize(); - } - // Populate link menu QList links = LinkManager::instance()->getLinks(); foreach(LinkInterface* link, links) @@ -197,7 +178,33 @@ MainWindow::MainWindow(QWidget *parent): // Initialize window state windowStateVal = windowState(); - show(); + // Restore the window setup + loadViewState(); + + // Restore the window position and size + if (settings.contains(getWindowGeometryKey())) + { + // Restore the window geometry + restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray()); + show(); + } + else + { + // Adjust the size + const int screenWidth = QApplication::desktop()->width(); + const int screenHeight = QApplication::desktop()->height(); + + if (screenWidth < 1200) + { + showFullScreen(); + } + else + { + resize(screenWidth*0.67f, qMin(screenHeight, (int)(screenWidth*0.67f*0.67f))); + show(); + } + + } connect(&windowNameUpdateTimer, SIGNAL(timeout()), this, SLOT(configureWindowName())); windowNameUpdateTimer.start(15000); @@ -381,19 +388,8 @@ void MainWindow::buildCommonWidgets() acceptList->append("-105,pitch deg,deg,+105,s"); acceptList->append("-105,heading deg,deg,+105,s"); - acceptList->append("-60,rollspeed d/s,deg/s,+60,s"); - acceptList->append("-60,pitchspeed d/s,deg/s,+60,s"); - acceptList->append("-60,yawspeed d/s,deg/s,+60,s"); - acceptList->append("0,airspeed,m/s,30"); - acceptList->append("0,groundspeed,m/s,30"); - acceptList->append("0,climbrate,m/s,30"); - acceptList->append("0,throttle,%,100"); - //FIXME: memory of acceptList2 will never be freed again QStringList* acceptList2 = new QStringList(); - acceptList2->append("900,servo #6,us,2100,s"); - acceptList2->append("900,servo #7,us,2100,s"); - acceptList2->append("900,servo #8,us,2100,s"); acceptList2->append("0,abs pressure,hPa,65500"); if (!parametersDockWidget) { @@ -1059,15 +1055,18 @@ void MainWindow::addLink(LinkInterface *link) bool found = false; - foreach (QAction* act, actions) { - if (act->data().toInt() == LinkManager::instance()->getLinks().indexOf(link)) { + foreach (QAction* act, actions) + { + if (act->data().toInt() == LinkManager::instance()->getLinks().indexOf(link)) + { found = true; } } UDPLink* udp = dynamic_cast(link); - if (!found || udp) { + if (!found || udp) + { CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this); QAction* action = commWidget->getAction(); ui.menuNetwork->addAction(action); @@ -1076,7 +1075,8 @@ void MainWindow::addLink(LinkInterface *link) connect(link, SIGNAL(communicationError(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection); // Special case for simulationlink MAVLinkSimulationLink* sim = dynamic_cast(link); - if (sim) { + if (sim) + { //connect(sim, SIGNAL(valueChanged(int,QString,double,quint64)), linechart, SLOT(appendData(int,QString,double,quint64))); connect(ui.actionSimulate, SIGNAL(triggered(bool)), sim, SLOT(connectLink(bool))); } @@ -1093,8 +1093,10 @@ void MainWindow::setActiveUAS(UASInterface* uas) void MainWindow::UASSpecsChanged(int uas) { UASInterface* activeUAS = UASManager::instance()->getActiveUAS(); - if (activeUAS) { - if (activeUAS->getUASID() == uas) { + if (activeUAS) + { + if (activeUAS->getUASID() == uas) + { ui.menuUnmanned_System->setTitle(activeUAS->getUASName()); } } @@ -1152,18 +1154,22 @@ void MainWindow::UASCreated(UASInterface* uas) ui.menuConnected_Systems->addAction(uasAction); // FIXME Should be not inside the mainwindow - if (debugConsoleDockWidget) { + if (debugConsoleDockWidget) + { DebugConsole *debugConsole = dynamic_cast(debugConsoleDockWidget->widget()); - if (debugConsole) { + if (debugConsole) + { connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), debugConsole, SLOT(receiveTextMessage(int,int,int,QString))); } } // Health / System status indicator - if (infoDockWidget) { + if (infoDockWidget) + { UASInfoWidget *infoWidget = dynamic_cast(infoDockWidget->widget()); - if (infoWidget) { + if (infoWidget) + { infoWidget->addUAS(uas); } } @@ -1202,7 +1208,8 @@ void MainWindow::UASCreated(UASInterface* uas) addTool(detectionDockWidget, tr("Object Recognition"), Qt::RightDockWidgetArea); } - if (!watchdogControlDockWidget) { + if (!watchdogControlDockWidget) + { watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this); watchdogControlDockWidget->setWidget( new WatchdogControl(this) ); watchdogControlDockWidget->setObjectName("WATCHDOG_CONTROL_DOCKWIDGET"); @@ -1288,6 +1295,10 @@ void MainWindow::loadViewState() } else { + // Hide custom widgets + if (detectionDockWidget) detectionDockWidget->hide(); + if (watchdogControlDockWidget) watchdogControlDockWidget->hide(); + // Load defaults switch (currentView) { @@ -1324,7 +1335,7 @@ void MainWindow::loadViewState() headDown2DockWidget->show(); rcViewDockWidget->hide(); headUpDockWidget->hide(); - video1DockWidget->show(); + video1DockWidget->hide(); video2DockWidget->hide(); break; case VIEW_MAVLINK: @@ -1346,25 +1357,42 @@ void MainWindow::loadViewState() video2DockWidget->hide(); break; case VIEW_OPERATOR: + centerStack->setCurrentWidget(mapWidget); + controlDockWidget->hide(); + listDockWidget->show(); + waypointsDockWidget->show(); + infoDockWidget->hide(); + debugConsoleDockWidget->show(); + logPlayerDockWidget->show(); + parametersDockWidget->hide(); + hsiDockWidget->show(); + headDown1DockWidget->hide(); + headDown2DockWidget->hide(); + rcViewDockWidget->hide(); + headUpDockWidget->show(); + video1DockWidget->hide(); + video2DockWidget->hide(); + mavlinkInspectorWidget->hide(); + break; case VIEW_UNCONNECTED: case VIEW_FULL: default: centerStack->setCurrentWidget(mapWidget); - controlDockWidget->show(); + controlDockWidget->hide(); listDockWidget->show(); - waypointsDockWidget->show(); - infoDockWidget->show(); + waypointsDockWidget->hide(); + infoDockWidget->hide(); debugConsoleDockWidget->show(); logPlayerDockWidget->show(); - mavlinkInspectorWidget->show(); parametersDockWidget->hide(); - hsiDockWidget->show(); + hsiDockWidget->hide(); headDown1DockWidget->hide(); headDown2DockWidget->hide(); rcViewDockWidget->hide(); headUpDockWidget->show(); video1DockWidget->hide(); video2DockWidget->hide(); + mavlinkInspectorWidget->show(); break; } } @@ -1378,7 +1406,8 @@ void MainWindow::loadViewState() void MainWindow::loadEngineerView() { - if (currentView != VIEW_ENGINEER) { + if (currentView != VIEW_ENGINEER) + { storeViewState(); currentView = VIEW_ENGINEER; ui.actionEngineersView->setChecked(true); @@ -1388,7 +1417,8 @@ void MainWindow::loadEngineerView() void MainWindow::loadOperatorView() { - if (currentView != VIEW_OPERATOR) { + if (currentView != VIEW_OPERATOR) + { storeViewState(); currentView = VIEW_OPERATOR; ui.actionOperatorsView->setChecked(true); diff --git a/src/ui/QGCWaypointListMulti.cc b/src/ui/QGCWaypointListMulti.cc index d63c60dbf..a71d54360 100644 --- a/src/ui/QGCWaypointListMulti.cc +++ b/src/ui/QGCWaypointListMulti.cc @@ -7,6 +7,7 @@ QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) : ui(new Ui::QGCWaypointListMulti) { ui->setupUi(this); + setMinimumSize(600, 80); connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(systemCreated(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(int)), this, SLOT(systemSetActive(int))); } diff --git a/src/ui/WaypointList.ui b/src/ui/WaypointList.ui index c00a83ca2..7c9784276 100644 --- a/src/ui/WaypointList.ui +++ b/src/ui/WaypointList.ui @@ -6,7 +6,7 @@ 0 0 - 476 + 798 218 @@ -19,14 +19,14 @@ Form - + 4 4 - + true @@ -36,8 +36,8 @@ 0 0 - 464 - 158 + 786 + 174 @@ -64,7 +64,7 @@ - + Read all waypoints from the MAV. Clears the list on this computer. @@ -79,12 +79,12 @@ Read - + :/images/status/software-update-available.svg:/images/status/software-update-available.svg - + Transmit all waypoints on this list to the MAV. @@ -99,28 +99,12 @@ Write - + :/images/devices/network-wireless.svg:/images/devices/network-wireless.svg - - - - The current waypoint transmission status - - - The current waypoint transmission status - - - The current waypoint transmission status - - - TextLabel - - - - + Add a new waypoint to this list. Transmit via write to the MAV. @@ -135,7 +119,7 @@ ... - + :/images/actions/list-add.svg:/images/actions/list-add.svg @@ -172,7 +156,7 @@ - + Qt::Horizontal @@ -185,7 +169,7 @@ - + Set the current vehicle position as new waypoint @@ -200,12 +184,12 @@ ... - + :/images/actions/go-bottom.svg:/images/actions/go-bottom.svg - + Delete all waypoints from this list. You have to click write to clear the list on the MAV as well. @@ -220,15 +204,31 @@ ... - + :/images/actions/process-stop.svg:/images/actions/process-stop.svg + + + + The current waypoint transmission status + + + The current waypoint transmission status + + + The current waypoint transmission status + + + Please add first waypoint. + + + - + :/images/actions/list-add.svg:/images/actions/list-add.svg @@ -240,7 +240,7 @@ - + :/images/devices/network-wireless.svg:/images/devices/network-wireless.svg @@ -252,7 +252,7 @@ - + :/images/status/software-update-available.svg:/images/status/software-update-available.svg @@ -261,7 +261,7 @@ - + diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index b3baa6487..f9889311d 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -14,20 +14,23 @@ #include "QGCCommandButton.h" #include "UASManager.h" -QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) : +QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* settings) : QWidget(parent), mav(NULL), mainMenuAction(NULL), widgetTitle(title), ui(new Ui::QGCToolWidget) { + ui->setupUi(this); + if (settings) loadSettings(*settings); + if (title == "Unnamed Tool") { widgetTitle = QString("%1 %2").arg(title).arg(QGCToolWidget::instances()->count()); } qDebug() << "WidgetTitle" << widgetTitle; - ui->setupUi(this); - setObjectName(title); + + setObjectName(widgetTitle); createActions(); toolLayout = ui->toolLayout; toolLayout->setAlignment(Qt::AlignTop); @@ -35,19 +38,18 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) : QDockWidget* dock = dynamic_cast(this->parentWidget()); if (dock) { - dock->setWindowTitle(title); - dock->setObjectName(title+"DOCK"); + dock->setWindowTitle(widgetTitle); + dock->setObjectName(widgetTitle+"DOCK"); } // Try with parent dock = dynamic_cast(parent); if (dock) { - dock->setWindowTitle(title); - dock->setObjectName(title+"DOCK"); + dock->setWindowTitle(widgetTitle); + dock->setObjectName(widgetTitle+"DOCK"); } - this->setWindowTitle(title); - + this->setWindowTitle(widgetTitle); QList systems = UASManager::instance()->getUASList(); foreach (UASInterface* uas, systems) { @@ -58,7 +60,11 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) : } } connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); - if (!instances()->contains(title)) instances()->insert(title, this); + if (!instances()->contains(widgetTitle)) instances()->insert(widgetTitle, this); + + // Enforce storage if this not loaded from settings + // is MUST NOT BE SAVED if it was loaded from settings! + if (!settings) storeWidgetsToSettings(); } QGCToolWidget::~QGCToolWidget() @@ -106,18 +112,22 @@ QList QGCToolWidget::createWidgetsFromSettings(QWidget* parent, for (int i = 0; i < size; i++) { settings->setArrayIndex(i); - QString name = settings->value("TITLE", tr("UNKNOWN WIDGET %1").arg(i)).toString(); + QString name = settings->value("TITLE", "").toString(); - if (!instances()->contains(name)) + if (!instances()->contains(name) && name.length() != 0) { qDebug() << "CREATED WIDGET:" << name; - QGCToolWidget* tool = new QGCToolWidget(name, parent); - instances()->insert(name, tool); + QGCToolWidget* tool = new QGCToolWidget(name, parent, settings); newWidgets.append(tool); } + else if (name.length() == 0) + { + // Silently catch empty widget name - sanity check + // to survive broken settings (e.g. from user manipulation) + } else { - qDebug() << "WIDGET DID ALREADY EXIST, REJECTING"; + qDebug() << "WIDGET" << name << "DID ALREADY EXIST, REJECTING"; } } settings->endArray(); @@ -145,7 +155,9 @@ bool QGCToolWidget::loadSettings(const QString& settings, bool singleinstance) { QString widgetName = groups.first(); if (singleinstance && QGCToolWidget::instances()->keys().contains(widgetName)) return false; - setTitle(widgetName); + // Do not use setTitle() here, + // interferes with loading settings + widgetTitle = widgetName; qDebug() << "WIDGET TITLE LOADED: " << widgetName; loadSettings(set); return true; @@ -214,11 +226,24 @@ void QGCToolWidget::storeWidgetsToSettings(QString settingsFile) qDebug() << "STORING SETTINGS TO DEFAULT" << settings->fileName(); } + int preArraySize = settings->beginReadArray("QGC_TOOL_WIDGET_NAMES"); + settings->endArray(); + settings->beginWriteArray("QGC_TOOL_WIDGET_NAMES"); - for (int i = 0; i < instances()->size(); ++i) + for (int i = 0; i < qMax(preArraySize, instances()->size()); ++i) { settings->setArrayIndex(i); - settings->setValue("TITLE", instances()->values().at(i)->getTitle()); + if (i < instances()->size()) + { + // Updating value + settings->setValue("TITLE", instances()->values().at(i)->getTitle()); + qDebug() << "WRITING TITLE" << instances()->values().at(i)->getTitle(); + } + else + { + // Deleting old value + settings->remove("TITLE"); + } } settings->endArray(); @@ -244,8 +269,8 @@ void QGCToolWidget::storeSettings(const QString& settingsFile) void QGCToolWidget::storeSettings(QSettings& settings) { - QString widgetName = getTitle(); - settings.beginGroup(widgetName); + qDebug() << "WRITING WIDGET" << widgetTitle << "TO SETTINGS"; + settings.beginGroup(widgetTitle); settings.beginWriteArray("QGC_TOOL_WIDGET_ITEMS"); int k = 0; // QGCToolItem counter for (int j = 0; j < children().size(); ++j) @@ -254,6 +279,7 @@ void QGCToolWidget::storeSettings(QSettings& settings) QGCToolWidgetItem* item = dynamic_cast(children().at(j)); if (item) { + // Only count actual tool widget item children settings.setArrayIndex(k++); // Store the ToolWidgetItem item->writeSettings(settings); @@ -424,20 +450,19 @@ void QGCToolWidget::setTitle() void QGCToolWidget::setWindowTitle(const QString& title) { // Sets title and calls setWindowTitle on QWidget - setTitle(title); + widgetTitle = title; + QWidget::setWindowTitle(title); } void QGCToolWidget::setTitle(QString title) { // Remove references to old title - QDockWidget* parent = dynamic_cast(this->parentWidget()); - if (parent) - { - QSettings settings; - settings.beginGroup(widgetTitle); - settings.remove(""); - settings.endGroup(); - } + QSettings settings; + settings.beginGroup(widgetTitle); + settings.remove(""); + settings.endGroup(); + settings.sync(); + if (instances()->contains(widgetTitle)) instances()->remove(widgetTitle); // Switch to new title @@ -445,7 +470,10 @@ void QGCToolWidget::setTitle(QString title) if (!instances()->contains(title)) instances()->insert(title, this); QWidget::setWindowTitle(title); + QDockWidget* parent = dynamic_cast(this->parentWidget()); if (parent) parent->setWindowTitle(title); + // Store all widgets + storeWidgetsToSettings(); emit titleChanged(title); if (mainMenuAction) mainMenuAction->setText(title); @@ -470,6 +498,5 @@ void QGCToolWidget::deleteWidget() storeWidgetsToSettings(); // Delete - mainMenuAction->deleteLater(); this->deleteLater(); } diff --git a/src/ui/designer/QGCToolWidget.h b/src/ui/designer/QGCToolWidget.h index 80ab4fc75..1a897ac1f 100644 --- a/src/ui/designer/QGCToolWidget.h +++ b/src/ui/designer/QGCToolWidget.h @@ -19,7 +19,7 @@ class QGCToolWidget : public QWidget Q_OBJECT public: - explicit QGCToolWidget(const QString& title=QString("Unnamed Tool"), QWidget *parent = 0); + explicit QGCToolWidget(const QString& title=QString("Unnamed Tool"), QWidget *parent = 0, QSettings* settings = 0); ~QGCToolWidget(); /** @brief Factory method to instantiate all tool widgets */ -- 2.22.0