2009-03-10 11:48:03 -05:00
|
|
|
#include "stream.h"
|
2008-05-03 09:37:10 -05:00
|
|
|
#include "streammodel.h"
|
|
|
|
#include "portgrouplist.h"
|
|
|
|
#include "qicon.h"
|
|
|
|
|
|
|
|
StreamModel::StreamModel(PortGroupList *p, QObject *parent)
|
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
pgl = p;
|
|
|
|
mCurrentPort = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StreamModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (parent.isValid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (mCurrentPort)
|
2008-08-23 23:39:08 -05:00
|
|
|
return mCurrentPort->numStreams();
|
2008-05-03 09:37:10 -05:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StreamModel::columnCount(const QModelIndex &parent ) const
|
|
|
|
{
|
|
|
|
return (int) StreamMaxFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags StreamModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
|
|
|
|
|
|
|
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case StreamIcon:
|
|
|
|
break;
|
|
|
|
case StreamName:
|
|
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
break;
|
|
|
|
case StreamStatus:
|
2009-03-10 11:48:03 -05:00
|
|
|
flags |= Qt::ItemIsUserCheckable;
|
|
|
|
break;
|
|
|
|
case StreamNextWhat:
|
2008-09-28 13:01:52 -05:00
|
|
|
flags |= Qt::ItemIsEditable;
|
2008-05-03 09:37:10 -05:00
|
|
|
break;
|
|
|
|
default:
|
2009-03-10 11:48:03 -05:00
|
|
|
//qFatal("Missed case in switch!");
|
2008-05-03 09:37:10 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
2009-03-10 11:48:03 -05:00
|
|
|
|
2008-05-03 09:37:10 -05:00
|
|
|
QVariant StreamModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
// Check for a valid index
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
// Check for row/column limits
|
2008-08-23 23:39:08 -05:00
|
|
|
if (index.row() >= mCurrentPort->numStreams())
|
2008-05-03 09:37:10 -05:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (index.column() >= StreamMaxFields)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (mCurrentPort == NULL)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
// Return data based on field and role
|
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case StreamIcon:
|
|
|
|
{
|
|
|
|
if (role == Qt::DecorationRole)
|
|
|
|
return QIcon(":/icons/stream_edit.png");
|
|
|
|
else
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StreamName:
|
|
|
|
{
|
|
|
|
if ((role == Qt::DisplayRole) || (role == Qt::EditRole))
|
2009-04-27 11:51:44 -05:00
|
|
|
return mCurrentPort->streamByIndex(index.row())->name();
|
2008-05-03 09:37:10 -05:00
|
|
|
else
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StreamStatus:
|
|
|
|
{
|
2009-03-10 11:48:03 -05:00
|
|
|
if ((role == Qt::CheckStateRole))
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-04-27 11:51:44 -05:00
|
|
|
if (mCurrentPort->streamByIndex(index.row())->isEnabled())
|
2008-05-03 09:37:10 -05:00
|
|
|
return Qt::Checked;
|
|
|
|
else
|
|
|
|
return Qt::Unchecked;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QVariant();
|
2009-03-10 11:48:03 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StreamNextWhat:
|
|
|
|
{
|
2009-04-27 11:51:44 -05:00
|
|
|
int val = mCurrentPort->streamByIndex(index.row())->nextWhat();
|
2009-03-10 11:48:03 -05:00
|
|
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
return nextWhatOptionList().at(val);
|
|
|
|
else if (role == Qt::EditRole)
|
|
|
|
return val;
|
|
|
|
else
|
|
|
|
return QVariant();
|
|
|
|
|
2008-05-03 09:37:10 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2009-03-10 11:48:03 -05:00
|
|
|
qFatal("-------------UNHANDLED STREAM FIELD----------------");
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StreamModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
if (mCurrentPort == NULL)
|
|
|
|
return false;
|
|
|
|
|
2009-03-10 11:48:03 -05:00
|
|
|
if (index.isValid())
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
2009-03-10 11:48:03 -05:00
|
|
|
// Edit Supported Fields
|
2008-05-03 09:37:10 -05:00
|
|
|
case StreamName:
|
2009-04-27 11:51:44 -05:00
|
|
|
mCurrentPort->streamByIndex(index.row())->setName(value.toString());
|
2009-03-10 11:48:03 -05:00
|
|
|
emit(dataChanged(index, index));
|
2008-05-03 09:37:10 -05:00
|
|
|
return true;
|
2009-03-10 11:48:03 -05:00
|
|
|
|
2008-05-03 09:37:10 -05:00
|
|
|
case StreamStatus:
|
2009-08-02 09:52:34 -05:00
|
|
|
mCurrentPort->streamByIndex(index.row())->setEnabled(value.toBool());
|
2009-03-10 11:48:03 -05:00
|
|
|
emit(dataChanged(index, index));
|
2008-05-03 09:37:10 -05:00
|
|
|
return true;
|
2009-03-10 11:48:03 -05:00
|
|
|
|
|
|
|
case StreamNextWhat:
|
|
|
|
if (role == Qt::EditRole)
|
|
|
|
{
|
2009-04-27 11:51:44 -05:00
|
|
|
mCurrentPort->streamByIndex(index.row())->setNextWhat(
|
2009-03-10 11:48:03 -05:00
|
|
|
(Stream::NextWhat)value.toInt());
|
|
|
|
emit(dataChanged(index, index));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2008-05-03 09:37:10 -05:00
|
|
|
|
|
|
|
// Edit Not Supported Fields
|
|
|
|
case StreamIcon:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Unhandled Stream Field
|
|
|
|
default:
|
|
|
|
qDebug("-------------UNHANDLED STREAM FIELD----------------");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-03-10 11:48:03 -05:00
|
|
|
|
2008-05-03 09:37:10 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant StreamModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (role != Qt::DisplayRole)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
switch(section)
|
|
|
|
{
|
|
|
|
case StreamIcon:
|
2009-03-10 11:48:03 -05:00
|
|
|
return QString("");
|
2008-05-03 09:37:10 -05:00
|
|
|
break;
|
|
|
|
case StreamName:
|
|
|
|
return QString("Name");
|
|
|
|
break;
|
|
|
|
case StreamStatus:
|
2009-03-10 11:48:03 -05:00
|
|
|
return QString("");
|
|
|
|
break;
|
|
|
|
case StreamNextWhat:
|
|
|
|
return QString("Goto");
|
2008-05-03 09:37:10 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug("-------------UNHANDLED STREAM FIELD----------------");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QString("%1").arg(section+1);
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StreamModel::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
qDebug("insertRows() row = %d", row);
|
|
|
|
qDebug("insertRows() count = %d", count);
|
|
|
|
beginInsertRows(QModelIndex(), row, row+count-1);
|
|
|
|
for (int i = 0; i < count; i++)
|
2008-08-23 23:39:08 -05:00
|
|
|
mCurrentPort->newStreamAt(row);
|
2008-05-03 09:37:10 -05:00
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StreamModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
qDebug("removeRows() row = %d", row);
|
|
|
|
qDebug("removeRows() count = %d", count);
|
|
|
|
beginRemoveRows(QModelIndex(), row, row+count-1);
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
2008-08-23 23:39:08 -05:00
|
|
|
mCurrentPort->deleteStreamAt(row);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
endRemoveRows();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------- SLOTS ------------------------
|
|
|
|
|
|
|
|
void StreamModel::setCurrentPortIndex(const QModelIndex ¤t)
|
|
|
|
{
|
|
|
|
if (!current.isValid() || !pgl->isPort(current))
|
|
|
|
{
|
|
|
|
qDebug("current is either invalid or not a port");
|
|
|
|
mCurrentPort = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("change to valid port");
|
|
|
|
quint16 pg = current.internalId() >> 16;
|
2009-11-14 09:09:19 -06:00
|
|
|
mCurrentPort = pgl->mPortGroups[pgl->indexOfPortGroup(pg)]->mPorts[current.row()];
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
reset();
|
|
|
|
}
|