AddressBookDialog::AddressBookDialog(Mode mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddressBookDialog),
- model(0)
+ model(0),
+ mode(mode)
{
ui->setupUi(this);
-
switch(mode)
{
case ForSending:
connect(ui->receiveTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_buttonBox_accepted()));
connect(ui->sendTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_buttonBox_accepted()));
- break;
- case ForEditing:
- connect(ui->receiveTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_editButton_clicked()));
- connect(ui->sendTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_editButton_clicked()));
+ ui->sendTableView->setFocus();
break;
}
}
AddressTableModel::Address, 320);
ui->sendTableView->horizontalHeader()->setResizeMode(
AddressTableModel::Label, QHeaderView::Stretch);
+
+ if(mode == ForSending)
+ {
+ // Auto-select first row when in sending mode
+ ui->sendTableView->selectRow(0);
+ }
}
void AddressBookDialog::setTab(int tab)
private:
Ui::AddressBookDialog *ui;
AddressTableModel *model;
+ Mode mode;
QString returnValue;
QTableView *getCurrentTable();
switch(index.column())
{
case Label:
- if(rec->label.isEmpty())
+ if(rec->label.isEmpty() && role == Qt::DisplayRole)
{
return tr("(no label)");
}
rec->label = value.toString();
break;
case Address:
+ // Refuse to set invalid address
+ if(!validateAddress(value.toString()))
+ return false;
// Double-check that we're not overwriting receiving address
if(rec->type == AddressTableEntry::Sending)
{
return QVariant();
}
+Qt::ItemFlags AddressTableModel::flags(const QModelIndex & index) const
+{
+ if(!index.isValid())
+ return 0;
+ AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
+
+ Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
+ // Can edit address and label for sending addresses,
+ // and only label for receiving addresses.
+ if(rec->type == AddressTableEntry::Sending ||
+ (rec->type == AddressTableEntry::Receiving && index.column()==Label))
+ {
+ retval |= Qt::ItemIsEditable;
+ }
+ return retval;
+}
+
QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & parent) const
{
Q_UNUSED(parent);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex & parent) const;
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
+ Qt::ItemFlags flags(const QModelIndex & index) const;
/* Add an address to the model.
Returns the added address on success, and an empty string otherwise.
</customwidgets>
<tabstops>
<tabstop>payTo</tabstop>
- <tabstop>addAsLabel</tabstop>
- <tabstop>payAmount</tabstop>
<tabstop>addressBookButton</tabstop>
<tabstop>pasteButton</tabstop>
+ <tabstop>addAsLabel</tabstop>
+ <tabstop>payAmount</tabstop>
<tabstop>sendButton</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>