2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portgrouplist.h"
|
|
|
|
|
2016-10-13 08:20:33 -05:00
|
|
|
#include "params.h"
|
|
|
|
|
2018-03-27 09:32:36 -05:00
|
|
|
#include "modeltest.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
PortGroupList::PortGroupList()
|
|
|
|
: mPortGroupListModel(this),
|
|
|
|
mStreamListModel(this),
|
2016-02-12 07:40:19 -06:00
|
|
|
mPortStatsModel(this, this),
|
2016-03-11 07:28:08 -06:00
|
|
|
mDeviceGroupModel(this),
|
|
|
|
mDeviceModel(this)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2018-04-02 10:09:44 -05:00
|
|
|
#if defined(QT_NO_DEBUG) || QT_VERSION < 0x050700
|
2015-04-16 11:50:07 -05:00
|
|
|
streamModelTester_ = NULL;
|
|
|
|
portModelTester_ = NULL;
|
|
|
|
portStatsModelTester_ = NULL;
|
2016-02-12 07:40:19 -06:00
|
|
|
deviceGroupModelTester_ = NULL;
|
2016-03-11 07:28:08 -06:00
|
|
|
deviceModelTester_ = NULL;
|
2015-04-16 11:50:07 -05:00
|
|
|
#else
|
|
|
|
streamModelTester_ = new ModelTest(getStreamModel());
|
|
|
|
portModelTester_ = new ModelTest(getPortModel());
|
|
|
|
portStatsModelTester_ = new ModelTest(getPortStatsModel());
|
2016-03-11 07:28:08 -06:00
|
|
|
deviceGroupModelTester_ = new ModelTest(getDeviceGroupModel());
|
|
|
|
deviceModelTester_ = new ModelTest(getDeviceModel());
|
2015-04-16 11:50:07 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PortGroupList::~PortGroupList()
|
|
|
|
{
|
|
|
|
delete portStatsModelTester_;
|
|
|
|
delete portModelTester_;
|
|
|
|
delete streamModelTester_;
|
2016-02-12 07:40:19 -06:00
|
|
|
delete deviceGroupModelTester_;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
while (!mPortGroups.isEmpty())
|
|
|
|
delete mPortGroups.takeFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PortGroupList::isPortGroup(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
return mPortGroupListModel.isPortGroup(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PortGroupList::isPort(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
return mPortGroupListModel.isPort(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
PortGroup& PortGroupList::portGroup(const QModelIndex& index)
|
|
|
|
{
|
2022-06-09 10:02:22 -05:00
|
|
|
Q_ASSERT(index.isValid());
|
2015-04-16 11:50:07 -05:00
|
|
|
Q_ASSERT(mPortGroupListModel.isPortGroup(index));
|
|
|
|
|
|
|
|
return *(mPortGroups[index.row()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Port& PortGroupList::port(const QModelIndex& index)
|
|
|
|
{
|
2022-06-09 10:02:22 -05:00
|
|
|
Q_ASSERT(index.isValid());
|
|
|
|
Q_ASSERT(index.parent().isValid());
|
2015-04-16 11:50:07 -05:00
|
|
|
Q_ASSERT(mPortGroupListModel.isPort(index));
|
|
|
|
return (*mPortGroups.at(index.parent().row())->mPorts[index.row()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroupList::addPortGroup(PortGroup &portGroup)
|
|
|
|
{
|
|
|
|
mPortGroupListModel.portGroupAboutToBeAppended();
|
|
|
|
|
|
|
|
connect(&portGroup, SIGNAL(portGroupDataChanged(int, int)),
|
|
|
|
&mPortGroupListModel, SLOT(when_portGroupDataChanged(int, int)));
|
|
|
|
#if 0
|
|
|
|
connect(&portGroup, SIGNAL(portListAboutToBeChanged(quint32)),
|
|
|
|
&mPortGroupListModel, SLOT(triggerLayoutAboutToBeChanged()));
|
|
|
|
connect(&portGroup, SIGNAL(portListChanged(quint32)),
|
|
|
|
&mPortGroupListModel, SLOT(triggerLayoutChanged()));
|
|
|
|
#endif
|
|
|
|
connect(&portGroup, SIGNAL(portListChanged(quint32)),
|
|
|
|
&mPortGroupListModel, SLOT(when_portListChanged()));
|
|
|
|
|
|
|
|
connect(&portGroup, SIGNAL(portListChanged(quint32)),
|
|
|
|
&mPortStatsModel, SLOT(when_portListChanged()));
|
|
|
|
|
2022-09-12 05:16:06 -05:00
|
|
|
connect(&portGroup, SIGNAL(portGroupDataChanged(int, int)),
|
|
|
|
&mPortStatsModel, SLOT(when_portGroupDataChanged(int, int)));
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
connect(&portGroup, SIGNAL(statsChanged(quint32)),
|
|
|
|
&mPortStatsModel, SLOT(when_portGroup_stats_update(quint32)));
|
|
|
|
|
|
|
|
mPortGroups.append(&portGroup);
|
|
|
|
portGroup.connectToHost();
|
|
|
|
|
|
|
|
mPortGroupListModel.portGroupAppended();
|
|
|
|
|
|
|
|
mPortStatsModel.when_portListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortGroupList::removePortGroup(PortGroup &portGroup)
|
|
|
|
{
|
2022-02-10 09:04:10 -06:00
|
|
|
// Disconnect before removing from list
|
|
|
|
portGroup.disconnectFromHost();
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2022-02-10 09:04:10 -06:00
|
|
|
mPortGroupListModel.portGroupAboutToBeRemoved(&portGroup);
|
2015-04-16 11:50:07 -05:00
|
|
|
PortGroup* pg = mPortGroups.takeAt(mPortGroups.indexOf(&portGroup));
|
|
|
|
qDebug("after takeAt()");
|
|
|
|
mPortGroupListModel.portGroupRemoved();
|
|
|
|
|
|
|
|
delete pg;
|
|
|
|
|
|
|
|
mPortStatsModel.when_portListChanged();
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
void PortGroupList::removeAllPortGroups()
|
|
|
|
{
|
2016-04-15 08:33:52 -05:00
|
|
|
if (mPortGroups.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
2016-04-13 21:14:07 -05:00
|
|
|
PortGroup *pg = mPortGroups.at(0);
|
2022-02-10 09:04:10 -06:00
|
|
|
pg->disconnectFromHost();
|
2016-04-13 21:14:07 -05:00
|
|
|
mPortGroupListModel.portGroupAboutToBeRemoved(pg);
|
|
|
|
mPortGroups.removeFirst();
|
|
|
|
delete pg;
|
2022-02-10 09:04:10 -06:00
|
|
|
mPortGroupListModel.portGroupRemoved();
|
2016-04-15 08:33:52 -05:00
|
|
|
} while (!mPortGroups.isEmpty());
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
mPortGroupListModel.when_portListChanged();
|
|
|
|
mPortStatsModel.when_portListChanged();
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
//....................
|
|
|
|
// Private Methods
|
|
|
|
//....................
|
|
|
|
int PortGroupList::indexOfPortGroup(quint32 portGroupId)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < mPortGroups.size(); i++) {
|
|
|
|
if (mPortGroups.value(i)->id() == portGroupId)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|