Browse Source

WIP: started to show namespace content. TODO: why only one row?

kevaview
Just Wonder 5 years ago
parent
commit
8ec4dfa663
  1. 2
      src/Makefile.qt.include
  2. 10
      src/qt/forms/kevadialog.ui
  3. 84
      src/qt/kevadialog.cpp
  4. 8
      src/qt/kevadialog.h
  5. 166
      src/qt/kevatablemodel.cpp
  6. 89
      src/qt/kevatablemodel.h
  7. 28
      src/qt/walletmodel.cpp
  8. 7
      src/qt/walletmodel.h

2
src/Makefile.qt.include

@ -174,6 +174,7 @@ QT_MOC_CPP = \
qt/moc_receivecoinsdialog.cpp \ qt/moc_receivecoinsdialog.cpp \
qt/moc_receiverequestdialog.cpp \ qt/moc_receiverequestdialog.cpp \
qt/moc_recentrequeststablemodel.cpp \ qt/moc_recentrequeststablemodel.cpp \
qt/moc_kevatablemodel.cpp \
qt/moc_rpcconsole.cpp \ qt/moc_rpcconsole.cpp \
qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsdialog.cpp \
qt/moc_sendcoinsentry.cpp \ qt/moc_sendcoinsentry.cpp \
@ -377,6 +378,7 @@ BITCOIN_QT_WALLET_CPP = \
qt/transactiontablemodel.cpp \ qt/transactiontablemodel.cpp \
qt/transactionview.cpp \ qt/transactionview.cpp \
qt/kevadialog.cpp \ qt/kevadialog.cpp \
qt/kevatablemodel.cpp \
qt/walletframe.cpp \ qt/walletframe.cpp \
qt/walletmodel.cpp \ qt/walletmodel.cpp \
qt/walletmodeltransaction.cpp \ qt/walletmodeltransaction.cpp \

10
src/qt/forms/kevadialog.ui

@ -29,9 +29,9 @@
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="4" column="2"> <item row="4" column="2">
<widget class="QLineEdit" name="reqLabel"> <widget class="QLineEdit" name="nameSpace">
<property name="toolTip"> <property name="toolTip">
<string>An optional label to associate with the new receiving address.</string> <string>The namespace ID with a prefix "N".</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -45,7 +45,7 @@
<item row="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="toolTip"> <property name="toolTip">
<string>The namespace ID, which has a prefix "N".</string> <string>The namespace ID with a prefix "N".</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Namespace:</string> <string>&amp;Namespace:</string>
@ -54,14 +54,14 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>reqLabel</cstring> <cstring>namespace</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="2"> <item row="7" column="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QPushButton" name="clearButton"> <widget class="QPushButton" name="showContent">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>

