[Qt] bantable polish
- add missing NULL pointer checks - add better comments and reorder some code in rpcconsole.cpp - remove unneeded leftovers in bantable.cpp - update bantable column sizes to prevent cutting of banned until
This commit is contained in:
parent
cdd72cd5fb
commit
51654deff2
3 changed files with 22 additions and 27 deletions
|
@ -14,8 +14,6 @@
|
|||
#include <QDebug>
|
||||
#include <QList>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/date_time/c_local_time_adjustor.hpp>
|
||||
|
||||
// private implementation
|
||||
class BanTablePriv
|
||||
|
@ -38,7 +36,6 @@ public:
|
|||
#if QT_VERSION >= 0x040700
|
||||
cachedBanlist.reserve(banMap.size());
|
||||
#endif
|
||||
std::map<CSubNet, int64_t>::iterator iter;
|
||||
foreach (const PAIRTYPE(CSubNet, int64_t)& banentry, banMap)
|
||||
{
|
||||
CCombinedBan banEntry;
|
||||
|
@ -104,9 +101,6 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
|
|||
date = date.addSecs(rec->bantil);
|
||||
return date.toString(Qt::SystemLocaleLongDate);
|
||||
}
|
||||
} else if (role == Qt::TextAlignmentRole) {
|
||||
if (index.column() == Bantime)
|
||||
return (QVariant)(Qt::AlignRight | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
|
@ -354,14 +354,14 @@ void RPCConsole::setClientModel(ClientModel *model)
|
|||
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
||||
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
// create context menu actions
|
||||
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
|
||||
QAction* banAction1h = new QAction(tr("&Ban Node for") + " " + tr("&1 hour"), this);
|
||||
QAction* banAction24h = new QAction(tr("&Ban Node for") + " " + tr("&24 hours"), this);
|
||||
QAction* banAction7d = new QAction(tr("&Ban Node for") + " " + tr("&7 days"), this);
|
||||
QAction* banAction365d = new QAction(tr("&Ban Node for") + " " + tr("&1 year"), this);
|
||||
// create peer table context menu actions
|
||||
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
|
||||
QAction* banAction1h = new QAction(tr("&Ban Node for") + " " + tr("&1 hour"), this);
|
||||
QAction* banAction24h = new QAction(tr("&Ban Node for") + " " + tr("&24 hours"), this);
|
||||
QAction* banAction7d = new QAction(tr("&Ban Node for") + " " + tr("&7 days"), this);
|
||||
QAction* banAction365d = new QAction(tr("&Ban Node for") + " " + tr("&1 year"), this);
|
||||
|
||||
// create context menu
|
||||
// create peer table context menu
|
||||
peersTableContextMenu = new QMenu();
|
||||
peersTableContextMenu->addAction(disconnectAction);
|
||||
peersTableContextMenu->addAction(banAction1h);
|
||||
|
@ -369,10 +369,6 @@ void RPCConsole::setClientModel(ClientModel *model)
|
|||
peersTableContextMenu->addAction(banAction7d);
|
||||
peersTableContextMenu->addAction(banAction365d);
|
||||
|
||||
// context menu signals
|
||||
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPeersTableContextMenu(const QPoint&)));
|
||||
connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
|
||||
|
||||
// Add a signal mapping to allow dynamic context menu arguments.
|
||||
// We need to use int (instead of int64_t), because signal mapper only supports
|
||||
// int or objects, which is okay because max bantime (1 year) is < int_max.
|
||||
|
@ -387,20 +383,25 @@ void RPCConsole::setClientModel(ClientModel *model)
|
|||
connect(banAction365d, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
||||
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(banSelectedNode(int)));
|
||||
|
||||
// connect the peerWidget selection model to our peerSelected() handler
|
||||
// peer table context menu signals
|
||||
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPeersTableContextMenu(const QPoint&)));
|
||||
connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
|
||||
|
||||
// peer table signal handling - update peer details when selecting new node
|
||||
connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
|
||||
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
|
||||
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
|
||||
// peer table signal handling - update peer details when new nodes are added to the model
|
||||
connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, SLOT(peerLayoutChanged()));
|
||||
|
||||
// set up ban table
|
||||
ui->banlistWidget->setModel(model->getBanTableModel());
|
||||
ui->banlistWidget->verticalHeader()->hide();
|
||||
ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
|
||||
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
|
||||
ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
|
||||
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
|
||||
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
// create ban table context menu action
|
||||
|
@ -629,7 +630,7 @@ void RPCConsole::peerSelected(const QItemSelection &selected, const QItemSelecti
|
|||
{
|
||||
Q_UNUSED(deselected);
|
||||
|
||||
if (!clientModel || selected.indexes().isEmpty())
|
||||
if (!clientModel || !clientModel->getPeerTableModel() || selected.indexes().isEmpty())
|
||||
return;
|
||||
|
||||
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.indexes().first().row());
|
||||
|
@ -639,7 +640,7 @@ void RPCConsole::peerSelected(const QItemSelection &selected, const QItemSelecti
|
|||
|
||||
void RPCConsole::peerLayoutChanged()
|
||||
{
|
||||
if (!clientModel)
|
||||
if (!clientModel || !clientModel->getPeerTableModel())
|
||||
return;
|
||||
|
||||
const CNodeCombinedStats *stats = NULL;
|
||||
|
@ -748,7 +749,7 @@ void RPCConsole::showEvent(QShowEvent *event)
|
|||
{
|
||||
QWidget::showEvent(event);
|
||||
|
||||
if (!clientModel)
|
||||
if (!clientModel || !clientModel->getPeerTableModel())
|
||||
return;
|
||||
|
||||
// start PeerTableModel auto refresh
|
||||
|
@ -759,7 +760,7 @@ void RPCConsole::hideEvent(QHideEvent *event)
|
|||
{
|
||||
QWidget::hideEvent(event);
|
||||
|
||||
if (!clientModel)
|
||||
if (!clientModel || !clientModel->getPeerTableModel())
|
||||
return;
|
||||
|
||||
// stop PeerTableModel auto refresh
|
||||
|
|
|
@ -108,8 +108,8 @@ private:
|
|||
ADDRESS_COLUMN_WIDTH = 200,
|
||||
SUBVERSION_COLUMN_WIDTH = 100,
|
||||
PING_COLUMN_WIDTH = 80,
|
||||
BANSUBNET_COLUMN_WIDTH = 250,
|
||||
BANTIME_COLUMN_WIDTH = 200
|
||||
BANSUBNET_COLUMN_WIDTH = 200,
|
||||
BANTIME_COLUMN_WIDTH = 250
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue