Commit 3a9207cc authored by DonLakeFlyer's avatar DonLakeFlyer

Coding style cleanup

parent 117e3dde
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.3 import QtQuick 2.3
import QtQml.Models 2.1 import QtQml.Models 2.1
...@@ -17,7 +26,7 @@ Item { ...@@ -17,7 +26,7 @@ Item {
property bool audioMuted: QGroundControl.settingsManager.appSettings.audioMuted.rawValue property bool audioMuted: QGroundControl.settingsManager.appSettings.audioMuted.rawValue
property ObjectModel checkListItems: _checkListItems property ObjectModel checkListItems: _checkListItems
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property int _checkState: _activeVehicle ? (_activeVehicle.armed ? 1 + (buttonActuators._state + buttonMotors._state + buttonMission._state + buttonSoundOutput._state) / 4 / 4 : 0) : 0 ; // Shows progress of checks inside the checklist - unlocks next check steps in groups property int _checkState: _activeVehicle ? (_activeVehicle.armed ? 1 + (buttonActuators.state + buttonMotors.state + buttonMission.state + buttonSoundOutput.state) / 4 / 4 : 0) : 0 ; // Shows progress of checks inside the checklist - unlocks next check steps in groups
// Connections // Connections
onBatPercentRemainingChanged: buttonBattery.updateItem(); onBatPercentRemainingChanged: buttonBattery.updateItem();
...@@ -75,13 +84,16 @@ Item { ...@@ -75,13 +84,16 @@ Item {
pendingtext: "Healthy & charged > 40%. Battery connector firmly plugged?" pendingtext: "Healthy & charged > 40%. Battery connector firmly plugged?"
function updateItem() { function updateItem() {
if (!_activeVehicle) { if (!_activeVehicle) {
_state = 0; state = statePassed
} else {
if (unhealthySensors & Vehicle.SysStatusSensorBattery) {
failuretext = qsTr("Not healthy. Check console.")
state = stateMajorIssue
} else if (batPercentRemaining < 40.0) {
failuretext = qsTr("Low (below 40%). Please recharge.")
state = stateMajorIssue
} else { } else {
if (!(unhealthySensors & Vehicle.SysStatusSensorBattery) && batPercentRemaining>=40.0) _state = 1+3*(_nrClicked>0); state = _nrClicked > 0 ? statePassed : statePending
else {
if(unhealthySensors & Vehicle.SysStatusSensorBattery) failuretext="Not healthy. Check console.";
else if(batPercentRemaining<40.0) failuretext="Low (below 40%). Please recharge.";
_state = 3;
} }
} }
} }
...@@ -91,7 +103,7 @@ Item { ...@@ -91,7 +103,7 @@ Item {
name: "Sensors" name: "Sensors"
function updateItem() { function updateItem() {
if (!_activeVehicle) { if (!_activeVehicle) {
_state = 0; state = statePassed
} else { } else {
if(!(unhealthySensors & Vehicle.SysStatusSensor3dMag) && if(!(unhealthySensors & Vehicle.SysStatusSensor3dMag) &&
!(unhealthySensors & Vehicle.SysStatusSensor3dAccel) && !(unhealthySensors & Vehicle.SysStatusSensor3dAccel) &&
...@@ -99,11 +111,11 @@ Item { ...@@ -99,11 +111,11 @@ Item {
!(unhealthySensors & Vehicle.SysStatusSensorAbsolutePressure) && !(unhealthySensors & Vehicle.SysStatusSensorAbsolutePressure) &&
!(unhealthySensors & Vehicle.SysStatusSensorDifferentialPressure) && !(unhealthySensors & Vehicle.SysStatusSensorDifferentialPressure) &&
!(unhealthySensors & Vehicle.SysStatusSensorGPS)) { !(unhealthySensors & Vehicle.SysStatusSensorGPS)) {
if(!gpsLock) { if (!gpsLock) {
pendingtext="Pending. Waiting for GPS lock."; pendingtext = qsTr("Pending. Waiting for GPS lock.")
_state=1; state = statePending
} else { } else {
_state = 4; // All OK state = statePassed
} }
} else { } else {
if(unhealthySensors & Vehicle.SysStatusSensor3dMag) failuretext="Failure. Magnetometer issues. Check console."; if(unhealthySensors & Vehicle.SysStatusSensor3dMag) failuretext="Failure. Magnetometer issues. Check console.";
...@@ -112,7 +124,7 @@ Item { ...@@ -112,7 +124,7 @@ Item {
else if(unhealthySensors & Vehicle.SysStatusSensorAbsolutePressure) failuretext="Failure. Barometer issues. Check console."; else if(unhealthySensors & Vehicle.SysStatusSensorAbsolutePressure) failuretext="Failure. Barometer issues. Check console.";
else if(unhealthySensors & Vehicle.SysStatusSensorDifferentialPressure) failuretext="Failure. Airspeed sensor issues. Check console."; else if(unhealthySensors & Vehicle.SysStatusSensorDifferentialPressure) failuretext="Failure. Airspeed sensor issues. Check console.";
else if(unhealthySensors & Vehicle.SysStatusSensorGPS) failuretext="Failure. No valid or low quality GPS signal. Check console."; else if(unhealthySensors & Vehicle.SysStatusSensorGPS) failuretext="Failure. No valid or low quality GPS signal. Check console.";
_state = 3; state = stateMajorIssue
} }
} }
} }
...@@ -124,10 +136,13 @@ Item { ...@@ -124,10 +136,13 @@ Item {
failuretext: "No signal or invalid autopilot-RC config. Check RC and console." failuretext: "No signal or invalid autopilot-RC config. Check RC and console."
function updateItem() { function updateItem() {
if (!_activeVehicle) { if (!_activeVehicle) {
_state = 0; state = statePassed
} else { } else {
if (unhealthySensors & Vehicle.SysStatusSensorRCReceiver) {_state = 3} if (unhealthySensors & Vehicle.SysStatusSensorRCReceiver) {
else {_state = 1+3*(_nrClicked>0);} state = stateMajorIssue
} else {
state = _nrClicked > 0 ? statePassed : statePending
}
} }
} }
} }
...@@ -136,10 +151,13 @@ Item { ...@@ -136,10 +151,13 @@ Item {
name: "Global position estimate" name: "Global position estimate"
function updateItem() { function updateItem() {
if (!_activeVehicle) { if (!_activeVehicle) {
_state = 0; state = statePassed
} else { } else {
if (unhealthySensors & Vehicle.SysStatusSensorAHRS) {_state = 3;} if (unhealthySensors & Vehicle.SysStatusSensorAHRS) {
else {_state = 4;} state = stateMajorIssue
} else {
state = statePassed
}
} }
} }
} }
...@@ -172,10 +190,14 @@ Item { ...@@ -172,10 +190,14 @@ Item {
failuretext: "Failure, QGC audio output is disabled. Please enable it under application settings->general to hear audio warnings!" failuretext: "Failure, QGC audio output is disabled. Please enable it under application settings->general to hear audio warnings!"
function updateItem() { function updateItem() {
if (!_activeVehicle) { if (!_activeVehicle) {
_state = 0; state = statePassed
} else { } else {
if (audioMuted) {_state = 3 ; _nrClicked=0;} if (audioMuted) {
else {_state = 1+3*(_nrClicked>0);} state = stateMajorIssue
_nrClicked = 0
} else {
state = _nrClicked > 0 ? statePassed : statePending
}
} }
} }
} }
......
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.3 import QtQuick 2.3
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Styles 1.4
...@@ -9,64 +18,98 @@ import QGroundControl.ScreenTools 1.0 ...@@ -9,64 +18,98 @@ import QGroundControl.ScreenTools 1.0
QGCButton { QGCButton {
property string name: "" property string name: ""
property int group: 0 property int group: 0
property string defaulttext: "Not checked yet" property string defaulttext: qsTr("Not checked yet")
property string pendingtext: "" property string pendingtext: ""
property string failuretext: "Failure. Check console." property string failuretext: qsTr("Failure. Check console.")
property int _state: 0 property int state: stateNotChecked
readonly property int stateNotChecked: 0
readonly property int statePending: 1
readonly property int stateMinorIssue: 2
readonly property int stateMajorIssue: 3
readonly property int statePassed: 4
property var _color: qgcPal.button property var _color: qgcPal.button
property int _nrClicked: 0 property int _nrClicked: 0
property string _text: qsTr(name)+ ": " + qsTr(defaulttext) property string _text: name + ": " + defaulttext
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
enabled: (!_activeVehicle || _activeVehicle.connectionLost) ? false : checklist._checkState >= group
opacity: (!_activeVehicle || _activeVehicle.connectionLost) ? 0.4 : 0.2 + (0.8 * (checklist._checkState >= group))
width: 40 * ScreenTools.defaultFontPixelWidth
enabled : (_activeVehicle==null || _activeVehicle.connectionLost) ? false : checklist._checkState>=group
opacity : (_activeVehicle==null || _activeVehicle.connectionLost) ? 0.4 : 0.2+0.8*(checklist._checkState >= group);
width: 40*ScreenTools.defaultFontPixelWidth
style: ButtonStyle { style: ButtonStyle {
background: Rectangle {color:_color; border.color: qgcPal.button; radius:3} background: Rectangle {color:_color; border.color: qgcPal.button; radius:3}
label: Label { label: Label {
text: _text text: _text
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
color: _state>0 ? qgcPal.mapWidgetBorderLight : qgcPal.buttonText color: state > 0 ? qgcPal.mapWidgetBorderLight : qgcPal.buttonText
} }
} }
// Connections onPendingtextChanged: { if (state === statePending) { getTextFromState(); getColorFromState(); } }
onPendingtextChanged: { if(_state==1) {getTextFromState(); getColorFromState();} } onFailuretextChanged: { if (state === stateMajorIssue) { getTextFromState(); getColorFromState(); } }
onFailuretextChanged: { if(_state==3) {getTextFromState(); getColorFromState();} } onStateChanged: { getTextFromState(); getColorFromState(); }
on_StateChanged: { getTextFromState(); getColorFromState(); }
onClicked: { onClicked: {
if(_state<2) _nrClicked=_nrClicked+1; //Only allow click-counter to increase when not failed yet if (state <= statePending) {
updateItem(); _nrClicked = _nrClicked + 1 //Only allow click-counter to increase when not failed yet
}
updateItem()
} }
//Functions
function updateItem() { function updateItem() {
// This is the default updateFunction. It assumes the item is a MANUAL check list item, i.e. one that // This is the default updateFunction. It assumes the item is a MANUAL check list item, i.e. one that
// only requires user clicks (one click if pendingtext="", two clicks otherwise) for completion. // only requires user clicks (one click if pendingtext="", two clicks otherwise) for completion.
if(_nrClicked===0) _state = 0; if (_nrClicked === 0) {
else if(_nrClicked===1) { state = stateNotChecked
if(pendingtext.length === 0) _state = 4; } else if (_nrClicked === 1) {
else _state = 1; if (pendingtext.length === 0) {
} else _state = 4; state = statePassed
} else {
state = statePending
}
} else {
state = statePassed
}
getTextFromState(); getTextFromState();
getColorFromState(); getColorFromState();
} }
function getTextFromState() { function getTextFromState() {
if(_state === 0) {_text= qsTr(name) + ": " + qsTr(defaulttext)} // Not checked yet if (state === stateNotChecked) {
else if(_state === 1) {_text= "<b>"+qsTr(name)+"</b>" +": " + qsTr(pendingtext)} // Pending _text = qsTr(name) + ": " + qsTr(defaulttext)
else if(_state === 2) {_text= "<b>"+qsTr(name)+"</b>" +": " + qsTr("Minor problem")} // Small problem or need further user action to resolve } else if (state === statePending) {
else if(_state === 3) {_text= "<b>"+qsTr(name)+"</b>" +": " + qsTr(failuretext)} // Big problem _text = "<b>"+qsTr(name)+"</b>" +": " + pendingtext
else {_text= "<b>"+qsTr(name)+"</b>" +": " + qsTr("OK")} // All OK } else if (state === stateMinorIssue) {
_text = "<b>"+qsTr(name)+"</b>" +": " + qsTr("Minor problem")
} else if (state === stateMajorIssue) {
_text = "<b>"+qsTr(name)+"</b>" +": " + failuretext
} else if (state === statePassed) {
_text = "<b>"+qsTr(name)+"</b>" +": " + qsTr("OK")
} else {
console.warn("Internal Error: invalid state", state)
}
} }
function getColorFromState() { function getColorFromState() {
if(_state === 0) {_color=qgcPal.button} // Not checked yet if (state === stateNotChecked) {
else if(_state === 1) {_color=Qt.rgba(0.9,0.47,0.2,1)} // Pending _color = qgcPal.button
else if(_state === 2) {_color=Qt.rgba(1.0,0.6,0.2,1)} // Small problem or need further user action to resolve } else if (state === statePending) {
else if(_state === 3) {_color=Qt.rgba(0.92,0.22,0.22,1)} // Big problem _color = Qt.rgba(0.9,0.47,0.2,1)
else {_color=Qt.rgba(0.27,0.67,0.42,1)} // All OK } else if (state === stateMinorIssue) {
_color = Qt.rgba(1.0,0.6,0.2,1)
} else if (state === stateMajorIssue) {
_color = Qt.rgba(0.92,0.22,0.22,1)
} else if (state === statePassed ) {
_color = Qt.rgba(0.27,0.67,0.42,1)
} else {
console.warn("Internal Error: invalid state", state)
}
} }
function resetNrClicks() { function resetNrClicks() {
_nrClicked=0; _nrClicked=0;
updateItem(); updateItem();
......
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