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 <QSet>
class PortStatsProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
PortStatsProxyModel(QSet<int> hiddenRows = QSet<int>(),
QObject *parent = 0)
: QSortFilterProxyModel(parent), hiddenRows_(hiddenRows)
PortStatsProxyModel(int userRow, QObject *parent = 0)
: QSortFilterProxyModel(parent), userRow_(userRow)
{
setFilterRegExp(QRegExp(".*"));
}
@ -39,7 +36,7 @@ protected:
bool filterAcceptsColumn(int sourceColumn,
const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(0, sourceColumn, sourceParent);
QModelIndex index = sourceModel()->index(userRow_, sourceColumn,sourceParent);
QString user = sourceModel()->data(index).toString();
return filterRegExp().exactMatch(user) ? true : false;
@ -47,10 +44,10 @@ protected:
bool filterAcceptsRow(int sourceRow,
const QModelIndex &/*sourceParent*/) const
{
return hiddenRows_.contains(sourceRow) ? false : true;
return sourceRow == userRow_ ? false : true;
}
private:
QSet<int> hiddenRows_;
int userRow_;
};
#endif

View File

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