1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

LP-230 UAVObject generator : Add enum count. Thanks @filnet

This commit is contained in:
Laurent Lalanne 2016-02-19 20:08:11 +01:00
parent 08e6dd8cc6
commit 220eb033d9
4 changed files with 33 additions and 12 deletions

View File

@ -2,7 +2,8 @@
******************************************************************************
*
* @file $(NAMELC).h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
@ -37,6 +38,13 @@
class UAVObjectManager;
class $(NAME)Constants : public QObject {
Q_OBJECT
public:
enum Enum { $(ENUMS_COUNT) };
Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5
};
$(ENUMS)
class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject

View File

@ -2,7 +2,8 @@
******************************************************************************
*
* @file uavobjectgeneratorgcs.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief produce gcs code for uavobjects
*
* @see The GNU Public License (GPL) Version 3
@ -54,6 +55,7 @@ struct Context {
ObjectInfo *object;
// enums
QString enums;
QString enumsCount;
QString registerImpl;
// interface
QString fields;
@ -222,6 +224,7 @@ QString generate(Context &ctxt, FieldContext &fieldCtxt, const QString &fragment
str.replace(":fieldLimitValues", fieldCtxt.field->limitValues);
str.replace(":elementCount", QString::number(fieldCtxt.field->numElements));
str.replace(":enumCount", QString::number(fieldCtxt.field->numOptions));
return str;
}
@ -362,6 +365,8 @@ void generateEnum(Context &ctxt, FieldContext &fieldCtxt)
" Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5\n"
"};\n\n").arg(enumStringList);
ctxt.enumsCount += generate(ctxt, fieldCtxt, ":PropNameCount = :enumCount, ");
ctxt.registerImpl += generate(ctxt, fieldCtxt,
" qmlRegisterType<:ClassName_:PropName>(\"%1.:ClassName\", 1, 0, \":PropName\");\n").arg("UAVTalk");
}
@ -622,6 +627,9 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo *object)
ctxt.registerImpl += ::generate(ctxt,
" qmlRegisterType<:ClassName>(\"%1.:ClassName\", 1, 0, \":ClassName\");\n").arg("UAVTalk");
ctxt.registerImpl += ::generate(ctxt,
" qmlRegisterType<:ClassNameConstants>(\"%1.:ClassName\", 1, 0, \":ClassNameConstants\");\n").arg("UAVTalk");
for (int n = 0; n < object->fields.length(); ++n) {
FieldInfo *field = object->fields[n];
@ -664,6 +672,7 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo *object)
}
outInclude.replace("$(ENUMS)", ctxt.enums);
outInclude.replace("$(ENUMS_COUNT)", ctxt.enumsCount);
outInclude.replace("$(DATAFIELDS)", ctxt.fields);
outInclude.replace("$(DATAFIELDINFO)", ctxt.fieldsInfo);
outInclude.replace("$(PROPERTIES)", ctxt.properties);

View File

@ -2,7 +2,8 @@
******************************************************************************
*
* @file uavobjectparser.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Parses XML files and extracts object information.
*
* @see The GNU Public License (GPL) Version 3
@ -545,7 +546,8 @@ QString UAVObjectParser::processObjectFields(QDomNode & childNode, ObjectInfo *i
}
}
}
if (field->options.length() == 0) {
field->numOptions = field->options.size();
if (field->numOptions == 0) {
return QString("Object:field:options attribute/element is missing");
}
}

View File

@ -2,7 +2,8 @@
******************************************************************************
*
* @file uavobjectparser.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Parses XML files and extracts object information.
*
* @see The GNU Public License (GPL) Version 3
@ -51,6 +52,7 @@ typedef struct {
QString units;
FieldType type;
int numElements;
int numOptions;
int numBytes;
QStringList elementNames;
QStringList options; // for enums only