84
src/qt/kevadialog.cpp

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <wallet/wallet.h> #include <wallet/wallet.h>
#include <keva/common.h>
#include <qt/kevadialog.h> #include <qt/kevadialog.h>
#include <qt/forms/ui_kevadialog.h> #include <qt/forms/ui_kevadialog.h>
@ -13,7 +14,7 @@
#include <qt/optionsmodel.h> #include <qt/optionsmodel.h>
#include <qt/platformstyle.h> #include <qt/platformstyle.h>
#include <qt/receiverequestdialog.h> #include <qt/receiverequestdialog.h>
#include <qt/recentrequeststablemodel.h> #include <qt/kevatablemodel.h>
#include <qt/walletmodel.h> #include <qt/walletmodel.h>
#include <QAction> #include <QAction>
@ -32,12 +33,10 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
if (!_platformStyle->getImagesOnButtons()) { if (!_platformStyle->getImagesOnButtons()) {
ui->clearButton->setIcon(QIcon());
ui->receiveButton->setIcon(QIcon()); ui->receiveButton->setIcon(QIcon());
ui->showRequestButton->setIcon(QIcon()); ui->showRequestButton->setIcon(QIcon());
ui->removeRequestButton->setIcon(QIcon()); ui->removeRequestButton->setIcon(QIcon());
} else { } else {
ui->clearButton->setIcon(_platformStyle->SingleColorIcon(":/icons/eye"));
ui->receiveButton->setIcon(_platformStyle->SingleColorIcon(":/icons/address-book")); ui->receiveButton->setIcon(_platformStyle->SingleColorIcon(":/icons/address-book"));
ui->showRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit")); ui->showRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit"));
ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove")); ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
@ -63,7 +62,6 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage())); connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount())); connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
} }
void KevaDialog::setModel(WalletModel *_model) void KevaDialog::setModel(WalletModel *_model)
@ -72,27 +70,24 @@ void KevaDialog::setModel(WalletModel *_model)
if(_model && _model->getOptionsModel()) if(_model && _model->getOptionsModel())
{ {
_model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder); _model->getKevaTableModel()->sort(KevaTableModel::Date, Qt::DescendingOrder);
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
updateDisplayUnit();
QTableView* tableView = ui->recentRequestsView; QTableView* tableView = ui->recentRequestsView;
tableView->verticalHeader()->hide(); tableView->verticalHeader()->hide();
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tableView->setModel(_model->getRecentRequestsTableModel()); tableView->setModel(_model->getKevaTableModel());
tableView->setAlternatingRowColors(true); tableView->setAlternatingRowColors(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows); tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection); tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH); tableView->setColumnWidth(KevaTableModel::Date, DATE_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH); tableView->setColumnWidth(KevaTableModel::Key, KEY_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); tableView->setColumnWidth(KevaTableModel::Block, BLOCK_MINIMUM_COLUMN_WIDTH);
connect(tableView->selectionModel(), connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection))); SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready. // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this); columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, BLOCK_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);
} }
} }
@ -103,7 +98,7 @@ KevaDialog::~KevaDialog()
void KevaDialog::clear() void KevaDialog::clear()
{ {
ui->reqLabel->setText(""); ui->nameSpace->setText("");
updateDisplayUnit(); updateDisplayUnit();
} }
@ -124,40 +119,29 @@ void KevaDialog::updateDisplayUnit()
} }
} }
void KevaDialog::on_receiveButton_clicked() void KevaDialog::on_showContent_clicked()
{ {
if(!model || !model->getOptionsModel() || !model->getAddressTableModel() || !model->getRecentRequestsTableModel()) if(!model || !model->getKevaTableModel())
return; return;
QString address; valtype namespaceVal;
QString label = ui->reqLabel->text(); QString nameSpace = ui->nameSpace->text();
/* Generate new receiving address */ if (!DecodeKevaNamespace(nameSpace.toStdString(), Params(), namespaceVal)) {
OutputType address_type; // TODO: show error dialog
address_type = model->getDefaultAddressType(); return;
if (address_type == OUTPUT_TYPE_BECH32) {
address_type = OUTPUT_TYPE_P2SH_SEGWIT;
} }
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type); std::vector<KevaEntry> vKevaEntries;
SendCoinsRecipient info(address, label, model->getKevaEntries(vKevaEntries, ValtypeToString(namespaceVal));
NULL, NULL); model->getKevaTableModel()->setKeva(vKevaEntries);
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModel(model->getOptionsModel());
dialog->setInfo(info);
dialog->show();
clear();
/* Store request for later reference */
model->getRecentRequestsTableModel()->addNewRequest(info);
} }
void KevaDialog::on_recentRequestsView_doubleClicked(const QModelIndex &index) void KevaDialog::on_recentRequestsView_doubleClicked(const QModelIndex &index)
{ {
const RecentRequestsTableModel *submodel = model->getRecentRequestsTableModel(); const KevaTableModel *submodel = model->getKevaTableModel();
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setModel(model->getOptionsModel()); dialog->setModel(model->getOptionsModel());
dialog->setInfo(submodel->entry(index.row()).recipient); //dialog->setInfo(submodel->entry(index.row()).recipient);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show(); dialog->show();
} }
@ -172,7 +156,7 @@ void KevaDialog::recentRequestsView_selectionChanged(const QItemSelection &selec
void KevaDialog::on_showRequestButton_clicked() void KevaDialog::on_showRequestButton_clicked()
{ {
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel()) if(!model || !model->getKevaTableModel() || !ui->recentRequestsView->selectionModel())
return; return;
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows(); QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
@ -183,14 +167,14 @@ void KevaDialog::on_showRequestButton_clicked()
void KevaDialog::on_removeRequestButton_clicked() void KevaDialog::on_removeRequestButton_clicked()
{ {
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel()) if(!model || !model->getKevaTableModel() || !ui->recentRequestsView->selectionModel())
return; return;
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows(); QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
if(selection.empty()) if(selection.empty())
return; return;
// correct for selection mode ContiguousSelection // correct for selection mode ContiguousSelection
QModelIndex firstIndex = selection.at(0); QModelIndex firstIndex = selection.at(0);
model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent()); model->getKevaTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
} }
// We override the virtual resizeEvent of the QWidget to adjust tables column // We override the virtual resizeEvent of the QWidget to adjust tables column
@ -198,7 +182,7 @@ void KevaDialog::on_removeRequestButton_clicked()
void KevaDialog::resizeEvent(QResizeEvent *event) void KevaDialog::resizeEvent(QResizeEvent *event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
columnResizingFixer->stretchColumnWidth(RecentRequestsTableModel::Message); columnResizingFixer->stretchColumnWidth(KevaTableModel::Block);
} }
void KevaDialog::keyPressEvent(QKeyEvent *event) void KevaDialog::keyPressEvent(QKeyEvent *event)
@ -206,10 +190,10 @@ void KevaDialog::keyPressEvent(QKeyEvent *event)
if (event->key() == Qt::Key_Return) if (event->key() == Qt::Key_Return)
{ {
// press return -> submit form // press return -> submit form
if (ui->reqLabel->hasFocus()) if (ui->nameSpace->hasFocus())
{ {
event->ignore(); event->ignore();
on_receiveButton_clicked(); on_showContent_clicked();
return; return;
} }
} }
@ -219,7 +203,7 @@ void KevaDialog::keyPressEvent(QKeyEvent *event)
QModelIndex KevaDialog::selectedRow() QModelIndex KevaDialog::selectedRow()
{ {
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel()) if(!model || !model->getKevaTableModel() || !ui->recentRequestsView->selectionModel())
return QModelIndex(); return QModelIndex();
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows(); QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
if(selection.empty()) if(selection.empty())
@ -236,7 +220,7 @@ void KevaDialog::copyColumnToClipboard(int column)
if (!firstIndex.isValid()) { if (!firstIndex.isValid()) {
return; return;
} }
GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString()); GUIUtil::setClipboard(model->getKevaTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
} }
// context menu // context menu
@ -251,30 +235,32 @@ void KevaDialog::showMenu(const QPoint &point)
// context menu action: copy URI // context menu action: copy URI
void KevaDialog::copyURI() void KevaDialog::copyURI()
{ {
#if 0
QModelIndex sel = selectedRow(); QModelIndex sel = selectedRow();
if (!sel.isValid()) { if (!sel.isValid()) {
return; return;
} }
const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel(); const KevaTableModel * const submodel = model->getKevaTableModel();
const QString uri = GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient); const QString uri = GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
GUIUtil::setClipboard(uri); GUIUtil::setClipboard(uri);
#endif
} }
// context menu action: copy label // context menu action: copy label
void KevaDialog::copyLabel() void KevaDialog::copyLabel()
{ {
copyColumnToClipboard(RecentRequestsTableModel::Label); copyColumnToClipboard(KevaTableModel::Key);
} }
// context menu action: copy message // context menu action: copy message
void KevaDialog::copyMessage() void KevaDialog::copyMessage()
{ {
copyColumnToClipboard(RecentRequestsTableModel::Message); copyColumnToClipboard(KevaTableModel::Value);
} }
// context menu action: copy amount // context menu action: copy amount
void KevaDialog::copyAmount() void KevaDialog::copyAmount()
{ {
copyColumnToClipboard(RecentRequestsTableModel::Amount); copyColumnToClipboard(KevaTableModel::Block);
} }

