mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
edit address dialog: basic data/widget binding
This commit is contained in:
parent
5c94371f9a
commit
44384a4602
@ -28,6 +28,7 @@ public:
|
|||||||
int rowCount(const QModelIndex &parent) const;
|
int rowCount(const QModelIndex &parent) const;
|
||||||
int columnCount(const QModelIndex &parent) const;
|
int columnCount(const QModelIndex &parent) const;
|
||||||
QVariant data(const QModelIndex &index, int role) 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;
|
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;
|
||||||
|
|
||||||
|
@ -3,9 +3,14 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QDataWidgetMapper;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class EditAddressDialog;
|
class EditAddressDialog;
|
||||||
}
|
}
|
||||||
|
class AddressTableModel;
|
||||||
|
|
||||||
class EditAddressDialog : public QDialog
|
class EditAddressDialog : public QDialog
|
||||||
{
|
{
|
||||||
@ -22,8 +27,12 @@ public:
|
|||||||
explicit EditAddressDialog(Mode mode, QWidget *parent = 0);
|
explicit EditAddressDialog(Mode mode, QWidget *parent = 0);
|
||||||
~EditAddressDialog();
|
~EditAddressDialog();
|
||||||
|
|
||||||
|
void setModel(AddressTableModel *model);
|
||||||
|
void loadRow(int row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::EditAddressDialog *ui;
|
Ui::EditAddressDialog *ui;
|
||||||
|
QDataWidgetMapper *mapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EDITADDRESSDIALOG_H
|
#endif // EDITADDRESSDIALOG_H
|
||||||
|
@ -87,11 +87,19 @@ void AddressBookDialog::on_copyToClipboard_clicked()
|
|||||||
|
|
||||||
void AddressBookDialog::on_editButton_clicked()
|
void AddressBookDialog::on_editButton_clicked()
|
||||||
{
|
{
|
||||||
|
QModelIndexList indexes = getCurrentTable()->selectionModel()->selectedRows();
|
||||||
|
if(indexes.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Double click also triggers edit button */
|
/* Double click also triggers edit button */
|
||||||
EditAddressDialog dlg(
|
EditAddressDialog dlg(
|
||||||
ui->tabWidget->currentIndex() == SendingTab ?
|
ui->tabWidget->currentIndex() == SendingTab ?
|
||||||
EditAddressDialog::EditSendingAddress :
|
EditAddressDialog::EditSendingAddress :
|
||||||
EditAddressDialog::EditReceivingAddress);
|
EditAddressDialog::EditReceivingAddress);
|
||||||
|
dlg.setModel(model);
|
||||||
|
dlg.loadRow(indexes.at(0).row());
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +109,7 @@ void AddressBookDialog::on_newAddressButton_clicked()
|
|||||||
ui->tabWidget->currentIndex() == SendingTab ?
|
ui->tabWidget->currentIndex() == SendingTab ?
|
||||||
EditAddressDialog::NewSendingAddress :
|
EditAddressDialog::NewSendingAddress :
|
||||||
EditAddressDialog::NewReceivingAddress);
|
EditAddressDialog::NewReceivingAddress);
|
||||||
|
dlg.setModel(model);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,10 +95,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
|
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())
|
switch(index.column())
|
||||||
{
|
{
|
||||||
case Label:
|
case Label:
|
||||||
@ -126,6 +124,30 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
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
|
QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if(orientation == Qt::Horizontal)
|
if(orientation == Qt::Horizontal)
|
||||||
|
@ -1,17 +1,56 @@
|
|||||||
#include "editaddressdialog.h"
|
#include "editaddressdialog.h"
|
||||||
#include "ui_editaddressdialog.h"
|
#include "ui_editaddressdialog.h"
|
||||||
|
#include "addresstablemodel.h"
|
||||||
#include "guiutil.h"
|
#include "guiutil.h"
|
||||||
|
|
||||||
|
#include <QDataWidgetMapper>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::EditAddressDialog)
|
ui(new Ui::EditAddressDialog), mapper(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
GUIUtil::setupAddressWidget(ui->addressEdit, 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()
|
EditAddressDialog::~EditAddressDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
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…
Reference in New Issue
Block a user