2010-08-20 23:18:20 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file configtaskwidget.cpp
|
|
|
|
* @author E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConfigPlugin Config Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The Configuration Gadget used to update settings in the firmware
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include "configtaskwidget.h"
|
|
|
|
#include <QtGui/QWidget>
|
2011-09-23 14:48:27 +02:00
|
|
|
#include "uavsettingsimportexport/uavsettingsimportexportfactory.h"
|
|
|
|
#include "configgadgetwidget.h"
|
2010-08-20 23:18:20 +02:00
|
|
|
|
2011-08-23 12:25:28 +02:00
|
|
|
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent),isConnected(false),smartsave(NULL),dirty(false)
|
2010-08-20 23:18:20 +02:00
|
|
|
{
|
2011-07-26 00:18:41 +02:00
|
|
|
pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
objManager = pm->getObject<UAVObjectManager>();
|
2011-09-23 14:48:27 +02:00
|
|
|
connect((ConfigGadgetWidget*)parent, SIGNAL(autopilotConnected()),this, SLOT(onAutopilotConnect()));
|
|
|
|
connect((ConfigGadgetWidget*)parent, SIGNAL(autopilotDisconnected()),this, SLOT(onAutopilotDisconnect()));
|
|
|
|
UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>();
|
|
|
|
connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(invalidateObjects()));
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-07-26 21:35:38 +02:00
|
|
|
void ConfigTaskWidget::addWidget(QWidget * widget)
|
2011-07-26 00:18:41 +02:00
|
|
|
{
|
2011-07-26 21:35:38 +02:00
|
|
|
addUAVObjectToWidgetRelation("","",widget);
|
|
|
|
}
|
|
|
|
void ConfigTaskWidget::addUAVObject(QString objectName)
|
|
|
|
{
|
|
|
|
addUAVObjectToWidgetRelation(objectName,"",NULL);
|
|
|
|
}
|
2011-08-04 17:58:41 +02:00
|
|
|
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, QString index)
|
|
|
|
{
|
|
|
|
UAVObject *obj=NULL;
|
|
|
|
UAVObjectField *_field=NULL;
|
|
|
|
obj = objManager->getObject(QString(object));
|
2011-09-07 08:47:10 +02:00
|
|
|
Q_ASSERT(obj);
|
2011-08-04 17:58:41 +02:00
|
|
|
_field = obj->getField(QString(field));
|
2011-09-07 08:47:10 +02:00
|
|
|
Q_ASSERT(_field);
|
2011-08-04 17:58:41 +02:00
|
|
|
addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, int index,int scale)
|
2011-07-26 21:35:38 +02:00
|
|
|
{
|
|
|
|
UAVObject *obj=NULL;
|
|
|
|
UAVObjectField *_field=NULL;
|
|
|
|
if(!object.isEmpty())
|
2011-08-04 17:58:41 +02:00
|
|
|
{
|
2011-07-26 21:35:38 +02:00
|
|
|
obj = objManager->getObject(QString(object));
|
2011-09-07 08:47:10 +02:00
|
|
|
Q_ASSERT(obj);
|
2011-09-23 14:48:27 +02:00
|
|
|
objectUpdates.insert(obj,false);
|
|
|
|
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this, SLOT(objectUpdated(UAVObject*)));
|
2011-08-04 17:58:41 +02:00
|
|
|
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
|
|
|
|
}
|
2011-07-26 00:18:41 +02:00
|
|
|
//smartsave->addObject(obj);
|
2011-07-26 21:35:38 +02:00
|
|
|
if(!field.isEmpty() && obj)
|
|
|
|
_field = obj->getField(QString(field));
|
2011-07-26 00:18:41 +02:00
|
|
|
objectToWidget * ow=new objectToWidget();
|
|
|
|
ow->field=_field;
|
|
|
|
ow->object=obj;
|
|
|
|
ow->widget=widget;
|
2011-08-04 17:58:41 +02:00
|
|
|
ow->index=index;
|
|
|
|
ow->scale=scale;
|
2011-07-26 00:18:41 +02:00
|
|
|
objOfInterest.append(ow);
|
2011-07-26 21:35:38 +02:00
|
|
|
if(obj)
|
2011-08-23 12:25:28 +02:00
|
|
|
smartsave->addObject((UAVDataObject*)obj);
|
2011-07-26 21:35:38 +02:00
|
|
|
if(widget==NULL)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
else if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
2011-07-26 00:18:41 +02:00
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(currentIndexChanged(int)),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
2011-07-26 21:35:38 +02:00
|
|
|
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(sliderMoved(int)),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
|
|
|
else if(MixerCurveWidget * cb=qobject_cast<MixerCurveWidget *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(curveUpdated(QList<double>,double)),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
|
|
|
else if(QTableWidget * cb=qobject_cast<QTableWidget *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(cellChanged(int,int)),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
|
|
|
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(valueChanged(int)),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
|
|
|
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(valueChanged(double)),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
2011-08-02 18:06:17 +02:00
|
|
|
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(clicked()),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
|
|
|
else if(QPushButton * cb=qobject_cast<QPushButton *>(widget))
|
|
|
|
{
|
|
|
|
connect(cb,SIGNAL(clicked()),this,SLOT(widgetsContentsChanged()));
|
|
|
|
}
|
|
|
|
|
2010-08-20 23:18:20 +02:00
|
|
|
}
|
|
|
|
|
2011-07-26 21:35:38 +02:00
|
|
|
|
2010-08-20 23:18:20 +02:00
|
|
|
ConfigTaskWidget::~ConfigTaskWidget()
|
|
|
|
{
|
2011-07-26 00:18:41 +02:00
|
|
|
delete smartsave;
|
2010-08-20 23:18:20 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 21:31:19 +02:00
|
|
|
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
|
|
|
|
{
|
2011-06-02 16:08:19 +02:00
|
|
|
// saveObjectToSD is now handled by the UAVUtils plugin in one
|
|
|
|
// central place (and one central queue)
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectUtilManager* utilMngr = pm->getObject<UAVObjectUtilManager>();
|
|
|
|
utilMngr->saveObjectToSD(obj);
|
2010-09-07 21:31:19 +02:00
|
|
|
}
|
2010-08-20 23:18:20 +02:00
|
|
|
|
|
|
|
|
2010-08-26 16:23:40 +02:00
|
|
|
UAVObjectManager* ConfigTaskWidget::getObjectManager() {
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
2011-03-28 20:43:15 +02:00
|
|
|
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
|
|
|
|
Q_ASSERT(objMngr);
|
|
|
|
return objMngr;
|
2010-08-26 16:23:40 +02:00
|
|
|
}
|
|
|
|
|
2011-03-28 20:43:15 +02:00
|
|
|
double ConfigTaskWidget::listMean(QList<double> list)
|
|
|
|
{
|
|
|
|
double accum = 0;
|
|
|
|
for(int i = 0; i < list.size(); i++)
|
|
|
|
accum += list[i];
|
|
|
|
return accum / list.size();
|
|
|
|
}
|
|
|
|
|
2011-06-07 16:56:16 +02:00
|
|
|
// ************************************
|
|
|
|
// telemetry start/stop connect/disconnect signals
|
|
|
|
|
|
|
|
void ConfigTaskWidget::onAutopilotDisconnect()
|
|
|
|
{
|
2011-08-23 12:25:28 +02:00
|
|
|
isConnected=false;
|
|
|
|
enableControls(false);
|
2011-09-23 14:48:27 +02:00
|
|
|
invalidateObjects();
|
2011-06-07 16:56:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::onAutopilotConnect()
|
|
|
|
{
|
2011-08-23 12:25:28 +02:00
|
|
|
dirty=false;
|
|
|
|
isConnected=true;
|
|
|
|
enableControls(true);
|
|
|
|
refreshWidgetsValues();
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::populateWidgets()
|
|
|
|
{
|
2011-08-02 18:06:17 +02:00
|
|
|
bool dirtyBack=dirty;
|
2011-07-26 00:18:41 +02:00
|
|
|
foreach(objectToWidget * ow,objOfInterest)
|
|
|
|
{
|
2011-07-26 21:35:38 +02:00
|
|
|
if(ow->object==NULL || ow->field==NULL)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
else if(QComboBox * cb=qobject_cast<QComboBox *>(ow->widget))
|
2011-07-26 00:18:41 +02:00
|
|
|
{
|
|
|
|
cb->addItems(ow->field->getOptions());
|
2011-08-04 17:58:41 +02:00
|
|
|
cb->setCurrentIndex(cb->findText(ow->field->getValue(ow->index).toString()));
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
else if(QLabel * cb=qobject_cast<QLabel *>(ow->widget))
|
|
|
|
{
|
2011-08-04 17:58:41 +02:00
|
|
|
cb->setText(ow->field->getValue(ow->index).toString());
|
|
|
|
}
|
|
|
|
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(ow->widget))
|
|
|
|
{
|
|
|
|
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-09-07 08:47:10 +02:00
|
|
|
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
|
|
|
|
{
|
|
|
|
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
|
|
|
|
}
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-08-02 18:06:17 +02:00
|
|
|
setDirty(dirtyBack);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::refreshWidgetsValues()
|
|
|
|
{
|
2011-08-02 18:06:17 +02:00
|
|
|
bool dirtyBack=dirty;
|
2011-07-26 00:18:41 +02:00
|
|
|
foreach(objectToWidget * ow,objOfInterest)
|
|
|
|
{
|
2011-07-26 21:35:38 +02:00
|
|
|
if(ow->object==NULL || ow->field==NULL)
|
|
|
|
{
|
|
|
|
//do nothing
|
|
|
|
}
|
|
|
|
else if(QComboBox * cb=qobject_cast<QComboBox *>(ow->widget))
|
2011-07-26 00:18:41 +02:00
|
|
|
{
|
2011-08-04 17:58:41 +02:00
|
|
|
cb->setCurrentIndex(cb->findText(ow->field->getValue(ow->index).toString()));
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
else if(QLabel * cb=qobject_cast<QLabel *>(ow->widget))
|
|
|
|
{
|
2011-08-04 17:58:41 +02:00
|
|
|
cb->setText(ow->field->getValue(ow->index).toString());
|
|
|
|
}
|
|
|
|
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(ow->widget))
|
|
|
|
{
|
|
|
|
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-09-07 08:47:10 +02:00
|
|
|
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
|
|
|
|
{
|
|
|
|
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
|
|
|
|
}
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-08-02 18:06:17 +02:00
|
|
|
setDirty(dirtyBack);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::updateObjectsFromWidgets()
|
|
|
|
{
|
|
|
|
foreach(objectToWidget * ow,objOfInterest)
|
|
|
|
{
|
2011-07-26 21:35:38 +02:00
|
|
|
if(ow->object==NULL || ow->field==NULL)
|
|
|
|
{
|
|
|
|
//do nothing
|
|
|
|
}
|
|
|
|
else if(QComboBox * cb=qobject_cast<QComboBox *>(ow->widget))
|
2011-07-26 00:18:41 +02:00
|
|
|
{
|
2011-08-04 17:58:41 +02:00
|
|
|
ow->field->setValue(cb->currentText(),ow->index);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
else if(QLabel * cb=qobject_cast<QLabel *>(ow->widget))
|
|
|
|
{
|
2011-08-04 17:58:41 +02:00
|
|
|
ow->field->setValue(cb->text(),ow->index);
|
|
|
|
}
|
|
|
|
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(ow->widget))
|
|
|
|
{
|
|
|
|
ow->field->setValue(cb->value()* ow->scale,ow->index);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-09-07 08:47:10 +02:00
|
|
|
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
|
|
|
|
{
|
|
|
|
ow->field->setValue(cb->value()* ow->scale,ow->index);
|
|
|
|
}
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
2011-06-07 16:56:16 +02:00
|
|
|
}
|
|
|
|
|
2011-07-26 00:18:41 +02:00
|
|
|
void ConfigTaskWidget::setupButtons(QPushButton *update, QPushButton *save)
|
|
|
|
{
|
|
|
|
smartsave=new smartSaveButton(update,save);
|
2011-08-02 18:06:17 +02:00
|
|
|
connect(smartsave,SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
|
2011-07-26 21:35:38 +02:00
|
|
|
connect(smartsave,SIGNAL(saveSuccessfull()),this,SLOT(clearDirty()));
|
|
|
|
connect(smartsave,SIGNAL(beginOp()),this,SLOT(disableObjUpdates()));
|
|
|
|
connect(smartsave,SIGNAL(endOp()),this,SLOT(enableObjUpdates()));
|
2011-08-17 13:43:08 +02:00
|
|
|
enableControls(false);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::enableControls(bool enable)
|
|
|
|
{
|
|
|
|
if(smartsave)
|
|
|
|
smartsave->enableControls(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::widgetsContentsChanged()
|
|
|
|
{
|
2011-08-02 18:06:17 +02:00
|
|
|
setDirty(true);
|
2011-07-26 00:18:41 +02:00
|
|
|
}
|
|
|
|
|
2011-07-26 21:35:38 +02:00
|
|
|
void ConfigTaskWidget::clearDirty()
|
|
|
|
{
|
2011-08-02 18:06:17 +02:00
|
|
|
setDirty(false);
|
|
|
|
}
|
|
|
|
void ConfigTaskWidget::setDirty(bool value)
|
|
|
|
{
|
|
|
|
dirty=value;
|
2011-07-26 21:35:38 +02:00
|
|
|
}
|
|
|
|
bool ConfigTaskWidget::isDirty()
|
|
|
|
{
|
2011-08-23 12:25:28 +02:00
|
|
|
if(isConnected)
|
|
|
|
return dirty;
|
|
|
|
else
|
|
|
|
return false;
|
2011-07-26 21:35:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::refreshValues()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::disableObjUpdates()
|
|
|
|
{
|
|
|
|
foreach(objectToWidget * obj,objOfInterest)
|
|
|
|
{
|
|
|
|
if(obj->object)
|
|
|
|
disconnect(obj->object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::enableObjUpdates()
|
|
|
|
{
|
|
|
|
foreach(objectToWidget * obj,objOfInterest)
|
|
|
|
{
|
|
|
|
if(obj->object)
|
|
|
|
connect(obj->object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-23 14:48:27 +02:00
|
|
|
void ConfigTaskWidget::objectUpdated(UAVObject *obj)
|
|
|
|
{
|
|
|
|
objectUpdates[obj]=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConfigTaskWidget::allObjectsUpdated()
|
|
|
|
{
|
|
|
|
bool ret=true;
|
|
|
|
foreach(UAVObject *obj, objectUpdates.keys())
|
|
|
|
{
|
|
|
|
ret=ret & objectUpdates[obj];
|
|
|
|
}
|
|
|
|
qDebug()<<"ALL OBJECTS UPDATE:"<<ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigTaskWidget::invalidateObjects()
|
|
|
|
{
|
|
|
|
foreach(UAVObject *obj, objectUpdates.keys())
|
|
|
|
{
|
|
|
|
objectUpdates[obj]=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-26 21:35:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-26 00:18:41 +02:00
|
|
|
|
2011-06-07 16:56:16 +02:00
|
|
|
|
2011-03-28 20:43:15 +02:00
|
|
|
|
2010-08-20 23:18:20 +02:00
|
|
|
/**
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
*/
|