From 36a00c5338df2df1be827c014dff63bfbf16cb34 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Tue, 24 Apr 2012 17:54:09 +0200
Subject: In contact name selection, only select text edit field, if it doesn't
 match any suggestion.

Resolves: #1098

License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php

diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp
index 5e2915f..9d071b9 100644
--- a/Swift/QtUI/QtContactEditWidget.cpp
+++ b/Swift/QtUI/QtContactEditWidget.cpp
@@ -121,11 +121,16 @@ void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& sug
 	nameRadioButton_ = new QRadioButton(tr("Name:"), this);
 	suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_);
 
-	if (name_->text().isEmpty()) {
-		QRadioButton* suggestedRadioButton = dynamic_cast<QRadioButton*>(suggestionsLayout_->itemAt(0)->widget());
-		if (suggestedRadioButton) {
-			suggestedRadioButton->setChecked(true);
+	QRadioButton* suggestedRadioButton = 0;
+	QList<QRadioButton*> radioButtons = findChildren<QRadioButton*>();
+	foreach (QRadioButton* candidate, radioButtons) {
+		if (candidate->text() == name_->text()) {
+			suggestedRadioButton = candidate;
+			break;
 		}
+	}
+	if (suggestedRadioButton) {
+		suggestedRadioButton->setChecked(true);
 	} else {
 		nameRadioButton_->setChecked(true);
 	}
-- 
cgit v0.10.2-6-g49f6