Show port name/description in port stats window

By default the port name (ifXXX for Windows) is shown. If a port has a
user description, that is shown instead of port name.
This commit is contained in:
Srivats P 2022-09-12 15:46:06 +05:30
parent 42091e5221
commit 32ddf223b6
4 changed files with 28 additions and 6 deletions

View File

@ -100,6 +100,9 @@ void PortGroupList::addPortGroup(PortGroup &portGroup)
connect(&portGroup, SIGNAL(portListChanged(quint32)), connect(&portGroup, SIGNAL(portListChanged(quint32)),
&mPortStatsModel, SLOT(when_portListChanged())); &mPortStatsModel, SLOT(when_portListChanged()));
connect(&portGroup, SIGNAL(portGroupDataChanged(int, int)),
&mPortStatsModel, SLOT(when_portGroupDataChanged(int, int)));
connect(&portGroup, SIGNAL(statsChanged(quint32)), connect(&portGroup, SIGNAL(statsChanged(quint32)),
&mPortStatsModel, SLOT(when_portGroup_stats_update(quint32))); &mPortStatsModel, SLOT(when_portGroup_stats_update(quint32)));

View File

@ -49,7 +49,8 @@ QList<uint> PortStatsFilterDialog::getItemList(bool* ok,
{ {
QStandardItem *item; QStandardItem *item;
item = new QStandardItem(model->headerData(i, orientation).toString()); item = new QStandardItem(model->headerData(i, orientation)
.toString().replace('\n', ' '));
item->setData(i, kLogicalIndex); item->setData(i, kLogicalIndex);
item->setData(initial.indexOf(i), kVisualIndex); item->setData(initial.indexOf(i), kVisualIndex);
item->setFlags(Qt::ItemIsSelectable item->setFlags(Qt::ItemIsSelectable

View File

@ -280,16 +280,23 @@ QVariant PortStatsModel::headerData(int section, Qt::Orientation orientation, in
if (numPorts.isEmpty() || section >= numPorts.last()) if (numPorts.isEmpty() || section >= numPorts.last())
return QVariant(); return QVariant();
getDomainIndexes(index(0, section), portGroupIdx, portIdx); getDomainIndexes(index(0, section), portGroupIdx, portIdx);
PortGroup *portGroup = pgl->mPortGroups.at(portGroupIdx);
Port *port = portGroup->mPorts.at(portIdx);
portName = QString("Port %1-%2") portName = QString("Port %1-%2")
.arg(pgl->mPortGroups.at(portGroupIdx)->id()) .arg(portGroup->id())
.arg(pgl->mPortGroups.at(portGroupIdx)->mPorts.at(portIdx)->id()); .arg(port->id());
if (portGroupIdx < (uint) pgl->mPortGroups.size() if (portGroupIdx < (uint) pgl->mPortGroups.size()
&& portIdx < (uint) pgl->mPortGroups.at(portGroupIdx)->mPorts.size()) && portIdx < (uint) portGroup->mPorts.size())
{ {
if (!pgl->mPortGroups.at(portGroupIdx)->mPorts[portIdx]->notes() if (!port->notes().isEmpty())
.isEmpty())
portName += " *"; portName += " *";
portName += "\n";
portName += port->userDescription().isEmpty() ?
port->userAlias() : port->userDescription();
} }
return portName; return portName;
} }
@ -363,6 +370,16 @@ void PortStatsModel::when_portListChanged()
endResetModel(); endResetModel();
} }
void PortStatsModel::when_portGroupDataChanged(int /*portGroupId*/, int /*portId*/)
{
if (!columnCount())
return;
// Port (user) description may have changed - update column headers
// TODO: update only the changed ports, not all
emit headerDataChanged(Qt::Horizontal, 0, columnCount()-1);
}
// FIXME: unused? if used, the index calculation row/column needs to be swapped // FIXME: unused? if used, the index calculation row/column needs to be swapped
#if 0 #if 0
void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/) void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/)

View File

@ -136,6 +136,7 @@ class PortStatsModel : public QAbstractTableModel
public slots: public slots:
void when_portListChanged(); void when_portListChanged();
//void on_portStatsUpdate(int port, void*stats); //void on_portStatsUpdate(int port, void*stats);
void when_portGroupDataChanged(int portGroupId, int portId);
void when_portGroup_stats_update(quint32 portGroupId); void when_portGroup_stats_update(quint32 portGroupId);
private slots: private slots: