From d950432bc9537b29f690c32de58f881e1a752a4e Mon Sep 17 00:00:00 2001 From: Srivats P Date: Sat, 4 Mar 2023 10:49:35 +0530 Subject: [PATCH] Move port stats hidden rows to the end This avoids having to recalculate row indices --- client/portstatsmodel.cpp | 2 +- client/portstatsmodel.h | 22 ++++++++++++---------- client/portstatsproxymodel.h | 12 ++++++++---- client/portstatswindow.cpp | 15 ++++++++------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/client/portstatsmodel.cpp b/client/portstatsmodel.cpp index 4280b9c..6ed13e7 100644 --- a/client/portstatsmodel.cpp +++ b/client/portstatsmodel.cpp @@ -279,7 +279,7 @@ QVariant PortStatsModel::headerData(int section, Qt::Orientation orientation, in { QPalette palette = QApplication::palette(); return section & 0x1 ? - palette.base() : palette.alternateBase(); + palette.alternateBase() : palette.base(); } if (role != Qt::DisplayRole) diff --git a/client/portstatsmodel.h b/client/portstatsmodel.h index 2d8aa02..18c60ff 100644 --- a/client/portstatsmodel.h +++ b/client/portstatsmodel.h @@ -26,15 +26,8 @@ along with this program. If not, see class QTimer; typedef enum { - // Info - e_INFO_START = 0, - - e_INFO_USER = e_INFO_START, - - e_INFO_END = e_INFO_USER, - // State - e_STATE_START, + e_STATE_START = 0, e_COMBO_STATE = e_STATE_START, @@ -71,12 +64,19 @@ typedef enum { e_STATISTICS_END = e_STAT_RX_FRAME_ERRORS, + // Info + e_INFO_START, + + // XXX: keep hidden rows at end to avoid having to recalculate rows + e_INFO_USER = e_INFO_START, + + e_INFO_END = e_INFO_USER, + + e_STAT_MAX } PortStat; static const QStringList PortStatName = (QStringList() - << "User" - << "Status" << "Frames Sent" @@ -102,6 +102,8 @@ static const QStringList PortStatName = (QStringList() << "Receive Errors" << "Receive Fifo Errors" << "Receive Frame Errors" + + << "User" ); static QStringList LinkStateName = (QStringList() diff --git a/client/portstatsproxymodel.h b/client/portstatsproxymodel.h index 9c78d67..104275e 100644 --- a/client/portstatsproxymodel.h +++ b/client/portstatsproxymodel.h @@ -22,12 +22,15 @@ along with this program. If not, see #include +#include + class PortStatsProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - PortStatsProxyModel(QObject *parent = 0) - : QSortFilterProxyModel(parent) + PortStatsProxyModel(QSet hiddenRows = QSet(), + QObject *parent = 0) + : QSortFilterProxyModel(parent), hiddenRows_(hiddenRows) { setFilterRegExp(QRegExp(".*")); } @@ -44,9 +47,10 @@ protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const { - // Hide row 0 - username (needed only by this filter class) - return (sourceRow > 0) ? true : false; + return hiddenRows_.contains(sourceRow) ? false : true; } +private: + QSet hiddenRows_; }; #endif diff --git a/client/portstatswindow.cpp b/client/portstatswindow.cpp index 57e59f7..32d2d78 100644 --- a/client/portstatswindow.cpp +++ b/client/portstatswindow.cpp @@ -43,7 +43,9 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent) this->pgl = pgl; model = pgl->getPortStatsModel(); - proxyStatsModel = new PortStatsProxyModel(this); + // Hide 'user' row + proxyStatsModel = new PortStatsProxyModel( + QSet({e_INFO_USER}), this); if (proxyStatsModel) { proxyStatsModel->setSourceModel(model); tvPortStats->setModel(proxyStatsModel); @@ -57,15 +59,14 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent) tvPortStats->verticalHeader()->minimumSectionSize()); // XXX: Set Delegates for port stats view - // RowBorderDelegate: Group related stats by drawing a horizontal line + // RowBorderDelegate: Group related stats using a horizontal line // IconOnlyDelegate : For status, show only icons not icons+text - int offset = proxyStatsModel ? -1 : 0; // adjust for hidden 'user' row tvPortStats->setItemDelegate( new RowBorderDelegate( QSet({ - e_STAT_FRAMES_SENT + offset, - e_STAT_FRAME_SEND_RATE + offset, - e_STAT_RX_DROPS + offset}), + e_STAT_FRAMES_SENT, + e_STAT_FRAME_SEND_RATE, + e_STAT_RX_DROPS}), this)); statusDelegate = new IconOnlyDelegate(this); @@ -81,7 +82,7 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent) statusDelegate); #else // ... so we use this hard-coded hack - tvPortStats->setItemDelegateForRow(e_COMBO_STATE + offset, statusDelegate); + tvPortStats->setItemDelegateForRow(e_COMBO_STATE, statusDelegate); #endif connect(tvPortStats->selectionModel(),