Skip to content

Commit

Permalink
[Qt] polish ban table
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Kaufmann authored and jonasschnelli committed Sep 16, 2015
1 parent 607809f commit 9e521c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
16 changes: 5 additions & 11 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ class BanTablePriv

CCombinedBan *index(int idx)
{
if(idx >= 0 && idx < cachedBanlist.size()) {
if (idx >= 0 && idx < cachedBanlist.size())
return &cachedBanlist[idx];
} else {
return 0;
}

return 0;
}
};

Expand Down Expand Up @@ -124,7 +123,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
}
} else if (role == Qt::TextAlignmentRole) {
if (index.column() == Bantime)
return (int)(Qt::AlignRight | Qt::AlignVCenter);
return (QVariant)(Qt::AlignRight | Qt::AlignVCenter);
}

return QVariant();
Expand Down Expand Up @@ -157,13 +156,8 @@ QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent)
CCombinedBan *data = priv->index(row);

if (data)
{
return createIndex(row, column, data);
}
else
{
return QModelIndex();
}
return QModelIndex();
}

void BanTableModel::refresh()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static void NotifyAlertChanged(ClientModel *clientmodel, const uint256 &hash, Ch

static void BannedListChanged(ClientModel *clientmodel)
{
qDebug() << "BannedListChanged";
qDebug() << QString("%1: Requesting update for peer banlist").arg(__func__);
QMetaObject::invokeMethod(clientmodel, "updateBanlist", Qt::QueuedConnection);
}

Expand Down
20 changes: 11 additions & 9 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "rpcconsole.h"
#include "ui_rpcconsole.h"

#include "bantablemodel.h"
#include "clientmodel.h"
#include "guiutil.h"
#include "platformstyle.h"
Expand Down Expand Up @@ -373,9 +374,9 @@ void RPCConsole::setClientModel(ClientModel *model)
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 a dynamic argument
//we need to use int (instead of int64_t) because signal mapper only supports int or objects
//this is okay because max bantime (1 Year) is smaler then int_max
// 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.
QSignalMapper* signalMapper = new QSignalMapper(this);
signalMapper->setMapping(banAction1h, 60*60);
signalMapper->setMapping(banAction24h, 60*60*24);
Expand All @@ -385,7 +386,7 @@ void RPCConsole::setClientModel(ClientModel *model)
connect(banAction24h, SIGNAL(triggered()), signalMapper, SLOT(map()));
connect(banAction7d, SIGNAL(triggered()), signalMapper, SLOT(map()));
connect(banAction365d, SIGNAL(triggered()), signalMapper, SLOT(map()));
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(banSelectedNode(int))) ;
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(banSelectedNode(int)));

// connect the peerWidget selection model to our peerSelected() handler
connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
Expand All @@ -403,8 +404,12 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);

// ensure ban table is shown or hidden (if empty)
connect(model, SIGNAL(banListChanged()), this, SLOT(showOrHideBanTableIfRequired()));
showOrHideBanTableIfRequired();

// create banlist context menu actions
QAction* unbanAction = new QAction(tr("&Unban Node"), this);
QAction* unbanAction = new QAction(tr("&Unban Node"), this);
banTableContextMenu = new QMenu();
banTableContextMenu->addAction(unbanAction);

Expand All @@ -419,9 +424,6 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->buildDate->setText(model->formatBuildDate());
ui->startupTime->setText(model->formatClientStartupTime());
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));

connect(model, SIGNAL(banListChanged()), this, SLOT(showOrHideBanTableIfRequired()));
showOrHideBanTableIfRequired();
}
}

Expand Down Expand Up @@ -833,7 +835,7 @@ void RPCConsole::showOrHideBanTableIfRequired()
{
if (!clientModel)
return;

bool visible = clientModel->getBanTableModel()->shouldShow();
ui->banlistWidget->setVisible(visible);
ui->banHeading->setVisible(visible);
Expand Down

0 comments on commit 9e521c1

Please sign in to comment.