sign: StreamStatsModel is now a nice table
This commit is contained in:
parent
fda7807797
commit
60be43006f
@ -21,23 +21,133 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "protocol.pb.h"
|
||||
|
||||
// XXX: Keep the enum in sync with it's string
|
||||
enum {
|
||||
kRxPkts,
|
||||
kTxPkts,
|
||||
kRxBytes,
|
||||
kTxBytes,
|
||||
kMaxStreamStats
|
||||
};
|
||||
static QStringList statTitles = QStringList()
|
||||
<< "Rx Pkts"
|
||||
<< "Tx Pkts"
|
||||
<< "Rx Bytes"
|
||||
<< "Tx Bytes";
|
||||
|
||||
StreamStatsModel::StreamStatsModel(QObject *parent)
|
||||
: QStringListModel(parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int StreamStatsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return guidList_.size();
|
||||
}
|
||||
|
||||
int StreamStatsModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return portList_.size() * kMaxStreamStats;
|
||||
}
|
||||
|
||||
QVariant StreamStatsModel::headerData(
|
||||
int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (orientation) {
|
||||
case Qt::Horizontal: // Column Header
|
||||
return QString("Port %1-%2\n%3")
|
||||
.arg(portList_.at(section/kMaxStreamStats).first)
|
||||
.arg(portList_.at(section/kMaxStreamStats).second)
|
||||
.arg(statTitles.at(section % kMaxStreamStats));
|
||||
case Qt::Vertical: // Row Header
|
||||
return QString("Stream GUID %1")
|
||||
.arg(guidList_.at(section));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant StreamStatsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
Guid guid = guidList_.at(index.row());
|
||||
PortGroupPort pgp = portList_.at(index.column()/kMaxStreamStats);
|
||||
int stat = index.column() % kMaxStreamStats;
|
||||
|
||||
switch (stat) {
|
||||
case kRxPkts:
|
||||
return streamStats_.value(guid).value(pgp).rxPkts;
|
||||
case kTxPkts:
|
||||
return streamStats_.value(guid).value(pgp).txPkts;
|
||||
case kRxBytes:
|
||||
return streamStats_.value(guid).value(pgp).rxBytes;
|
||||
case kTxBytes:
|
||||
return streamStats_.value(guid).value(pgp).txBytes;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// --------------------------------------------- //
|
||||
// Slots
|
||||
// --------------------------------------------- //
|
||||
void StreamStatsModel::clearStats()
|
||||
{
|
||||
stats_.clear();
|
||||
setStringList(stats_);
|
||||
#if QT_VERSION >= 0x040600
|
||||
beginResetModel();
|
||||
#endif
|
||||
|
||||
guidList_.clear();
|
||||
portList_.clear();
|
||||
streamStats_.clear();
|
||||
|
||||
#if QT_VERSION >= 0x040600
|
||||
endResetModel();
|
||||
#else
|
||||
reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
void StreamStatsModel::appendStreamStatsList(
|
||||
quint32 /*portGroupId*/,
|
||||
quint32 portGroupId,
|
||||
const OstProto::StreamStatsList *stats)
|
||||
{
|
||||
stats_.append(stats->DebugString().c_str());
|
||||
setStringList(stats_);
|
||||
int n = stats->stream_stats_size();
|
||||
|
||||
#if QT_VERSION >= 0x040600
|
||||
beginResetModel();
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
const OstProto::StreamStats &s = stats->stream_stats(i);
|
||||
PortGroupPort pgp = PortGroupPort(portGroupId, s.port_id().id());
|
||||
Guid guid = s.stream_guid().id();
|
||||
StreamStats &ss = streamStats_[guid][pgp];
|
||||
|
||||
ss.rxPkts = s.rx_pkts();
|
||||
ss.txPkts = s.tx_pkts();
|
||||
ss.rxBytes = s.rx_bytes();
|
||||
ss.txBytes = s.tx_bytes();
|
||||
|
||||
if (!portList_.contains(pgp))
|
||||
portList_.append(pgp);
|
||||
if (!guidList_.contains(guid))
|
||||
guidList_.append(guid);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x040600
|
||||
endResetModel();
|
||||
#else
|
||||
reset();
|
||||
#endif
|
||||
|
||||
// Prevent receiving any future updates from this sender
|
||||
disconnect(sender(), 0, this, 0);
|
||||
|
@ -20,24 +20,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#ifndef _STREAM_STATS_MODEL_H
|
||||
#define _STREAM_STATS_MODEL_H
|
||||
|
||||
#include <QStringListModel> // FIXME: remove
|
||||
#include <QAbstractTableModel>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QStringList>
|
||||
|
||||
namespace OstProto {
|
||||
class StreamStatsList;
|
||||
}
|
||||
|
||||
class StreamStatsModel: public QStringListModel // FIXME: change to TableModel
|
||||
class StreamStatsModel: public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StreamStatsModel(QObject *parent = 0);
|
||||
|
||||
int rowCount(const QModelIndex &parent=QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent=QModelIndex()) const;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
public slots:
|
||||
void clearStats();
|
||||
void appendStreamStatsList(quint32 portGroupId,
|
||||
const OstProto::StreamStatsList *stats);
|
||||
private:
|
||||
QList<QString> stats_; // FIXME: remove
|
||||
typedef QPair<uint, uint> PortGroupPort; // Pair = (PortGroupId, PortId)
|
||||
typedef uint Guid;
|
||||
struct StreamStats {
|
||||
quint64 rxPkts;
|
||||
quint64 txPkts;
|
||||
quint64 rxBytes;
|
||||
quint64 txBytes;
|
||||
};
|
||||
QList<Guid> guidList_;
|
||||
QList<PortGroupPort> portList_;
|
||||
QHash<Guid, QHash<PortGroupPort, StreamStats> > streamStats_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<ui version="4.0" >
|
||||
<class>StreamStatsWindow</class>
|
||||
<widget class="QWidget" name="streamStatsWindow" >
|
||||
<widget class="QWidget" name="StreamStatsWindow" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -14,7 +14,7 @@
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QListView" name="streamStats" />
|
||||
<widget class="QTableView" name="streamStats" />
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
Loading…
Reference in New Issue
Block a user