[Qt] tweak new peers tab in console window

- remove starting height as table header and replace with ping time
- remove columnResizingFixer
- add local address (if available) in detailed node view (on top of the
  right view below the remote address)
- remove some .c_str() by using QString::fromStdString()
- rename Address to Address/Hostname
- rename secs to just s for ping time
- use MODEL_UPDATE_DELAY from guiconstants.h for the peer refresh time
- make PeerTableModel::columnCount() return no hard-coded value
- remove and cleanup dup private: section in RPCConsole header
- add new defaults for column sizes
- remove behaviour which keeps disconnected peers selected and also remove
  code which keeps track of last selected peer stats
- add sync height to detail view
- add some additional NULL pointer checks for clientModel in
  rpcconsole.cpp
This commit is contained in:
Philip Kaufmann
2014-06-04 12:06:18 +02:00
parent d97a58f883
commit a5b2d9c82e
7 changed files with 445 additions and 356 deletions

View File

@@ -5,6 +5,8 @@
#include "peertablemodel.h"
#include "clientmodel.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "net.h"
#include "sync.h"
@@ -15,8 +17,8 @@
bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombinedStats &right) const
{
const CNodeStats *pLeft = &(left.nodestats);
const CNodeStats *pRight = &(right.nodestats);
const CNodeStats *pLeft = &(left.nodeStats);
const CNodeStats *pRight = &(right.nodeStats);
if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight);
@@ -27,8 +29,8 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
return pLeft->addrName.compare(pRight->addrName) < 0;
case PeerTableModel::Subversion:
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
case PeerTableModel::Height:
return pLeft->nStartingHeight < pRight->nStartingHeight;
case PeerTableModel::Ping:
return pLeft->dPingTime < pRight->dPingTime;
}
return false;
@@ -48,7 +50,8 @@ public:
std::map<NodeId, int> mapNodeRows;
/** Pull a full list of peers from vNodes into our cache */
void refreshPeers() {
void refreshPeers()
{
{
TRY_LOCK(cs_vNodes, lockNodes);
if (!lockNodes)
@@ -63,23 +66,17 @@ public:
BOOST_FOREACH(CNode* pnode, vNodes)
{
CNodeCombinedStats stats;
stats.statestats.nMisbehavior = -1;
pnode->copyStats(stats.nodestats);
stats.nodeStateStats.nMisbehavior = 0;
stats.nodeStateStats.nSyncHeight = -1;
stats.fNodeStateStatsAvailable = false;
pnode->copyStats(stats.nodeStats);
cachedNodeStats.append(stats);
}
}
// if we can, retrieve the CNodeStateStats for each node.
{
TRY_LOCK(cs_main, lockMain);
if (lockMain)
{
BOOST_FOREACH(CNodeCombinedStats &stats, cachedNodeStats)
{
GetNodeStateStats(stats.nodestats.nodeid, stats.statestats);
}
}
}
// Try to retrieve the CNodeStateStats for each node.
BOOST_FOREACH(CNodeCombinedStats &stats, cachedNodeStats)
stats.fNodeStateStatsAvailable = GetNodeStateStats(stats.nodeStats.nodeid, stats.nodeStateStats);
if (sortColumn >= 0)
// sort cacheNodeStats (use stable sort to prevent rows jumping around unneceesarily)
@@ -89,9 +86,7 @@ public:
mapNodeRows.clear();
int row = 0;
BOOST_FOREACH(CNodeCombinedStats &stats, cachedNodeStats)
{
mapNodeRows.insert(std::pair<NodeId, int>(stats.nodestats.nodeid, row++));
}
mapNodeRows.insert(std::pair<NodeId, int>(stats.nodeStats.nodeid, row++));
}
int size()
@@ -103,18 +98,18 @@ public:
{
if(idx >= 0 && idx < cachedNodeStats.size()) {
return &cachedNodeStats[idx];
}
else
{
} else {
return 0;
}
}
};
PeerTableModel::PeerTableModel(ClientModel *parent) :
QAbstractTableModel(parent),clientModel(parent),timer(0)
QAbstractTableModel(parent),
clientModel(parent),
timer(0)
{
columns << tr("Address") << tr("User Agent") << tr("Start Height");
columns << tr("Address/Hostname") << tr("User Agent") << tr("Ping Time");
priv = new PeerTablePriv();
// default to unsorted
priv->sortColumn = -1;
@@ -122,14 +117,14 @@ PeerTableModel::PeerTableModel(ClientModel *parent) :
// set up timer for auto refresh
timer = new QTimer();
connect(timer, SIGNAL(timeout()), SLOT(refresh()));
timer->setInterval(MODEL_UPDATE_DELAY);
// load initial data
refresh();
}
void PeerTableModel::startAutoRefresh(int msecs)
void PeerTableModel::startAutoRefresh()
{
timer->setInterval(1000);
timer->start();
}
@@ -147,7 +142,7 @@ int PeerTableModel::rowCount(const QModelIndex &parent) const
int PeerTableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
return columns.length();;
}
QVariant PeerTableModel::data(const QModelIndex &index, int role) const
@@ -162,11 +157,11 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
switch(index.column())
{
case Address:
return QVariant(rec->nodestats.addrName.c_str());
return QString::fromStdString(rec->nodeStats.addrName);
case Subversion:
return QVariant(rec->nodestats.cleanSubVer.c_str());
case Height:
return rec->nodestats.nStartingHeight;
return QString::fromStdString(rec->nodeStats.cleanSubVer);
case Ping:
return GUIUtil::formatPingTime(rec->nodeStats.dPingTime);
}
}
return QVariant();
@@ -208,7 +203,8 @@ QModelIndex PeerTableModel::index(int row, int column, const QModelIndex &parent
}
}
const CNodeCombinedStats *PeerTableModel::getNodeStats(int idx) {
const CNodeCombinedStats *PeerTableModel::getNodeStats(int idx)
{
return priv->index(idx);
}