mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
Generate properties for UAVDataObject fields.
Also changed UAVObject::requestUpdate() and UAVObject::update() to be slots. This makes possible to use objects directly from QML.
This commit is contained in:
parent
64202ce092
commit
aead288304
@ -99,8 +99,6 @@ public:
|
|||||||
virtual void setMetadata(const Metadata& mdata) = 0;
|
virtual void setMetadata(const Metadata& mdata) = 0;
|
||||||
virtual Metadata getMetadata() = 0;
|
virtual Metadata getMetadata() = 0;
|
||||||
virtual Metadata getDefaultMetadata() = 0;
|
virtual Metadata getDefaultMetadata() = 0;
|
||||||
void requestUpdate();
|
|
||||||
void updated();
|
|
||||||
void lock();
|
void lock();
|
||||||
void lock(int timeoutMs);
|
void lock(int timeoutMs);
|
||||||
void unlock();
|
void unlock();
|
||||||
@ -113,6 +111,10 @@ public:
|
|||||||
QString toStringData();
|
QString toStringData();
|
||||||
void emitTransactionCompleted(bool success);
|
void emitTransactionCompleted(bool success);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void requestUpdate();
|
||||||
|
void updated();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void objectUpdated(UAVObject* obj);
|
void objectUpdated(UAVObject* obj);
|
||||||
void objectUpdatedAuto(UAVObject* obj);
|
void objectUpdatedAuto(UAVObject* obj);
|
||||||
|
@ -50,6 +50,9 @@ $(FIELDSINIT)
|
|||||||
setDefaultFieldValues();
|
setDefaultFieldValues();
|
||||||
// Set the object description
|
// Set the object description
|
||||||
setDescription(DESCRIPTION);
|
setDescription(DESCRIPTION);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(objectUpdated(UAVObject*)),
|
||||||
|
SLOT(emitNotifications()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,6 +110,11 @@ void $(NAME)::setData(const DataFields& data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void $(NAME)::emitNotifications()
|
||||||
|
{
|
||||||
|
$(NOTIFY_PROPERTIES_CHANGED)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a clone of this object, a new instance ID must be specified.
|
* Create a clone of this object, a new instance ID must be specified.
|
||||||
* Do not use this function directly to create new instances, the
|
* Do not use this function directly to create new instances, the
|
||||||
@ -126,3 +134,5 @@ $(NAME)* $(NAME)::GetInstance(UAVObjectManager* objMngr, quint32 instID)
|
|||||||
{
|
{
|
||||||
return dynamic_cast<$(NAME)*>(objMngr->getObject($(NAME)::OBJID, instID));
|
return dynamic_cast<$(NAME)*>(objMngr->getObject($(NAME)::OBJID, instID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(PROPERTIES_IMPL)
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject
|
class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
$(PROPERTIES)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Field structure
|
// Field structure
|
||||||
@ -67,6 +68,17 @@ $(DATAFIELDINFO)
|
|||||||
|
|
||||||
static $(NAME)* GetInstance(UAVObjectManager* objMngr, quint32 instID = 0);
|
static $(NAME)* GetInstance(UAVObjectManager* objMngr, quint32 instID = 0);
|
||||||
|
|
||||||
|
$(PROPERTY_GETTERS)
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
$(PROPERTY_SETTERS)
|
||||||
|
|
||||||
|
signals:
|
||||||
|
$(PROPERTY_NOTIFICATIONS)
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void emitNotifications();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataFields data;
|
DataFields data;
|
||||||
|
|
||||||
|
@ -107,6 +107,99 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo* info)
|
|||||||
}
|
}
|
||||||
outInclude.replace(QString("$(DATAFIELDS)"), fields);
|
outInclude.replace(QString("$(DATAFIELDS)"), fields);
|
||||||
|
|
||||||
|
// Replace $(PROPERTIES) and related tags
|
||||||
|
QString properties;
|
||||||
|
QString propertiesImpl;
|
||||||
|
QString propertyGetters;
|
||||||
|
QString propertySetters;
|
||||||
|
QString propertyNotifications;
|
||||||
|
QString propertyNotificationsImpl;
|
||||||
|
|
||||||
|
//to avoid name conflicts
|
||||||
|
QStringList reservedProperties;
|
||||||
|
reservedProperties << "Description" << "Metadata";
|
||||||
|
|
||||||
|
for (int n = 0; n < info->fields.length(); ++n)
|
||||||
|
{
|
||||||
|
FieldInfo *field = info->fields[n];
|
||||||
|
|
||||||
|
if (reservedProperties.contains(field->name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Determine type
|
||||||
|
type = fieldTypeStrCPP[field->type];
|
||||||
|
// Append field
|
||||||
|
if ( field->numElements > 1 ) {
|
||||||
|
propertyGetters +=
|
||||||
|
QString(" Q_INVOKABLE %1 get%2(quint32 index) const;\n")
|
||||||
|
.arg(type).arg(field->name);
|
||||||
|
propertiesImpl +=
|
||||||
|
QString("%1 %2::get%3(quint32 index) const\n"
|
||||||
|
"{\n"
|
||||||
|
" QMutexLocker locker(mutex);\n"
|
||||||
|
" return data.%3[index];\n"
|
||||||
|
"}\n")
|
||||||
|
.arg(type).arg(info->name).arg(field->name);
|
||||||
|
propertySetters +=
|
||||||
|
QString(" void set%1(quint32 index, %2 value);\n")
|
||||||
|
.arg(field->name).arg(type);
|
||||||
|
propertiesImpl +=
|
||||||
|
QString("void %1::set%2(quint32 index, %3 value)\n"
|
||||||
|
"{\n"
|
||||||
|
" mutex->lock();\n"
|
||||||
|
" bool changed = data.%2[index] != value;\n"
|
||||||
|
" data.%2[index] = value;\n"
|
||||||
|
" mutex->unlock();\n"
|
||||||
|
" if (changed) emit %2Changed(index,value);\n"
|
||||||
|
"}\n\n")
|
||||||
|
.arg(info->name).arg(field->name).arg(type);
|
||||||
|
propertyNotifications +=
|
||||||
|
QString(" void %1Changed(quint32 index, %2 value);\n")
|
||||||
|
.arg(field->name).arg(type);
|
||||||
|
} else {
|
||||||
|
properties += QString(" Q_PROPERTY(%1 %2 READ get%2 WRITE set%2 NOTIFY %2Changed);\n")
|
||||||
|
.arg(type).arg(field->name);
|
||||||
|
propertyGetters +=
|
||||||
|
QString(" Q_INVOKABLE %1 get%2() const;\n")
|
||||||
|
.arg(type).arg(field->name);
|
||||||
|
propertiesImpl +=
|
||||||
|
QString("%1 %2::get%3() const\n"
|
||||||
|
"{\n"
|
||||||
|
" QMutexLocker locker(mutex);\n"
|
||||||
|
" return data.%3;\n"
|
||||||
|
"}\n")
|
||||||
|
.arg(type).arg(info->name).arg(field->name);
|
||||||
|
propertySetters +=
|
||||||
|
QString(" void set%1(%2 value);\n")
|
||||||
|
.arg(field->name).arg(type);
|
||||||
|
propertiesImpl +=
|
||||||
|
QString("void %1::set%2(%3 value)\n"
|
||||||
|
"{\n"
|
||||||
|
" mutex->lock();\n"
|
||||||
|
" bool changed = data.%2 != value;\n"
|
||||||
|
" data.%2 = value;\n"
|
||||||
|
" mutex->unlock();\n"
|
||||||
|
" if (changed) emit %2Changed(value);\n"
|
||||||
|
"}\n\n")
|
||||||
|
.arg(info->name).arg(field->name).arg(type);
|
||||||
|
propertyNotifications +=
|
||||||
|
QString(" void %1Changed(%2 value);\n")
|
||||||
|
.arg(field->name).arg(type);
|
||||||
|
propertyNotificationsImpl +=
|
||||||
|
QString(" //if (data.%1 != oldData.%1)\n"
|
||||||
|
" emit %1Changed(data.%1);\n")
|
||||||
|
.arg(field->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outInclude.replace(QString("$(PROPERTIES)"), properties);
|
||||||
|
outInclude.replace(QString("$(PROPERTY_GETTERS)"), propertyGetters);
|
||||||
|
outInclude.replace(QString("$(PROPERTY_SETTERS)"), propertySetters);
|
||||||
|
outInclude.replace(QString("$(PROPERTY_NOTIFICATIONS)"), propertyNotifications);
|
||||||
|
|
||||||
|
outCode.replace(QString("$(PROPERTIES_IMPL)"), propertiesImpl);
|
||||||
|
outCode.replace(QString("$(NOTIFY_PROPERTIES_CHANGED)"), propertyNotificationsImpl);
|
||||||
|
|
||||||
// Replace the $(FIELDSINIT) tag
|
// Replace the $(FIELDSINIT) tag
|
||||||
QString finit;
|
QString finit;
|
||||||
for (int n = 0; n < info->fields.length(); ++n)
|
for (int n = 0; n < info->fields.length(); ++n)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user