1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

OP-984 Added backing store for values when switching between uavos.

This commit is contained in:
m_thread 2014-01-09 13:02:03 +01:00
parent a3c03b0244
commit 088197ac69
5 changed files with 50 additions and 33 deletions

View File

@ -41,19 +41,25 @@
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/generalsettings.h>
#include "altitudeholdsettings.h"
#include "stabilizationsettings.h"
ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent),
boardModel(0), m_currentPIDBank(0)
boardModel(0), m_pidBankCount(0), m_currentPIDBank(0)
{
ui = new Ui_StabilizationWidget();
ui->setupUi(this);
StabilizationSettings* stabSettings = qobject_cast<StabilizationSettings*>(getObject("StabilizationSettings"));
Q_ASSERT(stabSettings);
m_pidBankCount = stabSettings->getField("FlightModeMap")->getOptions().count();
// Set up fake tab widget stuff for pid banks support
m_pidTabBars.append(ui->basicPIDBankTabBar);
m_pidTabBars.append(ui->advancedPIDBankTabBar);
m_pidTabBars.append(ui->expertPIDBankTabBar);
foreach(QTabBar * tabBar, m_pidTabBars) {
for (int i = 0; i < PID_BANKS; i++) {
for (int i = 0; i < m_pidBankCount; i++) {
tabBar->addTab(tr("PID Bank %1").arg(i + 1));
tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1));
}
@ -61,7 +67,7 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(pidBankChanged(int)));
}
for (int i = 0; i < PID_BANKS; i++) {
for (int i = 0; i < m_pidBankCount; i++) {
if(i > 0) {
m_stabilizationObjectsString.append(",");
}

View File

@ -54,8 +54,7 @@ private:
// Milliseconds between automatic 'Instant Updates'
static const int AUTOMATIC_UPDATE_RATE = 500;
static const int PID_BANKS = 3;
int m_pidBankCount;
int boardModel;
int m_currentPIDBank;
protected:

View File

@ -129,7 +129,6 @@ HEADERS += mainwindow.h \
uavgadgetdecorator.h \
workspacesettings.h \
uavconfiginfo.h \
authorsdialog.h \
iconfigurableplugin.h \
aboutdialog.h

View File

@ -278,7 +278,7 @@ void ConfigTaskWidget::onAutopilotConnect()
void ConfigTaskWidget::populateWidgets()
{
bool dirtyBack = m_isDirty;
bool dirtyBack = isDirty();
emit populateWidgetsRequested();
foreach(WidgetBinding * binding, m_widgetBindingsPerObject) {
@ -295,7 +295,7 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
return;
}
bool dirtyBack = m_isDirty;
bool dirtyBack = isDirty();
emit refreshWidgetsValuesRequested();
foreach(WidgetBinding * binding, m_widgetBindingsPerObject.values(obj)) {
if (binding->isEnabled() && binding->field() != NULL && binding->widget() != NULL) {
@ -310,8 +310,9 @@ void ConfigTaskWidget::updateObjectsFromWidgets()
emit updateObjectsFromWidgetsRequested();
foreach(WidgetBinding * binding, m_widgetBindingsPerObject) {
if (binding->isEnabled() && binding->object() != NULL && binding->field() != NULL) {
setFieldFromWidget(binding->widget(), binding->field(), binding->index(), binding->scale());
if (binding->object() != NULL && binding->field() != NULL) {
binding->updateObjectFieldFromValue();
//setFieldFromWidget(binding->widget(), binding->field(), binding->index(), binding->scale());
}
}
}
@ -399,6 +400,7 @@ void ConfigTaskWidget::widgetsContentsChanged()
QWidget *emitter = ((QWidget *)sender());
emit widgetContentsChanged(emitter);
double scale;
QVariant value;
foreach(WidgetBinding *binding ,m_widgetBindingsPerWidget.values(emitter)) {
if (binding && binding->isEnabled()) {
@ -415,12 +417,15 @@ void ConfigTaskWidget::widgetsContentsChanged()
}
}
}
value = getVariantFromWidget(emitter, scale, binding->units());
binding->setValue(value);
if (binding->widget() != emitter) {
disconnectWidgetUpdatesToSlot(binding->widget(), SLOT(widgetsContentsChanged()));
checkWidgetsLimits(binding->widget(), binding->field(), binding->index(), binding->isLimited(),
getVariantFromWidget(emitter, scale, binding->units()), binding->scale());
setWidgetFromVariant(binding->widget(), getVariantFromWidget(emitter, scale, binding->units()), binding->scale());
value, binding->scale());
setWidgetFromVariant(binding->widget(), value, binding->scale());
emit widgetContentsChanged(binding->widget());
connectWidgetUpdatesToSlot(binding->widget(), SLOT(widgetsContentsChanged()));
@ -430,8 +435,8 @@ void ConfigTaskWidget::widgetsContentsChanged()
disconnectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged()));
checkWidgetsLimits(shadow->widget(), binding->field(), binding->index(), shadow->isLimited(),
getVariantFromWidget(emitter, scale, binding->units()), shadow->scale());
setWidgetFromVariant(shadow->widget(), getVariantFromWidget(emitter, scale, binding->units()), shadow->scale());
value, shadow->scale());
setWidgetFromVariant(shadow->widget(), value, shadow->scale());
emit widgetContentsChanged(shadow->widget());
connectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged()));
@ -828,22 +833,6 @@ void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget, const char
}
}
bool ConfigTaskWidget::setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, double scale)
{
if (!widget || !field) {
return false;
}
QVariant ret = getVariantFromWidget(widget, scale, field->getUnits());
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, double scale, QString units)
{
if (QComboBox * cb = qobject_cast<QComboBox *>(widget)) {
@ -1139,6 +1128,7 @@ bool WidgetBinding::matches(QString objectName, QString fieldName, int index, qu
return false;
}
}
bool WidgetBinding::isEnabled() const
{
return m_isEnabled;
@ -1149,6 +1139,25 @@ void WidgetBinding::setIsEnabled(bool isEnabled)
m_isEnabled = isEnabled;
}
QVariant WidgetBinding::value() const
{
return m_value;
}
void WidgetBinding::setValue(const QVariant &value)
{
m_value = value;
if(m_object && m_field) {
qDebug() << "WidgetBinding" << m_object->getName() << ":" << m_field->getName() << "value =" << value.toString();
}
}
void WidgetBinding::updateObjectFieldFromValue()
{
if (m_value.isValid()) {
m_field->setValue(m_value, m_index);
}
}
ShadowWidgetBinding::ShadowWidgetBinding(QWidget *widget, double scale, bool isLimited)
{

View File

@ -80,12 +80,18 @@ public:
bool isEnabled() const;
void setIsEnabled(bool isEnabled);
QVariant value() const;
void setValue(const QVariant &value);
void updateObjectFieldFromValue();
private:
UAVObject *m_object;
UAVObjectField *m_field;
int m_index;
bool m_isEnabled;
QList<ShadowWidgetBinding *> m_shadows;
QVariant m_value;
};
class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget : public QWidget {
@ -214,7 +220,6 @@ private:
QString m_outOfLimitsStyle;
QTimer *m_realtimeUpdateTimer;
bool setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, double scale);
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits);
QVariant getVariantFromWidget(QWidget *widget, double scale, const QString units);
@ -225,7 +230,6 @@ private:
void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function);
void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, double sclale);
virtual UAVObject *getObject(const QString name, quint32 instId = 0);
int fieldIndexFromElementName(QString objectName, QString fieldName, QString elementName);
@ -245,7 +249,7 @@ protected slots:
protected:
virtual void enableControls(bool enable);
virtual QString mapObjectName(const QString objectName);
virtual UAVObject *getObject(const QString name, quint32 instId = 0);
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale);
void updateEnableControls();
};