Commit 0c506525 authored by John Tapsell's avatar John Tapsell

Reduce code duplication

parent f6ae5ed8
...@@ -51,7 +51,7 @@ QGCToolWidget::QGCToolWidget(const QString& objectName, const QString& title, QW ...@@ -51,7 +51,7 @@ QGCToolWidget::QGCToolWidget(const QString& objectName, const QString& title, QW
// Enforce storage if this not loaded from settings // Enforce storage if this not loaded from settings
// is MUST NOT BE SAVED if it was loaded from settings! // is MUST NOT BE SAVED if it was loaded from settings!
//if (!settings) storeWidgetsToSettings(); if (!settings) storeWidgetsToSettings();
} }
QGCToolWidget::~QGCToolWidget() QGCToolWidget::~QGCToolWidget()
...@@ -530,60 +530,35 @@ QList<QGCToolWidgetItem*>* QGCToolWidget::itemList() ...@@ -530,60 +530,35 @@ QList<QGCToolWidgetItem*>* QGCToolWidget::itemList()
if (!instances) instances = new QList<QGCToolWidgetItem*>(); if (!instances) instances = new QList<QGCToolWidgetItem*>();
return instances; return instances;
} }
void QGCToolWidget::addParam(int uas,int component,QString paramname,QVariant value) void QGCToolWidget::addParam(int uas,int component,QString paramname,QVariant value)
{ {
isFromMetaData = true; isFromMetaData = true;
QGCParamSlider* slider = new QGCParamSlider(this); QGCParamSlider* slider = new QGCParamSlider(this);
connect(slider, SIGNAL(destroyed()), this, SLOT(storeSettings())); addToolWidget(slider);
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(slider);
slider->setActiveUAS(mav); slider->setActiveUAS(mav);
slider->setParameterValue(uas,component,0,-1,paramname,value); slider->setParameterValue(uas,component,0,-1,paramname,value);
} }
void QGCToolWidget::addParam() void QGCToolWidget::addParam()
{ {
QGCParamSlider* slider = new QGCParamSlider(this); addToolWidgetAndEdit(new QGCParamSlider(this));
connect(slider, SIGNAL(destroyed()), this, SLOT(storeSettings()));
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(slider);
slider->startEditMode();
} }
void QGCToolWidget::addCommand() void QGCToolWidget::addCommand()
{ {
QGCCommandButton* button = new QGCCommandButton(this); addToolWidgetAndEdit(new QGCCommandButton(this));
connect(button, SIGNAL(destroyed()), this, SLOT(storeSettings()));
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(button);
button->startEditMode();
} }
void QGCToolWidget::addLabel() void QGCToolWidget::addLabel()
{ {
QGCTextLabel* label= new QGCTextLabel(this); addToolWidgetAndEdit(new QGCTextLabel(this));
connect(label, SIGNAL(destroyed()), this, SLOT(storeSettings())); }
if (ui->hintLabel)
{ void QGCToolWidget::addToolWidgetAndEdit(QGCToolWidgetItem* widget)
ui->hintLabel->deleteLater(); {
ui->hintLabel = NULL; addToolWidget(widget);
} widget->startEditMode();
toolLayout->addWidget(label);
label->startEditMode();
} }
void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget) void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget)
......
...@@ -91,6 +91,8 @@ protected: ...@@ -91,6 +91,8 @@ protected:
QList<QGCToolWidgetItem* >* itemList(); QList<QGCToolWidgetItem* >* itemList();
/** @brief Add an existing tool widget */ /** @brief Add an existing tool widget */
void addToolWidget(QGCToolWidgetItem* widget); void addToolWidget(QGCToolWidgetItem* widget);
/** @brief Add an existing tool widget and set it to edit mode */
void addToolWidgetAndEdit(QGCToolWidgetItem* widget);
void hideEvent(QHideEvent* event); void hideEvent(QHideEvent* event);
public slots: public slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment