Browse Source

Show help button on FactTextFields

QGC4.4
Don Gagne 9 years ago
parent
commit
0ea45f386d
  1. 16
      src/FactSystem/FactControls/FactTextField.qml
  2. 4
      src/FactSystem/FactMetaData.cc
  3. 3
      src/FactSystem/FactMetaData.h
  4. 10
      src/QmlControls/ParameterEditorDialog.qml
  5. 62
      src/QmlControls/QGCTextField.qml

16
src/FactSystem/FactControls/FactTextField.qml

@ -14,6 +14,7 @@ QGCTextField {
text: fact ? fact.valueString : "" text: fact ? fact.valueString : ""
unitsLabel: fact ? fact.units : "" unitsLabel: fact ? fact.units : ""
showUnits: true showUnits: true
showHelp: true
property Fact fact: null property Fact fact: null
property string _validateString property string _validateString
@ -31,7 +32,7 @@ QGCTextField {
fact.value = text fact.value = text
} else { } else {
_validateString = text _validateString = text
qgcView.showDialog(editorDialogComponent, qsTr("Invalid Parameter Value"), qgcView.showDialogDefaultWidth, StandardButton.Save) qgcView.showDialog(validationErrorDialogComponent, qsTr("Invalid Value"), qgcView.showDialogDefaultWidth, StandardButton.Save)
} }
} else { } else {
fact.value = text fact.value = text
@ -39,8 +40,11 @@ QGCTextField {
} }
} }
onHelpClicked: qgcView.showDialog(helpDialogComponent, qsTr("Value Details"), qgcView.showDialogDefaultWidth, StandardButton.Save)
Component { Component {
id: editorDialogComponent id: validationErrorDialogComponent
ParameterEditorDialog { ParameterEditorDialog {
validate: true validate: true
@ -48,4 +52,12 @@ QGCTextField {
fact: _textField.fact fact: _textField.fact
} }
} }
Component {
id: helpDialogComponent
ParameterEditorDialog {
fact: _textField.fact
}
}
} }

4
src/FactSystem/FactMetaData.cc

