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
// Enforce storage if this not loaded from settings
// is MUST NOT BE SAVED if it was loaded from settings!
//if (!settings) storeWidgetsToSettings();
if (!settings) storeWidgetsToSettings();
}
QGCToolWidget::~QGCToolWidget()
......@@ -530,60 +530,35 @@ QList<QGCToolWidgetItem*>* QGCToolWidget::itemList()
if (!instances) instances = new QList<QGCToolWidgetItem*>();
return instances;
}
void QGCToolWidget::addParam(int uas,int component,QString paramname,QVariant value)
{
isFromMetaData = true;
QGCParamSlider* slider = new QGCParamSlider(this);
connect(slider, SIGNAL(destroyed()), this, SLOT(storeSettings()));
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(slider);
addToolWidget(slider);
slider->setActiveUAS(mav);
slider->setParameterValue(uas,component,0,-1,paramname,value);
}
void QGCToolWidget::addParam()
{
QGCParamSlider* slider = new QGCParamSlider(this);
connect(slider, SIGNAL(destroyed()), this, SLOT(storeSettings()));
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(slider);
slider->startEditMode();
addToolWidgetAndEdit(new QGCParamSlider(this));
}
void QGCToolWidget::addCommand()
{
QGCCommandButton* button = new QGCCommandButton(this);
connect(button, SIGNAL(destroyed()), this, SLOT(storeSettings()));
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(button);
button->startEditMode();
addToolWidgetAndEdit(new QGCCommandButton(this));
}
void QGCToolWidget::addLabel()
{
QGCTextLabel* label= new QGCTextLabel(this);
connect(label, SIGNAL(destroyed()), this, SLOT(storeSettings()));
if (ui->hintLabel)
{
ui->hintLabel->deleteLater();
ui->hintLabel = NULL;
}
toolLayout->addWidget(label);
label->startEditMode();
addToolWidgetAndEdit(new QGCTextLabel(this));
}
void QGCToolWidget::addToolWidgetAndEdit(QGCToolWidgetItem* widget)
{
addToolWidget(widget);
widget->startEditMode();
}
void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget)
......
......@@ -91,6 +91,8 @@ protected:
QList<QGCToolWidgetItem* >* itemList();
/** @brief Add an existing tool 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);
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