mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-03-13 06:01:45 +00:00
WIP: started to show namespace content. TODO: why only one row?
This commit is contained in:
parent
2b406c1ae8
commit
8ec4dfa663
@ -174,6 +174,7 @@ QT_MOC_CPP = \
|
||||
qt/moc_receivecoinsdialog.cpp \
|
||||
qt/moc_receiverequestdialog.cpp \
|
||||
qt/moc_recentrequeststablemodel.cpp \
|
||||
qt/moc_kevatablemodel.cpp \
|
||||
qt/moc_rpcconsole.cpp \
|
||||
qt/moc_sendcoinsdialog.cpp \
|
||||
qt/moc_sendcoinsentry.cpp \
|
||||
@ -377,6 +378,7 @@ BITCOIN_QT_WALLET_CPP = \
|
||||
qt/transactiontablemodel.cpp \
|
||||
qt/transactionview.cpp \
|
||||
qt/kevadialog.cpp \
|
||||
qt/kevatablemodel.cpp \
|
||||
qt/walletframe.cpp \
|
||||
qt/walletmodel.cpp \
|
||||
qt/walletmodeltransaction.cpp \
|
||||
|
@ -29,9 +29,9 @@
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="2">
|
||||
<widget class="QLineEdit" name="reqLabel">
|
||||
<widget class="QLineEdit" name="nameSpace">
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
@ -45,7 +45,7 @@
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="toolTip">
|
||||
<string>The namespace ID, which has a prefix "N".</string>
|
||||
<string>The namespace ID with a prefix "N".</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Namespace:</string>
|
||||
@ -54,14 +54,14 @@
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>reqLabel</cstring>
|
||||
<cstring>namespace</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="clearButton">
|
||||
<widget class="QPushButton" name="showContent">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <wallet/wallet.h>
|
||||
#include <keva/common.h>
|
||||
|
||||
#include <qt/kevadialog.h>
|
||||
#include <qt/forms/ui_kevadialog.h>
|
||||
@ -13,7 +14,7 @@
|
||||
#include <qt/optionsmodel.h>
|
||||
#include <qt/platformstyle.h>
|
||||
#include <qt/receiverequestdialog.h>
|
||||
#include <qt/recentrequeststablemodel.h>
|
||||
#include <qt/kevatablemodel.h>
|
||||
#include <qt/walletmodel.h>
|
||||
|
||||
#include <QAction>
|
||||
@ -32,12 +33,10 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
|
||||
ui->setupUi(this);
|
||||
|
||||
if (!_platformStyle->getImagesOnButtons()) {
|
||||
ui->clearButton->setIcon(QIcon());
|
||||
ui->receiveButton->setIcon(QIcon());
|
||||
ui->showRequestButton->setIcon(QIcon());
|
||||
ui->removeRequestButton->setIcon(QIcon());
|
||||
} else {
|
||||
ui->clearButton->setIcon(_platformStyle->SingleColorIcon(":/icons/eye"));
|
||||
ui->receiveButton->setIcon(_platformStyle->SingleColorIcon(":/icons/address-book"));
|
||||
ui->showRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit"));
|
||||
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(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
|
||||
|
||||
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
||||
}
|
||||
|
||||
void KevaDialog::setModel(WalletModel *_model)
|
||||
@ -72,27 +70,24 @@ void KevaDialog::setModel(WalletModel *_model)
|
||||
|
||||
if(_model && _model->getOptionsModel())
|
||||
{
|
||||
_model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
|
||||
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
||||
updateDisplayUnit();
|
||||
|
||||
_model->getKevaTableModel()->sort(KevaTableModel::Date, Qt::DescendingOrder);
|
||||
QTableView* tableView = ui->recentRequestsView;
|
||||
|
||||
tableView->verticalHeader()->hide();
|
||||
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
tableView->setModel(_model->getRecentRequestsTableModel());
|
||||
tableView->setModel(_model->getKevaTableModel());
|
||||
tableView->setAlternatingRowColors(true);
|
||||
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
||||
tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
|
||||
tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
|
||||
tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
|
||||
tableView->setColumnWidth(KevaTableModel::Date, DATE_COLUMN_WIDTH);
|
||||
tableView->setColumnWidth(KevaTableModel::Key, KEY_COLUMN_WIDTH);
|
||||
tableView->setColumnWidth(KevaTableModel::Block, BLOCK_MINIMUM_COLUMN_WIDTH);
|
||||
|
||||
connect(tableView->selectionModel(),
|
||||
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
|
||||
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
|
||||
// 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()
|
||||
{
|
||||
ui->reqLabel->setText("");
|
||||
ui->nameSpace->setText("");
|
||||
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;
|
||||
|
||||
QString address;
|
||||
QString label = ui->reqLabel->text();
|
||||
/* Generate new receiving address */
|
||||
OutputType address_type;
|
||||
address_type = model->getDefaultAddressType();
|
||||
if (address_type == OUTPUT_TYPE_BECH32) {
|
||||
address_type = OUTPUT_TYPE_P2SH_SEGWIT;
|
||||
valtype namespaceVal;
|
||||
QString nameSpace = ui->nameSpace->text();
|
||||
if (!DecodeKevaNamespace(nameSpace.toStdString(), Params(), namespaceVal)) {
|
||||
// TODO: show error dialog
|
||||
return;
|
||||
}
|
||||
|
||||
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);
|
||||
SendCoinsRecipient info(address, label,
|
||||
NULL, NULL);
|
||||
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);
|
||||
std::vector<KevaEntry> vKevaEntries;
|
||||
model->getKevaEntries(vKevaEntries, ValtypeToString(namespaceVal));
|
||||
model->getKevaTableModel()->setKeva(vKevaEntries);
|
||||
}
|
||||
|
||||
void KevaDialog::on_recentRequestsView_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
const RecentRequestsTableModel *submodel = model->getRecentRequestsTableModel();
|
||||
const KevaTableModel *submodel = model->getKevaTableModel();
|
||||
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
|
||||
dialog->setModel(model->getOptionsModel());
|
||||
dialog->setInfo(submodel->entry(index.row()).recipient);
|
||||
//dialog->setInfo(submodel->entry(index.row()).recipient);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->show();
|
||||
}
|
||||
@ -172,7 +156,7 @@ void KevaDialog::recentRequestsView_selectionChanged(const QItemSelection &selec
|
||||
|
||||
void KevaDialog::on_showRequestButton_clicked()
|
||||
{
|
||||
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
|
||||
if(!model || !model->getKevaTableModel() || !ui->recentRequestsView->selectionModel())
|
||||
return;
|
||||
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
|
||||
|
||||
@ -183,14 +167,14 @@ void KevaDialog::on_showRequestButton_clicked()
|
||||
|
||||
void KevaDialog::on_removeRequestButton_clicked()
|
||||
{
|
||||
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
|
||||
if(!model || !model->getKevaTableModel() || !ui->recentRequestsView->selectionModel())
|
||||
return;
|
||||
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
|
||||
if(selection.empty())
|
||||
return;
|
||||
// correct for selection mode ContiguousSelection
|
||||
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
|
||||
@ -198,7 +182,7 @@ void KevaDialog::on_removeRequestButton_clicked()
|
||||
void KevaDialog::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
columnResizingFixer->stretchColumnWidth(RecentRequestsTableModel::Message);
|
||||
columnResizingFixer->stretchColumnWidth(KevaTableModel::Block);
|
||||
}
|
||||
|
||||
void KevaDialog::keyPressEvent(QKeyEvent *event)
|
||||
@ -206,10 +190,10 @@ void KevaDialog::keyPressEvent(QKeyEvent *event)
|
||||
if (event->key() == Qt::Key_Return)
|
||||
{
|
||||
// press return -> submit form
|
||||
if (ui->reqLabel->hasFocus())
|
||||
if (ui->nameSpace->hasFocus())
|
||||
{
|
||||
event->ignore();
|
||||
on_receiveButton_clicked();
|
||||
on_showContent_clicked();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -219,7 +203,7 @@ void KevaDialog::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
QModelIndex KevaDialog::selectedRow()
|
||||
{
|
||||
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
|
||||
if(!model || !model->getKevaTableModel() || !ui->recentRequestsView->selectionModel())
|
||||
return QModelIndex();
|
||||
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
|
||||
if(selection.empty())
|
||||
@ -236,7 +220,7 @@ void KevaDialog::copyColumnToClipboard(int column)
|
||||
if (!firstIndex.isValid()) {
|
||||
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
|
||||
@ -251,30 +235,32 @@ void KevaDialog::showMenu(const QPoint &point)
|
||||
// context menu action: copy URI
|
||||
void KevaDialog::copyURI()
|
||||
{
|
||||
#if 0
|
||||
QModelIndex sel = selectedRow();
|
||||
if (!sel.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
|
||||
const KevaTableModel * const submodel = model->getKevaTableModel();
|
||||
const QString uri = GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
|
||||
GUIUtil::setClipboard(uri);
|
||||
#endif
|
||||
}
|
||||
|
||||
// context menu action: copy label
|
||||
void KevaDialog::copyLabel()
|
||||
{
|
||||
copyColumnToClipboard(RecentRequestsTableModel::Label);
|
||||
copyColumnToClipboard(KevaTableModel::Key);
|
||||
}
|
||||
|
||||
// context menu action: copy message
|
||||
void KevaDialog::copyMessage()
|
||||
{
|
||||
copyColumnToClipboard(RecentRequestsTableModel::Message);
|
||||
copyColumnToClipboard(KevaTableModel::Value);
|
||||
}
|
||||
|
||||
// context menu action: copy amount
|
||||
void KevaDialog::copyAmount()
|
||||
{
|
||||
copyColumnToClipboard(RecentRequestsTableModel::Amount);
|
||||
copyColumnToClipboard(KevaTableModel::Block);
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ class KevaDialog : public QDialog
|
||||
public:
|
||||
enum ColumnWidths {
|
||||
DATE_COLUMN_WIDTH = 130,
|
||||
LABEL_COLUMN_WIDTH = 120,
|
||||
AMOUNT_MINIMUM_COLUMN_WIDTH = 180,
|
||||
MINIMUM_COLUMN_WIDTH = 130
|
||||
KEY_COLUMN_WIDTH = 120,
|
||||
BLOCK_MINIMUM_COLUMN_WIDTH = 100,
|
||||
MINIMUM_COLUMN_WIDTH = 100
|
||||
};
|
||||
|
||||
explicit KevaDialog(const PlatformStyle *platformStyle, QWidget *parent = 0);
|
||||
@ -64,7 +64,7 @@ private:
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_receiveButton_clicked();
|
||||
void on_showContent_clicked();
|
||||
void on_showRequestButton_clicked();
|
||||
void on_removeRequestButton_clicked();
|
||||
void on_recentRequestsView_doubleClicked(const QModelIndex &index);
|
||||
|
166
src/qt/kevatablemodel.cpp
Normal file
166
src/qt/kevatablemodel.cpp
Normal file
@ -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
Normal file
89
src/qt/kevatablemodel.h
Normal file
@ -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
|
@ -11,12 +11,15 @@
|
||||
#include <qt/optionsmodel.h>
|
||||
#include <qt/paymentserver.h>
|
||||
#include <qt/recentrequeststablemodel.h>
|
||||
#include <qt/kevatablemodel.h>
|
||||
#include <qt/sendcoinsdialog.h>
|
||||
#include <qt/transactiontablemodel.h>
|
||||
|
||||
#include <base58.h>
|
||||
#include <chain.h>
|
||||
#include <keystore.h>
|
||||
#include <keva/common.h>
|
||||
#include <keva/main.h>
|
||||
#include <validation.h>
|
||||
#include <net.h> // for g_connman
|
||||
#include <policy/fees.h>
|
||||
@ -41,6 +44,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O
|
||||
QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
|
||||
transactionTableModel(0),
|
||||
recentRequestsTableModel(0),
|
||||
kevaTableModel(0),
|
||||
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
|
||||
cachedEncryptionStatus(Unencrypted),
|
||||
cachedNumBlocks(0)
|
||||
@ -51,6 +55,7 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, O
|
||||
addressTableModel = new AddressTableModel(wallet, this);
|
||||
transactionTableModel = new TransactionTableModel(platformStyle, wallet, this);
|
||||
recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
|
||||
kevaTableModel = new KevaTableModel(wallet, this);
|
||||
|
||||
// This timer will be fired repeatedly to update the balance
|
||||
pollTimer = new QTimer(this);
|
||||
@ -393,6 +398,11 @@ RecentRequestsTableModel *WalletModel::getRecentRequestsTableModel()
|
||||
return recentRequestsTableModel;
|
||||
}
|
||||
|
||||
KevaTableModel *WalletModel::getKevaTableModel()
|
||||
{
|
||||
return kevaTableModel;
|
||||
}
|
||||
|
||||
WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
|
||||
{
|
||||
if(!wallet->IsCrypted())
|
||||
@ -743,3 +753,21 @@ int WalletModel::getDefaultConfirmTarget() const
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ class AddressTableModel;
|
||||
class OptionsModel;
|
||||
class PlatformStyle;
|
||||
class RecentRequestsTableModel;
|
||||
class KevaTableModel;
|
||||
class KevaEntry;
|
||||
class TransactionTableModel;
|
||||
class WalletModelTransaction;
|
||||
|
||||
@ -130,6 +132,7 @@ public:
|
||||
AddressTableModel *getAddressTableModel();
|
||||
TransactionTableModel *getTransactionTableModel();
|
||||
RecentRequestsTableModel *getRecentRequestsTableModel();
|
||||
KevaTableModel *getKevaTableModel();
|
||||
|
||||
CAmount getBalance(const CCoinControl *coinControl = nullptr) const;
|
||||
CAmount getUnconfirmedBalance() const;
|
||||
@ -220,6 +223,9 @@ public:
|
||||
|
||||
int getDefaultConfirmTarget() const;
|
||||
|
||||
// Keva
|
||||
void getKevaEntries(std::vector<KevaEntry>& vKevaEntries, std::string nameSpace);
|
||||
|
||||
private:
|
||||
CWallet *wallet;
|
||||
bool fHaveWatchOnly;
|
||||
@ -232,6 +238,7 @@ private:
|
||||
AddressTableModel *addressTableModel;
|
||||
TransactionTableModel *transactionTableModel;
|
||||
RecentRequestsTableModel *recentRequestsTableModel;
|
||||
KevaTableModel *kevaTableModel;
|
||||
|
||||
// Cache some values to be able to detect changes
|
||||
CAmount cachedBalance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user