Commit a37f8489 authored by Bryant's avatar Bryant

Make the UASQuickView support resetting to a default state after all UASes are removed.

parent b1fc82ac
...@@ -78,7 +78,6 @@ UASQuickView::UASQuickView(QWidget *parent) : ...@@ -78,7 +78,6 @@ UASQuickView::UASQuickView(QWidget *parent) :
updateTimer = new QTimer(this); updateTimer = new QTimer(this);
connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick())); connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick()));
updateTimer->start(1000);
} }
void UASQuickView::updateTimerTick() void UASQuickView::updateTimerTick()
{ {
...@@ -104,38 +103,54 @@ void UASQuickView::addUAS(UASInterface* uas) ...@@ -104,38 +103,54 @@ void UASQuickView::addUAS(UASInterface* uas)
void UASQuickView::setActiveUAS(UASInterface* uas) void UASQuickView::setActiveUAS(UASInterface* uas)
{ {
if (!uas) // Clean up from the old UAS
if (this->uas)
{ {
return; uasPropertyList.clear();
uasPropertyValueMap.clear();
uasPropertyToLabelMap.clear();
updateTimer->stop();
this->actions().clear();
} }
this->uas = uas; this->uas = uas;
connect(uas,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));
uasPropertyList.clear(); // And connect the new one if it exists.
qDebug() << "UASInfoWidget property count:" << uas->metaObject()->propertyCount(); if (this->uas)
for (int i=0;i<uas->metaObject()->propertyCount();i++)
{ {
if (uas->metaObject()->property(i).hasNotifySignal()) // Monitor new UAS for changes
connect(this->uas,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));
// Populate a right-click menu for selecting which properties to display
qDebug() << "UASInfoWidget property count:" << uas->metaObject()->propertyCount();
for (int i=0;i<this->uas->metaObject()->propertyCount();i++)
{ {
qDebug() << "Property:" << i << uas->metaObject()->property(i).name(); if (this->uas->metaObject()->property(i).hasNotifySignal())
uasPropertyList.append(uas->metaObject()->property(i).name());
if (!uasPropertyToLabelMap.contains(uas->metaObject()->property(i).name()))
{
QAction *action = new QAction(QString(uas->metaObject()->property(i).name()),this);
action->setCheckable(true);
connect(action,SIGNAL(toggled(bool)),this,SLOT(actionTriggered(bool)));
this->addAction(action);
}
qDebug() << "Signature:" << uas->metaObject()->property(i).notifySignal().signature();
int val = this->metaObject()->indexOfMethod("valChanged(double,QString)");
if (val != -1)
{ {
qDebug() << "Property:" << i << this->uas->metaObject()->property(i).name();
if (!connect(uas,uas->metaObject()->property(i).notifySignal(),this,this->metaObject()->method(val))) uasPropertyList.append(this->uas->metaObject()->property(i).name());
if (!uasPropertyToLabelMap.contains(this->uas->metaObject()->property(i).name()))
{ {
qDebug() << "Error connecting signal"; QAction *action = new QAction(QString(this->uas->metaObject()->property(i).name()),this);
action->setCheckable(true);
connect(action,SIGNAL(toggled(bool)),this,SLOT(actionTriggered(bool)));
this->addAction(action);
}
qDebug() << "Signature:" << uas->metaObject()->property(i).notifySignal().signature();
int val = this->metaObject()->indexOfMethod("valChanged(double,QString)");
if (val != -1)
{
if (!connect(uas,uas->metaObject()->property(i).notifySignal(),this,this->metaObject()->method(val)))
{
qDebug() << "Error connecting signal";
}
} }
} }
} }
// And periodically update the view.
updateTimer->start(1000);
} }
} }
void UASQuickView::actionTriggered(bool checked) void UASQuickView::actionTriggered(bool checked)
...@@ -162,11 +177,16 @@ void UASQuickView::actionTriggered(bool checked) ...@@ -162,11 +177,16 @@ void UASQuickView::actionTriggered(bool checked)
} }
void UASQuickView::valueChanged(const int uasid, const QString& name, const QString& unit, const QVariant value,const quint64 msecs) void UASQuickView::valueChanged(const int uasid, const QString& name, const QString& unit, const QVariant value,const quint64 msecs)
{ {
Q_UNUSED(uasid);
Q_UNUSED(unit);
Q_UNUSED(msecs);
uasPropertyValueMap[name] = value.toDouble(); uasPropertyValueMap[name] = value.toDouble();
} }
void UASQuickView::valChanged(double val,QString type) void UASQuickView::valChanged(double val,QString type)
{ {
Q_UNUSED(val);
Q_UNUSED(type);
//qDebug() << "Value changed:" << type << val; //qDebug() << "Value changed:" << type << val;
// uasPropertyValueMap[type] = val; // uasPropertyValueMap[type] = val;
} }
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