From be1174c9711c4ef0250b87082ec9ef32a329ae01 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Thu, 4 Aug 2022 18:31:56 +0200 Subject: [PATCH] Add Profile::assignProperties() method that takes a PropertyMap --- src/profile/Profile.cpp | 5 +++++ src/profile/Profile.h | 4 ++++ src/profile/ProfileManager.cpp | 10 ++++++---- src/session/SessionManager.cpp | 6 +----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/profile/Profile.cpp b/src/profile/Profile.cpp index 20e8eeab..3380a855 100644 --- a/src/profile/Profile.cpp +++ b/src/profile/Profile.cpp @@ -280,6 +280,11 @@ void Profile::setProperty(Property p, const QVariant &value) _propertyValues.insert(p, value); } +void Profile::assignProperties(const PropertyMap &map) +{ + _propertyValues.insert(map); +} + bool Profile::isPropertySet(Property p) const { return _propertyValues.contains(p); diff --git a/src/profile/Profile.h b/src/profile/Profile.h index f1d33969..dd9c5ebd 100644 --- a/src/profile/Profile.h +++ b/src/profile/Profile.h @@ -426,6 +426,10 @@ public: /** Sets the value of the specified @p property to @p value. */ virtual void setProperty(Property p, const QVariant &value); + + /** Sets the Porperty/value pairs from @p map on this Profile */ + void assignProperties(const PropertyMap &map); + /** Returns true if the specified property has been set in this Profile * instance. */ diff --git a/src/profile/ProfileManager.cpp b/src/profile/ProfileManager.cpp index 5e4ee5ae..412cf2e3 100644 --- a/src/profile/ProfileManager.cpp +++ b/src/profile/ProfileManager.cpp @@ -281,13 +281,15 @@ void ProfileManager::changeProfile(Profile::Ptr profile, Profile::PropertyMap pr bool isNameChanged = false; // Insert the changes into the existing Profile instance + profile->assignProperties(propertyMap); + + // Check if the name changed for (auto it = propertyMap.cbegin(); it != propertyMap.cend(); ++it) { const auto property = it.key(); - auto value = it.value(); - isNameChanged |= property == Profile::Name || property == Profile::UntranslatedName; - - profile->setProperty(property, value); + if (isNameChanged) { + break; + } } // when changing a group, iterate through the profiles diff --git a/src/session/SessionManager.cpp b/src/session/SessionManager.cpp index c5eb199f..c53d2e91 100644 --- a/src/session/SessionManager.cpp +++ b/src/session/SessionManager.cpp @@ -322,11 +322,7 @@ void SessionManager::sessionProfileCommandReceived(Session *session, const QStri newProfile = _sessionRuntimeProfiles[session]; } - QHashIterator iter(changes); - while (iter.hasNext()) { - iter.next(); - newProfile->setProperty(iter.key(), iter.value()); - } + newProfile->assignProperties(changes); _sessionProfiles[session] = newProfile; applyProfile(newProfile, true);