diff --git a/src/ui/QGCVehicleConfig.cc b/src/ui/QGCVehicleConfig.cc index 2aec8145aeb4dc80dfc75398a1db5ae90638c5aa..ad5f9e21077522c5ca27f89d7e032d815730278d 100644 --- a/src/ui/QGCVehicleConfig.cc +++ b/src/ui/QGCVehicleConfig.cc @@ -461,7 +461,7 @@ void QGCVehicleConfig::loadConfig() QList paramlist = tool->getParamList(); for (int i=0;iinsert(paramlist[i],tool); diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index 97d29e125f92e2059e16b9fadbce4ec85570ab0b..232d956e3c53984fed66fb12e0d35512ca40a08f 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -22,6 +22,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s widgetTitle(title), ui(new Ui::QGCToolWidget) { + isFromMetaData = false; ui->setupUi(this); if (settings) loadSettings(*settings); @@ -109,6 +110,7 @@ QList QGCToolWidget::createWidgetsFromSettings(QWidget* parent, } QList newWidgets; + settings->beginGroup("Custom_Tool_Widgets"); int size = settings->beginReadArray("QGC_TOOL_WIDGET_NAMES"); for (int i = 0; i < size; i++) { @@ -140,6 +142,8 @@ QList QGCToolWidget::createWidgetsFromSettings(QWidget* parent, { newWidgets.at(i)->loadSettings(*settings); } + settings->endGroup(); + settings->sync(); delete settings; return instances()->values(); @@ -171,6 +175,7 @@ bool QGCToolWidget::loadSettings(const QString& settings, bool singleinstance) } void QGCToolWidget::setSettings(QVariantMap& settings) { + isFromMetaData = true; settingsMap = settings; QString widgetName = getTitle(); int size = settingsMap["count"].toInt(); @@ -365,18 +370,23 @@ void QGCToolWidget::storeWidgetsToSettings(QString settingsFile) //qDebug() << "STORING SETTINGS TO DEFAULT" << settings->fileName(); } + settings->beginGroup("Custom_Tool_Widgets"); int preArraySize = settings->beginReadArray("QGC_TOOL_WIDGET_NAMES"); settings->endArray(); settings->beginWriteArray("QGC_TOOL_WIDGET_NAMES"); + int num = 0; for (int i = 0; i < qMax(preArraySize, instances()->size()); ++i) { - settings->setArrayIndex(i); if (i < instances()->size()) { // Updating value - settings->setValue("TITLE", instances()->values().at(i)->getTitle()); - //qDebug() << "WRITING TITLE" << instances()->values().at(i)->getTitle(); + if (!instances()->values().at(i)->fromMetaData()) + { + settings->setArrayIndex(num++); + settings->setValue("TITLE", instances()->values().at(i)->getTitle()); + //qDebug() << "WRITING TITLE" << instances()->values().at(i)->getTitle(); + } } else { @@ -391,6 +401,8 @@ void QGCToolWidget::storeWidgetsToSettings(QString settingsFile) { instances()->values().at(i)->storeSettings(*settings); } + settings->endGroup(); + settings->sync(); delete settings; } @@ -408,6 +420,11 @@ void QGCToolWidget::storeSettings(const QString& settingsFile) void QGCToolWidget::storeSettings(QSettings& settings) { + if (isFromMetaData) + { + //Refuse to store if this is loaded from metadata or dynamically generated. + return; + } //qDebug() << "WRITING WIDGET" << widgetTitle << "TO SETTINGS"; settings.beginGroup(widgetTitle); settings.beginWriteArray("QGC_TOOL_WIDGET_ITEMS"); @@ -511,6 +528,7 @@ QList* QGCToolWidget::itemList() } 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) @@ -611,11 +629,11 @@ void QGCToolWidget::setWindowTitle(const QString& title) void QGCToolWidget::setTitle(QString title) { // Remove references to old title - QSettings settings; + /*QSettings settings; settings.beginGroup(widgetTitle); settings.remove(""); settings.endGroup(); - settings.sync(); + settings.sync();*/ if (instances()->contains(widgetTitle)) instances()->remove(widgetTitle); @@ -645,10 +663,11 @@ void QGCToolWidget::deleteWidget() // Hide this->hide(); instances()->remove(getTitle()); - QSettings settings; + /*QSettings settings; settings.beginGroup(getTitle()); settings.remove(""); settings.endGroup(); + storeWidgetsToSettings();*/ storeWidgetsToSettings(); // Delete diff --git a/src/ui/designer/QGCToolWidget.h b/src/ui/designer/QGCToolWidget.h index ab07c8ba4d873252aded2fb22fc2ea5dcaa4e916..e261e47f7e2b69c7d5e4bc05280a9df314863cec 100644 --- a/src/ui/designer/QGCToolWidget.h +++ b/src/ui/designer/QGCToolWidget.h @@ -61,10 +61,12 @@ public slots: void setSettings(QVariantMap& settings); QList getParamList(); void setParameterValue(int uas, int component, QString parameterName, const QVariant value); + bool fromMetaData() { return isFromMetaData; } signals: void titleChanged(QString); protected: + bool isFromMetaData; QMap paramToItemMap; QList paramList; QVariantMap settingsMap;