Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt: peers-tab resizeColumnsToContents #338

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
case BanTableModel::Bantime:
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
case BanTableModel::Bumper:
return 0;
} // no default case, so the compiler can warn about missing cases
assert(false);
}
Expand Down Expand Up @@ -82,7 +84,7 @@ BanTableModel::BanTableModel(interfaces::Node& node, QObject* parent) :
QAbstractTableModel(parent),
m_node(node)
{
columns << tr("IP/Netmask") << tr("Banned Until");
columns << tr("IP/Netmask") << tr("Banned Until") << tr("•");
priv.reset(new BanTablePriv());

// load initial data
Expand Down Expand Up @@ -120,6 +122,8 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
const auto column = static_cast<ColumnIndex>(index.column());
if (role == Qt::DisplayRole) {
switch (column) {
case Bumper:
return QString::fromStdString("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be QString::fromStdString("")

case Address:
return QString::fromStdString(rec->subnet.ToString());
case Bantime:
Expand All @@ -129,6 +133,15 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
} // no default case, so the compiler can warn about missing cases
assert(false);
}
else if (role == Qt::TextAlignmentRole) {
switch (column) {
case Address:
case Bantime:
case Bumper:
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
}
assert(false);
}

return QVariant();
}
Expand Down
3 changes: 2 additions & 1 deletion src/qt/bantablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class BanTableModel : public QAbstractTableModel

enum ColumnIndex {
Address = 0,
Bantime = 1
Bantime,
Bumper
};

/** @name Methods overridden from QAbstractTableModel
Expand Down
10 changes: 7 additions & 3 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
case Subversion:
return QString::fromStdString(rec->nodeStats.cleanSubVer);
case Bumper:
return QString::fromStdString("");
} // no default case, so the compiler can warn about missing cases
assert(false);
} else if (role == Qt::TextAlignmentRole) {
Expand All @@ -100,10 +102,12 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
case Ping:
case Sent:
case Received:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case Subversion:
return {};
} // no default case, so the compiler can warn about missing cases
case Subversion:
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this unrelated to what you want to do?

case Bumper:
return QVariant(Qt::AlignCenter);
}
assert(false);
} else if (role == StatsRole) {
return QVariant::fromValue(rec);
Expand Down
7 changes: 5 additions & 2 deletions src/qt/peertablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class PeerTableModel : public QAbstractTableModel
Ping,
Sent,
Received,
Subversion
Subversion,
Bumper
};

enum {
Expand Down Expand Up @@ -104,7 +105,9 @@ public Q_SLOTS:
tr("Received"),
/*: Title of Peers Table column which contains the peer's
User Agent string. */
tr("User Agent")};
tr("User Agent"),
tr("•")};
std::unique_ptr<PeerTablePriv> priv;
QTimer *timer;
};

Expand Down
2 changes: 2 additions & 0 deletions src/qt/peertablesortproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
return left_stats.nRecvBytes < right_stats.nRecvBytes;
case PeerTableModel::Subversion:
return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
case PeerTableModel::Bumper:
return left_stats.nodeid < right_stats.nodeid;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this sorting scheme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting by nodeid was simply to have sorting functionality for that column as opposed to no sorting functionality.

} // no default case, so the compiler can warn about missing cases
assert(false);
}
13 changes: 13 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,15 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
}
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
ui->peerWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(6, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(7, QHeaderView::ResizeToContents);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(8, QHeaderView::ResizeToContents);

// create peer table context menu
peersTableContextMenu = new QMenu(this);
Expand All @@ -698,6 +707,9 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
}
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);

// create ban table context menu
banTableContextMenu = new QMenu(this);
Expand Down Expand Up @@ -1259,6 +1271,7 @@ void RPCConsole::banSelectedNode(int bantime)
}
clearSelectedNode();
clientModel->getBanTableModel()->refresh();
ui->banlistWidget->resizeColumnsToContents();
}

void RPCConsole::unbanSelectedNode()
Expand Down