Newer
Older
Michael Carpenter
committed
#include "UASQuickView.h"
#include <QMetaMethod>
#include <QDebug>
#include "UASQuickViewItemSelect.h"
Michael Carpenter
committed
#include "UASQuickViewTextItem.h"
Michael Carpenter
committed
#include <QSettings>
Michael Carpenter
committed
UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent)
{
quickViewSelectDialog=0;
Michael Carpenter
committed
ui.setupUi(this);
connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(setActiveUAS(UASInterface*)));
connect(UASManager::instance(),SIGNAL(UASCreated(UASInterface*)),this,SLOT(addUAS(UASInterface*)));
if (UASManager::instance()->getActiveUAS())
{
addUAS(UASManager::instance()->getActiveUAS());
}
this->setContextMenuPolicy(Qt::ActionsContextMenu);
loadSettings();
Michael Carpenter
committed
Michael Carpenter
committed
//If we don't have any predefined settings, set some defaults.
if (uasPropertyValueMap.size() == 0)
{
valueEnabled("altitude");
valueEnabled("groundSpeed");
valueEnabled("distToWaypoint");
valueEnabled("yaw");
valueEnabled("roll");
}
QAction *action = new QAction("Add Item",this);
action->setCheckable(false);
connect(action,SIGNAL(triggered()),this,SLOT(actionTriggered()));
this->addAction(action);
Michael Carpenter
committed
Michael Carpenter
committed
updateTimer = new QTimer(this);
connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick()));
updateTimer->start(1000);
}
Michael Carpenter
committed
UASQuickView::~UASQuickView()
{
if (quickViewSelectDialog)
{
delete quickViewSelectDialog;
}
}
void UASQuickView::actionTriggered()
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->show();
return;
}
quickViewSelectDialog = new UASQuickViewItemSelect();
connect(quickViewSelectDialog,SIGNAL(destroyed()),this,SLOT(selectDialogClosed()));
connect(quickViewSelectDialog,SIGNAL(valueDisabled(QString)),this,SLOT(valueDisabled(QString)));
connect(quickViewSelectDialog,SIGNAL(valueEnabled(QString)),this,SLOT(valueEnabled(QString)));
quickViewSelectDialog->setAttribute(Qt::WA_DeleteOnClose,true);
for (QMap<QString,double>::const_iterator i = uasPropertyValueMap.constBegin();i!=uasPropertyValueMap.constEnd();i++)
{
quickViewSelectDialog->addItem(i.key(),uasEnabledPropertyList.contains(i.key()));
}
quickViewSelectDialog->show();
}
void UASQuickView::saveSettings()
{
Michael Carpenter
committed
QSettings settings;
settings.beginWriteArray("UAS_QUICK_VIEW_ITEMS");
int count = 0;
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++)
{
settings.setArrayIndex(count++);
settings.setValue("name",i.key());
settings.setValue("type","text");
}
settings.endArray();
settings.sync();
}
void UASQuickView::loadSettings()
{
QSettings settings;
int size = settings.beginReadArray("UAS_QUICK_VIEW_ITEMS");
for (int i=0;i<size;i++)
{
settings.setArrayIndex(i);
QString nameval = settings.value("name").toString();
QString typeval = settings.value("type").toString();
if (typeval == "text" && !uasPropertyToLabelMap.contains(nameval))
{
valueEnabled(nameval);
}
}
}
void UASQuickView::valueEnabled(QString value)
{
Michael Carpenter
committed
UASQuickViewItem *item = new UASQuickViewTextItem(this);
item->setTitle(value);
ui.verticalLayout->addWidget(item);
uasPropertyToLabelMap[value] = item;
uasEnabledPropertyList.append(value);
if (!uasPropertyValueMap.contains(value))
{
uasPropertyValueMap[value] = 0;
}
saveSettings();
}
void UASQuickView::valueDisabled(QString value)
{
if (uasPropertyToLabelMap.contains(value))
{
UASQuickViewItem *item = uasPropertyToLabelMap[value];
uasPropertyToLabelMap.remove(value);
item->hide();
ui.verticalLayout->removeWidget(item);
item->deleteLater();
uasEnabledPropertyList.removeOne(value);
saveSettings();
}
}
void UASQuickView::selectDialogClosed()
{
quickViewSelectDialog = 0;
}
Michael Carpenter
committed
void UASQuickView::updateTimerTick()
{
//uasPropertyValueMap
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin(); i != uasPropertyToLabelMap.constEnd();i++)
Michael Carpenter
committed
{
if (uasPropertyValueMap.contains(i.key()))
Michael Carpenter
committed
{
i.value()->setValue(uasPropertyValueMap[i.key()]);
Michael Carpenter
committed
}
}
}
void UASQuickView::addUAS(UASInterface* uas)
{
if (uas)
{
if (!this->uas)
{
setActiveUAS(uas);
}
}
}
void UASQuickView::setActiveUAS(UASInterface* uas)
{
if (!uas)
{
return;
}
this->uas = uas;
Michael Carpenter
committed
connect(uas,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));
//connect(uas,SIGNAL())
}
void UASQuickView::addSource(MAVLinkDecoder *decoder)
{
connect(decoder,SIGNAL(valueChanged(int,QString,QString,double,quint64)),this,SLOT(valueChanged(int,QString,QString,double,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,qint8,quint64)),this,SLOT(valueChanged(int,QString,QString,qint8,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,qint16,quint64)),this,SLOT(valueChanged(int,QString,QString,qint16,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,qint32,quint64)),this,SLOT(valueChanged(int,QString,QString,qint32,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,qint64,quint64)),this,SLOT(valueChanged(int,QString,QString,qint64,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,quint8,quint64)),this,SLOT(valueChanged(int,QString,QString,quint8,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,quint16,quint64)),this,SLOT(valueChanged(int,QString,QString,quint16,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,quint32,quint64)),this,SLOT(valueChanged(int,QString,QString,quint32,quint64)));
connect(decoder,SIGNAL(valueChanged(int,QString,QString,quint64,quint64)),this,SLOT(valueChanged(int,QString,QString,quint64,quint64)));
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const quint8 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
Michael Carpenter
committed
}
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const qint8 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const quint16 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const qint16 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const quint32 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const qint32 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const quint64 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const qint64 value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const double value, const quint64 msec)
{
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
Michael Carpenter
committed
void UASQuickView::actionTriggered(bool checked)
{
QAction *senderlabel = qobject_cast<QAction*>(sender());
if (!senderlabel)
{
return;
}
if (checked)
{
Michael Carpenter
committed
UASQuickViewItem *item = new UASQuickViewTextItem(this);
Michael Carpenter
committed
item->setTitle(senderlabel->text());
ui.verticalLayout->addWidget(item);
uasPropertyToLabelMap[senderlabel->text()] = item;
}
else
{
ui.verticalLayout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]);
uasPropertyToLabelMap[senderlabel->text()]->deleteLater();
Michael Carpenter
committed
uasPropertyToLabelMap.remove(senderlabel->text());
Michael Carpenter
committed
}
}
Michael Carpenter
committed
void UASQuickView::valueChanged(const int uasid, const QString& name, const QString& unit, const QVariant value,const quint64 msecs)
{
uasPropertyValueMap[name] = value.toDouble();
}
Michael Carpenter
committed
void UASQuickView::valChanged(double val,QString type)
{
//qDebug() << "Value changed:" << type << val;
Michael Carpenter
committed
// uasPropertyValueMap[type] = val;