diff --git a/ground/src/plugins/coreplugin/dialogs/settingsdialog.cpp b/ground/src/plugins/coreplugin/dialogs/settingsdialog.cpp index a1aabbd82..266cb3cdc 100644 --- a/ground/src/plugins/coreplugin/dialogs/settingsdialog.cpp +++ b/ground/src/plugins/coreplugin/dialogs/settingsdialog.cpp @@ -164,9 +164,6 @@ void SettingsDialog::deletePage() { QTreeWidgetItem *item = pageTree->currentItem(); item->parent()->removeChild(item); - PageData data = item->data(0, Qt::UserRole).value(); - int index = data.index; - m_deletedPageIndices.append(index); pageSelected(); } @@ -218,7 +215,6 @@ void SettingsDialog::accept() { m_applied = true; foreach (IOptionsPage *page, m_pages) { - if (!m_deletedPageIndices.contains(m_pages.indexOf(page))) page->apply(); page->finish(); } @@ -235,7 +231,6 @@ void SettingsDialog::reject() void SettingsDialog::apply() { foreach (IOptionsPage *page, m_pages) { - if (!m_deletedPageIndices.contains(m_pages.indexOf(page))) page->apply(); } m_applied = true; diff --git a/ground/src/plugins/coreplugin/dialogs/settingsdialog.h b/ground/src/plugins/coreplugin/dialogs/settingsdialog.h index 730897ba9..82602ed99 100644 --- a/ground/src/plugins/coreplugin/dialogs/settingsdialog.h +++ b/ground/src/plugins/coreplugin/dialogs/settingsdialog.h @@ -78,7 +78,6 @@ private: bool m_applied; QString m_currentCategory; QString m_currentPage; - QList m_deletedPageIndices; }; } // namespace Internal diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 756ea3061..6c2c0a855 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -163,6 +163,7 @@ bool UAVGadgetInstanceManager::canDeleteConfiguration(IUAVGadgetConfiguration *c void UAVGadgetInstanceManager::deleteConfiguration(IUAVGadgetConfiguration *config) { + m_provisionalDeletes.append(config); if (m_provisionalConfigs.contains(config)) { int i = m_provisionalConfigs.indexOf(config); m_provisionalConfigs.removeAt(i); @@ -171,13 +172,7 @@ void UAVGadgetInstanceManager::deleteConfiguration(IUAVGadgetConfiguration *con m_takenNames[config->classId()].removeAt(j); m_settingsDialog->deletePage(); } else if (m_configurations.contains(config)) { - emit configurationToBeDeleted(config); - int i = m_configurations.indexOf(config); - m_provisionalConfigs.removeAt(i); - m_pm->removeObject(m_optionsPages.at(i)); - m_optionsPages.removeAt(i);//TODO delete m_settingsDialog->deletePage(); - m_configurations.removeAt(i); } configurationNameEdited("", false); } @@ -220,6 +215,19 @@ QString UAVGadgetInstanceManager::suggestName(QString classId, QString name) void UAVGadgetInstanceManager::applyChanges(IUAVGadgetConfiguration *config) { + if (m_provisionalDeletes.contains(config)) { + m_provisionalDeletes.removeAt(m_provisionalDeletes.indexOf(config)); + int i = m_configurations.indexOf(config); + if (i >= 0) { + emit configurationToBeDeleted(config); + int j = m_takenNames[config->classId()].indexOf(config->name()); + m_takenNames[config->classId()].removeAt(j); + m_pm->removeObject(m_optionsPages.at(i)); + m_configurations.removeAt(i); + m_optionsPages.removeAt(i);//TODO delete + } + return; + } if (config->provisionalName() != config->name()) { emit configurationNameChanged(config->name(), config->provisionalName()); config->setName(config->provisionalName()); @@ -228,10 +236,12 @@ void UAVGadgetInstanceManager::applyChanges(IUAVGadgetConfiguration *config) emit configurationChanged(config); } else if (m_provisionalConfigs.contains(config)) { emit configurationAdded(config); + int i = m_provisionalConfigs.indexOf(config); + IOptionsPage *page = m_provisionalOptionsPages.at(i); m_configurations.append(config); - IUAVGadgetFactory *f = factory(config->classId()); - IOptionsPage *page = f->createOptionsPage(config); m_optionsPages.append(page); + m_provisionalConfigs.removeAt(i); + m_provisionalOptionsPages.removeAt(i); m_pm->addObject(page); } } @@ -273,13 +283,13 @@ void UAVGadgetInstanceManager::settingsDialogRemoved() { m_takenNames.clear(); m_provisionalConfigs.clear(); + m_provisionalDeletes.clear(); m_provisionalOptionsPages.clear(); //TODO delete foreach (IUAVGadgetConfiguration *config, m_configurations) config->setProvisionalName(config->name()); m_settingsDialog = 0; } - QStringList UAVGadgetInstanceManager::configurationNames(QString classId) const { QStringList names; diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h index 9fda6a144..54b5e2dfa 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h @@ -88,6 +88,7 @@ private: QMap m_classIds; QMap m_takenNames; QList m_provisionalConfigs; + QList m_provisionalDeletes; QList m_provisionalOptionsPages; Core::Internal::SettingsDialog *m_settingsDialog; ExtensionSystem::PluginManager *m_pm;