[Qt] simplify ban list signal handling

- remove banListChanged signal from client model
- directly call clientModel->getBanTableModel()->refresh() without the way
  over clientModel->updateBanlist()

- also fix clearing peer detail window, when selecting (clicking)
  peers in the ban list
This commit is contained in:
Philip Kaufmann 2015-06-26 10:23:51 +02:00 committed by Jonas Schnelli
parent 43c1f5b8d7
commit cdd72cd5fb
4 changed files with 21 additions and 17 deletions

View file

@ -217,7 +217,6 @@ QString ClientModel::formatClientStartupTime() const
void ClientModel::updateBanlist() void ClientModel::updateBanlist()
{ {
banTableModel->refresh(); banTableModel->refresh();
emit banListChanged();
} }
// Handlers for core signals // Handlers for core signals

View file

@ -91,7 +91,6 @@ Q_SIGNALS:
void numBlocksChanged(int count, const QDateTime& blockDate); void numBlocksChanged(int count, const QDateTime& blockDate);
void alertsChanged(const QString &warnings); void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
void banListChanged();
//! Fired when a message should be reported to the user //! Fired when a message should be reported to the user
void message(const QString &title, const QString &message, unsigned int style); void message(const QString &title, const QString &message, unsigned int style);

View file

@ -331,8 +331,7 @@ void RPCConsole::setClientModel(ClientModel *model)
{ {
clientModel = model; clientModel = model;
ui->trafficGraph->setClientModel(model); ui->trafficGraph->setClientModel(model);
if(model) if (model && clientModel->getPeerTableModel() && clientModel->getBanTableModel()) {
{
// Keep up to date with client // Keep up to date with client
setNumConnections(model->getNumConnections()); setNumConnections(model->getNumConnections());
connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
@ -404,19 +403,23 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu); ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true); ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
// ensure ban table is shown or hidden (if empty) // create ban table context menu action
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);
// create ban table context menu
banTableContextMenu = new QMenu(); banTableContextMenu = new QMenu();
banTableContextMenu->addAction(unbanAction); banTableContextMenu->addAction(unbanAction);
// context menu signals // ban table context menu signals
connect(ui->banlistWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showBanTableContextMenu(const QPoint&))); connect(ui->banlistWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showBanTableContextMenu(const QPoint&)));
connect(unbanAction, SIGNAL(triggered()), this, SLOT(unbanSelectedNode())); connect(unbanAction, SIGNAL(triggered()), this, SLOT(unbanSelectedNode()));
// ban table signal handling - clear peer details when clicking a peer in the ban table
connect(ui->banlistWidget, SIGNAL(clicked(const QModelIndex&)), this, SLOT(clearSelectedNode()));
// ban table signal handling - ensure ban table is shown or hidden (if empty)
connect(model->getBanTableModel(), SIGNAL(layoutChanged()), this, SLOT(showOrHideBanTableIfRequired()));
showOrHideBanTableIfRequired();
// Provide initial values // Provide initial values
ui->clientVersion->setText(model->formatFullVersion()); ui->clientVersion->setText(model->formatFullVersion());
ui->clientUserAgent->setText(model->formatSubVersion()); ui->clientUserAgent->setText(model->formatSubVersion());
@ -790,6 +793,9 @@ void RPCConsole::disconnectSelectedNode()
void RPCConsole::banSelectedNode(int bantime) void RPCConsole::banSelectedNode(int bantime)
{ {
if (!clientModel)
return;
// Get currently selected peer address // Get currently selected peer address
QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address); QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address);
// Find possible nodes, ban it and clear the selected node // Find possible nodes, ban it and clear the selected node
@ -803,14 +809,15 @@ void RPCConsole::banSelectedNode(int bantime)
bannedNode->fDisconnect = true; bannedNode->fDisconnect = true;
clearSelectedNode(); clearSelectedNode();
ui->banlistWidget->setVisible(true); clientModel->getBanTableModel()->refresh();
ui->banHeading->setVisible(true);
clientModel->updateBanlist();
} }
} }
void RPCConsole::unbanSelectedNode() void RPCConsole::unbanSelectedNode()
{ {
if (!clientModel)
return;
// Get currently selected ban address // Get currently selected ban address
QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address); QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address);
CSubNet possibleSubnet(strNode.toStdString()); CSubNet possibleSubnet(strNode.toStdString());
@ -818,8 +825,7 @@ void RPCConsole::unbanSelectedNode()
if (possibleSubnet.IsValid()) if (possibleSubnet.IsValid())
{ {
CNode::Unban(possibleSubnet); CNode::Unban(possibleSubnet);
clientModel->updateBanlist(); clientModel->getBanTableModel()->refresh();
showOrHideBanTableIfRequired();
} }
} }

View file

@ -66,6 +66,8 @@ private Q_SLOTS:
void showBanTableContextMenu(const QPoint& point); void showBanTableContextMenu(const QPoint& point);
/** Hides ban table if no bans are present */ /** Hides ban table if no bans are present */
void showOrHideBanTableIfRequired(); void showOrHideBanTableIfRequired();
/** clear the selected node */
void clearSelectedNode();
public Q_SLOTS: public Q_SLOTS:
void clear(); void clear();
@ -100,8 +102,6 @@ private:
void setTrafficGraphRange(int mins); void setTrafficGraphRange(int mins);
/** show detailed information on ui about selected node */ /** show detailed information on ui about selected node */
void updateNodeDetail(const CNodeCombinedStats *stats); void updateNodeDetail(const CNodeCombinedStats *stats);
/** clear the selected node */
void clearSelectedNode();
enum ColumnWidths enum ColumnWidths
{ {