@ -750,7 +750,7 @@ int FactMetaData::decimalPlaces(void) const
return actualDecimalPlaces; return actualDecimalPlaces;
} }
FactMetaData* FactMetaData::_createFromJsonObject(const QJsonObject& json, QObject* metaDataParent) FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QObject* metaDataParent)
{ {
QString errorString; QString errorString;
@ -855,7 +855,7 @@ QMap<QString, FactMetaData*> FactMetaData::createMapFromJsonFile(const QString&
continue; continue;
} }
QJsonObject jsonObject = jsonValue.toObject(); QJsonObject jsonObject = jsonValue.toObject();
FactMetaData* metaData = _createFromJsonObject(jsonObject, metaDataParent); FactMetaData* metaData = createFromJsonObject(jsonObject, metaDataParent);
if (metaDataMap.contains(metaData->name())) { if (metaDataMap.contains(metaData->name())) {
qWarning() << QStringLiteral("Duplicate fact name:") << metaData->name(); qWarning() << QStringLiteral("Duplicate fact name:") << metaData->name();

3
src/FactSystem/FactMetaData.h

@ -48,6 +48,8 @@ public:
static QMap<QString, FactMetaData*> createMapFromJsonFile(const QString& jsonFilename, QObject* metaDataParent); static QMap<QString, FactMetaData*> createMapFromJsonFile(const QString& jsonFilename, QObject* metaDataParent);
static FactMetaData* createFromJsonObject(const QJsonObject& json, QObject* metaDataParent);
const FactMetaData& operator=(const FactMetaData& other); const FactMetaData& operator=(const FactMetaData& other);
/// Converts from meters to the user specified distance unit /// Converts from meters to the user specified distance unit
@ -144,7 +146,6 @@ private:
QVariant _minForType(void) const; QVariant _minForType(void) const;
QVariant _maxForType(void) const; QVariant _maxForType(void) const;
void _setAppSettingsTranslators(void); void _setAppSettingsTranslators(void);
static FactMetaData* _createFromJsonObject(const QJsonObject& json, QObject* metaDataParent);
// Built in translators // Built in translators
static QVariant _defaultTranslator(const QVariant& from) { return from; } static QVariant _defaultTranslator(const QVariant& from) { return from; }

10
src/QmlControls/ParameterEditorDialog.qml

@ -85,7 +85,8 @@ QGCViewDialog {
QGCLabel { QGCLabel {
width: parent.width width: parent.width
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: fact.shortDescription ? fact.shortDescription : qsTr("Parameter Description (not defined)") visible: fact.shortDescription
text: fact.shortDescription
} }
QGCLabel { QGCLabel {
@ -156,7 +157,10 @@ QGCViewDialog {
} }
} }
QGCLabel { text: fact.name } QGCLabel {
text: fact.name
visible: fact.componentId > 0 // > 0 means it's a parameter fact
}
Column { Column {
spacing: defaultTextHeight / 2 spacing: defaultTextHeight / 2
@ -202,7 +206,7 @@ QGCViewDialog {
QGCLabel { QGCLabel {
width: parent.width width: parent.width
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: qsTr("Warning: Modifying parameters while vehicle is in flight can lead to vehicle instability and possible vehicle loss. ") + text: qsTr("Warning: Modifying values while vehicle is in flight can lead to vehicle instability and possible vehicle loss. ") +
qsTr("Make sure you know what you are doing and double-check your values before Save!") qsTr("Make sure you know what you are doing and double-check your values before Save!")
} }

62
src/QmlControls/QGCTextField.qml

@ -1,6 +1,7 @@
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.2
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0 import QGroundControl.ScreenTools 1.0
@ -9,17 +10,22 @@ TextField {
id: root id: root
property bool showUnits: false property bool showUnits: false
property bool showHelp: false
property string unitsLabel: "" property string unitsLabel: ""
signal helpClicked
property real _helpLayoutWidth: 0
Component.onCompleted: { Component.onCompleted: {
if (typeof qgcTextFieldforwardKeysTo !== 'undefined') { if (typeof qgcTextFieldforwardKeysTo !== 'undefined') {
root.Keys.forwardTo = [qgcTextFieldforwardKeysTo] root.Keys.forwardTo = [qgcTextFieldforwardKeysTo]
} }
} }
property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
textColor: __qgcPal.textFieldText textColor: qgcPal.textFieldText
height: Math.round(Math.max(25, ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 2.5 : 1.2))) height: Math.round(Math.max(25, ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 2.5 : 1.2)))
QGCLabel { QGCLabel {
@ -35,6 +41,8 @@ TextField {
background: Item { background: Item {
id: backgroundItem id: backgroundItem
property bool showHelp: control.showHelp && control.activeFocus
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
anchors.bottomMargin: -1 anchors.bottomMargin: -1
@ -44,32 +52,58 @@ TextField {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
border.color: control.activeFocus ? "#47b" : "#999" border.color: control.activeFocus ? "#47b" : "#999"
color: __qgcPal.textField color: qgcPal.textField
} }
Text { RowLayout {
id: unitsLabel id: unitsHelpLayout
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.rightMargin: backgroundItem.showHelp ? 0 : control.__contentHeight * 0.333
anchors.right: parent.right
spacing: 4
verticalAlignment: Text.AlignVCenter Component.onCompleted: control._helpLayoutWidth = unitsHelpLayout.width
horizontalAlignment:Text.AlignHCenter onWidthChanged: control._helpLayoutWidth = unitsHelpLayout.width
x: parent.width - width
width: unitsLabelWidthGenerator.width
Text {
anchors.verticalCenter: parent.verticalCenter
text: control.unitsLabel text: control.unitsLabel
font.pointSize: ScreenTools.defaultFontPointSize font.pointSize: backgroundItem.showHelp ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
font.family: ScreenTools.normalFontFamily font.family: ScreenTools.normalFontFamily
antialiasing: true antialiasing: true
color: control.textColor color: control.textColor
visible: control.showUnits visible: control.showUnits
} }
Rectangle {
anchors.margins: 2
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
width: height * 0.75
color: control.textColor
radius: 2
visible: backgroundItem.showHelp
QGCLabel {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: qgcPal.textField
text: "?"
}
}
}
MouseArea {
anchors.fill: unitsHelpLayout
enabled: control.activeFocus
onClicked: root.helpClicked()
}
} }
padding.right: control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight * 0.333 padding.right: control._helpLayoutWidth //control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight * 0.333
} }
onActiveFocusChanged: { onActiveFocusChanged: {

Loading…
Cancel
Save