From af3204839fa05bc616d94d6daf4e4024a30955bb Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Wed, 2 Jan 2008 17:02:26 +0000 Subject: [PATCH] Make 'New Profile' button in Manage Profiles dialog create the new profile based on the selected profile if there is a selection or the default profile otherwise. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=756040 --- src/ManageProfilesDialog.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/ManageProfilesDialog.cpp b/src/ManageProfilesDialog.cpp index a04763eeb..81f3e5e90 100644 --- a/src/ManageProfilesDialog.cpp +++ b/src/ManageProfilesDialog.cpp @@ -226,6 +226,7 @@ void ManageProfilesDialog::tableSelectionChanged(const QItemSelection& selection } void ManageProfilesDialog::deleteSelected() { + Q_ASSERT( !selectedKey().isEmpty() ); Q_ASSERT( selectedKey() != SessionManager::instance()->defaultProfileKey() ); SessionManager::instance()->deleteProfile(selectedKey()); @@ -244,10 +245,19 @@ void ManageProfilesDialog::newType() { EditProfileDialog dialog(this); - // setup a temporary profile, inheriting from the default profile - Profile* defaultProfile = SessionManager::instance()->defaultProfile(); + // setup a temporary profile, inheriting from the selected profile + // or the default if no profile is selected + Profile* parentProfile = 0; - Profile* newProfile = new Profile(defaultProfile); + QString selectedProfileKey = selectedKey(); + if ( selectedProfileKey.isEmpty() ) + parentProfile = SessionManager::instance()->defaultProfile(); + else + parentProfile = SessionManager::instance()->profile(selectedProfileKey); + + Q_ASSERT( parentProfile ); + + Profile* newProfile = new Profile(parentProfile); newProfile->setProperty(Profile::Name,i18n("New Profile")); const QString& key = SessionManager::instance()->addProfile(newProfile); dialog.setProfile(key); @@ -264,18 +274,22 @@ void ManageProfilesDialog::newType() } void ManageProfilesDialog::editSelected() { + Q_ASSERT( !selectedKey().isEmpty() ); + EditProfileDialog dialog(this); dialog.setProfile(selectedKey()); dialog.exec(); } QString ManageProfilesDialog::selectedKey() const { - Q_ASSERT( _ui->sessionTable->selectionModel() && - _ui->sessionTable->selectionModel()->selectedRows().count() == 1 ); + QItemSelectionModel* selection = _ui->sessionTable->selectionModel(); + + if ( !selection || selection->selectedRows().count() != 1 ) + return QString(); + // TODO There has to be an easier way of getting the data // associated with the currently selected item - return _ui->sessionTable-> - selectionModel()-> + return selection-> selectedIndexes().first().data( Qt::UserRole + 1 ).value(); } void ManageProfilesDialog::updateFavoriteStatus(const QString& key , bool favorite)