Set label when selecting an address that already has a label. Fixes #1080.
[novacoin.git] / src / qt / sendcoinsentry.cpp
index 1802095..c8242d8 100644 (file)
@@ -44,6 +44,8 @@ void SendCoinsEntry::on_pasteButton_clicked()
 
 void SendCoinsEntry::on_addressBookButton_clicked()
 {
+    if(!model)
+        return;
     AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
     dlg.setModel(model->getAddressTableModel());
     if(dlg.exec())
@@ -55,12 +57,18 @@ void SendCoinsEntry::on_addressBookButton_clicked()
 
 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
 {
-    ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
+    if(!model)
+        return;
+    // Fill in label from address book, if address has an associated label
+    QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
+    if(!associatedLabel.isEmpty())
+        ui->addAsLabel->setText(associatedLabel);
 }
 
 void SendCoinsEntry::setModel(WalletModel *model)
 {
     this->model = model;
+    clear();
 }
 
 void SendCoinsEntry::setRemoveEnabled(bool enabled)
@@ -74,7 +82,7 @@ void SendCoinsEntry::clear()
     ui->addAsLabel->clear();
     ui->payAmount->clear();
     ui->payTo->setFocus();
-    if(model)
+    if(model && model->getOptionsModel())
     {
         ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
     }
@@ -147,3 +155,8 @@ bool SendCoinsEntry::isClear()
     return ui->payTo->text().isEmpty();
 }
 
+void SendCoinsEntry::setFocus()
+{
+    ui->payTo->setFocus();
+}
+