Skip to content

Commit

Permalink
Implement context menu and extra info on double-click for DIP3 master…
Browse files Browse the repository at this point in the history
…node list (#2459)

* Implement context menu and extra info on double-click for DIP3 masternode list

Menu items:
- "Copy ProTx hash"
- "Copy Collateral hash"

On double click:
Show simple message box with the json representation of the DMN.

* Fix review comments
  • Loading branch information
codablock authored Nov 21, 2018
1 parent e049f9c commit 7cabbad
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/qt/forms/masternodelist.ui
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down
81 changes: 81 additions & 0 deletions src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
#include "masternode-sync.h"
#include "masternodeconfig.h"
#include "masternodeman.h"
#include "netbase.h"
#include "qrdialog.h"
#include "sync.h"
#include "wallet/wallet.h"
#include "walletmodel.h"

#include <univalue.h>

#include <QMessageBox>
#include <QTimer>
#include <QtGui/QClipboard>

int GetOffsetFromUtc()
{
Expand Down Expand Up @@ -75,6 +79,7 @@ MasternodeList::MasternodeList(const PlatformStyle* platformStyle, QWidget* pare
ui->tableWidgetMasternodesDIP3->setColumnWidth(7, columnOperatorRewardWidth);

ui->tableWidgetMyMasternodes->setContextMenuPolicy(Qt::CustomContextMenu);
ui->tableWidgetMasternodesDIP3->setContextMenuPolicy(Qt::CustomContextMenu);

QAction* startAliasAction = new QAction(tr("Start alias"), this);
contextMenu = new QMenu();
Expand All @@ -83,6 +88,16 @@ MasternodeList::MasternodeList(const PlatformStyle* platformStyle, QWidget* pare
connect(ui->tableWidgetMyMasternodes, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_QRButton_clicked()));
connect(startAliasAction, SIGNAL(triggered()), this, SLOT(on_startButton_clicked()));

QAction* copyProTxHashAction = new QAction(tr("Copy ProTx Hash"), this);
QAction* copyCollateralOutpointAction = new QAction(tr("Copy Collateral Outpoint"), this);
contextMenuDIP3 = new QMenu();
contextMenuDIP3->addAction(copyProTxHashAction);
contextMenuDIP3->addAction(copyCollateralOutpointAction);
connect(ui->tableWidgetMasternodesDIP3, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenuDIP3(const QPoint&)));
connect(ui->tableWidgetMasternodesDIP3, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_extraInfoDIP3_clicked()));
connect(copyProTxHashAction, SIGNAL(triggered()), this, SLOT(on_copyProTxHash_clicked()));
connect(copyCollateralOutpointAction, SIGNAL(triggered()), this, SLOT(on_copyCollateralOutpoint_clicked()));

timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateNodeList()));
connect(timer, SIGNAL(timeout()), this, SLOT(updateMyNodeList()));
Expand Down Expand Up @@ -122,6 +137,12 @@ void MasternodeList::showContextMenu(const QPoint& point)
if (item) contextMenu->exec(QCursor::pos());
}

void MasternodeList::showContextMenuDIP3(const QPoint& point)
{
QTableWidgetItem* item = ui->tableWidgetMasternodesDIP3->itemAt(point);
if (item) contextMenuDIP3->exec(QCursor::pos());
}

void MasternodeList::StartAlias(std::string strAlias)
{
std::string strStatusHtml;
Expand Down Expand Up @@ -646,3 +667,63 @@ void MasternodeList::ShowQRCode(std::string strAlias)
dialog->setInfo(strWindowtitle, QString::fromStdString(strMNPrivKey), strHTML, strQRCodeTitle);
dialog->show();
}

CDeterministicMNCPtr MasternodeList::GetSelectedDIP3MN()
{
std::string strAddress;
{
LOCK(cs_dip3list);

QItemSelectionModel* selectionModel = ui->tableWidgetMasternodesDIP3->selectionModel();
QModelIndexList selected = selectionModel->selectedRows();

if (selected.count() == 0) return nullptr;

QModelIndex index = selected.at(0);
int nSelectedRow = index.row();
strAddress = ui->tableWidgetMasternodesDIP3->item(nSelectedRow, 0)->text().toStdString();
}
CService addr;
if (!Lookup(strAddress.c_str(), addr, Params().GetDefaultPort(), false)) {
return nullptr;
}
auto mnList = deterministicMNManager->GetListAtChainTip();
return mnList.GetUniquePropertyMN(addr);
}

void MasternodeList::on_extraInfoDIP3_clicked()
{
auto dmn = GetSelectedDIP3MN();
if (!dmn) {
return;
}

UniValue json(UniValue::VOBJ);
dmn->ToJson(json);

// Title of popup window
QString strWindowtitle = tr("Additional information for DIP3 Masternode %1").arg(QString::fromStdString(dmn->proTxHash.ToString()));
QString strText = QString::fromStdString(json.write(2));

QMessageBox::information(this, strWindowtitle, strText);
}

void MasternodeList::on_copyProTxHash_clicked()
{
auto dmn = GetSelectedDIP3MN();
if (!dmn) {
return;
}

QApplication::clipboard()->setText(QString::fromStdString(dmn->proTxHash.ToString()));
}

void MasternodeList::on_copyCollateralOutpoint_clicked()
{
auto dmn = GetSelectedDIP3MN();
if (!dmn) {
return;
}

QApplication::clipboard()->setText(QString::fromStdString(dmn->collateralOutpoint.ToStringShort()));
}
9 changes: 9 additions & 0 deletions src/qt/masternodelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "sync.h"
#include "util.h"

#include <evo/deterministicmns.h>

#include <QMenu>
#include <QTimer>
#include <QWidget>
Expand Down Expand Up @@ -40,9 +42,11 @@ class MasternodeList : public QWidget
void ShowQRCode(std::string strAlias);
void StartAlias(std::string strAlias);
void StartAll(std::string strCommand = "start-all");
CDeterministicMNCPtr GetSelectedDIP3MN();

private:
QMenu* contextMenu;
QMenu* contextMenuDIP3;
int64_t nTimeFilterUpdated;
int64_t nTimeFilterUpdatedDIP3;
bool fFilterUpdated;
Expand Down Expand Up @@ -77,6 +81,7 @@ public Q_SLOTS:

private Q_SLOTS:
void showContextMenu(const QPoint&);
void showContextMenuDIP3(const QPoint&);
void on_filterLineEdit_textChanged(const QString& strFilterIn);
void on_filterLineEditDIP3_textChanged(const QString& strFilterIn);
void on_QRButton_clicked();
Expand All @@ -85,5 +90,9 @@ private Q_SLOTS:
void on_startMissingButton_clicked();
void on_tableWidgetMyMasternodes_itemSelectionChanged();
void on_UpdateButton_clicked();

void on_extraInfoDIP3_clicked();
void on_copyProTxHash_clicked();
void on_copyCollateralOutpoint_clicked();
};
#endif // MASTERNODELIST_H

0 comments on commit 7cabbad

Please sign in to comment.