[Qt] banlist, UI optimizing and better signal handling

This commit is contained in:
Jonas Schnelli 2015-06-20 21:48:10 +02:00
parent 770ca79aa0
commit 6135309816
6 changed files with 28 additions and 22 deletions

View file

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

View file

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

View file

@ -752,7 +752,7 @@
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="cursor">
@ -780,12 +780,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>

View file

@ -352,7 +352,7 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH);
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
// create context menu actions
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
@ -373,8 +373,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, use int instead of int64_t for bantime because signalmapper only supports int or objects
//int is sufficient for our case
//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
QSignalMapper* signalMapper = new QSignalMapper(this);
signalMapper->setMapping(banAction1h, 60*60);
signalMapper->setMapping(banAction24h, 60*60*24);
@ -395,14 +396,14 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->banlistWidget->setModel(model->getBanTableModel());
ui->banlistWidget->verticalHeader()->hide();
ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->banlistWidget->setColumnWidth(BanTableModel::Address, ADDRESS_COLUMN_WIDTH);
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, PING_COLUMN_WIDTH);
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->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
// create context menu actions
// create banlist context menu actions
QAction* unbanAction = new QAction(tr("&Unban Node"), this);
banTableContextMenu = new QMenu();
banTableContextMenu->addAction(unbanAction);
@ -419,11 +420,8 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->startupTime->setText(model->formatClientStartupTime());
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
if (!clientModel->getBanTableModel()->shouldShow())
{
ui->banlistWidget->hide();
ui->banHeading->hide();
}
connect(model, SIGNAL(banListChanged()), this, SLOT(showOrHideBanTableIfRequired()));
showOrHideBanTableIfRequired();
}
}
@ -810,7 +808,7 @@ void RPCConsole::banSelectedNode(int bantime)
void RPCConsole::unbanSelectedNode()
{
// Get currently selected peer address
// Get currently selected ban address
QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address);
CSubNet possibleSubnet(strNode.toStdString());
@ -818,6 +816,7 @@ void RPCConsole::unbanSelectedNode()
{
CNode::Unban(possibleSubnet);
clientModel->updateBanlist();
showOrHideBanTableIfRequired();
}
}
@ -828,3 +827,10 @@ void RPCConsole::clearSelectedNode()
ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
}
void RPCConsole::showOrHideBanTableIfRequired()
{
bool visible = clientModel->getBanTableModel()->shouldShow();
ui->banlistWidget->setVisible(visible);
ui->banHeading->setVisible(visible);
}

View file

@ -64,6 +64,8 @@ private Q_SLOTS:
void showPeersTableContextMenu(const QPoint& point);
/** Show custom context menu on Bans tab */
void showBanTableContextMenu(const QPoint& point);
/** Hides ban table if no bans are present */
void showOrHideBanTableIfRequired();
public Q_SLOTS:
void clear();
@ -105,7 +107,10 @@ private:
{
ADDRESS_COLUMN_WIDTH = 200,
SUBVERSION_COLUMN_WIDTH = 100,
PING_COLUMN_WIDTH = 80
PING_COLUMN_WIDTH = 80,
BANSUBNET_COLUMN_WIDTH = 300,
BANTIME_COLUMN_WIDTH = 150
};
Ui::RPCConsole *ui;

View file

@ -580,7 +580,6 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
CNode::ClearBanned();
DumpBanlist(); //store banlist to disk
uiInterface.BannedListChanged();
return NullUniValue;