From 3029af276992d2a1b3018dd671703811e05210fa Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 22 Nov 2011 13:04:49 +0000 Subject: SettingsSelector: Use Edit role when renaming Also add a method to find the current index. Change-Id: I54074e7050200a77d35461c4f8064c1829b5927f Reviewed-by: Daniel Teske --- src/libs/utils/settingsselector.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/libs/utils/settingsselector.cpp') diff --git a/src/libs/utils/settingsselector.cpp b/src/libs/utils/settingsselector.cpp index fb4d1a06ed..66843e1db9 100644 --- a/src/libs/utils/settingsselector.cpp +++ b/src/libs/utils/settingsselector.cpp @@ -133,9 +133,14 @@ QMenu *SettingsSelector::addMenu() const return m_addButton->menu(); } +int SettingsSelector::currentIndex() const +{ + return m_configurationCombo->currentIndex(); +} + void SettingsSelector::removeButtonClicked() { - int pos = m_configurationCombo->currentIndex(); + int pos = currentIndex(); if (pos < 0) return; const QString title = m_kindOfDisplayName.isEmpty() ? tr("Remove") : @@ -157,19 +162,24 @@ void SettingsSelector::removeButtonClicked() void SettingsSelector::renameButtonClicked() { - int pos = m_configurationCombo->currentIndex(); + int pos = currentIndex(); if (pos < 0) return; + QAbstractItemModel *model = m_configurationCombo->model(); + int row = m_configurationCombo->currentIndex(); + QModelIndex idx = model->index(row, 0); + QString baseName = model->data(idx, Qt::EditRole).toString(); + bool ok; const QString &message = m_kindOfDisplayName.isEmpty() ? tr("New name for configuration %1:") - .arg(m_configurationCombo->currentText()) : + .arg(baseName) : tr("New name for %1: %2:") - .arg(m_kindOfDisplayName).arg(m_configurationCombo->currentText()); + .arg(m_kindOfDisplayName).arg(baseName); QString name = QInputDialog::getText(this, tr("Rename..."), message, - QLineEdit::Normal, m_configurationCombo->currentText(), &ok); + QLineEdit::Normal, baseName, &ok); if (!ok) return; -- cgit v1.2.1