From c9f5621259f3b3e9eec76bd8d6256fa8bc3eddac Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 9 May 2015 10:27:39 -0700 Subject: [PATCH] Use ViewWithDialog, support custom config --- .../PX4/AirframeComponent.qml | 245 +++++++++++------- .../PX4/AirframeComponentController.cc | 10 +- .../PX4/AirframeComponentController.h | 4 + 3 files changed, 161 insertions(+), 98 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/AirframeComponent.qml b/src/AutoPilotPlugins/PX4/AirframeComponent.qml index b7a483768..37a58d2f3 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponent.qml +++ b/src/AutoPilotPlugins/PX4/AirframeComponent.qml @@ -24,6 +24,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 +import QtQuick.Dialogs 1.2 import QGroundControl.FactSystem 1.0 import QGroundControl.FactControls 1.0 @@ -31,132 +32,190 @@ import QGroundControl.Palette 1.0 import QGroundControl.Controls 1.0 import QGroundControl.Controllers 1.0 -FactPanel { - id: panel +ViewWithDialog { + viewComponent: view - AirframeComponentController { id: controller; factPanel: panel } + Component { + id: view - Rectangle { - anchors.fill: parent + FactPanel { + id: panel + anchors.fill: parent - QGCPalette { id: qgcPal; colorGroupEnabled: true } + signal showDialog(Component component, string title, int charWidth, int buttons) + signal hideDialog - color: qgcPal.window + function doWorkAfterComponentCompleted() { + if (controller.showCustomConfigPanel) { + panel.showDialog(customConfigDialog, "Custom Airframe Config", 50, StandardButton.Reset) + } + } - Column { - anchors.fill: parent + AirframeComponentController { + id: controller + factPanel: panel + } - QGCLabel { - text: "AIRFRAME CONFIG" - font.pointSize: 20 + Component { + id: customConfigDialog + + QGCLabel { + id: customConfigPanel + anchors.fill: parent + wrapMode: Text.WordWrap + text: "Your vehicle is using a custom airframe configuration. " + + "This configuration can only be modified through the Parameter Editor.\n\n" + + "If you want to Reset your airframe configuration and select a standard configuration, click 'Reset' above." + + signal hideDialog + + Fact { id: sys_autostart; name: "SYS_AUTOSTART" } + + function accept() { + sys_autostart.value = 0 + customConfigPanel.hideDialog() + } + } } - Item { height: 20; width: 10 } // spacer + Rectangle { + anchors.fill: parent + + QGCPalette { id: qgcPal; colorGroupEnabled: true } + + color: qgcPal.window + + QGCLabel { + id: header + width: parent.width + font.pointSize: 20 + text: "AIRFRAME CONFIG" + } - Row { - width: parent.width + Item { + id: headingSpacer + anchors.top: header.bottom + height: 20 + width: 20 + } QGCLabel { - width: parent.width - applyButton.width - text: "Select you airframe type and specific vehicle bellow. Click 'Apply and Restart' when ready and your vehicle will be disconnected, rebooted to the new settings and re-connected." - wrapMode: Text.WordWrap + anchors.top: headingSpacer.bottom + width: parent.width - applyButton.width - 5 + text: "Select you airframe type and specific vehicle bellow. Click 'Apply and Restart' when ready and your vehicle will be disconnected, rebooted to the new settings and re-connected." + wrapMode: Text.WordWrap } QGCButton { - id: applyButton - text: "Apply and Restart" + id: applyButton + anchors.top: headingSpacer.bottom + anchors.right: parent.right + text: "Apply and Restart" + onClicked: { controller.changeAutostart() } } - } - Item { height: 20; width: 10 } // spacer + Item { + id: lastSpacer + anchors.top: applyButton.bottom + height: 20 + width: 10 + } - Flow { - width: parent.width - spacing: 10 + ScrollView { + id: scroll + anchors.top: lastSpacer.bottom + anchors.bottom: parent.bottom + width: parent.width + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff - ExclusiveGroup { - id: airframeTypeExclusive - } + Flow { + width: scroll.width + spacing: 10 - Repeater { - model: controller.airframeTypes + ExclusiveGroup { + id: airframeTypeExclusive + } - // Outer summary item rectangle - Rectangle { - readonly property real titleHeight: 30 - readonly property real innerMargin: 10 + Repeater { + model: controller.airframeTypes - width: 250 - height: 200 - color: qgcPal.windowShade + // Outer summary item rectangle + Rectangle { + readonly property real titleHeight: 30 + readonly property real innerMargin: 10 - Rectangle { - id: title - width: parent.width - height: parent.titleHeight - color: qgcPal.windowShadeDark + width: 250 + height: 200 + color: qgcPal.windowShade - Text { - anchors.fill: parent + Rectangle { + id: title + width: parent.width + height: parent.titleHeight + color: qgcPal.windowShadeDark - color: qgcPal.buttonText - font.pixelSize: 12 - text: modelData.name + Text { + anchors.fill: parent - verticalAlignment: TextEdit.AlignVCenter - horizontalAlignment: TextEdit.AlignHCenter - } - } + color: qgcPal.buttonText + font.pixelSize: 12 + text: modelData.name - Image { - id: image - x: innerMargin - width: parent.width - (innerMargin * 2) - height: parent.height - title.height - combo.height - (innerMargin * 3) - anchors.topMargin: innerMargin - anchors.top: title.bottom + verticalAlignment: TextEdit.AlignVCenter + horizontalAlignment: TextEdit.AlignHCenter + } + } - source: modelData.imageResource - fillMode: Image.PreserveAspectFit - smooth: true + Image { + id: image + x: innerMargin + width: parent.width - (innerMargin * 2) + height: parent.height - title.height - combo.height - (innerMargin * 3) + anchors.topMargin: innerMargin + anchors.top: title.bottom - } + source: modelData.imageResource + fillMode: Image.PreserveAspectFit + smooth: true - QGCCheckBox { - id: airframeCheckBox - anchors.bottom: image.bottom - anchors.right: image.right - checked: modelData.name == controller.currentAirframeType - exclusiveGroup: airframeTypeExclusive + } - onCheckedChanged: { - if (checked && combo.currentIndex != -1) { - controller.autostartId = modelData.airframes[combo.currentIndex].autostartId + QGCCheckBox { + id: airframeCheckBox + anchors.bottom: image.bottom + anchors.right: image.right + checked: modelData.name == controller.currentAirframeType + exclusiveGroup: airframeTypeExclusive + + onCheckedChanged: { + if (checked && combo.currentIndex != -1) { + controller.autostartId = modelData.airframes[combo.currentIndex].autostartId + } + } } - } - } - QGCComboBox { - id: combo - objectName: modelData.airframeType + "ComboBox" - x: innerMargin - anchors.topMargin: innerMargin - anchors.top: image.bottom - width: parent.width - (innerMargin * 2) - model: modelData.airframes - currentIndex: (modelData.name == controller.currentAirframeType) ? controller.currentVehicleIndex : 0 - - onCurrentIndexChanged: { - if (airframeCheckBox.checked) { - controller.autostartId = modelData.airframes[currentIndex].autostartId + QGCComboBox { + id: combo + objectName: modelData.airframeType + "ComboBox" + x: innerMargin + anchors.topMargin: innerMargin + anchors.top: image.bottom + width: parent.width - (innerMargin * 2) + model: modelData.airframes + currentIndex: (modelData.name == controller.currentAirframeType) ? controller.currentVehicleIndex : 0 + + onCurrentIndexChanged: { + if (airframeCheckBox.checked) { + controller.autostartId = modelData.airframes[currentIndex].autostartId + } + } } } - } - } - } - } - - } - } + } // Repeater - summary boxes + } // Flow - summary boxes + } // Scroll View - summary boxes + } // Rectangle - background + } // FactPanel + } // Component - View } \ No newline at end of file diff --git a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc index d0c9bf04e..2cc1386f4 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc +++ b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc @@ -40,7 +40,8 @@ bool AirframeComponentController::_typesRegistered = false; AirframeComponentController::AirframeComponentController(void) : _uas(NULL), _currentVehicleIndex(0), - _autostartId(0) + _autostartId(0), + _showCustomConfigPanel(false) { _uas = UASManager::instance()->getActiveUAS(); Q_ASSERT(_uas); @@ -82,10 +83,9 @@ AirframeComponentController::AirframeComponentController(void) : _airframeTypes.append(QVariant::fromValue(airframeType)); } - if (_autostartId != 0) { - // FIXME: Should be a user error - Q_UNUSED(autostartFound); - Q_ASSERT(autostartFound); + if (_autostartId != 0 && !autostartFound) { + _showCustomConfigPanel = true; + emit showCustomConfigPanelChanged(true); } } diff --git a/src/AutoPilotPlugins/PX4/AirframeComponentController.h b/src/AutoPilotPlugins/PX4/AirframeComponentController.h index 0e8b5ced7..79cfdcbf8 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponentController.h +++ b/src/AutoPilotPlugins/PX4/AirframeComponentController.h @@ -44,6 +44,8 @@ public: AirframeComponentController(void); ~AirframeComponentController(); + Q_PROPERTY(bool showCustomConfigPanel MEMBER _showCustomConfigPanel NOTIFY showCustomConfigPanelChanged) + Q_PROPERTY(QVariantList airframeTypes MEMBER _airframeTypes CONSTANT) Q_PROPERTY(QString currentAirframeType MEMBER _currentAirframeType CONSTANT) @@ -59,6 +61,7 @@ public: signals: void autostartIdChanged(int newAutostartId); + void showCustomConfigPanelChanged(bool show); private: static bool _typesRegistered; @@ -69,6 +72,7 @@ private: QString _currentVehicleName; int _currentVehicleIndex; int _autostartId; + bool _showCustomConfigPanel; }; class Airframe : public QObject -- 2.22.0