Fix empty port stats when viewing rsvd ports only

This was a regression introduced in 1.3.0 as part of the port stats UX
improvement. The 'user' row was changed from the first (0) to the last,
but the proxy model continued to use a hard-coded value of 0 to check
for user to determine whether to show a port column or not.
This commit is contained in:
Srivats P 2023-11-08 12:55:39 +05:30
parent d067019959
commit 483f7fb4c5
2 changed files with 6 additions and 10 deletions

View File

@ -22,15 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QSet>
class PortStatsProxyModel : public QSortFilterProxyModel class PortStatsProxyModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
PortStatsProxyModel(QSet<int> hiddenRows = QSet<int>(), PortStatsProxyModel(int userRow, QObject *parent = 0)
QObject *parent = 0) : QSortFilterProxyModel(parent), userRow_(userRow)
: QSortFilterProxyModel(parent), hiddenRows_(hiddenRows)
{ {
setFilterRegExp(QRegExp(".*")); setFilterRegExp(QRegExp(".*"));
} }
@ -39,7 +36,7 @@ protected:
bool filterAcceptsColumn(int sourceColumn, bool filterAcceptsColumn(int sourceColumn,
const QModelIndex &sourceParent) const const QModelIndex &sourceParent) const
{ {
QModelIndex index = sourceModel()->index(0, sourceColumn, sourceParent); QModelIndex index = sourceModel()->index(userRow_, sourceColumn,sourceParent);
QString user = sourceModel()->data(index).toString(); QString user = sourceModel()->data(index).toString();
return filterRegExp().exactMatch(user) ? true : false; return filterRegExp().exactMatch(user) ? true : false;
@ -47,10 +44,10 @@ protected:
bool filterAcceptsRow(int sourceRow, bool filterAcceptsRow(int sourceRow,
const QModelIndex &/*sourceParent*/) const const QModelIndex &/*sourceParent*/) const
{ {
return hiddenRows_.contains(sourceRow) ? false : true; return sourceRow == userRow_ ? false : true;
} }
private: private:
QSet<int> hiddenRows_; int userRow_;
}; };
#endif #endif

View File

@ -44,8 +44,7 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent)
model = pgl->getPortStatsModel(); model = pgl->getPortStatsModel();
// Hide 'user' row // Hide 'user' row
proxyStatsModel = new PortStatsProxyModel( proxyStatsModel = new PortStatsProxyModel(e_INFO_USER, this);
QSet<int>({e_INFO_USER}), this);
if (proxyStatsModel) { if (proxyStatsModel) {
proxyStatsModel->setSourceModel(model); proxyStatsModel->setSourceModel(model);
tvPortStats->setModel(proxyStatsModel); tvPortStats->setModel(proxyStatsModel);