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 {
|
enum {
|
||||||
kName,
|
kName,
|
||||||
kCount,
|
kVlanCount,
|
||||||
kVlan,
|
kDeviceCount, // Across all vlans
|
||||||
kIp,
|
kIp,
|
||||||
kFieldCount
|
kFieldCount
|
||||||
};
|
};
|
||||||
|
|
||||||
static QStringList columns_ = QStringList()
|
static QStringList columns_ = QStringList()
|
||||||
<< "Name"
|
<< "Name"
|
||||||
<< "Count"
|
<< "Vlans"
|
||||||
<< "Vlan"
|
<< "Devices"
|
||||||
<< "IP";
|
<< "IP";
|
||||||
|
|
||||||
DeviceGroupModel::DeviceGroupModel(QObject *parent)
|
DeviceGroupModel::DeviceGroupModel(QObject *parent)
|
||||||
@ -92,6 +92,8 @@ QVariant DeviceGroupModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
OstProto::DeviceGroup *devGrp = port_->deviceGroupByIndex(dgIdx);
|
OstProto::DeviceGroup *devGrp = port_->deviceGroupByIndex(dgIdx);
|
||||||
|
|
||||||
|
Q_ASSERT(devGrp);
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case kName:
|
case kName:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
@ -102,10 +104,12 @@ QVariant DeviceGroupModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
case kCount:
|
case kVlanCount:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return devGrp->device_count();
|
if (int v = vlanCount(devGrp))
|
||||||
|
return v;
|
||||||
|
return QString("None");
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return Qt::AlignRight;
|
return Qt::AlignRight;
|
||||||
default:
|
default:
|
||||||
@ -113,17 +117,12 @@ QVariant DeviceGroupModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
case kVlan:
|
case kDeviceCount:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::CheckStateRole:
|
case Qt::DisplayRole:
|
||||||
if (devGrp->has_encap()
|
return qMax(vlanCount(devGrp), 1)*devGrp->device_count();
|
||||||
&& devGrp->encap().HasExtension(OstEmul::vlan)
|
|
||||||
&& devGrp->encap().GetExtension(OstEmul::vlan)
|
|
||||||
.stack_size())
|
|
||||||
return Qt::Checked;
|
|
||||||
return Qt::Unchecked;
|
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return Qt::AlignCenter;
|
return Qt::AlignRight;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -171,3 +170,23 @@ void DeviceGroupModel::setPort(Port *port)
|
|||||||
port_ = port;
|
port_ = port;
|
||||||
reset();
|
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>
|
#include <QStringList>
|
||||||
|
|
||||||
class Port;
|
class Port;
|
||||||
|
namespace OstProto {
|
||||||
|
class DeviceGroup;
|
||||||
|
};
|
||||||
|
|
||||||
class DeviceGroupModel: public QAbstractTableModel
|
class DeviceGroupModel: public QAbstractTableModel
|
||||||
{
|
{
|
||||||
@ -41,7 +44,10 @@ public:
|
|||||||
int role = Qt::EditRole);
|
int role = Qt::EditRole);
|
||||||
|
|
||||||
void setPort(Port *port);
|
void setPort(Port *port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int vlanCount(const OstProto::DeviceGroup *deviceGroup) const;
|
||||||
|
|
||||||
Port *port_;
|
Port *port_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user