From: Wladimir J. van der Laan Date: Sat, 2 Jul 2011 15:31:27 +0000 (+0200) Subject: ui improvements: allow inline editing of labels/addresses in address book table,... X-Git-Tag: v0.4.0-unstable~226^2~57^2~173 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=154e25ff60115b9ff286b97ffc87d65736593c86 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 --- diff --git a/src/qt/addressbookdialog.cpp b/src/qt/addressbookdialog.cpp index 5eb60b7..5a744ae 100644 --- a/src/qt/addressbookdialog.cpp +++ b/src/qt/addressbookdialog.cpp @@ -11,19 +11,16 @@ 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; } } @@ -66,6 +63,12 @@ void AddressBookDialog::setModel(AddressTableModel *model) 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) diff --git a/src/qt/addressbookdialog.h b/src/qt/addressbookdialog.h index 25b8839..b032e55 100644 --- a/src/qt/addressbookdialog.h +++ b/src/qt/addressbookdialog.h @@ -36,6 +36,7 @@ public: private: Ui::AddressBookDialog *ui; AddressTableModel *model; + Mode mode; QString returnValue; QTableView *getCurrentTable(); diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 6829fea..e375ff8 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -109,7 +109,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const switch(index.column()) { case Label: - if(rec->label.isEmpty()) + if(rec->label.isEmpty() && role == Qt::DisplayRole) { return tr("(no label)"); } @@ -159,6 +159,9 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu 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) { @@ -190,6 +193,23 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } +Qt::ItemFlags AddressTableModel::flags(const QModelIndex & index) const +{ + if(!index.isValid()) + return 0; + AddressTableEntry *rec = static_cast(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); diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index b509481..6f34a60 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -34,6 +34,7 @@ public: 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. diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index 73a42b6..26de3d2 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -227,10 +227,10 @@ payTo - addAsLabel - payAmount addressBookButton pasteButton + addAsLabel + payAmount sendButton buttonBox