summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-05-31 09:22:18 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-05-31 09:22:18 (GMT)
commit59f1bfcf315a77834ddbce20cc05892d211ab55c (patch)
tree42212b6ae07539b3bfd6fdcb6903dab9aa6b61be /Swift
parent08399fe0e7d8d5ab42975b51c487c82caf845cef (diff)
downloadswift-contrib-59f1bfcf315a77834ddbce20cc05892d211ab55c.zip
swift-contrib-59f1bfcf315a77834ddbce20cc05892d211ab55c.tar.bz2
Render & in group names correctly in edit dialog.
Resolves: #1117
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/QtContactEditWidget.cpp16
-rw-r--r--Swift/QtUI/QtContactEditWidget.h4
2 files changed, 17 insertions, 3 deletions
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp
index 9d071b9..a347a00 100644
--- a/Swift/QtUI/QtContactEditWidget.cpp
+++ b/Swift/QtUI/QtContactEditWidget.cpp
@@ -46,20 +46,21 @@ QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups,
groupsArea->setWidgetResizable(true);
groupsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
groupsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QWidget* groups = new QWidget(groupsArea);
groupsArea->setWidget(groups);
QVBoxLayout* scrollLayout = new QVBoxLayout(groups);
foreach (std::string group, allGroups) {
+ QString groupName = doubleAmpersand(group);
QCheckBox* check = new QCheckBox(groups);
- check->setText(P2QSTRING(group));
+ check->setText(groupName);
check->setCheckState(Qt::Unchecked);
checkBoxes_[group] = check;
scrollLayout->addWidget(check);
}
QHBoxLayout* newGroupLayout = new QHBoxLayout();
newGroup_ = new QCheckBox(groups);
newGroup_->setText(tr("New Group:"));
newGroup_->setCheckState(Qt::Unchecked);
@@ -77,19 +78,19 @@ void QtContactEditWidget::setName(const std::string& name) {
std::string QtContactEditWidget::getName() const {
std::string name = Q2PSTRING(name_->text());
QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
foreach(const QRadioButton* button, buttons) {
if (button->isChecked()) {
if (button == nameRadioButton_) {
name = Q2PSTRING(name_->text());
} else {
- name = Q2PSTRING(button->text());
+ name = singleAmpersand(button->text());
}
break;
}
}
return name;
}
void QtContactEditWidget::setSelectedGroups(const std::vector<std::string>& groups) {
foreach (std::string group, groups) {
@@ -109,19 +110,19 @@ std::set<std::string> QtContactEditWidget::getSelectedGroups() const {
}
return groups;
}
void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& suggestions) {
throbberLabel_->movie()->stop();
throbberLabel_->hide();
foreach(const std::string& name, suggestions) {
- suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(P2QSTRING(name), this));
+ suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(doubleAmpersand(name), this));
}
nameRadioButton_ = new QRadioButton(tr("Name:"), this);
suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_);
QRadioButton* suggestedRadioButton = 0;
QList<QRadioButton*> radioButtons = findChildren<QRadioButton*>();
foreach (QRadioButton* candidate, radioButtons) {
if (candidate->text() == name_->text()) {
@@ -129,18 +130,27 @@ void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& sug
break;
}
}
if (suggestedRadioButton) {
suggestedRadioButton->setChecked(true);
} else {
nameRadioButton_->setChecked(true);
}
}
+QString QtContactEditWidget::doubleAmpersand(const std::string& name) const {
+ return P2QSTRING(name).replace("&", "&&");
+
+}
+
+std::string QtContactEditWidget::singleAmpersand(const QString& name) const {
+ return Q2PSTRING(QString(name).replace("&&", "&"));
+}
+
void QtContactEditWidget::clear() {
name_->clear();
setSelectedGroups(std::vector<std::string>());
newGroup_->setChecked(false);
newGroupName_->clear();
throbberLabel_->movie()->start();
throbberLabel_->show();
diff --git a/Swift/QtUI/QtContactEditWidget.h b/Swift/QtUI/QtContactEditWidget.h
index 5350762..6d55b80 100644
--- a/Swift/QtUI/QtContactEditWidget.h
+++ b/Swift/QtUI/QtContactEditWidget.h
@@ -32,18 +32,22 @@ namespace Swift {
std::string getName() const;
void setSelectedGroups(const std::vector<std::string>& groups);
std::set<std::string> getSelectedGroups() const;
void setNameSuggestions(const std::vector<std::string>& suggestions);
void clear();
+
+ private:
+ QString doubleAmpersand(const std::string& name) const;
+ std::string singleAmpersand(const QString& name) const;
private:
typedef std::map<std::string, QCheckBox*> CheckBoxMap;
CheckBoxMap checkBoxes_;
QHBoxLayout* nameLayout_;
QHBoxLayout* suggestionsLayout_;
QRadioButton* nameRadioButton_;
QLineEdit* name_;
QWidget* groups_;
QCheckBox* newGroup_;