diff --git a/client/port.h b/client/port.h index 04c0feb..a515325 100644 --- a/client/port.h +++ b/client/port.h @@ -115,12 +115,17 @@ public: Q_ASSERT(index < mStreams.size()); return mStreams[index]; } - Stream* mutableStreamByIndex(int index) + Stream* mutableStreamByIndex(int index, bool assumeChange = true) { Q_ASSERT(index < mStreams.size()); - setDirty(true); // assume - that's the best we can do atm + if (assumeChange) + setDirty(true); return mStreams[index]; } + void setLocalConfigChanged(bool changed) + { + setDirty(changed); + } OstProto::LinkState linkState() { return stats.state().link_state(); } diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 3a1c911..addec00 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -302,29 +302,26 @@ void PortsWindow::showMyReservedPortsOnly(bool enabled) void PortsWindow::on_tvStreamList_activated(const QModelIndex & index) { - QModelIndex currentPort = tvPortList->currentIndex(); - StreamConfigDialog *scd; - int ret; - - if (proxyPortModel) - currentPort = proxyPortModel->mapToSource(currentPort); - if (!index.isValid()) { qDebug("%s: invalid index", __FUNCTION__); return; } - QList streams; - streams.append(plm->port(currentPort).mutableStreamByIndex(index.row())); - scd = new StreamConfigDialog(streams, plm->port(currentPort), this); qDebug("stream list activated\n"); - ret = scd->exec(); - if (ret == QDialog::Accepted) - plm->port(currentPort).recalculateAverageRates(); + Port &curPort = plm->port(proxyPortModel ? + proxyPortModel->mapToSource(tvPortList->currentIndex()) : + tvPortList->currentIndex()); - delete scd; + QList streams; + streams.append(curPort.mutableStreamByIndex(index.row(), false)); + + StreamConfigDialog scd(streams, curPort, this); + if (scd.exec() == QDialog::Accepted) { + curPort.recalculateAverageRates(); + curPort.setLocalConfigChanged(true); + } } void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex, @@ -493,21 +490,15 @@ void PortsWindow::updateStreamViewActions() tvStreamList->selectionModel()->selection().size()); // If more than one non-contiguous ranges selected, - // disable "New" and "Edit" + // disable "New" if (tvStreamList->selectionModel()->selection().size() > 1) { actionNew_Stream->setDisabled(true); - actionEdit_Stream->setDisabled(true); } else { actionNew_Stream->setEnabled(true); - - // Enable "Edit" only if the single range has a single row - if (tvStreamList->selectionModel()->selection().at(0).height() > 1) - actionEdit_Stream->setDisabled(true); - else - actionEdit_Stream->setEnabled(true); + actionEdit_Stream->setEnabled(true); } // Duplicate/Delete are always enabled as long as we have a selection @@ -795,12 +786,22 @@ void PortsWindow::on_actionEdit_Stream_triggered() { qDebug("Edit Stream Action"); - // Ensure we have only one range selected which contains only one row - if ((tvStreamList->selectionModel()->selection().size() == 1) && - (tvStreamList->selectionModel()->selection().at(0).height() == 1)) - { - on_tvStreamList_activated(tvStreamList->selectionModel()-> - selection().at(0).topLeft()); + QItemSelectionModel* streamModel = tvStreamList->selectionModel(); + if (!streamModel->hasSelection()) + return; + + Port &curPort = plm->port(proxyPortModel ? + proxyPortModel->mapToSource(tvPortList->currentIndex()) : + tvPortList->currentIndex()); + + QList streams; + foreach(QModelIndex index, streamModel->selectedRows()) + streams.append(curPort.mutableStreamByIndex(index.row(), false)); + + StreamConfigDialog scd(streams, curPort, this); + if (scd.exec() == QDialog::Accepted) { + curPort.recalculateAverageRates(); + curPort.setLocalConfigChanged(true); } } diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 8daa491..e8db52e 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -43,17 +43,24 @@ StreamConfigDialog::StreamConfigDialog( QList &streamList, const Port &port, QWidget *parent) - : QDialog (parent), streamList_(streamList), mPort(port) + : QDialog (parent), _userStreamList(streamList), mPort(port) { - OstProto::Stream s; mCurrentStreamIndex = 0; - // FIXME: temporary till we support a list - Q_ASSERT(streamList_.size() == 1); + Q_ASSERT(_userStreamList.size() > 0); - mpStream = new Stream; - streamList_.at(mCurrentStreamIndex)->protoDataCopyInto(s); - mpStream->protoDataCopyFrom(s); + // Create a copy of the user provided stream list + // We need a copy because user may edit multiple streams and then + // discard the edit - in this case the user provided stream list + // should not be modified on return + foreach(Stream* stm, _userStreamList) { + OstProto::Stream s; + stm->protoDataCopyInto(s); + _streamList.append(new Stream()); + _streamList.last()->protoDataCopyFrom(s); + } + + mpStream = _streamList.at(mCurrentStreamIndex); _iter = mpStream->createProtocolListIterator(); isUpdateInProgress = false; @@ -158,8 +165,6 @@ StreamConfigDialog::StreamConfigDialog( this, SLOT(when_lvSelectedProtocols_currentChanged(const QModelIndex&, const QModelIndex&))); - variableFieldsWidget->setStream(mpStream); - LoadCurrentStream(); mpPacketModel = new PacketModel(this); tvPacketTree->setModel(mpPacketModel); @@ -172,10 +177,9 @@ StreamConfigDialog::StreamConfigDialog( vwPacketDump->setModel(mpPacketModel); vwPacketDump->setSelectionModel(tvPacketTree->selectionModel()); - // TODO(MED): - //! \todo Enable navigation of streams - pbPrev->setHidden(true); - pbNext->setHidden(true); + pbPrev->setDisabled(mCurrentStreamIndex == 0); + pbNext->setDisabled(int(mCurrentStreamIndex) == (_streamList.size()-1)); + //! \todo Support Goto Stream Id leStreamId->setHidden(true); disconnect(rbActionGotoStream, SIGNAL(toggled(bool)), leStreamId, SLOT(setEnabled(bool))); @@ -325,7 +329,8 @@ StreamConfigDialog::~StreamConfigDialog() } delete _iter; - delete mpStream; + while (!_streamList.isEmpty()) + delete _streamList.takeFirst(); } void StreamConfigDialog::loadProtocolWidgets() @@ -406,30 +411,6 @@ void StreamConfigDialog::on_cmbPktLenMode_currentIndexChanged(QString mode) } } -void StreamConfigDialog::on_pbPrev_clicked() -{ -#if 0 - StoreCurrentStream(currStreamIdx); - currStreamIdx--; - LoadCurrentStream(currStreamIdx); - - pbPrev->setDisabled((currStreamIdx == 0)); - pbNext->setDisabled((currStreamIdx == 2)); -#endif -} - -void StreamConfigDialog::on_pbNext_clicked() -{ -#if 0 - StoreCurrentStream(currStreamIdx); - currStreamIdx++; - LoadCurrentStream(currStreamIdx); - - pbPrev->setDisabled((currStreamIdx == 0)); - pbNext->setDisabled((currStreamIdx == 2)); -#endif -} - void StreamConfigDialog::on_tbSelectProtocols_currentChanged(int index) { qDebug("%s, index = %d", __FUNCTION__, index); @@ -967,6 +948,7 @@ void StreamConfigDialog::LoadCurrentStream() QString str; qDebug("loading mpStream %p", mpStream); + variableFieldsWidget->setStream(mpStream); // Meta Data { @@ -986,6 +968,7 @@ void StreamConfigDialog::LoadCurrentStream() // Variable Fields { + variableFieldsWidget->clear(); variableFieldsWidget->load(); } @@ -1202,13 +1185,9 @@ void StreamConfigDialog::on_leBitsPerSec_textEdited(const QString &text) } } -void StreamConfigDialog::on_pbOk_clicked() +bool StreamConfigDialog::isCurrentStreamValid() { QString log; - OstProto::Stream s; - - // Store dialog contents into stream - StoreCurrentStream(); if ((mPort.transmitMode() == OstProto::kInterleavedTransmit) && (mpStream->isFrameVariable())) @@ -1224,12 +1203,68 @@ void StreamConfigDialog::on_pbOk_clicked() if (QMessageBox::warning(this, "Preflight Check", log + "\nContinue?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) - return; + return false; } - // Copy the data from the "local working copy of stream" to "actual stream" - mpStream->protoDataCopyInto(s); - streamList_[mCurrentStreamIndex]->protoDataCopyFrom(s); + return true; +} + +void StreamConfigDialog::on_pbPrev_clicked() +{ + Q_ASSERT(mCurrentStreamIndex > 0); + + StoreCurrentStream(); + + if (!isCurrentStreamValid()) + return; + + delete _iter; + mpStream = _streamList.at(--mCurrentStreamIndex); + _iter = mpStream->createProtocolListIterator(); + + LoadCurrentStream(); + on_twTopLevel_currentChanged(twTopLevel->currentIndex()); + + pbPrev->setDisabled(mCurrentStreamIndex == 0); + pbNext->setDisabled(int(mCurrentStreamIndex) == (_streamList.size()-1)); +} + +void StreamConfigDialog::on_pbNext_clicked() +{ + Q_ASSERT(int(mCurrentStreamIndex) < (_streamList.size()-1)); + + StoreCurrentStream(); + + if (!isCurrentStreamValid()) + return; + + delete _iter; + mpStream = _streamList.at(++mCurrentStreamIndex); + _iter = mpStream->createProtocolListIterator(); + + LoadCurrentStream(); + on_twTopLevel_currentChanged(twTopLevel->currentIndex()); + + pbPrev->setDisabled(mCurrentStreamIndex == 0); + pbNext->setDisabled(int(mCurrentStreamIndex) == (_streamList.size()-1)); + +} + +void StreamConfigDialog::on_pbOk_clicked() +{ + // Store dialog contents into current stream + StoreCurrentStream(); + + if (!isCurrentStreamValid()) + return; + + // Copy the working copy of streams to user provided streams + Q_ASSERT(_userStreamList.size() == _streamList.size()); + for (int i = 0; i < _streamList.size(); i++) { + OstProto::Stream s; + _streamList.at(i)->protoDataCopyInto(s); + _userStreamList[i]->protoDataCopyFrom(s); + } qDebug("stream stored"); diff --git a/client/streamconfigdialog.h b/client/streamconfigdialog.h index 11f0b29..cecb9cc 100644 --- a/client/streamconfigdialog.h +++ b/client/streamconfigdialog.h @@ -73,7 +73,8 @@ private: QStringListModel *mpAvailableProtocolsModel; QStringListModel *mpSelectedProtocolsModel; - QList streamList_; + QList _userStreamList; + QList _streamList; const Port& mPort; uint mCurrentStreamIndex; @@ -94,6 +95,7 @@ private: static int lastProtocolDataIndex; void setupUiExtra(); + bool isCurrentStreamValid(); void LoadCurrentStream(); void StoreCurrentStream(); void loadProtocolWidgets();