McuSupport: Only store valid paths to settings

The plugin currently requires valid packages before updating kits.
Invalid packages are ignored. This change makes writing to settings
consistent with this approach. If any of the given paths are invalid,
changes are not applied.

In order to not accidentally include changes made to packages for
other targets than the one visible in the UI, the Apply-button in the
Devices page now only stores the current target. This also avoids
unpredictable behavior when more than one target in the repo track
the same dependencies. The path shown in the UI is the one which is
applied, not a hidden path currently stored in another target.

Change-Id: Id0a6ec1aebd53357d0ee2fb68f14529f34ae887f
Reviewed-by: Daniele Bortolotti <daniele.bortolotti@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Sivert Krøvel
2022-10-27 02:12:10 +02:00
parent 8afdb62564
commit db7674307d

View File

@@ -7,6 +7,7 @@
#include "mcusupportconstants.h" #include "mcusupportconstants.h"
#include "mcusupportoptions.h" #include "mcusupportoptions.h"
#include "mcusupportsdk.h" #include "mcusupportsdk.h"
#include "mcusupporttr.h"
#include "mcutarget.h" #include "mcutarget.h"
#include "mcutargetfactory.h" #include "mcutargetfactory.h"
#include "settingshandler.h" #include "settingshandler.h"
@@ -28,6 +29,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
@@ -288,8 +290,27 @@ void McuSupportOptionsWidget::apply()
m_settingsHandler->setAutomaticKitCreation(m_options.automaticKitCreationEnabled()); m_settingsHandler->setAutomaticKitCreation(m_options.automaticKitCreationEnabled());
McuTargetFactory::expandVariables(m_options.sdkRepository.packages); McuTargetFactory::expandVariables(m_options.sdkRepository.packages);
QMessageBox warningPopup(QMessageBox::Icon::Warning,
Tr::tr("Warning"),
Tr::tr("Unable to apply changes."),
QMessageBox::Ok,
this);
auto target = currentMcuTarget();
if (!target) {
warningPopup.setInformativeText(Tr::tr("No target selected."));
warningPopup.exec();
return;
}
if (!target->isValid()) {
warningPopup.setInformativeText(Tr::tr("Invalid path(s) present."));
warningPopup.exec();
return;
}
pathsChanged |= m_options.qtForMCUsSdkPackage->writeToSettings(); pathsChanged |= m_options.qtForMCUsSdkPackage->writeToSettings();
for (const auto &package : std::as_const(m_options.sdkRepository.packages)) for (const auto &package : target->packages())
pathsChanged |= package->writeToSettings(); pathsChanged |= package->writeToSettings();
if (pathsChanged) { if (pathsChanged) {