Commit b297d591 authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

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

(cherry picked from commit bc41efd8)
parent b3c08be8
......@@ -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)
if (selected.isEmpty()) {
const auto profile = currentProfile();
const bool isNotDefault = profile != ProfileManager::instance()->defaultProfile();
// See comment about isProfileWritable(profile) in editSelected()
......@@ -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()));
// 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();
Supports Markdown
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