Unverified Commit fee0d4d1 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6001 from mavlink/factMetadataCrash

Fixed crash in FactMetadata constructor.
parents 2af0422b db27a9ea
......@@ -32,8 +32,8 @@ const qreal FactMetaData::UnitConsts_s::milesToMeters = 1609.344;
const qreal FactMetaData::UnitConsts_s::feetToMeters = 0.3048;
const qreal FactMetaData::UnitConsts_s::inchesToCentimeters = 2.54;
const QString FactMetaData::defaultCategory = tr("Other");
const QString FactMetaData::defaultGroup = tr("Misc");
static const char* kDefaultCategory = QT_TRANSLATE_NOOP("FactMetaData", "Other");
static const char* kDefaultGroup = QT_TRANSLATE_NOOP("FactMetaData", "Misc");
// Built in translations for all Facts
const FactMetaData::BuiltInTranslation_s FactMetaData::_rgBuiltInTranslations[] = {
......@@ -84,8 +84,6 @@ FactMetaData::FactMetaData(QObject* parent)
, _decimalPlaces (unknownDecimalPlaces)
, _rawDefaultValue (0)
, _defaultValueAvailable(false)
, _category (defaultCategory)
, _group (defaultGroup)
, _rawMax (_maxForType())
, _maxIsDefaultForType (true)
, _rawMin (_minForType())
......@@ -97,7 +95,8 @@ FactMetaData::FactMetaData(QObject* parent)
, _hasControl (true)
, _readOnly (false)
{
_category = kDefaultCategory;
_group = kDefaultGroup;
}
FactMetaData::FactMetaData(ValueType_t type, QObject* parent)
......@@ -106,8 +105,6 @@ FactMetaData::FactMetaData(ValueType_t type, QObject* parent)
, _decimalPlaces (unknownDecimalPlaces)
, _rawDefaultValue (0)
, _defaultValueAvailable(false)
, _category (defaultCategory)
, _group (defaultGroup)
, _rawMax (_maxForType())
, _maxIsDefaultForType (true)
, _rawMin (_minForType())
......@@ -119,7 +116,8 @@ FactMetaData::FactMetaData(ValueType_t type, QObject* parent)
, _hasControl (true)
, _readOnly (false)
{
_category = kDefaultCategory;
_group = kDefaultGroup;
}
FactMetaData::FactMetaData(const FactMetaData& other, QObject* parent)
......@@ -134,8 +132,6 @@ FactMetaData::FactMetaData(ValueType_t type, const QString name, QObject* parent
, _decimalPlaces (unknownDecimalPlaces)
, _rawDefaultValue (0)
, _defaultValueAvailable(false)
, _category (defaultCategory)
, _group (defaultGroup)
, _rawMax (_maxForType())
, _maxIsDefaultForType (true)
, _rawMin (_minForType())
......@@ -148,7 +144,8 @@ FactMetaData::FactMetaData(ValueType_t type, const QString name, QObject* parent
, _hasControl (true)
, _readOnly (false)
{
_category = kDefaultCategory;
_group = kDefaultGroup;
}
const FactMetaData& FactMetaData::operator=(const FactMetaData& other)
......@@ -181,6 +178,16 @@ const FactMetaData& FactMetaData::operator=(const FactMetaData& other)
return *this;
}
const QString FactMetaData::defaultCategory()
{
return QString(kDefaultCategory);
}
const QString FactMetaData::defaultGroup()
{
return QString(kDefaultGroup);
}
QVariant FactMetaData::rawDefaultValue(void) const
{
if (_defaultValueAvailable) {
......@@ -253,7 +260,7 @@ QVariant FactMetaData::_minForType(void) const
case valueTypeCustom:
return QVariant();
}
// Make windows compiler happy, even switch is full cased
return QVariant();
}
......@@ -285,7 +292,7 @@ QVariant FactMetaData::_maxForType(void) const
case valueTypeCustom:
return QVariant();
}
// Make windows compiler happy, even switch is full cased
return QVariant();
}
......@@ -293,9 +300,9 @@ QVariant FactMetaData::_maxForType(void) const
bool FactMetaData::convertAndValidateRaw(const QVariant& rawValue, bool convertOnly, QVariant& typedValue, QString& errorString)
{
bool convertOk = false;
errorString.clear();
switch (type()) {
case FactMetaData::valueTypeInt8:
case FactMetaData::valueTypeInt16:
......@@ -347,11 +354,11 @@ bool FactMetaData::convertAndValidateRaw(const QVariant& rawValue, bool convertO
typedValue = QVariant(rawValue.toByteArray());
break;
}
if (!convertOk) {
errorString += tr("Invalid number");
}
return convertOk && errorString.isEmpty();
}
......
......@@ -27,7 +27,7 @@
class FactMetaData : public QObject
{
Q_OBJECT
public:
typedef enum {
valueTypeUint8,
......@@ -45,7 +45,7 @@ public:
} ValueType_t;
typedef QVariant (*Translator)(const QVariant& from);
FactMetaData(QObject* parent = NULL);
FactMetaData(ValueType_t type, QObject* parent = NULL);
FactMetaData(ValueType_t type, const QString name, QObject* parent = NULL);
......@@ -76,6 +76,9 @@ public:
/// Returns the string for distance units which has configued by user
static QString appSettingsAreaUnitsString(void);
static const QString defaultCategory ();
static const QString defaultGroup ();
int decimalPlaces (void) const;
QVariant rawDefaultValue (void) const;
QVariant cookedDefaultValue (void) const { return _rawTranslator(rawDefaultValue()); }
......@@ -160,9 +163,6 @@ public:
static ValueType_t stringToType(const QString& typeString, bool& unknownType);
static size_t typeToSize(ValueType_t type);
static const QString defaultCategory;
static const QString defaultGroup;
private:
QVariant _minForType(void) const;
QVariant _maxForType(void) const;
......
......@@ -306,7 +306,7 @@ void APMParameterMetaData::correctGroupMemberships(ParameterNametoFactMetaDataMa
foreach(const QString& groupName, groupMembers.keys()) {
if (groupMembers[groupName].count() == 1) {
foreach(const QString& parameter, groupMembers.value(groupName)) {
parameterToFactMetaDataMap[parameter]->group = FactMetaData::defaultGroup;
parameterToFactMetaDataMap[parameter]->group = FactMetaData::defaultGroup();
}
}
}
......
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