Add feature to duplicate selected streams to create user defined number of copies

Fixes issue 23
This commit is contained in:
Srivats P. 2015-03-01 21:58:40 +05:30
parent e3e61b7320
commit ecbb257912
7 changed files with 65 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

View File

@ -33,6 +33,7 @@
<file>icons/sound_none.png</file> <file>icons/sound_none.png</file>
<file>icons/stream_add.png</file> <file>icons/stream_add.png</file>
<file>icons/stream_delete.png</file> <file>icons/stream_delete.png</file>
<file>icons/stream_duplicate.png</file>
<file>icons/stream_edit.png</file> <file>icons/stream_edit.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -422,6 +422,31 @@ void Port::updateStats(OstProto::PortStats *portStats)
} }
} }
void Port::duplicateStreams(const QList<int> &list, int count)
{
QList<OstProto::Stream> sources;
foreach(int index, list) {
OstProto::Stream stream;
Q_ASSERT(index < mStreams.size());
mStreams.at(index)->protoDataCopyInto(stream);
sources.append(stream);
}
int insertAt = mStreams.size();
for (int i=0; i < count; i++) {
for (int j=0; j < sources.size(); j++) {
newStreamAt(insertAt, &sources.at(j));
// Rename stream by appending the copy count
mStreams.at(insertAt)->setName(QString("%1 (%2)")
.arg(mStreams.at(insertAt)->name())
.arg(i+1));
insertAt++;
}
}
emit streamListChanged(mPortGroupId, mPortId);
}
bool Port::openStreams(QString fileName, bool append, QString &error) bool Port::openStreams(QString fileName, bool append, QString &error)
{ {
bool ret = false; bool ret = false;

View File

@ -138,6 +138,8 @@ public:
void recalculateAverageRates(); void recalculateAverageRates();
void updateStats(OstProto::PortStats *portStats); void updateStats(OstProto::PortStats *portStats);
void duplicateStreams(const QList<int> &list, int count);
bool openStreams(QString fileName, bool append, QString &error); bool openStreams(QString fileName, bool append, QString &error);
bool saveStreams(QString fileName, QString fileType, QString &error); bool saveStreams(QString fileName, QString fileType, QString &error);

View File

@ -60,6 +60,7 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
// Populate StramList Context Menu Actions // Populate StramList Context Menu Actions
tvStreamList->addAction(actionNew_Stream); tvStreamList->addAction(actionNew_Stream);
tvStreamList->addAction(actionEdit_Stream); tvStreamList->addAction(actionEdit_Stream);
tvStreamList->addAction(actionDuplicate_Stream);
tvStreamList->addAction(actionDelete_Stream); tvStreamList->addAction(actionDelete_Stream);
sep = new QAction(this); sep = new QAction(this);
@ -280,7 +281,8 @@ void PortsWindow::updateStreamViewActions()
actionEdit_Stream->setEnabled(true); actionEdit_Stream->setEnabled(true);
} }
// Delete is always enabled as long as we have a selection // Duplicate/Delete are always enabled as long as we have a selection
actionDuplicate_Stream->setEnabled(true);
actionDelete_Stream->setEnabled(true); actionDelete_Stream->setEnabled(true);
} }
else else
@ -291,6 +293,7 @@ void PortsWindow::updateStreamViewActions()
else else
actionNew_Stream->setDisabled(true); actionNew_Stream->setDisabled(true);
actionEdit_Stream->setDisabled(true); actionEdit_Stream->setDisabled(true);
actionDuplicate_Stream->setDisabled(true);
actionDelete_Stream->setDisabled(true); actionDelete_Stream->setDisabled(true);
} }
actionOpen_Streams->setEnabled(plm->isPort( actionOpen_Streams->setEnabled(plm->isPort(
@ -525,6 +528,30 @@ void PortsWindow::on_actionEdit_Stream_triggered()
} }
} }
void PortsWindow::on_actionDuplicate_Stream_triggered()
{
QItemSelectionModel* model = tvStreamList->selectionModel();
QModelIndex current = tvPortList->selectionModel()->currentIndex();
qDebug("Duplicate Stream Action");
if (model->hasSelection())
{
bool isOk;
int count = QInputDialog::getInteger(this, "Duplicate Streams",
"Count", 1, 1, 9999, 1, &isOk);
if (!isOk)
return;
QList<int> list;
foreach(QModelIndex index, model->selectedRows())
list.append(index.row());
plm->port(current).duplicateStreams(list, count);
}
else
qDebug("No selection");
}
void PortsWindow::on_actionDelete_Stream_triggered() void PortsWindow::on_actionDelete_Stream_triggered()
{ {
qDebug("Delete Stream Action"); qDebug("Delete Stream Action");

View File

@ -74,6 +74,7 @@ private slots:
void on_actionNew_Stream_triggered(); void on_actionNew_Stream_triggered();
void on_actionEdit_Stream_triggered(); void on_actionEdit_Stream_triggered();
void on_actionDuplicate_Stream_triggered();
void on_actionDelete_Stream_triggered(); void on_actionDelete_Stream_triggered();
void on_actionOpen_Streams_triggered(); void on_actionOpen_Streams_triggered();

View File

@ -258,6 +258,14 @@
<string>Port Configuration ...</string> <string>Port Configuration ...</string>
</property> </property>
</action> </action>
<action name="actionDuplicate_Stream" >
<property name="icon" >
<iconset resource="ostinato.qrc" >:/icons/stream_duplicate.png</iconset>
</property>
<property name="text" >
<string>Duplicate Stream</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="ostinato.qrc" /> <include location="ostinato.qrc" />