ui improvements: allow inline editing of labels/addresses in address book table, better tab order in send dialog, set focus on sending address table when coming from send coins dialog

This commit is contained in:
Wladimir J. van der Laan 2011-07-02 17:31:27 +02:00
parent c1ffa5b1c5
commit 154e25ff60
5 changed files with 34 additions and 9 deletions

View File

@ -11,19 +11,16 @@
AddressBookDialog::AddressBookDialog(Mode mode, QWidget *parent) : AddressBookDialog::AddressBookDialog(Mode mode, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::AddressBookDialog), ui(new Ui::AddressBookDialog),
model(0) model(0),
mode(mode)
{ {
ui->setupUi(this); ui->setupUi(this);
switch(mode) switch(mode)
{ {
case ForSending: case ForSending:
connect(ui->receiveTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_buttonBox_accepted())); connect(ui->receiveTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_buttonBox_accepted()));
connect(ui->sendTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_buttonBox_accepted())); connect(ui->sendTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_buttonBox_accepted()));
break; ui->sendTableView->setFocus();
case ForEditing:
connect(ui->receiveTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_editButton_clicked()));
connect(ui->sendTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_editButton_clicked()));
break; break;
} }
} }
@ -66,6 +63,12 @@ void AddressBookDialog::setModel(AddressTableModel *model)
AddressTableModel::Address, 320); AddressTableModel::Address, 320);
ui->sendTableView->horizontalHeader()->setResizeMode( ui->sendTableView->horizontalHeader()->setResizeMode(
AddressTableModel::Label, QHeaderView::Stretch); AddressTableModel::Label, QHeaderView::Stretch);
if(mode == ForSending)
{
// Auto-select first row when in sending mode
ui->sendTableView->selectRow(0);
}
} }
void AddressBookDialog::setTab(int tab) void AddressBookDialog::setTab(int tab)

View File

@ -36,6 +36,7 @@ public:
private: private:
Ui::AddressBookDialog *ui; Ui::AddressBookDialog *ui;
AddressTableModel *model; AddressTableModel *model;
Mode mode;
QString returnValue; QString returnValue;
QTableView *getCurrentTable(); QTableView *getCurrentTable();

View File

@ -109,7 +109,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
switch(index.column()) switch(index.column())
{ {
case Label: case Label:
if(rec->label.isEmpty()) if(rec->label.isEmpty() && role == Qt::DisplayRole)
{ {
return tr("(no label)"); return tr("(no label)");
} }
@ -159,6 +159,9 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
rec->label = value.toString(); rec->label = value.toString();
break; break;
case Address: case Address:
// Refuse to set invalid address
if(!validateAddress(value.toString()))
return false;
// Double-check that we're not overwriting receiving address // Double-check that we're not overwriting receiving address
if(rec->type == AddressTableEntry::Sending) if(rec->type == AddressTableEntry::Sending)
{ {
@ -190,6 +193,23 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,
return QVariant(); 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 QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);

View File

@ -34,6 +34,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex & parent) const; QModelIndex index(int row, int column, const QModelIndex & parent) const;
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
Qt::ItemFlags flags(const QModelIndex & index) const;
/* Add an address to the model. /* Add an address to the model.
Returns the added address on success, and an empty string otherwise. Returns the added address on success, and an empty string otherwise.

View File

@ -227,10 +227,10 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>payTo</tabstop> <tabstop>payTo</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>addressBookButton</tabstop> <tabstop>addressBookButton</tabstop>
<tabstop>pasteButton</tabstop> <tabstop>pasteButton</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>sendButton</tabstop> <tabstop>sendButton</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
</tabstops> </tabstops>