diff options
author | Tobias Markmann <tm@ayena.de> | 2013-10-15 14:31:02 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2013-10-17 08:03:37 (GMT) |
commit | 5f0eeca41f0559c5b416c78fd51445fd93cf61ff (patch) | |
tree | ad4b7bb586385be7916213999dfb4248dae2c437 /Swift | |
parent | 040ceccfc67ce41fdd836ae874da68e04e6ca944 (diff) | |
download | swift-5f0eeca41f0559c5b416c78fd51445fd93cf61ff.zip swift-5f0eeca41f0559c5b416c78fd51445fd93cf61ff.tar.bz2 |
VCard: Assert existence of field widgets instead of if-testing.
Change-Id: Ie92f4f1714b8fb6dc5c1e2729151c8e00c33215b
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp | 38 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp | 24 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp | 28 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp | 39 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp | 15 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp | 15 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp | 29 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp | 15 |
11 files changed, 121 insertions, 106 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp index d9bb4fe..f394af0 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp @@ -138,20 +138,30 @@ VCard::Address QtVCardAddressField::getAddress() const { } void QtVCardAddressField::handleEditibleChanged(bool isEditable) { - if (streetLineEdit) streetLineEdit->setEditable(isEditable); - if (poboxLineEdit) poboxLineEdit->setEditable(isEditable); - if (addressextLineEdit) addressextLineEdit->setEditable(isEditable); - if (cityLineEdit) cityLineEdit->setEditable(isEditable); - if (pocodeLineEdit) pocodeLineEdit->setEditable(isEditable); - if (regionLineEdit) regionLineEdit->setEditable(isEditable); - if (countryLineEdit) countryLineEdit->setEditable(isEditable); - - if (deliveryTypeLabel) { - deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text()); - deliveryTypeLabel->setVisible(!isEditable); - } - if (domesticRadioButton) domesticRadioButton->setVisible(isEditable); - if (internationalRadioButton) internationalRadioButton->setVisible(isEditable); + assert(streetLineEdit); + assert(poboxLineEdit); + assert(addressextLineEdit); + assert(cityLineEdit); + assert(pocodeLineEdit); + assert(regionLineEdit); + assert(countryLineEdit); + assert(deliveryTypeLabel); + assert(domesticRadioButton); + assert(internationalRadioButton); + + streetLineEdit->setEditable(isEditable); + poboxLineEdit->setEditable(isEditable); + addressextLineEdit->setEditable(isEditable); + cityLineEdit->setEditable(isEditable); + pocodeLineEdit->setEditable(isEditable); + regionLineEdit->setEditable(isEditable); + countryLineEdit->setEditable(isEditable); + + deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text()); + deliveryTypeLabel->setVisible(!isEditable); + + domesticRadioButton->setVisible(isEditable); + internationalRadioButton->setVisible(isEditable); foreach (QWidget* widget, textFields) { QtResizableLineEdit* lineEdit; diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp index 20f48b9..98e313f 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp @@ -81,17 +81,19 @@ VCard::AddressLabel QtVCardAddressLabelField::getAddressLabel() const { } void QtVCardAddressLabelField::handleEditibleChanged(bool isEditable) { - if (addressLabelPlainTextEdit) { - addressLabelPlainTextEdit->setReadOnly(!isEditable); - addressLabelPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }"); - } - - if (deliveryTypeLabel) { - deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text()); - deliveryTypeLabel->setVisible(!isEditable); - } - if (domesticRadioButton) domesticRadioButton->setVisible(isEditable); - if (internationalRadioButton) internationalRadioButton->setVisible(isEditable); + assert(addressLabelPlainTextEdit); + assert(deliveryTypeLabel); + assert(domesticRadioButton); + assert(internationalRadioButton); + + addressLabelPlainTextEdit->setReadOnly(!isEditable); + addressLabelPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }"); + + deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text()); + deliveryTypeLabel->setVisible(!isEditable); + + domesticRadioButton->setVisible(isEditable); + internationalRadioButton->setVisible(isEditable); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp index f907d78..f16c351 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp @@ -44,21 +44,21 @@ std::string QtVCardDescriptionField::getDescription() const { } void QtVCardDescriptionField::handleEditibleChanged(bool isEditable) { - if (descriptionPlainTextEdit) { - if (isEditable) { - descriptionPlainTextEdit->setMinimumHeight(70); - } else { - QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont()); - QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999); - QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A"); - int left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); - int height = boundingRect.height() + top + bottom + inputMetrics.height(); - descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height); - } - descriptionPlainTextEdit->setReadOnly(!isEditable); - descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }"); + assert(descriptionPlainTextEdit); + + if (isEditable) { + descriptionPlainTextEdit->setMinimumHeight(70); + } else { + QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont()); + QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999); + QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A"); + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + int height = boundingRect.height() + top + bottom + inputMetrics.height(); + descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height); } + descriptionPlainTextEdit->setReadOnly(!isEditable); + descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }"); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp index 5b3ef87..f8b9247 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "QtVCardGeneralField.h" +#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h> + +#include <cassert> #include <QHBoxLayout> -#include <Swiften/Base/Log.h> namespace Swift { QtVCardGeneralField::QtVCardGeneralField(QWidget* parent, QGridLayout* layout, bool editable, int row, QString label, bool preferrable, bool taggable) : - QWidget(parent), preferrable(preferrable), taggable(taggable), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label), + QWidget(parent), editable(editable), preferrable(preferrable), taggable(taggable), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label), tagComboBox(0), closeButton(0) { - setEditable(editable); } QtVCardGeneralField::~QtVCardGeneralField() { @@ -54,6 +54,7 @@ void QtVCardGeneralField::initialize() { tagLabel->hide(); childWidgets << label << tagComboBox << tagLabel << closeButton; + setEditable(editable); } bool QtVCardGeneralField::isEditable() const { @@ -61,24 +62,22 @@ bool QtVCardGeneralField::isEditable() const { } void QtVCardGeneralField::setEditable(bool editable) { + assert(tagComboBox); + assert(closeButton); + this->editable = editable; - if (tagComboBox) { - if (taggable) { - tagLabel->setText(tagComboBox->itemText(0)); - tagComboBox->setVisible(editable); - tagLabel->setVisible(!editable); - } else { - tagLabel->hide(); - tagComboBox->hide(); - } + if (taggable) { + tagLabel->setText(tagComboBox->itemText(0)); + tagComboBox->setVisible(editable); + tagLabel->setVisible(!editable); + } else { + tagLabel->hide(); + tagComboBox->hide(); } - if (closeButton) closeButton->setVisible(editable); - if (preferredCheckBox) { - if (editable) { - preferredCheckBox->show(); - } else if (!preferredCheckBox->isChecked()) { - preferredCheckBox->hide(); - } + closeButton->setVisible(editable); + if (preferrable) { + assert(preferredCheckBox); + preferredCheckBox->setVisible(editable ? true : preferredCheckBox->isChecked()); preferredCheckBox->setEnabled(editable); } editableChanged(this->editable); diff --git a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp index b946fc4..e6f8298 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp @@ -66,15 +66,16 @@ VCard::EMailAddress QtVCardInternetEMailField::getInternetEMailAddress() const { } void QtVCardInternetEMailField::handleEditibleChanged(bool isEditable) { + assert(emailLineEdit); + assert(emailLabel); + if (isEditable) { - if (emailLineEdit) emailLineEdit->show(); - if (emailLabel) emailLabel->hide(); + emailLineEdit->show(); + emailLabel->hide(); } else { - if (emailLineEdit) emailLineEdit->hide(); - if (emailLabel) { - emailLabel->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(QtUtilities::htmlEscape(emailLineEdit->text()))); - emailLabel->show(); - } + emailLineEdit->hide(); + emailLabel->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(QtUtilities::htmlEscape(emailLineEdit->text()))); + emailLabel->show(); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp index ecb5533..23a2b5d 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp @@ -57,15 +57,16 @@ JID QtVCardJIDField::getJID() const { } void QtVCardJIDField::handleEditibleChanged(bool isEditable) { + assert(jidLineEdit); + assert(jidLabel); + if (isEditable) { - if (jidLineEdit) jidLineEdit->show(); - if (jidLabel) jidLabel->hide(); + jidLineEdit->show(); + jidLabel->hide(); } else { - if (jidLineEdit) jidLineEdit->hide(); - if (jidLabel) { - jidLabel->setText(QString("<a href=\"xmpp:%1\">%1</a>").arg(QtUtilities::htmlEscape(jidLineEdit->text()))); - jidLabel->show(); - } + jidLineEdit->hide(); + jidLabel->setText(QString("<a href=\"xmpp:%1\">%1</a>").arg(QtUtilities::htmlEscape(jidLineEdit->text()))); + jidLabel->show(); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp index 9ecc8e0..7f6c23d 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp @@ -96,23 +96,24 @@ VCard::Organization QtVCardOrganizationField::getOrganization() const { } void QtVCardOrganizationField::handleEditibleChanged(bool isEditable) { - if (organizationLineEdit) { - organizationLineEdit->setVisible(isEditable); - organizationLabel->setVisible(!isEditable); - - if (!isEditable) { - QString label; - for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) { - QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i); - if (!row->text(0).isEmpty()) { - label += row->text(0) + ", "; - } + assert(organizationLineEdit); + assert(unitsTreeWidget); + + organizationLineEdit->setVisible(isEditable); + organizationLabel->setVisible(!isEditable); + + if (!isEditable) { + QString label; + for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i); + if (!row->text(0).isEmpty()) { + label += row->text(0) + ", "; } - label += organizationLineEdit->text(); - organizationLabel->setText(label); } + label += organizationLineEdit->text(); + organizationLabel->setText(label); } - if (unitsTreeWidget) unitsTreeWidget->setVisible(isEditable); + unitsTreeWidget->setVisible(isEditable); } void QtVCardOrganizationField::handleItemChanged(QTreeWidgetItem *, int) { diff --git a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp index 8af4e64..b9da767 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp @@ -41,10 +41,10 @@ std::string QtVCardRoleField::getRole() const { } void QtVCardRoleField::handleEditibleChanged(bool isEditable) { - if (roleLineEdit) { - roleLineEdit->setEditable(isEditable); - roleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }"); - } + assert(roleLineEdit); + + roleLineEdit->setEditable(isEditable); + roleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }"); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp index ee93c01..063319e 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp @@ -91,10 +91,10 @@ VCard::Telephone QtVCardTelephoneField::getTelephone() const { } void QtVCardTelephoneField::handleEditibleChanged(bool isEditable) { - if (telephoneLineEdit) { - telephoneLineEdit->setEditable(isEditable); - telephoneLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }"); - } + assert(telephoneLineEdit); + + telephoneLineEdit->setEditable(isEditable); + telephoneLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }"); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp index aac4e31..43972d0 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp @@ -42,10 +42,10 @@ std::string QtVCardTitleField::getTitle() const { } void QtVCardTitleField::handleEditibleChanged(bool isEditable) { - if (titleLineEdit) { - titleLineEdit->setEditable(isEditable); - titleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }"); - } + assert(titleLineEdit); + + titleLineEdit->setEditable(isEditable); + titleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }"); } } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp index 35cc4ce..b39eeaa 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp @@ -55,15 +55,16 @@ std::string QtVCardURLField::getURL() const { } void QtVCardURLField::handleEditibleChanged(bool isEditable) { + assert(urlLineEdit); + assert(urlLabel); + if (isEditable) { - if (urlLineEdit) urlLineEdit->show(); - if (urlLabel) urlLabel->hide(); + urlLineEdit->show(); + urlLabel->hide(); } else { - if (urlLineEdit) urlLineEdit->hide(); - if (urlLabel) { - urlLabel->setText(QString("<a href=\"%1\">%1</a>").arg(QtUtilities::htmlEscape(urlLineEdit->text()))); - urlLabel->show(); - } + urlLineEdit->hide(); + urlLabel->setText(QString("<a href=\"%1\">%1</a>").arg(QtUtilities::htmlEscape(urlLineEdit->text()))); + urlLabel->show(); } } |