diff --git a/client/portswindow.cpp b/client/portswindow.cpp index addec00..216f04c 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -768,18 +768,37 @@ void PortsWindow::on_actionNew_Stream_triggered() { qDebug("New Stream Action"); + QItemSelectionModel* selectionModel = tvStreamList->selectionModel(); + if (selectionModel->selection().size() > 1) { + qDebug("%s: Unexpected selection size %d, can't add", + selectionModel->selection().size()); + return; + } + // In case nothing is selected, insert 1 row at the end - int row = plm->getStreamModel()->rowCount(), count = 1; + StreamModel *streamModel = plm->getStreamModel(); + int row = streamModel->rowCount(), count = 1; // In case we have a single range selected; insert as many rows as // in the singe selected range before the top of the selected range - if (tvStreamList->selectionModel()->selection().size() == 1) + if (selectionModel->selection().size() == 1) { - row = tvStreamList->selectionModel()->selection().at(0).top(); - count = tvStreamList->selectionModel()->selection().at(0).height(); + row = selectionModel->selection().at(0).top(); + count = selectionModel->selection().at(0).height(); } - plm->getStreamModel()->insertRows(row, count); + Port &curPort = plm->port(proxyPortModel ? + proxyPortModel->mapToSource(tvPortList->currentIndex()) : + tvPortList->currentIndex()); + + QList streams; + for (int i = 0; i < count; i++) + streams.append(new Stream); + + StreamConfigDialog scd(streams, curPort, this); + scd.setWindowTitle(tr("Add Stream(s)")); + if (scd.exec() == QDialog::Accepted) + streamModel->insert(row, streams); } void PortsWindow::on_actionEdit_Stream_triggered() diff --git a/client/streammodel.cpp b/client/streammodel.cpp index 99c12ef..a97acde 100644 --- a/client/streammodel.cpp +++ b/client/streammodel.cpp @@ -223,6 +223,30 @@ QVariant StreamModel::headerData(int section, Qt::Orientation orientation, int r return QVariant(); } +/*! + * Inserts streams before the given row + * + * StreamModel takes ownership of the passed streams; caller should + * not try to access them after calling this function + */ +bool StreamModel::insert(int row, QList &streams) +{ + int count = streams.size(); + qDebug("insert row = %d", row); + qDebug("insert count = %d", count); + beginInsertRows(QModelIndex(), row, row+count-1); + for (int i = 0; i < count; i++) { + OstProto::Stream s; + streams.at(i)->protoDataCopyInto(s); + mCurrentPort->newStreamAt(row+i, &s); + delete streams.at(i); + } + streams.clear(); + endInsertRows(); + + return true; +} + bool StreamModel::insertRows(int row, int count, const QModelIndex &/*parent*/) { qDebug("insertRows() row = %d", row); diff --git a/client/streammodel.h b/client/streammodel.h index d559618..57cdb97 100644 --- a/client/streammodel.h +++ b/client/streammodel.h @@ -25,6 +25,7 @@ along with this program. If not, see #include "port.h" class PortGroupList; +class Stream; class StreamModel : public QAbstractTableModel { @@ -44,6 +45,7 @@ class StreamModel : public QAbstractTableModel int role = Qt::EditRole); QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + bool insert(int row, QList &streams); bool insertRows (int row, int count, const QModelIndex & parent = QModelIndex()); bool removeRows (int row, int count,