Skip to content

Commit

Permalink
[Qt] bantable polish
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Philip Kaufmann authored and jonasschnelli committed Sep 16, 2015
1 parent cdd72cd commit 51654de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
6 changes: 0 additions & 6 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +36,6 @@ class BanTablePriv
#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;
Expand Down Expand Up @@ -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();
Expand Down
41 changes: 21 additions & 20 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,25 +354,21 @@ 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 context menu
// 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 peer table context menu
peersTableContextMenu = new QMenu();
peersTableContextMenu->addAction(disconnectAction);
peersTableContextMenu->addAction(banAction1h);
peersTableContextMenu->addAction(banAction24h);
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.
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down Expand Up @@ -748,7 +749,7 @@ void RPCConsole::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);

if (!clientModel)
if (!clientModel || !clientModel->getPeerTableModel())
return;

// start PeerTableModel auto refresh
Expand All @@ -759,7 +760,7 @@ void RPCConsole::hideEvent(QHideEvent *event)
{
QWidget::hideEvent(event);

if (!clientModel)
if (!clientModel || !clientModel->getPeerTableModel())
return;

// stop PeerTableModel auto refresh
Expand Down
4 changes: 2 additions & 2 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public Q_SLOTS:
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

};

Expand Down

0 comments on commit 51654de

Please sign in to comment.