Commit b6b24a16 authored by Don Gagne's avatar Don Gagne

New naming scheme for non-default component

parent 4787a4fc
......@@ -51,6 +51,11 @@ QString FactBinder::name(void) const
}
}
int FactBinder::componentId(void) const
{
return _componentId;
}
void FactBinder::setName(const QString& name)
{
if (_fact) {
......@@ -59,13 +64,25 @@ void FactBinder::setName(const QString& name)
}
if (!name.isEmpty()) {
if (_autopilotPlugin->factExists(FactSystem::ParameterProvider, _componentId, name)) {
_fact = _autopilotPlugin->getFact(FactSystem::ParameterProvider, _componentId, name);
QString parsedName = name;
// Component id + name combination?
if (name.contains(":")) {
QStringList parts = name.split(":");
if (parts.count() == 2) {
parsedName = parts[0];
_componentId = parts[1].toInt();
}
}
if (_autopilotPlugin->factExists(FactSystem::ParameterProvider, _componentId, parsedName)) {
_fact = _autopilotPlugin->getFact(FactSystem::ParameterProvider, _componentId, parsedName);
connect(_fact, &Fact::valueChanged, this, &FactBinder::valueChanged);
emit valueChanged();
emit nameChanged();
} else {
emit metaDataChanged();
} else {
qWarning() << "FAILED BINDING PARAM" << name << ": PARAM DOES NOT EXIST ON SYSTEM!";
Q_ASSERT(false);
}
......@@ -108,3 +125,66 @@ QString FactBinder::units(void) const
return QString();
}
}
QVariant FactBinder::defaultValue(void)
{
if (_fact) {
return _fact->defaultValue();
} else {
return QVariant(0);
}
}
FactMetaData::ValueType_t FactBinder::type(void)
{
if (_fact) {
return _fact->type();
} else {
return FactMetaData::valueTypeUint32;
}
}
QString FactBinder::shortDescription(void)
{
if (_fact) {
return _fact->shortDescription();
} else {
return QString();
}
}
QString FactBinder::longDescription(void)
{
if (_fact) {
return _fact->longDescription();
} else {
return QString();
}
}
QVariant FactBinder::min(void)
{
if (_fact) {
return _fact->min();
} else {
return QVariant(0);
}
}
QVariant FactBinder::max(void)
{
if (_fact) {
return _fact->max();
} else {
return QVariant(0);
}
}
QString FactBinder::group(void)
{
if (_fact) {
return _fact->group();
} else {
return QString();
}
}
......@@ -38,17 +38,23 @@ class FactBinder : public QObject
{
Q_OBJECT
Q_PROPERTY(int componentId MEMBER _componentId NOTIFY componentIdChanged)
Q_PROPERTY(int componentId READ componentId NOTIFY nameChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true)
Q_PROPERTY(QVariant valueString READ valueString NOTIFY valueChanged)
Q_PROPERTY(QString units READ units CONSTANT)
Q_PROPERTY(QString units READ units NOTIFY metaDataChanged)
Q_PROPERTY(QVariant defaultValue READ defaultValue NOTIFY metaDataChanged)
Q_PROPERTY(FactMetaData::ValueType_t type READ type NOTIFY metaDataChanged)
Q_PROPERTY(QString shortDescription READ shortDescription NOTIFY metaDataChanged)
Q_PROPERTY(QString longDescription READ longDescription NOTIFY metaDataChanged)
Q_PROPERTY(QVariant min READ min NOTIFY metaDataChanged)
Q_PROPERTY(QVariant max READ max NOTIFY metaDataChanged)
Q_PROPERTY(QString group READ group NOTIFY metaDataChanged)
public:
FactBinder(void);
int componentId(void) const;
void setComponentId(int componentId);
QString name(void) const;
void setName(const QString& name);
......@@ -58,13 +64,19 @@ public:
QString valueString(void) const;
/// Read accesor for units property
QString units(void) const;
QVariant defaultValue(void);
FactMetaData::ValueType_t type(void);
QString shortDescription(void);
QString longDescription(void);
QVariant min(void);
QVariant max(void);
QString group(void);
signals:
void componentIdChanged(void);
void nameChanged(void);
void valueChanged(void);
void metaDataChanged(void);
private:
AutoPilotPlugin* _autopilotPlugin;
......
......@@ -40,7 +40,7 @@ FactSystem::FactSystem(QObject* parent) :
QGCSingleton(parent)
{
qmlRegisterType<FactBinder>(_factSystemQmlUri, 1, 0, "Fact");
qmlRegisterUncreatableType<VehicleComponent>(_factSystemQmlUri, 1, 0, "VehicleComponent", "Can only reference VehicleComponent");
qmlRegisterUncreatableType<VehicleComponent>(_factSystemQmlUri, 1, 0, "VehicleComponent", "Can only reference, cannot create");
}
FactSystem::~FactSystem()
......
......@@ -37,7 +37,7 @@ Item {
// Use specific component id
TextInput {
objectName: "testControl"
Fact { id: fact2; name: "COMPONENT_51"; componentId: 51 }
Fact { id: fact2; name: "COMPONENT_51:51" }
text: fact2.value
onAccepted: { fact2.value = text; }
}
......
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