8
src/qt/kevadialog.h

@ -34,9 +34,9 @@ class KevaDialog : public QDialog
public: public:
enum ColumnWidths { enum ColumnWidths {
DATE_COLUMN_WIDTH = 130, DATE_COLUMN_WIDTH = 130,
LABEL_COLUMN_WIDTH = 120, KEY_COLUMN_WIDTH = 120,
AMOUNT_MINIMUM_COLUMN_WIDTH = 180, BLOCK_MINIMUM_COLUMN_WIDTH = 100,
MINIMUM_COLUMN_WIDTH = 130 MINIMUM_COLUMN_WIDTH = 100
}; };
explicit KevaDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); explicit KevaDialog(const PlatformStyle *platformStyle, QWidget *parent = 0);
@ -64,7 +64,7 @@ private:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
private Q_SLOTS: private Q_SLOTS:
void on_receiveButton_clicked(); void on_showContent_clicked();
void on_showRequestButton_clicked(); void on_showRequestButton_clicked();
void on_removeRequestButton_clicked(); void on_removeRequestButton_clicked();
void on_recentRequestsView_doubleClicked(const QModelIndex &index); void on_recentRequestsView_doubleClicked(const QModelIndex &index);

166
src/qt/kevatablemodel.cpp

@ -0,0 +1,166 @@
// Copyright (c) 2011-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/kevatablemodel.h>
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <clientversion.h>
#include <streams.h>
KevaTableModel::KevaTableModel(CWallet *wallet, WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent)
{
Q_UNUSED(wallet)
/* These columns must match the indices in the ColumnIndex enumeration */
columns << tr("Date") << tr("Key") << tr("Value") << tr("Block");
// TODO: display new keva entry when it arrives.
// connect(walletModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
}
KevaTableModel::~KevaTableModel()
{
/* Intentionally left empty */
}
int KevaTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return list.length();
}
int KevaTableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return columns.length();
}
QVariant KevaTableModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid() || index.row() >= list.length())
return QVariant();
if(role == Qt::DisplayRole || role == Qt::EditRole)
{
const KevaEntry *rec = &list[index.row()];
switch(index.column())
{
case Date:
return GUIUtil::dateTimeStr(rec->date);
case Key:
return QString::fromStdString(rec->key);
case Value:
return QString::fromStdString(rec->value);
case Block:
return QString::number(rec->block);
}
}
else if (role == Qt::TextAlignmentRole)
{
if (index.column() == Block)
return (int)(Qt::AlignRight|Qt::AlignVCenter);
}
return QVariant();
}
bool KevaTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
return true;
}
QVariant KevaTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal)
{
if(role == Qt::DisplayRole && section < columns.size())
{
return columns[section];
}
}
return QVariant();
}
/** Gets title for amount column including current display unit if optionsModel reference available. */
QString KevaTableModel::getAmountTitle()
{
return (this->walletModel->getOptionsModel() != nullptr) ? tr("Requested") + " ("+BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) + ")" : "";
}
QModelIndex KevaTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
return createIndex(row, column);
}
bool KevaTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(parent);
if(count > 0 && row >= 0 && (row+count) <= list.size())
{
beginRemoveRows(parent, row, row + count - 1);
list.erase(list.begin() + row, list.begin() + row + count);
endRemoveRows();
return true;
} else {
return false;
}
}
Qt::ItemFlags KevaTableModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
// actually add to table in GUI
void KevaTableModel::setKeva(std::vector<KevaEntry>& vKevaEntries)
{
list.clear();
beginInsertRows(QModelIndex(), 0, 0);
for (auto it = vKevaEntries.begin(); it != vKevaEntries.end(); it++) {
list.prepend(*it);
}
endInsertRows();
}
void KevaTableModel::sort(int column, Qt::SortOrder order)
{
qSort(list.begin(), list.end(), KevaEntryLessThan(column, order));
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex()));
}
void KevaTableModel::updateDisplayUnit()
{
}
bool KevaEntryLessThan::operator()(KevaEntry &left, KevaEntry &right) const
{
KevaEntry *pLeft = &left;
KevaEntry *pRight = &right;
if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight);
switch(column)
{
case KevaTableModel::Date:
return pLeft->date.toTime_t() < pRight->date.toTime_t();
case KevaTableModel::Block:
return pLeft->block < pRight->block;
case KevaTableModel::Key:
return pLeft->key < pRight->key;
case KevaTableModel::Value:
return pLeft->value < pRight->value;
default:
return pLeft->date.toTime_t() < pRight->date.toTime_t();
}
}

