Browse Source

edit address dialog: basic data/widget binding

pull/1/head
Wladimir J. van der Laan 12 years ago
parent
commit
44384a4602
  1. 1
      gui/include/addresstablemodel.h
  2. 9
      gui/include/editaddressdialog.h
  3. 9
      gui/src/addressbookdialog.cpp
  4. 28
      gui/src/addresstablemodel.cpp
  5. 41
      gui/src/editaddressdialog.cpp

1
gui/include/addresstablemodel.h

@ -28,6 +28,7 @@ public: @@ -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;

9
gui/include/editaddressdialog.h

@ -3,9 +3,14 @@ @@ -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: @@ -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

9
gui/src/addressbookdialog.cpp

@ -87,11 +87,19 @@ void AddressBookDialog::on_copyToClipboard_clicked() @@ -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() @@ -101,6 +109,7 @@ void AddressBookDialog::on_newAddressButton_clicked()
ui->tabWidget->currentIndex() == SendingTab ?
EditAddressDialog::NewSendingAddress :
EditAddressDialog::NewReceivingAddress);
dlg.setModel(model);
dlg.exec();
}

28
gui/src/addresstablemodel.cpp

@ -95,10 +95,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const @@ -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 @@ -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)

41
gui/src/editaddressdialog.cpp

@ -1,17 +1,56 @@ @@ -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);
}

Loading…
Cancel
Save