2008-06-14 01:35:17 -05:00
|
|
|
#include <QHostAddress>
|
2008-05-25 06:30:30 -05:00
|
|
|
#include "packetmodel.h"
|
|
|
|
|
|
|
|
PacketModel::PacketModel(Stream *pStream, QObject *parent)
|
|
|
|
{
|
|
|
|
mpStream = pStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PacketModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
IndexId parentId;
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
// Parent == Invalid i.e. Invisible Root.
|
|
|
|
// ==> Children are Protocol (Top Level) Items
|
2008-05-25 06:53:49 -05:00
|
|
|
if (!parent.isValid())
|
2008-08-23 23:39:08 -05:00
|
|
|
return mpStream->numProtocols();
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
// Parent - Valid Item
|
|
|
|
parentId.w = parent.internalId();
|
|
|
|
switch(parentId.ws.type)
|
2008-05-25 06:30:30 -05:00
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
case ITYP_PROTOCOL:
|
2008-08-23 23:39:08 -05:00
|
|
|
return mpStream->protocol(parentId.ws.protocol)->numFields();
|
2008-05-25 06:53:49 -05:00
|
|
|
case ITYP_FIELD:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
2008-05-25 06:30:30 -05:00
|
|
|
}
|
|
|
|
|
2008-06-14 01:35:17 -05:00
|
|
|
Q_ASSERT(1 == 1); // Unreachable code
|
2008-05-25 06:53:49 -05:00
|
|
|
qWarning("%s: Catch all - need to investigate", __FUNCTION__);
|
2008-05-25 06:30:30 -05:00
|
|
|
return 0; // catch all
|
|
|
|
}
|
|
|
|
|
|
|
|
int PacketModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex PacketModel::index(int row, int col, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index;
|
|
|
|
IndexId id, parentId;
|
|
|
|
|
|
|
|
if (!hasIndex(row, col, parent))
|
|
|
|
goto _exit;
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
// Parent is Invisible Root
|
|
|
|
// Request for a Protocol Item
|
|
|
|
if (!parent.isValid())
|
2008-05-25 06:30:30 -05:00
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
id.w = 0;
|
|
|
|
id.ws.type = ITYP_PROTOCOL;
|
2008-06-14 01:35:17 -05:00
|
|
|
id.ws.protocol = row;
|
2008-05-25 06:30:30 -05:00
|
|
|
index = createIndex(row, col, id.w);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
// Parent is a Valid Item
|
|
|
|
parentId.w = parent.internalId();
|
|
|
|
id.w = parentId.w;
|
|
|
|
switch(parentId.ws.type)
|
2008-05-25 06:30:30 -05:00
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
case ITYP_PROTOCOL:
|
|
|
|
id.ws.type = ITYP_FIELD;
|
2008-05-25 06:30:30 -05:00
|
|
|
index = createIndex(row, col, id.w);
|
|
|
|
goto _exit;
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
case ITYP_FIELD:
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
default:
|
|
|
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
|
|
|
}
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-06-14 01:35:17 -05:00
|
|
|
Q_ASSERT(1 == 1); // Unreachable code
|
|
|
|
|
2008-05-25 06:30:30 -05:00
|
|
|
_exit:
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex PacketModel::parent(const QModelIndex &index) const
|
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
QModelIndex parentIndex;
|
2008-05-25 06:30:30 -05:00
|
|
|
IndexId id, parentId;
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
if (!index.isValid())
|
|
|
|
return QModelIndex();
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
id.w = index.internalId();
|
|
|
|
parentId.w = id.w;
|
|
|
|
switch(id.ws.type)
|
2008-05-25 06:30:30 -05:00
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
case ITYP_PROTOCOL:
|
|
|
|
// return invalid index for invisible root
|
|
|
|
goto _exit;
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
case ITYP_FIELD:
|
|
|
|
parentId.ws.type = ITYP_PROTOCOL;
|
2008-06-14 01:35:17 -05:00
|
|
|
parentIndex = createIndex(id.ws.protocol, 0, parentId.w);
|
2008-05-25 06:53:49 -05:00
|
|
|
goto _exit;
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
default:
|
|
|
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
2008-05-25 06:30:30 -05:00
|
|
|
}
|
|
|
|
|
2008-06-14 01:35:17 -05:00
|
|
|
Q_ASSERT(1 == 1); // Unreachable code
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
_exit:
|
|
|
|
return parentIndex;
|
2008-05-25 06:30:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant PacketModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2008-05-25 06:53:49 -05:00
|
|
|
IndexId id;
|
|
|
|
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
2008-08-30 03:49:08 -05:00
|
|
|
id.w = index.internalId();
|
|
|
|
|
|
|
|
// FIXME(HI): Relook at this completely
|
|
|
|
if (role == Qt::UserRole)
|
|
|
|
{
|
|
|
|
switch(id.ws.type)
|
|
|
|
{
|
|
|
|
case ITYP_PROTOCOL:
|
|
|
|
return QByteArray();
|
|
|
|
|
|
|
|
case ITYP_FIELD:
|
|
|
|
return mpStream->protocol(id.ws.protocol)->fieldRawValue(
|
|
|
|
index.row());
|
|
|
|
|
|
|
|
default:
|
|
|
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
|
|
|
}
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
if (role != Qt::DisplayRole)
|
|
|
|
return QVariant();
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
switch(id.ws.type)
|
|
|
|
{
|
|
|
|
case ITYP_PROTOCOL:
|
2008-08-23 23:39:08 -05:00
|
|
|
return QString("%1 (%2)")
|
|
|
|
.arg(mpStream->protocol(id.ws.protocol)->protocolShortName())
|
|
|
|
.arg(mpStream->protocol(id.ws.protocol)->protocolName());
|
2008-05-25 06:53:49 -05:00
|
|
|
|
|
|
|
case ITYP_FIELD:
|
2008-08-23 23:39:08 -05:00
|
|
|
return mpStream->protocol(id.ws.protocol)->fieldName(index.row()) +
|
|
|
|
QString(" : ") +
|
|
|
|
mpStream->protocol(id.ws.protocol)->fieldTextValue(index.row());
|
2008-05-25 06:53:49 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
|
|
|
}
|
2008-05-25 06:30:30 -05:00
|
|
|
|
2008-06-14 01:35:17 -05:00
|
|
|
Q_ASSERT(1 == 1); // Unreachable code
|
|
|
|
|
2008-05-25 06:53:49 -05:00
|
|
|
return QVariant();
|
2008-05-25 06:30:30 -05:00
|
|
|
}
|