Device Emulation (contd.): Display vlan count and change device count to show total number of devices across all vlans
This commit is contained in:
parent
c569328bb3
commit
264fe20c34
@ -25,16 +25,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
enum {
|
||||
kName,
|
||||
kCount,
|
||||
kVlan,
|
||||
kVlanCount,
|
||||
kDeviceCount, // Across all vlans
|
||||
kIp,
|
||||
kFieldCount
|
||||
};
|
||||
|
||||
static QStringList columns_ = QStringList()
|
||||
<< "Name"
|
||||
<< "Count"
|
||||
<< "Vlan"
|
||||
<< "Vlans"
|
||||
<< "Devices"
|
||||
<< "IP";
|
||||
|
||||
DeviceGroupModel::DeviceGroupModel(QObject *parent)
|
||||
@ -92,6 +92,8 @@ QVariant DeviceGroupModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
OstProto::DeviceGroup *devGrp = port_->deviceGroupByIndex(dgIdx);
|
||||
|
||||
Q_ASSERT(devGrp);
|
||||
|
||||
switch (field) {
|
||||
case kName:
|
||||
switch (role) {
|
||||
@ -102,10 +104,12 @@ QVariant DeviceGroupModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
return QVariant();
|
||||
|
||||
case kCount:
|
||||
case kVlanCount:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return devGrp->device_count();
|
||||
if (int v = vlanCount(devGrp))
|
||||
return v;
|
||||
return QString("None");
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignRight;
|
||||
default:
|
||||
@ -113,17 +117,12 @@ QVariant DeviceGroupModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
return QVariant();
|
||||
|
||||
case kVlan:
|
||||
case kDeviceCount:
|
||||
switch (role) {
|
||||
case Qt::CheckStateRole:
|
||||
if (devGrp->has_encap()
|
||||
&& devGrp->encap().HasExtension(OstEmul::vlan)
|
||||
&& devGrp->encap().GetExtension(OstEmul::vlan)
|
||||
.stack_size())
|
||||
return Qt::Checked;
|
||||
return Qt::Unchecked;
|
||||
case Qt::DisplayRole:
|
||||
return qMax(vlanCount(devGrp), 1)*devGrp->device_count();
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
return Qt::AlignRight;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -171,3 +170,23 @@ void DeviceGroupModel::setPort(Port *port)
|
||||
port_ = port;
|
||||
reset();
|
||||
}
|
||||
|
||||
//
|
||||
// ---------------------- Private Methods -----------------------
|
||||
//
|
||||
int DeviceGroupModel::vlanCount(const OstProto::DeviceGroup *deviceGroup) const
|
||||
{
|
||||
if (!deviceGroup->has_encap()
|
||||
|| !deviceGroup->encap().HasExtension(OstEmul::vlan))
|
||||
return 0;
|
||||
|
||||
OstEmul::VlanEmulation vlan = deviceGroup->encap()
|
||||
.GetExtension(OstEmul::vlan);
|
||||
int numTags = vlan.stack_size();
|
||||
int count = 1;
|
||||
|
||||
for (int i = 0; i < numTags; i++)
|
||||
count *= vlan.stack(i).count();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include <QStringList>
|
||||
|
||||
class Port;
|
||||
namespace OstProto {
|
||||
class DeviceGroup;
|
||||
};
|
||||
|
||||
class DeviceGroupModel: public QAbstractTableModel
|
||||
{
|
||||
@ -41,7 +44,10 @@ public:
|
||||
int role = Qt::EditRole);
|
||||
|
||||
void setPort(Port *port);
|
||||
|
||||
private:
|
||||
int vlanCount(const OstProto::DeviceGroup *deviceGroup) const;
|
||||
|
||||
Port *port_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user