added input type to API
This commit is contained in:
parent
df00303bed
commit
d510157b26
@ -368,6 +368,29 @@ QList<ParamType> DevicePlugin::parseParamTypes(const QJsonArray &array) const
|
||||
foreach (const QJsonValue &allowedTypesJson, pt.value("allowedValues").toArray()) {
|
||||
allowedValues.append(allowedTypesJson.toVariant());
|
||||
}
|
||||
// set the input type if there is any
|
||||
if (pt.contains("inputType")) {
|
||||
QString inputTypeString = pt.value("inputType").toString();
|
||||
if (inputTypeString == "TextLine") {
|
||||
paramType.setInputType(Types::InputTypeTextLine);
|
||||
} else if (inputTypeString == "TextArea") {
|
||||
paramType.setInputType(Types::InputTypeTextArea);
|
||||
} else if (inputTypeString == "Password") {
|
||||
paramType.setInputType(Types::InputTypePassword);
|
||||
} else if (inputTypeString == "Search") {
|
||||
paramType.setInputType(Types::InputTypeSearch);
|
||||
} else if (inputTypeString == "Mail") {
|
||||
paramType.setInputType(Types::InputTypeMail);
|
||||
} else if (inputTypeString == "IPv4Address") {
|
||||
paramType.setInputType(Types::InputTypeIPv4Address);
|
||||
} else if (inputTypeString == "IPv6Address") {
|
||||
paramType.setInputType(Types::InputTypeIPv6Address);
|
||||
} else if (inputTypeString == "Url") {
|
||||
paramType.setInputType(Types::InputTypeUrl);
|
||||
} else if (inputTypeString == "MacAddress") {
|
||||
paramType.setInputType(Types::InputTypeMacAddress);
|
||||
}
|
||||
}
|
||||
paramType.setAllowedValues(allowedValues);
|
||||
paramType.setLimits(pt.value("minValue").toVariant(), pt.value("maxValue").toVariant());
|
||||
paramTypes.append(paramType);
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue):
|
||||
m_name(name),
|
||||
m_type(type),
|
||||
m_defaultValue(defaultValue)
|
||||
m_defaultValue(defaultValue),
|
||||
m_inputType(Types::InputTypeNone)
|
||||
{
|
||||
}
|
||||
|
||||
@ -96,6 +97,18 @@ void ParamType::setMaxValue(const QVariant &maxValue)
|
||||
m_maxValue = maxValue;
|
||||
}
|
||||
|
||||
/*! Returns the input type of this ParamType. */
|
||||
Types::InputType ParamType::inputType() const
|
||||
{
|
||||
return m_inputType;
|
||||
}
|
||||
|
||||
/*! Sets the input value of this ParamType to the given \a inputType. */
|
||||
void ParamType::setInputType(const Types::InputType &inputType)
|
||||
{
|
||||
m_inputType = inputType;
|
||||
}
|
||||
|
||||
/*! Returns the limits of this ParamType. limits(minValue, maxValue). */
|
||||
QPair<QVariant, QVariant> ParamType::limits() const
|
||||
{
|
||||
|
||||
@ -21,10 +21,11 @@
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include "typeutils.h"
|
||||
|
||||
class ParamType
|
||||
{
|
||||
public:
|
||||
public:
|
||||
ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue = QVariant());
|
||||
|
||||
QString name() const;
|
||||
@ -42,6 +43,9 @@ public:
|
||||
QVariant maxValue() const;
|
||||
void setMaxValue(const QVariant &maxValue);
|
||||
|
||||
Types::InputType inputType() const;
|
||||
void setInputType(const Types::InputType &inputType);
|
||||
|
||||
QPair<QVariant, QVariant> limits() const;
|
||||
void setLimits(const QVariant &min, const QVariant &max);
|
||||
|
||||
@ -54,6 +58,7 @@ private:
|
||||
QVariant m_defaultValue;
|
||||
QVariant m_minValue;
|
||||
QVariant m_maxValue;
|
||||
Types::InputType m_inputType;
|
||||
QVariantList m_allowedValues;
|
||||
};
|
||||
|
||||
|
||||
@ -57,8 +57,22 @@ class Types
|
||||
Q_GADGET
|
||||
Q_ENUMS(StateOperator)
|
||||
Q_ENUMS(ValueOperator)
|
||||
Q_ENUMS(InputType)
|
||||
|
||||
public:
|
||||
enum InputType {
|
||||
InputTypeNone,
|
||||
InputTypeTextLine,
|
||||
InputTypeTextArea,
|
||||
InputTypePassword,
|
||||
InputTypeSearch,
|
||||
InputTypeMail,
|
||||
InputTypeIPv4Address,
|
||||
InputTypeIPv6Address,
|
||||
InputTypeUrl,
|
||||
InputTypeMacAddress
|
||||
};
|
||||
|
||||
enum ValueOperator {
|
||||
ValueOperatorEquals,
|
||||
ValueOperatorNotEquals,
|
||||
@ -75,5 +89,6 @@ public:
|
||||
|
||||
Q_DECLARE_METATYPE(Types::ValueOperator)
|
||||
Q_DECLARE_METATYPE(Types::StateOperator)
|
||||
Q_DECLARE_METATYPE(Types::InputType)
|
||||
|
||||
#endif // TYPEUTILS_H
|
||||
|
||||
@ -33,6 +33,7 @@ QString JsonTypes::s_lastError;
|
||||
QVariantList JsonTypes::s_basicType;
|
||||
QVariantList JsonTypes::s_stateOperator;
|
||||
QVariantList JsonTypes::s_valueOperator;
|
||||
QVariantList JsonTypes::s_inputType;
|
||||
QVariantList JsonTypes::s_createMethod;
|
||||
QVariantList JsonTypes::s_setupMethod;
|
||||
QVariantList JsonTypes::s_removePolicy;
|
||||
@ -69,6 +70,7 @@ void JsonTypes::init()
|
||||
s_basicType = enumToStrings(JsonTypes::staticMetaObject, "BasicType");
|
||||
s_stateOperator = enumToStrings(Types::staticMetaObject, "StateOperator");
|
||||
s_valueOperator = enumToStrings(Types::staticMetaObject, "ValueOperator");
|
||||
s_inputType = enumToStrings(Types::staticMetaObject, "InputType");
|
||||
s_createMethod = enumToStrings(DeviceClass::staticMetaObject, "CreateMethod");
|
||||
s_setupMethod = enumToStrings(DeviceClass::staticMetaObject, "SetupMethod");
|
||||
s_removePolicy = enumToStrings(RuleEngine::staticMetaObject, "RemovePolicy");
|
||||
@ -86,6 +88,7 @@ void JsonTypes::init()
|
||||
s_paramType.insert("o:minValue", basicTypeToString(Variant));
|
||||
s_paramType.insert("o:maxValue", basicTypeToString(Variant));
|
||||
s_paramType.insert("o:allowedValues", QVariantList() << basicTypeToString(Variant));
|
||||
s_paramType.insert("o:inputType",basicTypeToString(Variant));
|
||||
|
||||
// Param
|
||||
s_param.insert("name", basicTypeToString(String));
|
||||
@ -220,6 +223,7 @@ QVariantMap JsonTypes::allTypes()
|
||||
QVariantMap allTypes;
|
||||
allTypes.insert("BasicType", basicType());
|
||||
allTypes.insert("ParamType", paramTypeDescription());
|
||||
allTypes.insert("InputType", inputType());
|
||||
allTypes.insert("CreateMethod", createMethod());
|
||||
allTypes.insert("SetupMethod", setupMethod());
|
||||
allTypes.insert("ValueOperator", valueOperator());
|
||||
@ -391,6 +395,9 @@ QVariantMap JsonTypes::packParamType(const ParamType ¶mType)
|
||||
if (!paramType.allowedValues().isEmpty()) {
|
||||
variantMap.insert("allowedValues", paramType.allowedValues());
|
||||
}
|
||||
if (paramType.inputType() != Types::InputTypeNone) {
|
||||
variantMap.insert("inputType", s_inputType.at(paramType.inputType()));
|
||||
}
|
||||
return variantMap;
|
||||
}
|
||||
|
||||
@ -515,7 +522,7 @@ QVariantMap JsonTypes::packLogEntry(const LogEntry &logEntry)
|
||||
break;
|
||||
case Logging::LoggingSourceSystem:
|
||||
// FIXME: Update this once we support error codes for the general system
|
||||
// logEntryMap.insert("errorCode", "");
|
||||
// logEntryMap.insert("errorCode", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -568,7 +575,7 @@ ParamList JsonTypes::unpackParams(const QVariantList ¶mList)
|
||||
{
|
||||
ParamList params;
|
||||
foreach (const QVariant ¶mVariant, paramList) {
|
||||
// qDebug() << "unpacking param" << paramVariant;
|
||||
// qDebug() << "unpacking param" << paramVariant;
|
||||
params.append(unpackParam(paramVariant.toMap()));
|
||||
}
|
||||
return params;
|
||||
@ -703,7 +710,7 @@ QPair<bool, QString> JsonTypes::validateList(const QVariantList &templateList, c
|
||||
|
||||
for (int i = 0; i < list.count(); ++i) {
|
||||
QVariant listEntry = list.at(i);
|
||||
// qDebug() << "validating" << list << templateList;
|
||||
// qDebug() << "validating" << list << templateList;
|
||||
QPair<bool, QString> result = validateVariant(entryTemplate, listEntry);
|
||||
if (!result.first) {
|
||||
qDebug() << "List entry not matching template";
|
||||
@ -720,14 +727,14 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
||||
if (templateVariant.toString().startsWith("$ref:")) {
|
||||
QString refName = templateVariant.toString();
|
||||
if (refName == actionRef()) {
|
||||
// qDebug() << "validating action";
|
||||
// qDebug() << "validating action";
|
||||
QPair<bool, QString> result = validateMap(actionDescription(), variant.toMap());
|
||||
if (!result.first) {
|
||||
qDebug() << "Error validating action";
|
||||
return result;
|
||||
}
|
||||
} else if (refName == eventRef()) {
|
||||
// qDebug() << "validating event";
|
||||
// qDebug() << "validating event";
|
||||
QPair<bool, QString> result = validateMap(eventDescription(), variant.toMap());
|
||||
if (!result.first) {
|
||||
qDebug() << "event not valid";
|
||||
|
||||
@ -92,6 +92,7 @@ public:
|
||||
DECLARE_TYPE(basicType, "BasicType", JsonTypes, BasicType)
|
||||
DECLARE_TYPE(stateOperator, "StateOperator", Types, StateOperator)
|
||||
DECLARE_TYPE(valueOperator, "ValueOperator", Types, ValueOperator)
|
||||
DECLARE_TYPE(inputType, "InputType", Types, InputType)
|
||||
DECLARE_TYPE(createMethod, "CreateMethod", DeviceClass, CreateMethod)
|
||||
DECLARE_TYPE(setupMethod, "SetupMethod", DeviceClass, SetupMethod)
|
||||
DECLARE_TYPE(deviceError, "DeviceError", DeviceManager, DeviceError)
|
||||
|
||||
Reference in New Issue
Block a user