89
src/qt/kevatablemodel.h

@ -0,0 +1,89 @@
// Copyright (c) 2011-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_KEVATABLEMODEL_H
#define BITCOIN_QT_KEVATABLEMODEL_H
#include <qt/walletmodel.h>
#include <QAbstractTableModel>
#include <QStringList>
#include <QDateTime>
class CWallet;
class KevaEntry
{
public:
KevaEntry() { }
std::string key;
std::string value;
int64_t block;
QDateTime date;
};
class KevaEntryLessThan
{
public:
KevaEntryLessThan(int nColumn, Qt::SortOrder fOrder):
column(nColumn), order(fOrder) {}
bool operator()(KevaEntry &left, KevaEntry &right) const;
private:
int column;
Qt::SortOrder order;
};
/** Model for list of recently generated payment requests / bitcoin: URIs.
* Part of wallet model.
*/
class KevaTableModel: public QAbstractTableModel
{
Q_OBJECT
public:
explicit KevaTableModel(CWallet *wallet, WalletModel *parent);
~KevaTableModel();
enum ColumnIndex {
Date = 0,
Key = 1,
Value = 2,
Block = 3,
NUMBER_OF_COLUMNS
};
/** @name Methods overridden from QAbstractTableModel
@{*/
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;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
Qt::ItemFlags flags(const QModelIndex &index) const;
/*@}*/
const KevaEntry &entry(int row) const { return list[row]; }
void setKeva(std::vector<KevaEntry>& vKevaEntries);
public Q_SLOTS:
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
void updateDisplayUnit();
private:
WalletModel *walletModel;
QStringList columns;
QList<KevaEntry> list;
int64_t nReceiveRequestsMaxId;
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
void updateAmountColumnTitle();
/** Gets title for amount column including current display unit if optionsModel reference available. */
QString getAmountTitle();
};
#endif // BITCOIN_QT_KEVATABLEMODEL_H

