Reset port widget current on portgroup disconnect

Failure to do so was causing a crash because port widget was trying to
disconnect signal from a non-existent port (corresponding to the current
index that was not reset) after the portgroup reconnected or another
portgroup came up and a port was selected in the port list.

This bug was a regression caused by the refactoring changes when
portwidget (and streamswidget) was extracted from portswindow.
This commit is contained in:
Srivats P 2022-12-08 16:22:39 +05:30
parent 1e50f9b095
commit f07cba39d5
6 changed files with 35 additions and 21 deletions

View File

@ -174,6 +174,7 @@ MainWindow::MainWindow(QWidget *parent)
this, SLOT(onNewVersion(QString)));
updater->checkForNewVersion();
// TODO: If session file specified (and valid?), don't add local drone PG
// Add the "Local" Port Group
if (appParams.optLocalDrone()) {
PortGroup *pg = new PortGroup;

View File

@ -108,7 +108,8 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
connect(this,
SIGNAL(currentPortChanged(const QModelIndex&, const QModelIndex&)),
portWidget, SLOT(setCurrentPortIndex(const QModelIndex&)));
portWidget,
SLOT(setCurrentPortIndex(const QModelIndex&, const QModelIndex&)));
connect(this,
SIGNAL(currentPortChanged(const QModelIndex&, const QModelIndex&)),
streamsWidget, SLOT(setCurrentPortIndex(const QModelIndex&)));

View File

@ -48,30 +48,34 @@ PortWidget::~PortWidget()
{
}
void PortWidget::setCurrentPortIndex(const QModelIndex &portIndex)
void PortWidget::setCurrentPortIndex(const QModelIndex &currentIndex,
const QModelIndex &previousIndex)
{
if (!plm)
return;
// XXX: We assume portIndex corresponds to sourceModel, not proxyModel
if (!plm->isPort(portIndex))
return;
qDebug("In %s", __PRETTY_FUNCTION__);
qDebug("In %s", __FUNCTION__);
// XXX: We assume indices corresponds to sourceModel, not proxyModel
// - caller/sender should ensure this
// Disconnect previous port
if (plm->isPort(currentPortIndex_))
disconnect(&(plm->port(currentPortIndex_)),
if (plm->isPort(previousIndex))
disconnect(&(plm->port(previousIndex)),
SIGNAL(portRateChanged(int, int)),
this, SLOT(updatePortRates()));
currentPortIndex_ = portIndex;
if (!plm->isPort(currentIndex)) {
currentPortIndex_ = QModelIndex(); // set to invalid
return;
}
currentPortIndex_ = currentIndex;
// Connect current port
if (plm->isPort(currentPortIndex_))
connect(&(plm->port(currentPortIndex_)),
SIGNAL(portRateChanged(int, int)),
this, SLOT(updatePortRates()));
connect(&(plm->port(currentPortIndex_)),
SIGNAL(portRateChanged(int, int)),
this, SLOT(updatePortRates()));
double speed = plm->port(currentPortIndex_).speed();
portSpeed->setText(QString("Max %L1 Mbps").arg(speed));

View File

@ -37,7 +37,8 @@ public:
void setPortGroupList(PortGroupList *portGroups);
public slots:
void setCurrentPortIndex(const QModelIndex &portIndex);
void setCurrentPortIndex(const QModelIndex &currentIndex,
const QModelIndex &previousIndex);
private slots:

View File

@ -361,15 +361,13 @@ void StreamModel::setCurrentPortIndex(const QModelIndex &current)
else
{
qDebug("change to valid port");
// Disconnect any existing connection to avoid duplication
// Qt 4.6 has Qt::UniqueConnection, but we want to remain compatible
// with earlier Qt versions
if (mCurrentPort)
{
disconnect(mCurrentPort, SIGNAL(streamListChanged(int, int)),
this, SLOT(when_mCurrentPort_streamListChanged(int, int)));
}
quint16 pg = current.internalId() >> 16;
// TODO: make mCurrentPort a smart weak pointer
mCurrentPort = pgl->mPortGroups[pgl->indexOfPortGroup(pg)]->mPorts[current.row()];
connect(mCurrentPort, SIGNAL(streamListChanged(int, int)),
this, SLOT(when_mCurrentPort_streamListChanged(int, int)));

View File

@ -126,6 +126,8 @@ void StreamsWidget::on_tvStreamList_activated(const QModelIndex & index)
qDebug("stream list activated\n");
Q_ASSERT(plm->isPort(currentPortIndex_));
Port &curPort = plm->port(currentPortIndex_);
QList<Stream*> streams;
@ -143,11 +145,10 @@ void StreamsWidget::setCurrentPortIndex(const QModelIndex &portIndex)
if (!plm)
return;
// XXX: We assume portIndex corresponds to sourceModel, not proxyModel
if (!plm->isPort(portIndex))
return;
// XXX: We assume portIndex corresponds to sourceModel, not proxyModel;
// caller should ensure this
qDebug("In %s", __FUNCTION__);
qDebug("In %s", __PRETTY_FUNCTION__);
currentPortIndex_ = portIndex;
plm->getStreamModel()->setCurrentPortIndex(portIndex);
@ -223,6 +224,8 @@ void StreamsWidget::on_actionNew_Stream_triggered()
count = selectionModel->selection().at(0).height();
}
Q_ASSERT(plm->isPort(currentPortIndex_));
Port &curPort = plm->port(currentPortIndex_);
QList<Stream*> streams;
@ -243,6 +246,8 @@ void StreamsWidget::on_actionEdit_Stream_triggered()
if (!streamModel->hasSelection())
return;
Q_ASSERT(plm->isPort(currentPortIndex_));
Port &curPort = plm->port(currentPortIndex_);
QList<Stream*> streams;
@ -262,6 +267,8 @@ void StreamsWidget::on_actionDuplicate_Stream_triggered()
qDebug("Duplicate Stream Action");
Q_ASSERT(plm->isPort(currentPortIndex_));
if (model->hasSelection())
{
bool isOk;
@ -304,6 +311,8 @@ void StreamsWidget::on_actionFind_Replace_triggered()
{
qDebug("Find & Replace Action");
Q_ASSERT(plm->isPort(currentPortIndex_));
QItemSelectionModel* selectionModel = tvStreamList->selectionModel();
FindReplaceDialog::Action action;