diff --git a/QGCApplication.pro b/QGCApplication.pro index 0732ea762c5739b864d0fe14378db3a499cc8a60..eae4279a1b6e3857c0cbc502f806da44c6f4c03b 100644 --- a/QGCApplication.pro +++ b/QGCApplication.pro @@ -596,14 +596,13 @@ INCLUDEPATH += \ src/VehicleSetup FORMS += \ - src/VehicleSetup/ParameterEditor.ui \ src/VehicleSetup/SetupView.ui \ HEADERS+= \ src/VehicleSetup/SetupView.h \ - src/VehicleSetup/ParameterEditor.h \ src/VehicleSetup/VehicleComponent.h \ src/VehicleSetup/FirmwareUpgradeController.h \ + src/VehicleSetup/ParameterEditorController.h \ src/VehicleSetup/PX4Bootloader.h \ src/VehicleSetup/PX4FirmwareUpgradeThread.h \ src/AutoPilotPlugins/AutoPilotPluginManager.h \ @@ -626,9 +625,9 @@ HEADERS+= \ SOURCES += \ src/VehicleSetup/SetupView.cc \ - src/VehicleSetup/ParameterEditor.cc \ src/VehicleSetup/VehicleComponent.cc \ src/VehicleSetup/FirmwareUpgradeController.cc \ + src/VehicleSetup/ParameterEditorController.cc \ src/VehicleSetup/PX4Bootloader.cc \ src/VehicleSetup/PX4FirmwareUpgradeThread.cc \ src/AutoPilotPlugins/AutoPilotPluginManager.cc \ diff --git a/src/VehicleSetup/ParameterEditor.cc b/src/VehicleSetup/ParameterEditor.cc deleted file mode 100644 index ed43081d2c03ced9d81cace5f896a937005e157f..0000000000000000000000000000000000000000 --- a/src/VehicleSetup/ParameterEditor.cc +++ /dev/null @@ -1,46 +0,0 @@ -/*===================================================================== - - QGroundControl Open Source Ground Control Station - - (c) 2009 - 2014 QGROUNDCONTROL PROJECT - - This file is part of the QGROUNDCONTROL project - - QGROUNDCONTROL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - QGROUNDCONTROL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QGROUNDCONTROL. If not, see . - - ======================================================================*/ - -/// @file -/// @author Don Gagne - -#include "ParameterEditor.h" -#include "ui_ParameterEditor.h" - -ParameterEditor::ParameterEditor(UASInterface* uas, const QStringList& filterList, QWidget* parent) : - QWidget(parent), - _ui(new Ui::ParameterEditor) -{ - _ui->setupUi(this); - - _ui->paramTreeWidget->setFilterList(filterList); - _ui->paramTreeWidget->setUAS(uas); - _ui->paramTreeWidget->handleOnboardParameterListUpToDate(); - _ui->pendingCommitsWidget->setUAS(uas); - _ui->pendingCommitsWidget->update(); -} - -ParameterEditor::~ParameterEditor() -{ - delete _ui; -} diff --git a/src/VehicleSetup/ParameterEditor.qml b/src/VehicleSetup/ParameterEditor.qml new file mode 100644 index 0000000000000000000000000000000000000000..da3e113d46d0bf5b08f42c6ecfd3d63d4412999f --- /dev/null +++ b/src/VehicleSetup/ParameterEditor.qml @@ -0,0 +1,230 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.2 + +import QGroundControl.Controls 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.Controllers 1.0 +import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 + +Rectangle { + QGCPalette { id: qgcPal; colorGroupEnabled: true } + ScreenTools { id: screenTools } + ParameterEditorController { id: controller } + QGCLabel { id: charWidth; text: "X"; visible: false } + + readonly property real leftMargin: 10 + readonly property real rightMargin: 20 + readonly property int maxParamChars: 16 + + color: qgcPal.window + + // We use an ExclusiveGroup to maintain the visibility of a single editing control at a time + ExclusiveGroup { + id: exclusiveEditorGroup + } + + Column { + anchors.fill:parent + + QGCLabel { + text: "PARAMETER EDITOR" + font.pointSize: screenTools.dpiAdjustedPointSize(20) + } + + Item { + height: 20 + width: 5 + } + + Row { + spacing: 10 + layoutDirection: Qt.RightToLeft + width: parent.width + + QGCButton { + text: "Clear RC to Param" + onClicked: controller.clearRCToParam() + } + QGCButton { + text: "Save to file" + onClicked: controller.saveToFile() + } + QGCButton { + text: "Load from file" + onClicked: controller.loadFromFile() + } + QGCButton { + id: firstButton + text: "Refresh" + onClicked: controller.refresh() + } + QGCLabel { + width: firstButton.x - parent.spacing + wrapMode: Text.WordWrap + text: "Click a parameter value to modify. Right-click to set an RC to Param mapping. Use caution when modifying parameters here since the values are not checked for validity." + } + } + + Item { + id: lastSpacer + height: 10 + width: 5 + } + + ScrollView { + id : scrollView + width: parent.width + height: parent.height - (lastSpacer.y + lastSpacer.height) + + Column { + Repeater { + model: controller.componentIds + + Column { + id: componentColumn + + property int componentId: parseInt(modelData) + + QGCLabel { + text: "Component #: " + componentId.toString() + font.pointSize: screenTools.dpiAdjustedPointSize(qgcPal.defaultFontPointSize + 4); + } + + Item { + height: 10 + width: 10 + } + + Repeater { + model: controller.getGroupsForComponent(componentColumn.componentId) + + Column { + Rectangle { + id: groupRect + color: qgcPal.windowShade + height: groupBlock.height + width: scrollView.viewport.width - rightMargin + + Column { + id: groupBlock + + Rectangle { + color: qgcPal.windowShadeDark + height: groupLabel.height + width: groupRect.width + + QGCLabel { + id: groupLabel + height: contentHeight + 5 + x: leftMargin + text: modelData + verticalAlignment: Text.AlignVCenter + font.pointSize: screenTools.dpiAdjustedPointSize(qgcPal.defaultFontPointSize + 2); + } + } + + Repeater { + model: controller.getFactsForGroup(componentColumn.componentId, modelData) + + Row { + spacing: 10 + x: leftMargin + + Fact { id: modelFact; name: modelData + ":" + componentColumn.componentId } + + QGCLabel { + text: modelFact.name + width: charWidth.contentWidth * (maxParamChars + 2) + } + + QGCLabel { + + text: modelFact.valueString + " " + modelFact.units + width: charWidth.contentWidth * 20 + height: contentHeight + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onClicked: { + if (mouse.button == Qt.LeftButton) { + editor.checked = true + editor.focus = true + } else if (mouse.button == Qt.RightButton) { + controller.setRCToParam(modelData) + } + } + } + + FactTextField { + id: editor + y: (parent.height - height) / 2 + width: parent.width + visible: checked + focus: true + fact: modelFact + showUnits: true + onEditingFinished: checked = false + + // We use an ExclusiveGroup to manage visibility + property bool checked: false + property ExclusiveGroup exclusiveGroup: exclusiveEditorGroup + onExclusiveGroupChanged: { + if (exclusiveGroup) + exclusiveGroup.bindCheckable(editor) + } + } + } + + QGCLabel { + text: modelFact.shortDescription + } + } // Row - Fact value + } // Repeater - Facts + } // Column - Fact rows + } // Rectangle - Group + + Item { + height: 10 + width: 10 + } + } // Column - Group + } // Repeater - Groups + + Item { + height: 10 + width: 10 + } + } // Column - Component + } // Repeater - Components + } // Column - Component + } // ScrollView + } // Column - Outer +} diff --git a/src/VehicleSetup/ParameterEditor.ui b/src/VehicleSetup/ParameterEditor.ui deleted file mode 100644 index ba61c7fa684f36aa3677ce9e608fe1fdf50dd3c8..0000000000000000000000000000000000000000 --- a/src/VehicleSetup/ParameterEditor.ui +++ /dev/null @@ -1,191 +0,0 @@ - - - ParameterEditor - - - - 0 - 0 - 750 - 600 - - - - - 0 - 0 - - - - - 802 - 471 - - - - Form - - - - - - - - - 3 - 1 - - - - Onboard Configuration - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - true - - - - - - - - - - - - - - Qt::Horizontal - - - - 10 - 20 - - - - - - - - - 2 - 0 - - - - - 329 - 400 - - - - Changes Pending - - - - - - -1 - - - - - - 0 - 0 - - - - true - - - - - - - - - - - - Qt::Horizontal - - - - 10 - 20 - - - - - - - - - - - 0 - 0 - - - - Status - - - - - - - - QGCPendingParamWidget - QWidget -
ui/QGCPendingParamWidget.h
- 1 -
- - QGCParamWidget - QWidget -
ui/QGCParamWidget.h
- 1 -
-
- - -
diff --git a/src/VehicleSetup/ParameterEditorController.cc b/src/VehicleSetup/ParameterEditorController.cc new file mode 100644 index 0000000000000000000000000000000000000000..03e000f2bd46089b7ec30a5464d761e4f522a80e --- /dev/null +++ b/src/VehicleSetup/ParameterEditorController.cc @@ -0,0 +1,134 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +/// @file +/// @author Don Gagne + +#include "ParameterEditorController.h" +#include "UASManager.h" +#include "AutoPilotPluginManager.h" +#include "QGCFileDialog.h" +#include "QGCMessageBox.h" +#include "QGCMapRCToParamDialog.h" +#include "MainWindow.h" + +/// @Brief Constructs a new ParameterEditorController Widget. This widget is used within the PX4VehicleConfig set of screens. +ParameterEditorController::ParameterEditorController(void) : + _uas(NULL), + _autopilot(NULL) +{ + _uas = UASManager::instance()->getActiveUAS(); + Q_ASSERT(_uas); + + _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uas); + Q_ASSERT(_autopilot); + Q_ASSERT(_autopilot->pluginReady()); + + const QMap >& groupMap = _autopilot->getGroupMap(); + + foreach (int componentId, groupMap.keys()) { + _componentIds += QString("%1").arg(componentId); + } +} + +QStringList ParameterEditorController::getGroupsForComponent(int componentId) +{ + const QMap >& groupMap = _autopilot->getGroupMap(); + + return groupMap[componentId].keys(); +} + +QStringList ParameterEditorController::getFactsForGroup(int componentId, QString group) +{ + const QMap >& groupMap = _autopilot->getGroupMap(); + + return groupMap[componentId][group]; +} + +void ParameterEditorController::clearRCToParam(void) +{ + Q_ASSERT(_uas); + _uas->unsetRCToParameterMap(); +} + +void ParameterEditorController::saveToFile(void) +{ + Q_ASSERT(_autopilot); + + QString msgTitle("Save Parameters"); + + QString fileName = QGCFileDialog::getSaveFileName(NULL, + msgTitle, + qgcApp()->savedParameterFilesLocation(), + "Parameter Files (*.params)", + "params", + true); + if (!fileName.isEmpty()) { + QFile file(fileName); + + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QGCMessageBox::critical(msgTitle, "Unable to create file"); + return; + } + + QTextStream stream(&file); + _autopilot->writeParametersToStream(stream); + file.close(); + } +} + +void ParameterEditorController::loadFromFile(void) +{ + Q_ASSERT(_autopilot); + + QString msgTitle("Load Parameters"); + + QString fileName = QGCFileDialog::getOpenFileName(NULL, + msgTitle, + qgcApp()->savedParameterFilesLocation(), + "Parameter Files (*.params);;All Files (*)"); + if (!fileName.isEmpty()) { + QFile file(fileName); + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QGCMessageBox::critical(msgTitle, "Unable to open file"); + return; + } + + QTextStream stream(&file); + _autopilot->readParametersFromStream(stream); + file.close(); + } +} + +void ParameterEditorController::refresh(void) +{ + _autopilot->refreshAllParameters(); +} + +void ParameterEditorController::setRCToParam(const QString& paramName) +{ + Q_ASSERT(_uas); + QGCMapRCToParamDialog * d = new QGCMapRCToParamDialog(paramName, _uas, MainWindow::instance()); + d->exec(); +} diff --git a/src/VehicleSetup/ParameterEditor.h b/src/VehicleSetup/ParameterEditorController.h similarity index 54% rename from src/VehicleSetup/ParameterEditor.h rename to src/VehicleSetup/ParameterEditorController.h index 55d349265281f4d16deae0c70543f462444ceeeb..3f38266712e2a54576a32afd34fdc2f63940ec60 100644 --- a/src/VehicleSetup/ParameterEditor.h +++ b/src/VehicleSetup/ParameterEditorController.h @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station - (c) 2009 - 2014 QGROUNDCONTROL PROJECT + (c) 2009, 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -21,31 +21,42 @@ ======================================================================*/ -#ifndef PARAMETEREDITOR_H -#define PARAMETEREDITOR_H - -#include - -#include "UASInterface.h" - /// @file -/// @brief This is the Parameter Editor widget which is used in the Parameters tab of Vehicle Setup. /// @author Don Gagne -namespace Ui { - class ParameterEditor; -} +#ifndef PARAMETEREDITORCONTROLLER_H +#define PARAMETEREDITORCONTROLLER_H + +#include +#include -class ParameterEditor : public QWidget +#include "AutoPilotPlugin.h" +#include "UASInterface.h" + +class ParameterEditorController : public QObject { Q_OBJECT - + public: - explicit ParameterEditor(UASInterface* uas, const QStringList& filterList, QWidget* parent = 0); - ~ParameterEditor(); - + ParameterEditorController(void); + + Q_PROPERTY(QStringList componentIds MEMBER _componentIds CONSTANT) + + Q_INVOKABLE QStringList getGroupsForComponent(int componentId); + Q_INVOKABLE QStringList getFactsForGroup(int componentId, QString group); + + Q_INVOKABLE void clearRCToParam(void); + Q_INVOKABLE void saveToFile(void); + Q_INVOKABLE void loadFromFile(void); + Q_INVOKABLE void refresh(void); + Q_INVOKABLE void setRCToParam(const QString& paramName); + + QList model(void); + private: - Ui::ParameterEditor* _ui; + UASInterface* _uas; + AutoPilotPlugin* _autopilot; + QStringList _componentIds; }; #endif diff --git a/src/VehicleSetup/SetupView.cc b/src/VehicleSetup/SetupView.cc index e90a46cc3610097d6fdad459750fa87a5cd14671..adefb4a73c53a9f4114f64203ab1e67a2331b831 100644 --- a/src/VehicleSetup/SetupView.cc +++ b/src/VehicleSetup/SetupView.cc @@ -30,11 +30,11 @@ #include "UASManager.h" #include "AutoPilotPluginManager.h" #include "VehicleComponent.h" -#include "ParameterEditor.h" #include "QGCQmlWidgetHolder.h" #include "MainWindow.h" #include "QGCMessageBox.h" #include "FirmwareUpgradeController.h" +#include "ParameterEditorController.h" #include #include @@ -54,8 +54,9 @@ SetupView::SetupView(QWidget* parent) : Q_UNUSED(fSucceeded); Q_ASSERT(fSucceeded); - qmlRegisterType("QGroundControl.FirmwareUpgradeController", 1, 0, "FirmwareUpgradeController"); - + qmlRegisterType("QGroundControl.Controllers", 1, 0, "FirmwareUpgradeController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); + _ui->buttonHolder->rootContext()->setContextProperty("controller", this); _ui->buttonHolder->setAutoPilot(NULL); _ui->buttonHolder->setSource(QUrl::fromUserInput("qrc:/qml/SetupViewButtonsDisconnected.qml")); @@ -131,8 +132,14 @@ void SetupView::firmwareButtonClicked(void) void SetupView::parametersButtonClicked(void) { - ParameterEditor* setup = new ParameterEditor(_uasCurrent, QStringList(), this); - _changeSetupWidget(setup); + QGCQmlWidgetHolder* setup = new QGCQmlWidgetHolder; + Q_CHECK_PTR(setup); + + Q_ASSERT(_autoPilotPlugin); + setup->setAutoPilot(_autoPilotPlugin); + setup->setSource(QUrl::fromUserInput("qrc:/qml/ParameterEditor.qml")); + + _changeSetupWidget(setup); } void SetupView::summaryButtonClicked(void) diff --git a/src/VehicleSetup/SetupView.h b/src/VehicleSetup/SetupView.h index 821bef72259182cf467bb14dfdaa18f2759c9193..0a931ca0390a69cfbc2a46df2a2281e8422acc80 100644 --- a/src/VehicleSetup/SetupView.h +++ b/src/VehicleSetup/SetupView.h @@ -25,7 +25,6 @@ #define SETUPVIEW_H #include "UASInterface.h" -#include "ParameterEditor.h" #include "VehicleComponent.h" #include "AutoPilotPlugin.h"