From bc41efd855013e9a230cab54e55feb3149975214 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 15 Mar 2021 20:08:27 +0200 Subject: [PATCH] Fix crash in ProfileSettings; clone selected profile settings to new profile - If there is no selection only enable the "New" button, this fixes a crash if you select a profile, then Ctrl+Click to unselect it, the set as default button would still be enabled and clicking it caused a crash - If a profile is selected, clone its properties, otherwise the fallback profile properties will be used, this more expected --- src/settings/ProfileSettings.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/settings/ProfileSettings.cpp b/src/settings/ProfileSettings.cpp index 218b071e..0506a682 100644 --- a/src/settings/ProfileSettings.cpp +++ b/src/settings/ProfileSettings.cpp @@ -90,13 +90,20 @@ void ProfileSettings::populateTable() connect(profilesList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Konsole::ProfileSettings::tableSelectionChanged); } -void ProfileSettings::tableSelectionChanged(const QItemSelection&) +void ProfileSettings::tableSelectionChanged(const QItemSelection &selected) { + newProfileButton->setEnabled(true); + + if (selected.isEmpty()) { + editProfileButton->setEnabled(false); + deleteProfileButton->setEnabled(false); + setAsDefaultButton->setEnabled(false); + return; + } + const auto profile = currentProfile(); const bool isNotDefault = profile != ProfileManager::instance()->defaultProfile(); - newProfileButton->setEnabled(true); - // See comment about isProfileWritable(profile) in editSelected() editProfileButton->setEnabled(isProfileWritable(profile)); @@ -126,14 +133,14 @@ void ProfileSettings::setSelectedAsDefault() void ProfileSettings::createProfile() { - // setup a temporary profile which is a clone of the selected profile - // or the default if no profile is selected - Profile::Ptr sourceProfile = currentProfile() ? currentProfile() : ProfileManager::instance()->defaultProfile(); + auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile())); - Q_ASSERT(sourceProfile); + // If a profile is selected, clone its properties, otherwise the + // the fallback profile properties will be used + if (currentProfile()) { + newProfile->clone(currentProfile(), true); + } - auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile())); - newProfile->clone(sourceProfile, true); const QString uniqueName = ProfileManager::instance()->generateUniqueName(); newProfile->setProperty(Profile::Name, uniqueName); newProfile->setProperty(Profile::UntranslatedName, uniqueName); @@ -189,7 +196,7 @@ Profile::Ptr ProfileSettings::currentProfile() const { QItemSelectionModel* selection = profilesList->selectionModel(); - if ((selection == nullptr) || selection->selectedRows().count() != 1) { + if ((selection == nullptr) || !selection->hasSelection()) { return Profile::Ptr(); }