28
src/qt/walletmodel.cpp

@ -11,12 +11,15 @@
#include <qt/optionsmodel.h> #include <qt/optionsmodel.h>
#include <qt/paymentserver.h> #include <qt/paymentserver.h>
#include <qt/recentrequeststablemodel.h> #include <qt/recentrequeststablemodel.h>
#include <qt/kevatablemodel.h>
#include <qt/sendcoinsdialog.h> #include <qt/sendcoinsdialog.h>
#include <qt/transactiontablemodel.h> #include <qt/transactiontablemodel.h>
#include <base58.h> #include <base58.h>
#include <chain.h> #include <chain.h>
#include <keystore.h> #include <keystore.h>
#include <keva/common.h>
#include <keva/main.h>
#include <validation.h> #include <validation.h>
#include <net.h> // for g_connman #include <net.h> // for g_connman
#include <policy/fees.h> #include <policy/fees.h>
@ -41,6 +44,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O
QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0), QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
transactionTableModel(0), transactionTableModel(0),
recentRequestsTableModel(0), recentRequestsTableModel(0),
kevaTableModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0), cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
cachedEncryptionStatus(Unencrypted), cachedEncryptionStatus(Unencrypted),
cachedNumBlocks(0) cachedNumBlocks(0)
@ -51,6 +55,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O
addressTableModel = new AddressTableModel(wallet, this); addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(platformStyle, wallet, this); transactionTableModel = new TransactionTableModel(platformStyle, wallet, this);
recentRequestsTableModel = new RecentRequestsTableModel(wallet, this); recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
kevaTableModel = new KevaTableModel(wallet, this);
// This timer will be fired repeatedly to update the balance // This timer will be fired repeatedly to update the balance
pollTimer = new QTimer(this); pollTimer = new QTimer(this);
@ -393,6 +398,11 @@ RecentRequestsTableModel *WalletModel::getRecentRequestsTableModel()
return recentRequestsTableModel; return recentRequestsTableModel;
} }
KevaTableModel *WalletModel::getKevaTableModel()
{
return kevaTableModel;
}
WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
{ {
if(!wallet->IsCrypted()) if(!wallet->IsCrypted())
@ -743,3 +753,21 @@ int WalletModel::getDefaultConfirmTarget() const
{ {
return nTxConfirmTarget; return nTxConfirmTarget;
} }
void WalletModel::getKevaEntries(std::vector<KevaEntry>& vKevaEntries, std::string nameSpace)
{
LOCK(cs_main);
valtype key;
CKevaData data;
std::unique_ptr<CKevaIterator> iter(pcoinsTip->IterateKeys(ValtypeFromString(nameSpace)));
while (iter->next(key, data)) {
KevaEntry entry;
entry.key = ValtypeToString(key);
entry.value = ValtypeToString(data.getValue());
entry.block = data.getHeight();
// TODO: figure out how to get the date time from block.
entry.date = QDateTime::currentDateTime();
vKevaEntries.push_back(std::move(entry));
}
}

7
src/qt/walletmodel.h

@ -21,6 +21,8 @@ class AddressTableModel;
class OptionsModel; class OptionsModel;
class PlatformStyle; class PlatformStyle;
class RecentRequestsTableModel; class RecentRequestsTableModel;
class KevaTableModel;
class KevaEntry;
class TransactionTableModel; class TransactionTableModel;
class WalletModelTransaction; class WalletModelTransaction;
@ -130,6 +132,7 @@ public:
AddressTableModel *getAddressTableModel(); AddressTableModel *getAddressTableModel();
TransactionTableModel *getTransactionTableModel(); TransactionTableModel *getTransactionTableModel();
RecentRequestsTableModel *getRecentRequestsTableModel(); RecentRequestsTableModel *getRecentRequestsTableModel();
KevaTableModel *getKevaTableModel();
CAmount getBalance(const CCoinControl *coinControl = nullptr) const; CAmount getBalance(const CCoinControl *coinControl = nullptr) const;
CAmount getUnconfirmedBalance() const; CAmount getUnconfirmedBalance() const;
@ -220,6 +223,9 @@ public:
int getDefaultConfirmTarget() const; int getDefaultConfirmTarget() const;
// Keva
void getKevaEntries(std::vector<KevaEntry>& vKevaEntries, std::string nameSpace);
private: private:
CWallet *wallet; CWallet *wallet;
bool fHaveWatchOnly; bool fHaveWatchOnly;
@ -232,6 +238,7 @@ private:
AddressTableModel *addressTableModel; AddressTableModel *addressTableModel;
TransactionTableModel *transactionTableModel; TransactionTableModel *transactionTableModel;
RecentRequestsTableModel *recentRequestsTableModel; RecentRequestsTableModel *recentRequestsTableModel;
KevaTableModel *kevaTableModel;
// Cache some values to be able to detect changes // Cache some values to be able to detect changes
CAmount cachedBalance; CAmount cachedBalance;

Loading…
Cancel
Save