Commit 526e5c53 authored by Don Gagne's avatar Don Gagne

Fact string support

parent 8783b20d
......@@ -16,12 +16,14 @@ QGCTextField {
showUnits: true
showHelp: true
property Fact fact: null
property Fact fact: null
property string _validateString
property bool _factIsString: fact ? fact.type === FactMetaData.valueTypeString : false
// At this point all Facts are numeric
inputMethodHints: ScreenTools.isiOS ?
Qt.ImhNone : // iOS numeric keyboard has not done button, we can't use it
inputMethodHints: (_factIsString || ScreenTools.isiOS) ?
Qt.ImhNone : // iOS numeric keyboard has no done button, we can't use it
Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard
onEditingFinished: {
......
......@@ -7,12 +7,6 @@
*
****************************************************************************/
/// @file
/// @brief Object which exposes a FactMetaData
///
/// @author Don Gagne <don@thegagnes.com>
#include "FactMetaData.h"
#include "SettingsManager.h"
#include "JsonHelper.h"
......@@ -157,7 +151,7 @@ QVariant FactMetaData::rawDefaultValue(void) const
void FactMetaData::setRawDefaultValue(const QVariant& rawDefaultValue)
{
if (_rawMin <= rawDefaultValue && rawDefaultValue <= _rawMax) {
if (_type == valueTypeString || (_rawMin <= rawDefaultValue && rawDefaultValue <= _rawMax)) {
_rawDefaultValue = rawDefaultValue;
_defaultValueAvailable = true;
} else {
......@@ -208,6 +202,8 @@ QVariant FactMetaData::_minForType(void) const
return QVariant(-std::numeric_limits<float>::max());
case valueTypeDouble:
return QVariant(-std::numeric_limits<double>::max());
case valueTypeString:
return QVariant();
}
// Make windows compiler happy, even switch is full cased
......@@ -233,6 +229,8 @@ QVariant FactMetaData::_maxForType(void) const
return QVariant(std::numeric_limits<float>::max());
case valueTypeDouble:
return QVariant(std::numeric_limits<double>::max());
case valueTypeString:
return QVariant();
}
// Make windows compiler happy, even switch is full cased
......@@ -285,6 +283,10 @@ bool FactMetaData::convertAndValidateRaw(const QVariant& rawValue, bool convertO
}
}
break;
case FactMetaData::valueTypeString:
convertOk = true;
typedValue = QVariant(rawValue.toString());
break;
}
if (!convertOk) {
......@@ -340,6 +342,10 @@ bool FactMetaData::convertAndValidateCooked(const QVariant& cookedValue, bool co
}
}
break;
case FactMetaData::valueTypeString:
convertOk = true;
typedValue = QVariant(cookedValue.toString());
break;
}
if (!convertOk) {
......@@ -556,7 +562,8 @@ FactMetaData::ValueType_t FactMetaData::stringToType(const QString& typeString,
<< QStringLiteral("Uint32")
<< QStringLiteral("Int32")
<< QStringLiteral("Float")
<< QStringLiteral("Double");
<< QStringLiteral("Double")
<< QStringLiteral("String");
knownTypes << valueTypeUint8
<< valueTypeInt8
......@@ -565,7 +572,8 @@ FactMetaData::ValueType_t FactMetaData::stringToType(const QString& typeString,
<< valueTypeUint32
<< valueTypeInt32
<< valueTypeFloat
<< valueTypeDouble;
<< valueTypeDouble
<< valueTypeString;
for (int i=0; i<knownTypeStrings.count(); i++) {
if (knownTypeStrings[i].compare(typeString, Qt::CaseInsensitive) == 0) {
......@@ -599,7 +607,7 @@ size_t FactMetaData::typeToSize(ValueType_t type)
default:
qWarning() << "Unsupported fact value type" << type;
return 4;
return 0;
}
}
......@@ -766,8 +774,8 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QObjec
// Validate key types
QStringList keys;
QList<QJsonValue::Type> types;
keys << _nameJsonKey << _decimalPlacesJsonKey << _typeJsonKey << _shortDescriptionJsonKey << _longDescriptionJsonKey << _unitsJsonKey << _defaultValueJsonKey << _minJsonKey << _maxJsonKey;
types << QJsonValue::String << QJsonValue::Double << QJsonValue::String << QJsonValue::String << QJsonValue::String << QJsonValue::String << QJsonValue::Double << QJsonValue::Double << QJsonValue::Double;
keys << _nameJsonKey << _decimalPlacesJsonKey << _typeJsonKey << _shortDescriptionJsonKey << _longDescriptionJsonKey << _unitsJsonKey << _minJsonKey << _maxJsonKey;
types << QJsonValue::String << QJsonValue::Double << QJsonValue::String << QJsonValue::String << QJsonValue::String << QJsonValue::String << QJsonValue::Double << QJsonValue::Double;
if (!JsonHelper::validateKeyTypes(json, keys, types, errorString)) {
qWarning() << errorString;
return new FactMetaData(valueTypeUint32, metaDataParent);
......@@ -811,7 +819,7 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QObjec
metaData->setRawUnits(json[_unitsJsonKey].toString());
}
if (json.contains(_defaultValueJsonKey)) {
metaData->setRawDefaultValue(json[_defaultValueJsonKey].toDouble());
metaData->setRawDefaultValue(json[_defaultValueJsonKey]);
}
if (json.contains(_minJsonKey)) {
metaData->setRawMin(json[_minJsonKey].toDouble());
......
......@@ -37,9 +37,12 @@ public:
valueTypeUint32,
valueTypeInt32,
valueTypeFloat,
valueTypeDouble
valueTypeDouble,
valueTypeString
} ValueType_t;
Q_ENUM(ValueType_t)
typedef QVariant (*Translator)(const QVariant& from);
FactMetaData(QObject* parent = NULL);
......
......@@ -30,6 +30,7 @@ void FactSystem::setToolbox(QGCToolbox *toolbox)
QGCTool::setToolbox(toolbox);
qmlRegisterType<Fact> (_factSystemQmlUri, 1, 0, "Fact");
qmlRegisterType<FactMetaData> (_factSystemQmlUri, 1, 0, "FactMetaData");
qmlRegisterType<FactPanelController>(_factSystemQmlUri, 1, 0, "FactPanelController");
qmlRegisterUncreatableType<FactGroup>(_factSystemQmlUri, 1, 0, "FactGroup", "ReferenceOnly");
......
......@@ -39,22 +39,26 @@ QVariant APMParameterMetaData::_stringToTypedVariant(const QString& string,
int convertTo = QVariant::Int; // keep compiler warning happy
switch (type) {
case FactMetaData::valueTypeUint8:
case FactMetaData::valueTypeUint16:
case FactMetaData::valueTypeUint32:
convertTo = QVariant::UInt;
break;
case FactMetaData::valueTypeInt8:
case FactMetaData::valueTypeInt16:
case FactMetaData::valueTypeInt32:
convertTo = QVariant::Int;
break;
case FactMetaData::valueTypeFloat:
convertTo = QMetaType::Float;
break;
case FactMetaData::valueTypeDouble:
convertTo = QVariant::Double;
break;
case FactMetaData::valueTypeUint8:
case FactMetaData::valueTypeUint16:
case FactMetaData::valueTypeUint32:
convertTo = QVariant::UInt;
break;
case FactMetaData::valueTypeInt8:
case FactMetaData::valueTypeInt16:
case FactMetaData::valueTypeInt32:
convertTo = QVariant::Int;
break;
case FactMetaData::valueTypeFloat:
convertTo = QMetaType::Float;
break;
case FactMetaData::valueTypeDouble:
convertTo = QVariant::Double;
break;
case FactMetaData::valueTypeString:
qWarning() << "Internal Error: No support for string parameters";
convertTo = QVariant::String;
break;
}
*convertOk = var.convert(convertTo);
......
......@@ -39,22 +39,26 @@ QVariant PX4ParameterMetaData::_stringToTypedVariant(const QString& string, Fact
int convertTo = QVariant::Int; // keep compiler warning happy
switch (type) {
case FactMetaData::valueTypeUint8:
case FactMetaData::valueTypeUint16:
case FactMetaData::valueTypeUint32:
convertTo = QVariant::UInt;
break;
case FactMetaData::valueTypeInt8:
case FactMetaData::valueTypeInt16:
case FactMetaData::valueTypeInt32:
convertTo = QVariant::Int;
break;
case FactMetaData::valueTypeFloat:
convertTo = QMetaType::Float;
break;
case FactMetaData::valueTypeDouble:
convertTo = QVariant::Double;
break;
case FactMetaData::valueTypeUint8:
case FactMetaData::valueTypeUint16:
case FactMetaData::valueTypeUint32:
convertTo = QVariant::UInt;
break;
case FactMetaData::valueTypeInt8:
case FactMetaData::valueTypeInt16:
case FactMetaData::valueTypeInt32:
convertTo = QVariant::Int;
break;
case FactMetaData::valueTypeFloat:
convertTo = QMetaType::Float;
break;
case FactMetaData::valueTypeDouble:
convertTo = QVariant::Double;
break;
case FactMetaData::valueTypeString:
qWarning() << "Internal Error: No support for string parameters";
convertTo = QVariant::String;
break;
}
*convertOk = var.convert(convertTo);
......
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