UX: Open StreamConfigDialog on add stream

Add+Edit is now reduced to single step. For new users, it is easier to
comprehend this single step and no text hint is needed for edit
This commit is contained in:
Srivats P 2017-09-20 22:00:47 +05:30
parent 360fa13c97
commit fd243f6847
3 changed files with 50 additions and 5 deletions

View File

@ -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<Stream*> 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()

View File

@ -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<Stream*> &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);

View File

@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#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<Stream*> &streams);
bool insertRows (int row, int count,
const QModelIndex & parent = QModelIndex());
bool removeRows (int row, int count,