aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-06-02 17:48:45 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-06-02 17:56:51 +0200
commit44384a4602821216023ee63157ac6e376d1e9e10 (patch)
tree8820866d45114cdc0cec86fcde05a4fb80ff8317
parent5c94371f9a9bf41a5544403ee87ac331c2b0b1c3 (diff)
edit address dialog: basic data/widget binding
-rw-r--r--gui/include/addresstablemodel.h1
-rw-r--r--gui/include/editaddressdialog.h9
-rw-r--r--gui/src/addressbookdialog.cpp9
-rw-r--r--gui/src/addresstablemodel.cpp28
-rw-r--r--gui/src/editaddressdialog.cpp41
5 files changed, 84 insertions, 4 deletions
diff --git a/gui/include/addresstablemodel.h b/gui/include/addresstablemodel.h
index 6617bb3e89..f9ccab4eb6 100644
--- a/gui/include/addresstablemodel.h
+++ b/gui/include/addresstablemodel.h
@@ -28,6 +28,7 @@ public:
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
+ bool setData(const QModelIndex & index, const QVariant & value, int role);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex & parent) const;
diff --git a/gui/include/editaddressdialog.h b/gui/include/editaddressdialog.h
index 8e4a0388c2..3d8a5dcf8d 100644
--- a/gui/include/editaddressdialog.h
+++ b/gui/include/editaddressdialog.h
@@ -3,9 +3,14 @@
#include <QDialog>
+QT_BEGIN_NAMESPACE
+class QDataWidgetMapper;
+QT_END_NAMESPACE
+
namespace Ui {
class EditAddressDialog;
}
+class AddressTableModel;
class EditAddressDialog : public QDialog
{
@@ -22,8 +27,12 @@ public:
explicit EditAddressDialog(Mode mode, QWidget *parent = 0);
~EditAddressDialog();
+ void setModel(AddressTableModel *model);
+ void loadRow(int row);
+
private:
Ui::EditAddressDialog *ui;
+ QDataWidgetMapper *mapper;
};
#endif // EDITADDRESSDIALOG_H
diff --git a/gui/src/addressbookdialog.cpp b/gui/src/addressbookdialog.cpp
index 853da5852e..3f8e38152a 100644
--- a/gui/src/addressbookdialog.cpp
+++ b/gui/src/addressbookdialog.cpp
@@ -87,11 +87,19 @@ void AddressBookDialog::on_copyToClipboard_clicked()
void AddressBookDialog::on_editButton_clicked()
{
+ QModelIndexList indexes = getCurrentTable()->selectionModel()->selectedRows();
+ if(indexes.isEmpty())
+ {
+ return;
+ }
+
/* Double click also triggers edit button */
EditAddressDialog dlg(
ui->tabWidget->currentIndex() == SendingTab ?
EditAddressDialog::EditSendingAddress :
EditAddressDialog::EditReceivingAddress);
+ dlg.setModel(model);
+ dlg.loadRow(indexes.at(0).row());
dlg.exec();
}
@@ -101,6 +109,7 @@ void AddressBookDialog::on_newAddressButton_clicked()
ui->tabWidget->currentIndex() == SendingTab ?
EditAddressDialog::NewSendingAddress :
EditAddressDialog::NewReceivingAddress);
+ dlg.setModel(model);
dlg.exec();
}
diff --git a/gui/src/addresstablemodel.cpp b/gui/src/addresstablemodel.cpp
index c375ca7555..1cacd08fee 100644
--- a/gui/src/addresstablemodel.cpp
+++ b/gui/src/addresstablemodel.cpp
@@ -95,10 +95,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
- if(role == Qt::DisplayRole)
+ if(role == Qt::DisplayRole || role == Qt::EditRole)
{
- /* index.row(), index.column() */
- /* Return QString */
switch(index.column())
{
case Label:
@@ -126,6 +124,30 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+bool AddressTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
+{
+ if(!index.isValid())
+ return false;
+
+ if(role == Qt::EditRole)
+ {
+ switch(index.column())
+ {
+ case Label:
+ /* TODO */
+ break;
+ case Address:
+ /* TODO */
+ /* Double-check that we're not overwriting receiving address */
+ /* Note that changing address changes index in map */
+ break;
+ }
+ /* emit dataChanged(index, index); */
+ return true;
+ }
+ return false;
+}
+
QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal)
diff --git a/gui/src/editaddressdialog.cpp b/gui/src/editaddressdialog.cpp
index 0699b56321..6c0148d9d7 100644
--- a/gui/src/editaddressdialog.cpp
+++ b/gui/src/editaddressdialog.cpp
@@ -1,17 +1,56 @@
#include "editaddressdialog.h"
#include "ui_editaddressdialog.h"
+#include "addresstablemodel.h"
#include "guiutil.h"
+#include <QDataWidgetMapper>
+#include <QDebug>
+
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
QDialog(parent),
- ui(new Ui::EditAddressDialog)
+ ui(new Ui::EditAddressDialog), mapper(0)
{
ui->setupUi(this);
GUIUtil::setupAddressWidget(ui->addressEdit, this);
+
+ switch(mode)
+ {
+ case NewReceivingAddress:
+ setWindowTitle(tr("New receiving address"));
+ ui->addressEdit->setEnabled(false);
+ break;
+ case NewSendingAddress:
+ setWindowTitle(tr("New sending address"));
+ break;
+ case EditReceivingAddress:
+ setWindowTitle(tr("Edit receiving address"));
+ ui->addressEdit->setReadOnly(true);
+ break;
+ case EditSendingAddress:
+ setWindowTitle(tr("Edit sending address"));
+ break;
+ }
+
+ mapper = new QDataWidgetMapper(this);
+
}
EditAddressDialog::~EditAddressDialog()
{
delete ui;
}
+
+void EditAddressDialog::setModel(AddressTableModel *model)
+{
+ qDebug() << "setModel " << model;
+ mapper->setModel(model);
+ mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
+ mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
+}
+
+void EditAddressDialog::loadRow(int row)
+{
+ qDebug() << "loadRow " << row;
+ mapper->setCurrentIndex(row);
+}