mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
Moved framework to its own plugin
This commit is contained in:
parent
32ebdb63a3
commit
6d6111b9ac
@ -10,5 +10,6 @@
|
||||
<dependency name="UAVTalk" version="1.0.0"/>
|
||||
<dependency name="UAVObjectUtil" version="1.0.0"/>
|
||||
<dependency name="UAVSettingsImportExport" version="1.0.0"/>
|
||||
<dependency name="UAVObjectWidgetUtils" version="1.0.0"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
||||
|
7
ground/openpilotgcs/src/plugins/config/config.pri
Normal file
7
ground/openpilotgcs/src/plugins/config/config.pri
Normal file
@ -0,0 +1,7 @@
|
||||
#include(config_dependencies.pri)
|
||||
include(../../plugins/uavsettingsimportexport/uavsettingsimportexport.pri)
|
||||
include(../../plugins/uavtalk/uavtalk.pri)
|
||||
# Add the include path to the built-in uavobject include files.
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
LIBS *= -l$$qtLibraryName(Config)
|
@ -1,13 +1,8 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = Config
|
||||
DEFINES += CONFIG_LIBRARY
|
||||
QT += svg
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../libs/utils/utils.pri)
|
||||
include(../../plugins/uavtalk/uavtalk.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../../plugins/uavobjectutil/uavobjectutil.pri)
|
||||
include(../../plugins/uavsettingsimportexport/uavsettingsimportexport.pri)
|
||||
include(config_dependencies.pri)
|
||||
INCLUDEPATH += ../../libs/eigen
|
||||
OTHER_FILES += Config.pluginspec
|
||||
HEADERS += configplugin.h \
|
||||
@ -19,25 +14,21 @@ HEADERS += configplugin.h \
|
||||
fancytabwidget.h \
|
||||
configinputwidget.h \
|
||||
configoutputwidget.h \
|
||||
configtaskwidget.h \
|
||||
configairframewidget.h \
|
||||
config_pro_hw_widget.h \
|
||||
config_cc_hw_widget.h \
|
||||
configahrswidget.h \
|
||||
configccattitudewidget.h \
|
||||
mixercurvewidget.h \
|
||||
mixercurvepoint.h \
|
||||
mixercurveline.h \
|
||||
configccpmwidget.h \
|
||||
configstabilizationwidget.h \
|
||||
assertions.h \
|
||||
calibration.h \
|
||||
defaultattitudewidget.h \
|
||||
smartsavebutton.h \
|
||||
defaulthwsettingswidget.h \
|
||||
inputchannelform.h \
|
||||
configcamerastabilizationwidget.h \
|
||||
outputchannelform.h
|
||||
outputchannelform.h \
|
||||
config_global.h
|
||||
SOURCES += configplugin.cpp \
|
||||
configgadgetconfiguration.cpp \
|
||||
configgadgetwidget.cpp \
|
||||
@ -45,7 +36,6 @@ SOURCES += configplugin.cpp \
|
||||
configgadgetoptionspage.cpp \
|
||||
configgadget.cpp \
|
||||
fancytabwidget.cpp \
|
||||
configtaskwidget.cpp \
|
||||
configinputwidget.cpp \
|
||||
configoutputwidget.cpp \
|
||||
configairframewidget.cpp \
|
||||
@ -53,9 +43,6 @@ SOURCES += configplugin.cpp \
|
||||
config_cc_hw_widget.cpp \
|
||||
configahrswidget.cpp \
|
||||
configccattitudewidget.cpp \
|
||||
mixercurvewidget.cpp \
|
||||
mixercurvepoint.cpp \
|
||||
mixercurveline.cpp \
|
||||
configccpmwidget.cpp \
|
||||
configstabilizationwidget.cpp \
|
||||
twostep.cpp \
|
||||
@ -63,7 +50,6 @@ SOURCES += configplugin.cpp \
|
||||
gyro-calibration.cpp \
|
||||
alignment-calibration.cpp \
|
||||
defaultattitudewidget.cpp \
|
||||
smartsavebutton.cpp \
|
||||
defaulthwsettingswidget.cpp \
|
||||
inputchannelform.cpp \
|
||||
configcamerastabilizationwidget.cpp \
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGCCHWWIDGET_H
|
||||
|
||||
#include "ui_cc_hw_settings.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -0,0 +1,8 @@
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../libs/utils/utils.pri)
|
||||
include(../../plugins/uavtalk/uavtalk.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../../plugins/uavobjectutil/uavobjectutil.pri)
|
||||
include(../../plugins/uavsettingsimportexport/uavsettingsimportexport.pri)
|
||||
include(../../plugins/uavobjectwidgetutils/uavobjectwidgetutils.pri)
|
41
ground/openpilotgcs/src/plugins/config/config_global.h
Normal file
41
ground/openpilotgcs/src/plugins/config/config_global.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file config_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup Congig Plugin
|
||||
* @{
|
||||
* @brief The Congig GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_GLOBAL_H
|
||||
#define CONFIG_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(CONFIG_LIBRARY)
|
||||
# define CONFIG_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define CONFIG_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CONFIG_GLOBAL_H
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGPROHWWIDGET_H
|
||||
|
||||
#include "ui_pro_hw_settings.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <Eigen/StdVector>
|
||||
|
||||
#include "ui_ahrs.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGAIRFRAMEWIDGET_H
|
||||
|
||||
#include "ui_airframe.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGCAMERASTABILIZATIONWIDGET_H
|
||||
|
||||
#include "ui_camerastabilization.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CCATTITUDEWIDGET_H
|
||||
|
||||
#include "ui_ccattitude.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGccpmWIDGET_H
|
||||
|
||||
#include "ui_ccpm.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGGADGET_H
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "configgadgetwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
|
||||
class IUAVGadget;
|
||||
//class QList<int>;
|
||||
@ -46,7 +46,7 @@ public:
|
||||
ConfigGadget(QString classId, ConfigGadgetWidget *widget, QWidget *parent = 0);
|
||||
~ConfigGadget();
|
||||
|
||||
QWidget *widget() { return m_widget; }
|
||||
QWidget *widget() { return (QWidget*)m_widget; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
private:
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <QMessageBox>
|
||||
//#include "fancytabwidget.h"
|
||||
#include "utils/mytabbedstackwidget.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
|
||||
class ConfigGadgetWidget: public QWidget
|
||||
{
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGINPUTWIDGET_H
|
||||
|
||||
#include "ui_input.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGOUTPUTWIDGET_H
|
||||
|
||||
#include "ui_output.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define CONFIGSTABILIZATIONWIDGET_H
|
||||
|
||||
#include "ui_stabilization.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define DEFAULTATTITUDEWIDGET_H
|
||||
|
||||
#include "ui_defaultattitude.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define DEFAULTHWSETTINGSt_H
|
||||
|
||||
#include "ui_defaulthwsettings.h"
|
||||
#include "configtaskwidget.h"
|
||||
#include "../uavobjectwidgetutils/configtaskwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
QString contextHelpId() const { return QString(); }
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
QWidget *m_widget;
|
||||
QList<int> m_context;
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,6 @@ TARGET = DebugGadget
|
||||
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../libs/libqxt/core/logengines.pri)
|
||||
HEADERS += debugplugin.h \
|
||||
debugengine.h
|
||||
HEADERS += debuggadget.h
|
||||
|
@ -112,6 +112,7 @@ SUBDIRS += plugin_systemhealth
|
||||
plugin_config.subdir = config
|
||||
plugin_config.depends = plugin_coreplugin
|
||||
plugin_config.depends += plugin_uavobjects
|
||||
plugin_config.depends += plugin_uavobjectwidgetutils
|
||||
plugin_config.depends += plugin_uavsettingsimportexport
|
||||
SUBDIRS += plugin_config
|
||||
|
||||
@ -183,6 +184,12 @@ plugin_uavobjectutil.depends = plugin_coreplugin
|
||||
plugin_uavobjectutil.depends += plugin_uavobjects
|
||||
SUBDIRS += plugin_uavobjectutil
|
||||
|
||||
# UAV Object Widget Utility plugin
|
||||
plugin_uavobjectwidgetutils.subdir = uavobjectwidgetutils
|
||||
plugin_uavobjectwidgetutils.depends = plugin_coreplugin
|
||||
plugin_uavobjectwidgetutils.depends += plugin_uavobjects
|
||||
SUBDIRS += plugin_uavobjectwidgetutils
|
||||
|
||||
# Magic Waypoint gadget
|
||||
plugin_magicwaypoint.subdir = magicwaypoint
|
||||
plugin_magicwaypoint.depends = plugin_coreplugin
|
||||
|
@ -6,6 +6,6 @@
|
||||
<url>http://www.openpilot.org</url>
|
||||
<dependencyList>
|
||||
<dependency name="Core" version="1.0.0"/>
|
||||
<dependency name="UAVObjects" version="1.0.0"/>
|
||||
<dependency name="UAVObjects" version="1.0.0"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
||||
|
@ -0,0 +1,13 @@
|
||||
<plugin name="UAVObjectWidgetUtils" version="1.0.0" compatVersion="1.0.0">
|
||||
<vendor>The OpenPilot Project</vendor>
|
||||
<copyright>(C) 2010 OpenPilot Project</copyright>
|
||||
<license>The GNU Public License (GPL) Version 3</license>
|
||||
<description>Utils classes for UAVObjects to Widget relations</description>
|
||||
<url>http://www.openpilot.org</url>
|
||||
<dependencyList>
|
||||
<dependency name="Core" version="1.0.0"/>
|
||||
<dependency name="UAVObjects" version="1.0.0"/>
|
||||
<dependency name="UAVObjectUtil" version="1.0.0"/>
|
||||
<dependency name="UAVSettingsImportExport" version="1.0.0"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
@ -1,862 +1,865 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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>
|
||||
#include "uavsettingsimportexport/uavsettingsimportexportfactory.h"
|
||||
#include "configgadgetwidget.h"
|
||||
|
||||
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent),isConnected(false),smartsave(NULL),dirty(false),outOfLimitsStyle("background-color: rgb(255, 0, 0);")
|
||||
{
|
||||
pm = ExtensionSystem::PluginManager::instance();
|
||||
objManager = pm->getObject<UAVObjectManager>();
|
||||
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()));
|
||||
}
|
||||
void ConfigTaskWidget::addWidget(QWidget * widget)
|
||||
{
|
||||
addUAVObjectToWidgetRelation("","",widget);
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObject(QString objectName)
|
||||
{
|
||||
addUAVObjectToWidgetRelation(objectName,"",NULL);
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, QString index)
|
||||
{
|
||||
UAVObject *obj=NULL;
|
||||
UAVObjectField *_field=NULL;
|
||||
obj = objManager->getObject(QString(object));
|
||||
Q_ASSERT(obj);
|
||||
_field = obj->getField(QString(field));
|
||||
Q_ASSERT(_field);
|
||||
addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index));
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString element, float scale, bool isLimited, QList<int> *defaultReloadGroups)
|
||||
{
|
||||
UAVObject *obj=objManager->getObject(QString(object));
|
||||
Q_ASSERT(obj);
|
||||
UAVObjectField *_field;
|
||||
if(!field.isEmpty() && obj)
|
||||
_field = obj->getField(QString(field));
|
||||
int index=_field->getElementNames().indexOf(QString(element));
|
||||
addUAVObjectToWidgetRelation(object, field, widget,index,scale,isLimited,defaultReloadGroups);
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, int index,float scale,bool isLimited,QList<int>* defaultReloadGroups)
|
||||
{
|
||||
if(addShadowWidget(object,field,widget,index,scale,isLimited,defaultReloadGroups))
|
||||
return;
|
||||
|
||||
UAVObject *obj=NULL;
|
||||
UAVObjectField *_field=NULL;
|
||||
if(!object.isEmpty())
|
||||
{
|
||||
obj = objManager->getObject(QString(object));
|
||||
Q_ASSERT(obj);
|
||||
objectUpdates.insert(obj,true);
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this, SLOT(objectUpdated(UAVObject*)));
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
|
||||
}
|
||||
if(!field.isEmpty() && obj)
|
||||
_field = obj->getField(QString(field));
|
||||
objectToWidget * ow=new objectToWidget();
|
||||
ow->field=_field;
|
||||
ow->object=obj;
|
||||
ow->widget=widget;
|
||||
ow->index=index;
|
||||
ow->scale=scale;
|
||||
ow->isLimited=isLimited;
|
||||
objOfInterest.append(ow);
|
||||
if(obj)
|
||||
{
|
||||
if(smartsave)
|
||||
{
|
||||
smartsave->addObject((UAVDataObject*)obj);
|
||||
emit objectAdded(obj);
|
||||
}
|
||||
}
|
||||
if(widget==NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
connectWidgetUpdatesToSlot(widget,SLOT(widgetsContentsChanged()));
|
||||
if(defaultReloadGroups)
|
||||
addWidgetToDefaultReloadGroups(widget,defaultReloadGroups);
|
||||
shadowsList.insert(widget,ow);
|
||||
loadWidgetLimits(widget,_field,index,isLimited,scale);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigTaskWidget::~ConfigTaskWidget()
|
||||
{
|
||||
if(smartsave)
|
||||
delete smartsave;
|
||||
foreach(QList<objectToWidget*>* pointer,defaultReloadGroups.values())
|
||||
{
|
||||
if(pointer)
|
||||
delete pointer;
|
||||
}
|
||||
foreach (objectToWidget* oTw, objOfInterest)
|
||||
{
|
||||
if(oTw)
|
||||
delete oTw;
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
|
||||
{
|
||||
qDebug()<<"ConfigTaskWidget::saveObjectToSD";
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
UAVObjectManager* ConfigTaskWidget::getObjectManager() {
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(objMngr);
|
||||
return objMngr;
|
||||
}
|
||||
|
||||
double ConfigTaskWidget::listMean(QList<double> list)
|
||||
{
|
||||
double accum = 0;
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
accum += list[i];
|
||||
return accum / list.size();
|
||||
}
|
||||
|
||||
// ************************************
|
||||
// telemetry start/stop connect/disconnect signals
|
||||
|
||||
void ConfigTaskWidget::onAutopilotDisconnect()
|
||||
{
|
||||
isConnected=false;
|
||||
enableControls(false);
|
||||
invalidateObjects();
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::onAutopilotConnect()
|
||||
{
|
||||
invalidateObjects();
|
||||
dirty=false;
|
||||
isConnected=true;
|
||||
enableControls(true);
|
||||
refreshWidgetsValues();
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::populateWidgets()
|
||||
{
|
||||
bool dirtyBack=dirty;
|
||||
foreach(objectToWidget * ow,objOfInterest)
|
||||
{
|
||||
if(ow->object==NULL || ow->field==NULL || ow->widget==NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else
|
||||
setWidgetFromField(ow->widget,ow->field,ow->index,ow->scale,ow->isLimited);
|
||||
}
|
||||
setDirty(dirtyBack);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::refreshWidgetsValues()
|
||||
{
|
||||
bool dirtyBack=dirty;
|
||||
foreach(objectToWidget * ow,objOfInterest)
|
||||
{
|
||||
if(ow->object==NULL || ow->field==NULL || ow->widget==NULL)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
setWidgetFromField(ow->widget,ow->field,ow->index,ow->scale,ow->isLimited);
|
||||
}
|
||||
|
||||
}
|
||||
setDirty(dirtyBack);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::updateObjectsFromWidgets()
|
||||
{
|
||||
foreach(objectToWidget * ow,objOfInterest)
|
||||
{
|
||||
if(ow->object==NULL || ow->field==NULL)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
setFieldFromWidget(ow->widget,ow->field,ow->index,ow->scale);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *save)
|
||||
{
|
||||
smartsave=new smartSaveButton(update,save);
|
||||
connect(smartsave,SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
|
||||
connect(smartsave,SIGNAL(saveSuccessfull()),this,SLOT(clearDirty()));
|
||||
connect(smartsave,SIGNAL(beginOp()),this,SLOT(disableObjUpdates()));
|
||||
connect(smartsave,SIGNAL(endOp()),this,SLOT(enableObjUpdates()));
|
||||
if(objOfInterest.count()>0)
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
smartsave->addObject((UAVDataObject*)oTw->object);
|
||||
emit objectAdded(oTw->object);
|
||||
}
|
||||
}
|
||||
enableControls(false);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::enableControls(bool enable)
|
||||
{
|
||||
if(smartsave)
|
||||
smartsave->enableControls(enable);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::widgetsContentsChanged()
|
||||
{
|
||||
float scale;
|
||||
objectToWidget * oTw= shadowsList.value((QWidget*)sender(),NULL);
|
||||
|
||||
/*
|
||||
qDebug()<<"sender:"<<(quint32)sender();
|
||||
foreach(QWidget * w,shadowsList.keys())
|
||||
qDebug()<<"in list:"<<(quint32)w;
|
||||
if(oTw)
|
||||
qDebug()<<"in oTw OK"<<(quint32)oTw->widget;
|
||||
*/
|
||||
if(oTw)
|
||||
{
|
||||
if(oTw->widget==(QWidget*)sender())
|
||||
{
|
||||
scale=oTw->scale;
|
||||
checkWidgetsLimits((QWidget*)sender(),oTw->field,oTw->index,oTw->isLimited,getVariantFromWidget((QWidget*)sender(),oTw->scale),oTw->scale);
|
||||
qDebug()<<"sender was master";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (shadow * sh, oTw->shadowsList)
|
||||
{
|
||||
if(sh->widget==(QWidget*)sender())
|
||||
{
|
||||
scale=sh->scale;
|
||||
checkWidgetsLimits((QWidget*)sender(),oTw->field,oTw->index,sh->isLimited,getVariantFromWidget((QWidget*)sender(),scale),scale);
|
||||
qDebug()<<"sender was shadow";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(oTw->widget!=(QWidget *)sender())
|
||||
{
|
||||
checkWidgetsLimits(oTw->widget,oTw->field,oTw->index,oTw->isLimited,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
|
||||
setWidgetFromVariant(oTw->widget,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
|
||||
}
|
||||
foreach (shadow * sh, oTw->shadowsList)
|
||||
{
|
||||
if(sh->widget!=(QWidget*)sender())
|
||||
{
|
||||
checkWidgetsLimits(sh->widget,oTw->field,oTw->index,sh->isLimited,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
|
||||
setWidgetFromVariant(sh->widget,getVariantFromWidget((QWidget*)sender(),scale),sh->scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::clearDirty()
|
||||
{
|
||||
setDirty(false);
|
||||
}
|
||||
void ConfigTaskWidget::setDirty(bool value)
|
||||
{
|
||||
dirty=value;
|
||||
}
|
||||
bool ConfigTaskWidget::isDirty()
|
||||
{
|
||||
if(isConnected)
|
||||
return dirty;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::objectUpdated(UAVObject *obj)
|
||||
{
|
||||
objectUpdates[obj]=true;
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::removeObject(UAVObject * obj)
|
||||
{
|
||||
emit objectRemoved(obj);
|
||||
QList<objectToWidget*> toRemove;
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
if(oTw->object==obj)
|
||||
{
|
||||
toRemove.append(oTw);
|
||||
}
|
||||
}
|
||||
foreach(objectToWidget * oTw,toRemove)
|
||||
{
|
||||
objOfInterest.removeAll(oTw);
|
||||
smartsave->removeObject((UAVDataObject*)oTw->object);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::removeAllObjects()
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
emit objectRemoved(oTw->object);
|
||||
}
|
||||
objOfInterest.clear();
|
||||
smartsave->removeAllObjects();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::addShadowWidget(QString object, QString field, QWidget *widget, int index, float scale, bool isLimited,QList<int>* defaultReloadGroups)
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
if(!oTw->object || !oTw->widget)
|
||||
continue;
|
||||
if(oTw->object->getName()==object && oTw->field->getName()==field && oTw->index==index)
|
||||
{
|
||||
shadow * sh=new shadow;
|
||||
sh->isLimited=isLimited;
|
||||
sh->scale=scale;
|
||||
sh->widget=widget;
|
||||
oTw->shadowsList.append(sh);
|
||||
shadowsList.insert(widget,oTw);
|
||||
connectWidgetUpdatesToSlot(widget,SLOT(widgetsContentsChanged()));
|
||||
if(defaultReloadGroups)
|
||||
addWidgetToDefaultReloadGroups(widget,defaultReloadGroups);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::autoLoadWidgets()
|
||||
{
|
||||
QPushButton * saveButtonWidget=NULL;
|
||||
QPushButton * applyButtonWidget=NULL;
|
||||
foreach(QObject * widget,this->children())
|
||||
{
|
||||
QVariant info=widget->property("objrelation");
|
||||
if(info.isValid())
|
||||
{
|
||||
uiRelationAutomation uiRelation;
|
||||
uiRelation.buttonType=none;
|
||||
foreach(QString str, info.toStringList())
|
||||
{
|
||||
QString prop=str.split(":").at(0);
|
||||
QString value=str.split(":").at(1);
|
||||
if(prop== "objname")
|
||||
uiRelation.objname=value;
|
||||
else if(prop== "fieldname")
|
||||
uiRelation.fieldname=value;
|
||||
else if(prop=="element")
|
||||
uiRelation.element=value;
|
||||
else if(prop== "scale")
|
||||
{
|
||||
if(value=="null")
|
||||
uiRelation.scale=1;
|
||||
else
|
||||
uiRelation.scale=value.toFloat();
|
||||
}
|
||||
else if(prop== "ismaster")
|
||||
{
|
||||
if(value=="yes")
|
||||
uiRelation.ismaster=true;
|
||||
else
|
||||
uiRelation.ismaster=false;
|
||||
}
|
||||
else if(prop== "haslimits")
|
||||
{
|
||||
if(value=="yes")
|
||||
uiRelation.haslimits=true;
|
||||
else
|
||||
uiRelation.haslimits=false;
|
||||
}
|
||||
else if(prop== "button")
|
||||
{
|
||||
if(value=="save")
|
||||
uiRelation.buttonType=save_button;
|
||||
else if(value=="apply")
|
||||
uiRelation.buttonType=apply_button;
|
||||
else if(value=="reload")
|
||||
uiRelation.buttonType=reload_button;
|
||||
else if(value=="default")
|
||||
uiRelation.buttonType=default_button;
|
||||
}
|
||||
else if(prop== "buttongroup")
|
||||
{
|
||||
foreach(QString s,value.split(","))
|
||||
{
|
||||
uiRelation.buttonGroup.append(s.toInt());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(!uiRelation.buttonType==none)
|
||||
{
|
||||
QPushButton * button=NULL;
|
||||
switch(uiRelation.buttonType)
|
||||
{
|
||||
case save_button:
|
||||
saveButtonWidget=qobject_cast<QPushButton *>(widget);
|
||||
break;
|
||||
case apply_button:
|
||||
applyButtonWidget=qobject_cast<QPushButton *>(widget);
|
||||
break;
|
||||
case default_button:
|
||||
button=qobject_cast<QPushButton *>(widget);
|
||||
if(button)
|
||||
addDefaultButton(button,uiRelation.buttonGroup.at(0));
|
||||
break;
|
||||
case reload_button:
|
||||
button=qobject_cast<QPushButton *>(widget);
|
||||
if(button)
|
||||
addReloadButton(button,uiRelation.buttonGroup.at(0));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(uiRelation.ismaster)
|
||||
{
|
||||
QWidget * wid=qobject_cast<QWidget *>(widget);
|
||||
if(wid)
|
||||
addUAVObjectToWidgetRelation(uiRelation.objname,uiRelation.fieldname,wid,uiRelation.element,uiRelation.haslimits,&uiRelation.buttonGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(saveButtonWidget && applyButtonWidget)
|
||||
addApplySaveButtons(applyButtonWidget,saveButtonWidget);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::addWidgetToDefaultReloadGroups(QWidget *widget, QList<int> * groups)
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
bool addOTW=false;
|
||||
if(oTw->widget==widget)
|
||||
addOTW=true;
|
||||
else
|
||||
{
|
||||
foreach(shadow * sh, oTw->shadowsList)
|
||||
{
|
||||
if(sh->widget==widget)
|
||||
addOTW=true;
|
||||
}
|
||||
}
|
||||
if(addOTW)
|
||||
{
|
||||
foreach(int i,*groups)
|
||||
{
|
||||
if(defaultReloadGroups.contains(i))
|
||||
{
|
||||
defaultReloadGroups.value(i)->append(oTw);
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultReloadGroups.insert(i,new QList<objectToWidget*>());
|
||||
defaultReloadGroups.value(i)->append(oTw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void ConfigTaskWidget::addDefaultButton(QPushButton *button, int buttonGroup)
|
||||
{
|
||||
button->setProperty("group",buttonGroup);
|
||||
connect(button,SIGNAL(clicked()),this,SLOT(defaultButtonClicked()));
|
||||
}
|
||||
void ConfigTaskWidget::addReloadButton(QPushButton *button, int buttonGroup)
|
||||
{
|
||||
button->setProperty("group",buttonGroup);
|
||||
connect(button,SIGNAL(clicked()),this,SLOT(reloadButtonClicked()));
|
||||
}
|
||||
void ConfigTaskWidget::defaultButtonClicked()
|
||||
{
|
||||
int group=sender()->property("group").toInt();
|
||||
QList<objectToWidget*> * list=defaultReloadGroups.value(group);
|
||||
foreach(objectToWidget * oTw,*list)
|
||||
{
|
||||
if(!oTw->object)
|
||||
continue;
|
||||
UAVDataObject * temp=((UAVDataObject*)oTw->object)->dirtyClone();
|
||||
setWidgetFromField(oTw->widget,temp->getField(oTw->field->getName()),oTw->index,oTw->scale,oTw->isLimited);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::reloadButtonClicked()
|
||||
{
|
||||
int group=sender()->property("group").toInt();
|
||||
QList<objectToWidget*> * list=defaultReloadGroups.value(group);
|
||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
|
||||
QTimer * timeOut=new QTimer(this);
|
||||
QEventLoop * eventLoop=new QEventLoop(this);
|
||||
connect(timeOut, SIGNAL(timeout()),eventLoop,SLOT(quit()));
|
||||
connect(objper, SIGNAL(objectUpdated(UAVObject*)), eventLoop, SLOT(quit()));
|
||||
foreach(objectToWidget * oTw,*list)
|
||||
{
|
||||
if (oTw->object != NULL)
|
||||
{
|
||||
ObjectPersistence::DataFields data;
|
||||
data.Operation = ObjectPersistence::OPERATION_LOAD;
|
||||
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
|
||||
data.ObjectID = oTw->object->getObjID();
|
||||
data.InstanceID = oTw->object->getInstID();
|
||||
objper->setData(data);
|
||||
objper->updated();
|
||||
timeOut->start(500);
|
||||
eventLoop->exec();
|
||||
if(timeOut->isActive())
|
||||
{
|
||||
setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited);
|
||||
}
|
||||
timeOut->stop();
|
||||
}
|
||||
}
|
||||
delete eventLoop;
|
||||
delete timeOut;
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::connectWidgetUpdatesToSlot(QWidget * widget,const char* function)
|
||||
{
|
||||
if(!widget)
|
||||
return;
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(currentIndexChanged(int)),this,function);
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(sliderMoved(int)),this,function);
|
||||
}
|
||||
else if(MixerCurveWidget * cb=qobject_cast<MixerCurveWidget *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(curveUpdated(QList<double>,double)),this,function);
|
||||
}
|
||||
else if(QTableWidget * cb=qobject_cast<QTableWidget *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(cellChanged(int,int)),this,function);
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(valueChanged(int)),this,function);
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(valueChanged(double)),this,function);
|
||||
}
|
||||
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(clicked()),this,function);
|
||||
}
|
||||
else if(QPushButton * cb=qobject_cast<QPushButton *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(clicked()),this,function);
|
||||
}
|
||||
else
|
||||
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
|
||||
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setFieldFromWidget(QWidget * widget,UAVObjectField * field,int index,float scale)
|
||||
{
|
||||
if(!widget || !field)
|
||||
return false;
|
||||
QVariant ret=getVariantFromWidget(widget,scale);
|
||||
if(ret.isValid())
|
||||
{
|
||||
field->setValue(ret,index);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget * widget,float scale)
|
||||
{
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
return (QString)cb->currentText();
|
||||
}
|
||||
else if(QLabel * cb=qobject_cast<QLabel *>(widget))
|
||||
{
|
||||
return (QString)cb->text();
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
return (double)(cb->value()* scale);
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
return (int)(cb->value()* (int)scale);
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
return(int)(cb->value()* (int)scale);
|
||||
}
|
||||
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
||||
{
|
||||
return (bool)(cb->isChecked()?"TRUE":"FALSE");
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, float scale)
|
||||
{
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
cb->setCurrentIndex(cb->findText(value.toString()));
|
||||
return true;
|
||||
}
|
||||
else if(QLabel * cb=qobject_cast<QLabel *>(widget))
|
||||
{
|
||||
cb->setText(value.toString());
|
||||
return true;
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
cb->setValue(value.toDouble()/scale);
|
||||
return true;
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
cb->setValue(value.toInt()/(int)scale);
|
||||
return true;
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
cb->setValue(value.toInt()/(int)scale);
|
||||
return true;
|
||||
}
|
||||
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
||||
{
|
||||
cb->setChecked(value.toBool());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromField(QWidget * widget,UAVObjectField * field,int index,float scale,bool hasLimits)
|
||||
{
|
||||
if(!widget || !field)
|
||||
return false;
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
if(cb->count()==0)
|
||||
loadWidgetLimits(cb,field,index,hasLimits,scale);
|
||||
}
|
||||
QVariant var=field->getValue(index);
|
||||
checkWidgetsLimits(widget,field,index,hasLimits,var,scale);
|
||||
bool ret=setWidgetFromVariant(widget,var,scale);
|
||||
if(ret)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void ConfigTaskWidget::checkWidgetsLimits(QWidget * widget,UAVObjectField * field,int index,bool hasLimits, QVariant value, float scale)
|
||||
{
|
||||
if(!hasLimits)
|
||||
return;
|
||||
qDebug()<<"check widget"<<widget->accessibleName()<<"value"<<value.toString()<<"result"<<field->isWithinLimits(value,index);
|
||||
if(!field->isWithinLimits(value,index))
|
||||
{
|
||||
if(!widget->property("styleBackup").isValid())
|
||||
widget->setProperty("styleBackup",widget->styleSheet());
|
||||
widget->setStyleSheet(outOfLimitsStyle);
|
||||
widget->setProperty("wasOverLimits",(bool)true);
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
if(cb->findText(value.toString())==-1)
|
||||
cb->addItem(value.toString());
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
if(value.toDouble()/scale>cb->maximum())
|
||||
{
|
||||
cb->setMaximum(value.toDouble()/scale);
|
||||
}
|
||||
else if(value.toDouble()/scale<cb->minimum())
|
||||
{
|
||||
cb->setMinimum(value.toDouble()/scale);
|
||||
}
|
||||
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
if(value.toInt()/scale>cb->maximum())
|
||||
{
|
||||
cb->setMaximum(value.toInt()/scale);
|
||||
}
|
||||
else if(value.toInt()/scale<cb->minimum())
|
||||
{
|
||||
cb->setMinimum(value.toInt()/scale);
|
||||
}
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
if(value.toInt()/scale>cb->maximum())
|
||||
{
|
||||
cb->setMaximum(value.toInt()/scale);
|
||||
}
|
||||
else if(value.toInt()/scale<cb->minimum())
|
||||
{
|
||||
cb->setMinimum(value.toInt()/scale);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(widget->property("wasOverLimits").isValid())
|
||||
{
|
||||
qDebug()<<"1wasOverLimits";
|
||||
if(widget->property("wasOverLimits").toBool())
|
||||
{
|
||||
qDebug()<<"2";
|
||||
widget->setProperty("wasOverLimits",(bool)false);
|
||||
if(widget->property("styleBackup").isValid())
|
||||
{
|
||||
qDebug()<<"3";
|
||||
QString style=widget->property("styleBackup").toString();
|
||||
qDebug()<<"STYLE"<<style;
|
||||
widget->setStyleSheet(style);
|
||||
}
|
||||
loadWidgetLimits(widget,field,index,hasLimits,scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
void ConfigTaskWidget::loadWidgetLimits(QWidget * widget,UAVObjectField * field,int index,bool hasLimits,float scale)
|
||||
{
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
cb->clear();
|
||||
QStringList option=field->getOptions();
|
||||
if(hasLimits)
|
||||
{
|
||||
foreach(QString str,option)
|
||||
{
|
||||
if(field->isWithinLimits(str,index))
|
||||
cb->addItem(str);
|
||||
}
|
||||
}
|
||||
else
|
||||
cb->addItems(option);
|
||||
}
|
||||
if(!hasLimits)
|
||||
return;
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
if(field->getMaxLimit(index).isValid())
|
||||
{
|
||||
cb->setMaximum(field->getMaxLimit(index).toDouble()/scale);
|
||||
}
|
||||
if(field->getMinLimit(index).isValid())
|
||||
{
|
||||
cb->setMinimum(field->getMinLimit(index).toDouble()/scale);
|
||||
}
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
if(field->getMaxLimit(index).isValid())
|
||||
{
|
||||
cb->setMaximum((int)(field->getMaxLimit(index).toInt()/scale));
|
||||
}
|
||||
if(field->getMinLimit(index).isValid())
|
||||
{
|
||||
cb->setMinimum((int)(field->getMinLimit(index).toInt()/scale));
|
||||
}
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
if(field->getMaxLimit(index).isValid())
|
||||
{
|
||||
cb->setMaximum((int)(field->getMaxLimit(index).toInt()/scale));
|
||||
}
|
||||
if(field->getMinLimit(index).isValid())
|
||||
{
|
||||
cb->setMinimum((int)(field->getMinLimit(index).toInt()/scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@}
|
||||
@}
|
||||
*/
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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>
|
||||
#include "uavsettingsimportexport/uavsettingsimportexportfactory.h"
|
||||
|
||||
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent),isConnected(false),smartsave(NULL),dirty(false),outOfLimitsStyle("background-color: rgb(255, 0, 0);")
|
||||
{
|
||||
pm = ExtensionSystem::PluginManager::instance();
|
||||
objManager = pm->getObject<UAVObjectManager>();
|
||||
TelemetryManager* telMngr = pm->getObject<TelemetryManager>();
|
||||
connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
|
||||
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
|
||||
UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>();
|
||||
connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(invalidateObjects()));
|
||||
}
|
||||
void ConfigTaskWidget::addWidget(QWidget * widget)
|
||||
{
|
||||
addUAVObjectToWidgetRelation("","",widget);
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObject(QString objectName)
|
||||
{
|
||||
addUAVObjectToWidgetRelation(objectName,"",NULL);
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, QString index)
|
||||
{
|
||||
UAVObject *obj=NULL;
|
||||
UAVObjectField *_field=NULL;
|
||||
obj = objManager->getObject(QString(object));
|
||||
Q_ASSERT(obj);
|
||||
_field = obj->getField(QString(field));
|
||||
Q_ASSERT(_field);
|
||||
addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index));
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString element, float scale, bool isLimited, QList<int> *defaultReloadGroups)
|
||||
{
|
||||
UAVObject *obj=objManager->getObject(QString(object));
|
||||
Q_ASSERT(obj);
|
||||
UAVObjectField *_field;
|
||||
if(!field.isEmpty() && obj)
|
||||
_field = obj->getField(QString(field));
|
||||
int index=_field->getElementNames().indexOf(QString(element));
|
||||
addUAVObjectToWidgetRelation(object, field, widget,index,scale,isLimited,defaultReloadGroups);
|
||||
}
|
||||
void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString field, QWidget * widget, int index,float scale,bool isLimited,QList<int>* defaultReloadGroups)
|
||||
{
|
||||
if(addShadowWidget(object,field,widget,index,scale,isLimited,defaultReloadGroups))
|
||||
return;
|
||||
|
||||
UAVObject *obj=NULL;
|
||||
UAVObjectField *_field=NULL;
|
||||
if(!object.isEmpty())
|
||||
{
|
||||
obj = objManager->getObject(QString(object));
|
||||
Q_ASSERT(obj);
|
||||
objectUpdates.insert(obj,true);
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this, SLOT(objectUpdated(UAVObject*)));
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
|
||||
}
|
||||
if(!field.isEmpty() && obj)
|
||||
_field = obj->getField(QString(field));
|
||||
objectToWidget * ow=new objectToWidget();
|
||||
ow->field=_field;
|
||||
ow->object=obj;
|
||||
ow->widget=widget;
|
||||
ow->index=index;
|
||||
ow->scale=scale;
|
||||
ow->isLimited=isLimited;
|
||||
objOfInterest.append(ow);
|
||||
if(obj)
|
||||
{
|
||||
if(smartsave)
|
||||
{
|
||||
smartsave->addObject((UAVDataObject*)obj);
|
||||
emit objectAdded(obj);
|
||||
}
|
||||
}
|
||||
if(widget==NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
connectWidgetUpdatesToSlot(widget,SLOT(widgetsContentsChanged()));
|
||||
if(defaultReloadGroups)
|
||||
addWidgetToDefaultReloadGroups(widget,defaultReloadGroups);
|
||||
shadowsList.insert(widget,ow);
|
||||
loadWidgetLimits(widget,_field,index,isLimited,scale);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigTaskWidget::~ConfigTaskWidget()
|
||||
{
|
||||
if(smartsave)
|
||||
delete smartsave;
|
||||
foreach(QList<objectToWidget*>* pointer,defaultReloadGroups.values())
|
||||
{
|
||||
if(pointer)
|
||||
delete pointer;
|
||||
}
|
||||
foreach (objectToWidget* oTw, objOfInterest)
|
||||
{
|
||||
if(oTw)
|
||||
delete oTw;
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
|
||||
{
|
||||
qDebug()<<"ConfigTaskWidget::saveObjectToSD";
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
UAVObjectManager* ConfigTaskWidget::getObjectManager() {
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(objMngr);
|
||||
return objMngr;
|
||||
}
|
||||
|
||||
double ConfigTaskWidget::listMean(QList<double> list)
|
||||
{
|
||||
double accum = 0;
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
accum += list[i];
|
||||
return accum / list.size();
|
||||
}
|
||||
|
||||
// ************************************
|
||||
// telemetry start/stop connect/disconnect signals
|
||||
|
||||
void ConfigTaskWidget::onAutopilotDisconnect()
|
||||
{
|
||||
isConnected=false;
|
||||
enableControls(false);
|
||||
invalidateObjects();
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::onAutopilotConnect()
|
||||
{
|
||||
invalidateObjects();
|
||||
dirty=false;
|
||||
isConnected=true;
|
||||
enableControls(true);
|
||||
refreshWidgetsValues();
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::populateWidgets()
|
||||
{
|
||||
bool dirtyBack=dirty;
|
||||
foreach(objectToWidget * ow,objOfInterest)
|
||||
{
|
||||
if(ow->object==NULL || ow->field==NULL || ow->widget==NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else
|
||||
setWidgetFromField(ow->widget,ow->field,ow->index,ow->scale,ow->isLimited);
|
||||
}
|
||||
setDirty(dirtyBack);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::refreshWidgetsValues()
|
||||
{
|
||||
bool dirtyBack=dirty;
|
||||
foreach(objectToWidget * ow,objOfInterest)
|
||||
{
|
||||
if(ow->object==NULL || ow->field==NULL || ow->widget==NULL)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
setWidgetFromField(ow->widget,ow->field,ow->index,ow->scale,ow->isLimited);
|
||||
}
|
||||
|
||||
}
|
||||
setDirty(dirtyBack);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::updateObjectsFromWidgets()
|
||||
{
|
||||
foreach(objectToWidget * ow,objOfInterest)
|
||||
{
|
||||
if(ow->object==NULL || ow->field==NULL)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
setFieldFromWidget(ow->widget,ow->field,ow->index,ow->scale);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *save)
|
||||
{
|
||||
smartsave=new smartSaveButton(update,save);
|
||||
connect(smartsave,SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
|
||||
connect(smartsave,SIGNAL(saveSuccessfull()),this,SLOT(clearDirty()));
|
||||
connect(smartsave,SIGNAL(beginOp()),this,SLOT(disableObjUpdates()));
|
||||
connect(smartsave,SIGNAL(endOp()),this,SLOT(enableObjUpdates()));
|
||||
if(objOfInterest.count()>0)
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
smartsave->addObject((UAVDataObject*)oTw->object);
|
||||
emit objectAdded(oTw->object);
|
||||
}
|
||||
}
|
||||
enableControls(false);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::enableControls(bool enable)
|
||||
{
|
||||
if(smartsave)
|
||||
smartsave->enableControls(enable);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::widgetsContentsChanged()
|
||||
{
|
||||
float scale;
|
||||
objectToWidget * oTw= shadowsList.value((QWidget*)sender(),NULL);
|
||||
|
||||
/*
|
||||
qDebug()<<"sender:"<<(quint32)sender();
|
||||
foreach(QWidget * w,shadowsList.keys())
|
||||
qDebug()<<"in list:"<<(quint32)w;
|
||||
if(oTw)
|
||||
qDebug()<<"in oTw OK"<<(quint32)oTw->widget;
|
||||
*/
|
||||
if(oTw)
|
||||
{
|
||||
if(oTw->widget==(QWidget*)sender())
|
||||
{
|
||||
scale=oTw->scale;
|
||||
checkWidgetsLimits((QWidget*)sender(),oTw->field,oTw->index,oTw->isLimited,getVariantFromWidget((QWidget*)sender(),oTw->scale),oTw->scale);
|
||||
qDebug()<<"sender was master";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (shadow * sh, oTw->shadowsList)
|
||||
{
|
||||
if(sh->widget==(QWidget*)sender())
|
||||
{
|
||||
scale=sh->scale;
|
||||
checkWidgetsLimits((QWidget*)sender(),oTw->field,oTw->index,sh->isLimited,getVariantFromWidget((QWidget*)sender(),scale),scale);
|
||||
qDebug()<<"sender was shadow";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(oTw->widget!=(QWidget *)sender())
|
||||
{
|
||||
checkWidgetsLimits(oTw->widget,oTw->field,oTw->index,oTw->isLimited,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
|
||||
setWidgetFromVariant(oTw->widget,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
|
||||
}
|
||||
foreach (shadow * sh, oTw->shadowsList)
|
||||
{
|
||||
if(sh->widget!=(QWidget*)sender())
|
||||
{
|
||||
checkWidgetsLimits(sh->widget,oTw->field,oTw->index,sh->isLimited,getVariantFromWidget((QWidget*)sender(),scale),oTw->scale);
|
||||
setWidgetFromVariant(sh->widget,getVariantFromWidget((QWidget*)sender(),scale),sh->scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::clearDirty()
|
||||
{
|
||||
setDirty(false);
|
||||
}
|
||||
void ConfigTaskWidget::setDirty(bool value)
|
||||
{
|
||||
dirty=value;
|
||||
}
|
||||
bool ConfigTaskWidget::isDirty()
|
||||
{
|
||||
if(isConnected)
|
||||
return dirty;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::objectUpdated(UAVObject *obj)
|
||||
{
|
||||
objectUpdates[obj]=true;
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::removeObject(UAVObject * obj)
|
||||
{
|
||||
emit objectRemoved(obj);
|
||||
QList<objectToWidget*> toRemove;
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
if(oTw->object==obj)
|
||||
{
|
||||
toRemove.append(oTw);
|
||||
}
|
||||
}
|
||||
foreach(objectToWidget * oTw,toRemove)
|
||||
{
|
||||
objOfInterest.removeAll(oTw);
|
||||
smartsave->removeObject((UAVDataObject*)oTw->object);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::removeAllObjects()
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
emit objectRemoved(oTw->object);
|
||||
}
|
||||
objOfInterest.clear();
|
||||
smartsave->removeAllObjects();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::addShadowWidget(QString object, QString field, QWidget *widget, int index, float scale, bool isLimited,QList<int>* defaultReloadGroups)
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
if(!oTw->object || !oTw->widget)
|
||||
continue;
|
||||
if(oTw->object->getName()==object && oTw->field->getName()==field && oTw->index==index)
|
||||
{
|
||||
shadow * sh=new shadow;
|
||||
sh->isLimited=isLimited;
|
||||
sh->scale=scale;
|
||||
sh->widget=widget;
|
||||
oTw->shadowsList.append(sh);
|
||||
shadowsList.insert(widget,oTw);
|
||||
connectWidgetUpdatesToSlot(widget,SLOT(widgetsContentsChanged()));
|
||||
if(defaultReloadGroups)
|
||||
addWidgetToDefaultReloadGroups(widget,defaultReloadGroups);
|
||||
loadWidgetLimits(widget,oTw->field,oTw->index,isLimited,scale);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::autoLoadWidgets()
|
||||
{
|
||||
QPushButton * saveButtonWidget=NULL;
|
||||
QPushButton * applyButtonWidget=NULL;
|
||||
foreach(QObject * widget,this->children())
|
||||
{
|
||||
QVariant info=widget->property("objrelation");
|
||||
if(info.isValid())
|
||||
{
|
||||
uiRelationAutomation uiRelation;
|
||||
uiRelation.buttonType=none;
|
||||
foreach(QString str, info.toStringList())
|
||||
{
|
||||
QString prop=str.split(":").at(0);
|
||||
QString value=str.split(":").at(1);
|
||||
if(prop== "objname")
|
||||
uiRelation.objname=value;
|
||||
else if(prop== "fieldname")
|
||||
uiRelation.fieldname=value;
|
||||
else if(prop=="element")
|
||||
uiRelation.element=value;
|
||||
else if(prop== "scale")
|
||||
{
|
||||
if(value=="null")
|
||||
uiRelation.scale=1;
|
||||
else
|
||||
uiRelation.scale=value.toFloat();
|
||||
}
|
||||
else if(prop== "ismaster")
|
||||
{
|
||||
if(value=="yes")
|
||||
uiRelation.ismaster=true;
|
||||
else
|
||||
uiRelation.ismaster=false;
|
||||
}
|
||||
else if(prop== "haslimits")
|
||||
{
|
||||
if(value=="yes")
|
||||
uiRelation.haslimits=true;
|
||||
else
|
||||
uiRelation.haslimits=false;
|
||||
}
|
||||
else if(prop== "button")
|
||||
{
|
||||
if(value=="save")
|
||||
uiRelation.buttonType=save_button;
|
||||
else if(value=="apply")
|
||||
uiRelation.buttonType=apply_button;
|
||||
else if(value=="reload")
|
||||
uiRelation.buttonType=reload_button;
|
||||
else if(value=="default")
|
||||
uiRelation.buttonType=default_button;
|
||||
}
|
||||
else if(prop== "buttongroup")
|
||||
{
|
||||
foreach(QString s,value.split(","))
|
||||
{
|
||||
uiRelation.buttonGroup.append(s.toInt());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(!uiRelation.buttonType==none)
|
||||
{
|
||||
QPushButton * button=NULL;
|
||||
switch(uiRelation.buttonType)
|
||||
{
|
||||
case save_button:
|
||||
saveButtonWidget=qobject_cast<QPushButton *>(widget);
|
||||
break;
|
||||
case apply_button:
|
||||
applyButtonWidget=qobject_cast<QPushButton *>(widget);
|
||||
break;
|
||||
case default_button:
|
||||
button=qobject_cast<QPushButton *>(widget);
|
||||
if(button)
|
||||
addDefaultButton(button,uiRelation.buttonGroup.at(0));
|
||||
break;
|
||||
case reload_button:
|
||||
button=qobject_cast<QPushButton *>(widget);
|
||||
if(button)
|
||||
addReloadButton(button,uiRelation.buttonGroup.at(0));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(uiRelation.ismaster)
|
||||
{
|
||||
QWidget * wid=qobject_cast<QWidget *>(widget);
|
||||
if(wid)
|
||||
addUAVObjectToWidgetRelation(uiRelation.objname,uiRelation.fieldname,wid,uiRelation.element,uiRelation.haslimits,&uiRelation.buttonGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(saveButtonWidget && applyButtonWidget)
|
||||
addApplySaveButtons(applyButtonWidget,saveButtonWidget);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::addWidgetToDefaultReloadGroups(QWidget *widget, QList<int> * groups)
|
||||
{
|
||||
foreach(objectToWidget * oTw,objOfInterest)
|
||||
{
|
||||
bool addOTW=false;
|
||||
if(oTw->widget==widget)
|
||||
addOTW=true;
|
||||
else
|
||||
{
|
||||
foreach(shadow * sh, oTw->shadowsList)
|
||||
{
|
||||
if(sh->widget==widget)
|
||||
addOTW=true;
|
||||
}
|
||||
}
|
||||
if(addOTW)
|
||||
{
|
||||
foreach(int i,*groups)
|
||||
{
|
||||
if(defaultReloadGroups.contains(i))
|
||||
{
|
||||
defaultReloadGroups.value(i)->append(oTw);
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultReloadGroups.insert(i,new QList<objectToWidget*>());
|
||||
defaultReloadGroups.value(i)->append(oTw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void ConfigTaskWidget::addDefaultButton(QPushButton *button, int buttonGroup)
|
||||
{
|
||||
button->setProperty("group",buttonGroup);
|
||||
connect(button,SIGNAL(clicked()),this,SLOT(defaultButtonClicked()));
|
||||
}
|
||||
void ConfigTaskWidget::addReloadButton(QPushButton *button, int buttonGroup)
|
||||
{
|
||||
button->setProperty("group",buttonGroup);
|
||||
connect(button,SIGNAL(clicked()),this,SLOT(reloadButtonClicked()));
|
||||
}
|
||||
void ConfigTaskWidget::defaultButtonClicked()
|
||||
{
|
||||
int group=sender()->property("group").toInt();
|
||||
QList<objectToWidget*> * list=defaultReloadGroups.value(group);
|
||||
foreach(objectToWidget * oTw,*list)
|
||||
{
|
||||
if(!oTw->object)
|
||||
continue;
|
||||
UAVDataObject * temp=((UAVDataObject*)oTw->object)->dirtyClone();
|
||||
setWidgetFromField(oTw->widget,temp->getField(oTw->field->getName()),oTw->index,oTw->scale,oTw->isLimited);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::reloadButtonClicked()
|
||||
{
|
||||
int group=sender()->property("group").toInt();
|
||||
QList<objectToWidget*> * list=defaultReloadGroups.value(group);
|
||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
|
||||
QTimer * timeOut=new QTimer(this);
|
||||
QEventLoop * eventLoop=new QEventLoop(this);
|
||||
connect(timeOut, SIGNAL(timeout()),eventLoop,SLOT(quit()));
|
||||
connect(objper, SIGNAL(objectUpdated(UAVObject*)), eventLoop, SLOT(quit()));
|
||||
foreach(objectToWidget * oTw,*list)
|
||||
{
|
||||
if (oTw->object != NULL)
|
||||
{
|
||||
ObjectPersistence::DataFields data;
|
||||
data.Operation = ObjectPersistence::OPERATION_LOAD;
|
||||
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
|
||||
data.ObjectID = oTw->object->getObjID();
|
||||
data.InstanceID = oTw->object->getInstID();
|
||||
objper->setData(data);
|
||||
objper->updated();
|
||||
timeOut->start(500);
|
||||
eventLoop->exec();
|
||||
if(timeOut->isActive())
|
||||
{
|
||||
setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited);
|
||||
}
|
||||
timeOut->stop();
|
||||
}
|
||||
}
|
||||
delete eventLoop;
|
||||
delete timeOut;
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::connectWidgetUpdatesToSlot(QWidget * widget,const char* function)
|
||||
{
|
||||
if(!widget)
|
||||
return;
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(currentIndexChanged(int)),this,function);
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(sliderMoved(int)),this,function);
|
||||
}
|
||||
else if(MixerCurveWidget * cb=qobject_cast<MixerCurveWidget *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(curveUpdated(QList<double>,double)),this,function);
|
||||
}
|
||||
else if(QTableWidget * cb=qobject_cast<QTableWidget *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(cellChanged(int,int)),this,function);
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(valueChanged(int)),this,function);
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(valueChanged(double)),this,function);
|
||||
}
|
||||
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(clicked()),this,function);
|
||||
}
|
||||
else if(QPushButton * cb=qobject_cast<QPushButton *>(widget))
|
||||
{
|
||||
connect(cb,SIGNAL(clicked()),this,function);
|
||||
}
|
||||
else
|
||||
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
|
||||
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setFieldFromWidget(QWidget * widget,UAVObjectField * field,int index,float scale)
|
||||
{
|
||||
if(!widget || !field)
|
||||
return false;
|
||||
QVariant ret=getVariantFromWidget(widget,scale);
|
||||
if(ret.isValid())
|
||||
{
|
||||
field->setValue(ret,index);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget * widget,float scale)
|
||||
{
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
return (QString)cb->currentText();
|
||||
}
|
||||
else if(QLabel * cb=qobject_cast<QLabel *>(widget))
|
||||
{
|
||||
return (QString)cb->text();
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
return (double)(cb->value()* scale);
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
return (int)(cb->value()* (int)scale);
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
return(int)(cb->value()* (int)scale);
|
||||
}
|
||||
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
||||
{
|
||||
return (bool)(cb->isChecked()?"TRUE":"FALSE");
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, float scale)
|
||||
{
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
cb->setCurrentIndex(cb->findText(value.toString()));
|
||||
return true;
|
||||
}
|
||||
else if(QLabel * cb=qobject_cast<QLabel *>(widget))
|
||||
{
|
||||
cb->setText(value.toString());
|
||||
return true;
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
cb->setValue(value.toDouble()/scale);
|
||||
return true;
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
cb->setValue(value.toInt()/(int)scale);
|
||||
return true;
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
cb->setValue(value.toInt()/(int)scale);
|
||||
return true;
|
||||
}
|
||||
else if(QCheckBox * cb=qobject_cast<QCheckBox *>(widget))
|
||||
{
|
||||
cb->setChecked(value.toBool());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromField(QWidget * widget,UAVObjectField * field,int index,float scale,bool hasLimits)
|
||||
{
|
||||
if(!widget || !field)
|
||||
return false;
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
if(cb->count()==0)
|
||||
loadWidgetLimits(cb,field,index,hasLimits,scale);
|
||||
}
|
||||
QVariant var=field->getValue(index);
|
||||
checkWidgetsLimits(widget,field,index,hasLimits,var,scale);
|
||||
bool ret=setWidgetFromVariant(widget,var,scale);
|
||||
if(ret)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
qDebug()<<__FUNCTION__<<"widget to uavobject relation not implemented"<<widget->metaObject()->className();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void ConfigTaskWidget::checkWidgetsLimits(QWidget * widget,UAVObjectField * field,int index,bool hasLimits, QVariant value, float scale)
|
||||
{
|
||||
if(!hasLimits)
|
||||
return;
|
||||
qDebug()<<"check widget"<<widget->accessibleName()<<"value"<<value.toString()<<"result"<<field->isWithinLimits(value,index);
|
||||
if(!field->isWithinLimits(value,index))
|
||||
{
|
||||
if(!widget->property("styleBackup").isValid())
|
||||
widget->setProperty("styleBackup",widget->styleSheet());
|
||||
widget->setStyleSheet(outOfLimitsStyle);
|
||||
widget->setProperty("wasOverLimits",(bool)true);
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
if(cb->findText(value.toString())==-1)
|
||||
cb->addItem(value.toString());
|
||||
}
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
if(value.toDouble()/scale>cb->maximum())
|
||||
{
|
||||
cb->setMaximum(value.toDouble()/scale);
|
||||
}
|
||||
else if(value.toDouble()/scale<cb->minimum())
|
||||
{
|
||||
cb->setMinimum(value.toDouble()/scale);
|
||||
}
|
||||
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
if(value.toInt()/scale>cb->maximum())
|
||||
{
|
||||
cb->setMaximum(value.toInt()/scale);
|
||||
}
|
||||
else if(value.toInt()/scale<cb->minimum())
|
||||
{
|
||||
cb->setMinimum(value.toInt()/scale);
|
||||
}
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
if(value.toInt()/scale>cb->maximum())
|
||||
{
|
||||
cb->setMaximum(value.toInt()/scale);
|
||||
}
|
||||
else if(value.toInt()/scale<cb->minimum())
|
||||
{
|
||||
cb->setMinimum(value.toInt()/scale);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(widget->property("wasOverLimits").isValid())
|
||||
{
|
||||
qDebug()<<"1wasOverLimits";
|
||||
if(widget->property("wasOverLimits").toBool())
|
||||
{
|
||||
qDebug()<<"2";
|
||||
widget->setProperty("wasOverLimits",(bool)false);
|
||||
if(widget->property("styleBackup").isValid())
|
||||
{
|
||||
qDebug()<<"3";
|
||||
QString style=widget->property("styleBackup").toString();
|
||||
qDebug()<<"STYLE"<<style;
|
||||
widget->setStyleSheet(style);
|
||||
}
|
||||
loadWidgetLimits(widget,field,index,hasLimits,scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
void ConfigTaskWidget::loadWidgetLimits(QWidget * widget,UAVObjectField * field,int index,bool hasLimits,float scale)
|
||||
{
|
||||
if(!widget || !field)
|
||||
return;
|
||||
if(QComboBox * cb=qobject_cast<QComboBox *>(widget))
|
||||
{
|
||||
cb->clear();
|
||||
QStringList option=field->getOptions();
|
||||
if(hasLimits)
|
||||
{
|
||||
foreach(QString str,option)
|
||||
{
|
||||
if(field->isWithinLimits(str,index))
|
||||
cb->addItem(str);
|
||||
}
|
||||
}
|
||||
else
|
||||
cb->addItems(option);
|
||||
}
|
||||
if(!hasLimits)
|
||||
return;
|
||||
else if(QDoubleSpinBox * cb=qobject_cast<QDoubleSpinBox *>(widget))
|
||||
{
|
||||
if(field->getMaxLimit(index).isValid())
|
||||
{
|
||||
cb->setMaximum(field->getMaxLimit(index).toDouble()/scale);
|
||||
}
|
||||
if(field->getMinLimit(index).isValid())
|
||||
{
|
||||
cb->setMinimum(field->getMinLimit(index).toDouble()/scale);
|
||||
}
|
||||
}
|
||||
else if(QSpinBox * cb=qobject_cast<QSpinBox *>(widget))
|
||||
{
|
||||
if(field->getMaxLimit(index).isValid())
|
||||
{
|
||||
cb->setMaximum((int)(field->getMaxLimit(index).toInt()/scale));
|
||||
}
|
||||
if(field->getMinLimit(index).isValid())
|
||||
{
|
||||
cb->setMinimum((int)(field->getMinLimit(index).toInt()/scale));
|
||||
}
|
||||
}
|
||||
else if(QSlider * cb=qobject_cast<QSlider *>(widget))
|
||||
{
|
||||
if(field->getMaxLimit(index).isValid())
|
||||
{
|
||||
cb->setMaximum((int)(field->getMaxLimit(index).toInt()/scale));
|
||||
}
|
||||
if(field->getMinLimit(index).isValid())
|
||||
{
|
||||
cb->setMinimum((int)(field->getMinLimit(index).toInt()/scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@}
|
||||
@}
|
||||
*/
|
@ -1,158 +1,159 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file configtaskwidget.h
|
||||
* @author 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 (task widget)
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
#ifndef CONFIGTASKWIDGET_H
|
||||
#define CONFIGTASKWIDGET_H
|
||||
|
||||
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectutilmanager.h"
|
||||
#include <QQueue>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QList>
|
||||
#include <QLabel>
|
||||
#include "smartsavebutton.h"
|
||||
#include "mixercurvewidget.h"
|
||||
#include <QTableWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
|
||||
class ConfigTaskWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct shadow
|
||||
{
|
||||
QWidget * widget;
|
||||
float scale;
|
||||
bool isLimited;
|
||||
};
|
||||
struct objectToWidget
|
||||
{
|
||||
UAVObject * object;
|
||||
UAVObjectField * field;
|
||||
QWidget * widget;
|
||||
int index;
|
||||
float scale;
|
||||
bool isLimited;
|
||||
QList<shadow *> shadowsList;
|
||||
};
|
||||
|
||||
enum buttonTypeEnum {none,save_button,apply_button,reload_button,default_button};
|
||||
struct uiRelationAutomation
|
||||
{
|
||||
QString objname;
|
||||
QString fieldname;
|
||||
QString element;
|
||||
int scale;
|
||||
bool ismaster;
|
||||
bool haslimits;
|
||||
buttonTypeEnum buttonType;
|
||||
QList<int> buttonGroup;
|
||||
};
|
||||
|
||||
ConfigTaskWidget(QWidget *parent = 0);
|
||||
~ConfigTaskWidget();
|
||||
|
||||
void saveObjectToSD(UAVObject *obj);
|
||||
UAVObjectManager* getObjectManager();
|
||||
static double listMean(QList<double> list);
|
||||
|
||||
void addUAVObject(QString objectName);
|
||||
void addWidget(QWidget * widget);
|
||||
|
||||
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,int index=0,float scale=1,bool isLimited=false,QList<int>* defaultReloadGroups=0);
|
||||
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,QString element,float scale,bool isLimited=false,QList<int>* defaultReloadGroups=0);
|
||||
void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString index);
|
||||
|
||||
//BUTTONS//
|
||||
void addApplySaveButtons(QPushButton * update,QPushButton * save);
|
||||
void addReloadButton(QPushButton * button,int buttonGroup);
|
||||
void addDefaultButton(QPushButton * button,int buttonGroup);
|
||||
//////////
|
||||
|
||||
void addWidgetToDefaultReloadGroups(QWidget * widget, QList<int> *groups);
|
||||
|
||||
bool addShadowWidget(QWidget * masterWidget, QWidget * shadowWidget,float shadowScale=1,bool shadowIsLimited=false);
|
||||
bool addShadowWidget(QString object,QString field,QWidget * widget,int index=0,float scale=1,bool isLimited=false, QList<int> *defaultReloadGroups=NULL);
|
||||
|
||||
void autoLoadWidgets();
|
||||
|
||||
bool isDirty();
|
||||
void setDirty(bool value);
|
||||
|
||||
bool allObjectsUpdated();
|
||||
|
||||
public slots:
|
||||
void onAutopilotDisconnect();
|
||||
void onAutopilotConnect();
|
||||
void invalidateObjects();
|
||||
void removeObject(UAVObject*);
|
||||
void removeAllObjects();
|
||||
signals:
|
||||
void objectAdded(UAVObject*);
|
||||
void objectRemoved(UAVObject*);
|
||||
private slots:
|
||||
void objectUpdated(UAVObject*);
|
||||
void defaultButtonClicked();
|
||||
void reloadButtonClicked();
|
||||
private:
|
||||
bool isConnected;
|
||||
QStringList objectsList;
|
||||
QList <objectToWidget*> objOfInterest;
|
||||
ExtensionSystem::PluginManager *pm;
|
||||
UAVObjectManager *objManager;
|
||||
smartSaveButton *smartsave;
|
||||
QMap<UAVObject *,bool> objectUpdates;
|
||||
QMap<int,QList<objectToWidget*> *> defaultReloadGroups;
|
||||
QMap<QWidget *,objectToWidget*> shadowsList;
|
||||
bool dirty;
|
||||
bool setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, float scale);
|
||||
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, float scale, bool hasLimits);
|
||||
QVariant getVariantFromWidget(QWidget *widget, float scale);
|
||||
bool setWidgetFromVariant(QWidget *widget,QVariant value,float scale);
|
||||
void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
|
||||
void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, float sclale);
|
||||
QString outOfLimitsStyle;
|
||||
protected slots:
|
||||
virtual void disableObjUpdates();
|
||||
virtual void enableObjUpdates();
|
||||
virtual void clearDirty();
|
||||
virtual void widgetsContentsChanged();
|
||||
virtual void populateWidgets();
|
||||
virtual void refreshWidgetsValues();
|
||||
virtual void updateObjectsFromWidgets();
|
||||
protected:
|
||||
virtual void enableControls(bool enable);
|
||||
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, float scale);
|
||||
};
|
||||
|
||||
#endif // CONFIGTASKWIDGET_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file configtaskwidget.h
|
||||
* @author 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 (task widget)
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
#ifndef CONFIGTASKWIDGET_H
|
||||
#define CONFIGTASKWIDGET_H
|
||||
|
||||
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectutilmanager.h"
|
||||
#include <QQueue>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QList>
|
||||
#include <QLabel>
|
||||
#include "smartsavebutton.h"
|
||||
#include "mixercurvewidget.h"
|
||||
#include <QTableWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
#include "uavobjectwidgetutils_global.h"
|
||||
|
||||
class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct shadow
|
||||
{
|
||||
QWidget * widget;
|
||||
float scale;
|
||||
bool isLimited;
|
||||
};
|
||||
struct objectToWidget
|
||||
{
|
||||
UAVObject * object;
|
||||
UAVObjectField * field;
|
||||
QWidget * widget;
|
||||
int index;
|
||||
float scale;
|
||||
bool isLimited;
|
||||
QList<shadow *> shadowsList;
|
||||
};
|
||||
|
||||
enum buttonTypeEnum {none,save_button,apply_button,reload_button,default_button};
|
||||
struct uiRelationAutomation
|
||||
{
|
||||
QString objname;
|
||||
QString fieldname;
|
||||
QString element;
|
||||
int scale;
|
||||
bool ismaster;
|
||||
bool haslimits;
|
||||
buttonTypeEnum buttonType;
|
||||
QList<int> buttonGroup;
|
||||
};
|
||||
|
||||
ConfigTaskWidget(QWidget *parent = 0);
|
||||
~ConfigTaskWidget();
|
||||
|
||||
void saveObjectToSD(UAVObject *obj);
|
||||
UAVObjectManager* getObjectManager();
|
||||
static double listMean(QList<double> list);
|
||||
|
||||
void addUAVObject(QString objectName);
|
||||
void addWidget(QWidget * widget);
|
||||
|
||||
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,int index=0,float scale=1,bool isLimited=false,QList<int>* defaultReloadGroups=0);
|
||||
void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,QString element,float scale,bool isLimited=false,QList<int>* defaultReloadGroups=0);
|
||||
void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString index);
|
||||
|
||||
//BUTTONS//
|
||||
void addApplySaveButtons(QPushButton * update,QPushButton * save);
|
||||
void addReloadButton(QPushButton * button,int buttonGroup);
|
||||
void addDefaultButton(QPushButton * button,int buttonGroup);
|
||||
//////////
|
||||
|
||||
void addWidgetToDefaultReloadGroups(QWidget * widget, QList<int> *groups);
|
||||
|
||||
bool addShadowWidget(QWidget * masterWidget, QWidget * shadowWidget,float shadowScale=1,bool shadowIsLimited=false);
|
||||
bool addShadowWidget(QString object,QString field,QWidget * widget,int index=0,float scale=1,bool isLimited=false, QList<int> *defaultReloadGroups=NULL);
|
||||
|
||||
void autoLoadWidgets();
|
||||
|
||||
bool isDirty();
|
||||
void setDirty(bool value);
|
||||
|
||||
bool allObjectsUpdated();
|
||||
|
||||
public slots:
|
||||
void onAutopilotDisconnect();
|
||||
void onAutopilotConnect();
|
||||
void invalidateObjects();
|
||||
void removeObject(UAVObject*);
|
||||
void removeAllObjects();
|
||||
signals:
|
||||
void objectAdded(UAVObject*);
|
||||
void objectRemoved(UAVObject*);
|
||||
private slots:
|
||||
void objectUpdated(UAVObject*);
|
||||
void defaultButtonClicked();
|
||||
void reloadButtonClicked();
|
||||
private:
|
||||
bool isConnected;
|
||||
QStringList objectsList;
|
||||
QList <objectToWidget*> objOfInterest;
|
||||
ExtensionSystem::PluginManager *pm;
|
||||
UAVObjectManager *objManager;
|
||||
smartSaveButton *smartsave;
|
||||
QMap<UAVObject *,bool> objectUpdates;
|
||||
QMap<int,QList<objectToWidget*> *> defaultReloadGroups;
|
||||
QMap<QWidget *,objectToWidget*> shadowsList;
|
||||
bool dirty;
|
||||
bool setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, float scale);
|
||||
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, float scale, bool hasLimits);
|
||||
QVariant getVariantFromWidget(QWidget *widget, float scale);
|
||||
bool setWidgetFromVariant(QWidget *widget,QVariant value,float scale);
|
||||
void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
|
||||
void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, float sclale);
|
||||
QString outOfLimitsStyle;
|
||||
protected slots:
|
||||
virtual void disableObjUpdates();
|
||||
virtual void enableObjUpdates();
|
||||
virtual void clearDirty();
|
||||
virtual void widgetsContentsChanged();
|
||||
virtual void populateWidgets();
|
||||
virtual void refreshWidgetsValues();
|
||||
virtual void updateObjectsFromWidgets();
|
||||
protected:
|
||||
virtual void enableControls(bool enable);
|
||||
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, float scale);
|
||||
};
|
||||
|
||||
#endif // CONFIGTASKWIDGET_H
|
@ -33,9 +33,9 @@
|
||||
#include <QtSvg/QGraphicsSvgItem>
|
||||
#include "mixercurvepoint.h"
|
||||
#include "mixercurveline.h"
|
||||
#include "uavobjectwidgetutils_global.h"
|
||||
|
||||
|
||||
class MixerCurveWidget : public QGraphicsView
|
||||
class UAVOBJECTWIDGETUTILS_EXPORT MixerCurveWidget : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -0,0 +1,6 @@
|
||||
include(uavobjectwidgetutils_dependencies.pri)
|
||||
|
||||
# Add the include path to the built-in uavobject include files.
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
LIBS *= -l$$qtLibraryName(UAVObjectWidgetUtils)
|
@ -0,0 +1,22 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = UAVObjectWidgetUtils
|
||||
DEFINES += UAVOBJECTWIDGETUTILS_LIBRARY
|
||||
QT += svg
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(uavobjectwidgetutils_dependencies.pri)
|
||||
HEADERS += uavobjectwidgetutils_global.h \
|
||||
uavobjectwidgetutilsplugin.h \
|
||||
configtaskwidget.h \
|
||||
mixercurvewidget.h \
|
||||
mixercurvepoint.h \
|
||||
mixercurveline.h \
|
||||
smartsavebutton.h
|
||||
SOURCES += uavobjectwidgetutilsplugin.cpp \
|
||||
configtaskwidget.cpp \
|
||||
mixercurvewidget.cpp \
|
||||
mixercurvepoint.cpp \
|
||||
mixercurveline.cpp \
|
||||
smartsavebutton.cpp
|
||||
|
||||
|
||||
OTHER_FILES += UAVObjectWidgetUtils.pluginspec
|
@ -0,0 +1,6 @@
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../libs/utils/utils.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../uavobjectutil/uavobjectutil.pri)
|
||||
include(../uavsettingsimportexport/uavsettingsimportexport.pri)
|
||||
include(../uavtalk/uavtalk.pri)
|
@ -0,0 +1,40 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectwidgetutils_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup UAVObjectWidgetUtilsPlugin
|
||||
* @{
|
||||
* @brief The UAVUObjectWidgetUtils GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef UAVOBJECTWIDGETUTILS_GLOBAL_H
|
||||
#define UAVOBJECTWIDGETUTILS_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(UAVOBJECTWIDGETUTILS_LIBRARY)
|
||||
# define UAVOBJECTWIDGETUTILS_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define UAVOBJECTWIDGETUTILS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectutilplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup UAVObjectUtilPlugin UAVObjectUtil Plugin
|
||||
* @{
|
||||
* @brief The UAVUObjectUtil GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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 "uavobjectwidgetutilsplugin.h"
|
||||
|
||||
UAVObjectWidgetUtilsPlugin::UAVObjectWidgetUtilsPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
UAVObjectWidgetUtilsPlugin::~UAVObjectWidgetUtilsPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
void UAVObjectWidgetUtilsPlugin::extensionsInitialized()
|
||||
{
|
||||
}
|
||||
|
||||
bool UAVObjectWidgetUtilsPlugin::initialize(const QStringList & arguments, QString * errorString)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(errorString)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAVObjectWidgetUtilsPlugin::shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(UAVObjectWidgetUtilsPlugin)
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectutilplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup UAVObjectUtilPlugin UAVObjectUtil Plugin
|
||||
* @{
|
||||
* @brief The UAVUObjectUtil GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
#ifndef UAVOBJECTWIDGETUTILSPLUGIN_H
|
||||
#define UAVOBJECTWIDGETUTILSPLUGIN_H
|
||||
|
||||
#include "uavobjectwidgetutils_global.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <QtPlugin>
|
||||
|
||||
class UAVOBJECTWIDGETUTILS_EXPORT UAVObjectWidgetUtilsPlugin: public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectWidgetUtilsPlugin();
|
||||
~UAVObjectWidgetUtilsPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user