2008-05-03 09:37:10 -05:00
|
|
|
#include "portgrouplist.h"
|
|
|
|
|
|
|
|
// TODO(LOW): Remove
|
|
|
|
#include <modeltest.h>
|
|
|
|
|
|
|
|
PortGroupList::PortGroupList()
|
2009-12-28 02:31:28 -06:00
|
|
|
: mPortGroupListModel(this),
|
|
|
|
mStreamListModel(this),
|
|
|
|
mPortStatsModel(this, this)
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
PortGroup *pg;
|
|
|
|
|
|
|
|
// TODO(LOW): Remove
|
|
|
|
new ModelTest(getStreamModel());
|
|
|
|
new ModelTest(getPortModel());
|
|
|
|
new ModelTest(getPortStatsModel());
|
|
|
|
|
|
|
|
// Add the "Local" Port Group
|
|
|
|
pg = new PortGroup;
|
|
|
|
addPortGroup(*pg);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PortGroupList::isPortGroup(const QModelIndex& index)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return mPortGroupListModel.isPortGroup(index);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PortGroupList::isPort(const QModelIndex& index)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return mPortGroupListModel.isPort(index);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PortGroup& PortGroupList::portGroup(const QModelIndex& index)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(mPortGroupListModel.isPortGroup(index));
|
2009-11-14 09:09:19 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
return *(mPortGroups[index.row()]);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Port& PortGroupList::port(const QModelIndex& index)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(mPortGroupListModel.isPort(index));
|
|
|
|
return (*mPortGroups.at(index.parent().row())->mPorts[index.row()]);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroupList::addPortGroup(PortGroup &portGroup)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
mPortGroupListModel.portGroupAboutToBeAppended();
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
connect(&portGroup, SIGNAL(portGroupDataChanged(int, int)),
|
|
|
|
&mPortGroupListModel, SLOT(when_portGroupDataChanged(int, int)));
|
2008-05-03 09:37:10 -05:00
|
|
|
#if 0
|
2009-12-28 02:31:28 -06:00
|
|
|
connect(&portGroup, SIGNAL(portListAboutToBeChanged(quint32)),
|
|
|
|
&mPortGroupListModel, SLOT(triggerLayoutAboutToBeChanged()));
|
|
|
|
connect(&portGroup, SIGNAL(portListChanged(quint32)),
|
|
|
|
&mPortGroupListModel, SLOT(triggerLayoutChanged()));
|
2008-05-03 09:37:10 -05:00
|
|
|
#endif
|
2009-12-28 02:31:28 -06:00
|
|
|
connect(&portGroup, SIGNAL(portListChanged(quint32)),
|
|
|
|
&mPortGroupListModel, SLOT(when_portListChanged()));
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
connect(&portGroup, SIGNAL(portListChanged(quint32)),
|
|
|
|
&mPortStatsModel, SLOT(when_portListChanged()));
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
connect(&portGroup, SIGNAL(statsChanged(quint32)),
|
|
|
|
&mPortStatsModel, SLOT(when_portGroup_stats_update(quint32)));
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
mPortGroups.append(&portGroup);
|
|
|
|
portGroup.connectToHost();
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
mPortGroupListModel.portGroupAppended();
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
mPortStatsModel.when_portListChanged();
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroupList::removePortGroup(PortGroup &portGroup)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
mPortGroupListModel.portGroupAboutToBeRemoved(&portGroup);
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
PortGroup* pg = mPortGroups.takeAt(mPortGroups.indexOf(&portGroup));
|
|
|
|
qDebug("after takeAt()");
|
|
|
|
mPortGroupListModel.portGroupRemoved();
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
delete pg;
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
mPortStatsModel.when_portListChanged();
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//....................
|
|
|
|
// Private Methods
|
|
|
|
//....................
|
|
|
|
int PortGroupList::indexOfPortGroup(quint32 portGroupId)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
for (int i = 0; i < mPortGroups.size(); i++) {
|
|
|
|
if (mPortGroups.value(i)->id() == portGroupId)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|