feat: show fake data network, stream, and particles data
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#include "particlelistmodel.h"
|
||||
|
||||
ParticleListModel::ParticleListModel(Data *data, QObject *parent)
|
||||
: QAbstractListModel(parent), m_data(data), m_currentStreamId()
|
||||
{
|
||||
}
|
||||
|
||||
int ParticleListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_currentStreamId.isEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_data->particleCount(m_currentStreamId);
|
||||
}
|
||||
|
||||
QVariant ParticleListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || role != Qt::DisplayRole)
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (m_currentStreamId.isEmpty())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const QList<Particle> &particles = m_data->particlesForStream(m_currentStreamId);
|
||||
|
||||
if (index.row() < 0 || index.row() >= particles.size())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const Particle &particle = particles.at(index.row());
|
||||
|
||||
// Show dot (•) for unseen, nothing for seen
|
||||
if (particle.seen)
|
||||
{
|
||||
return particle.type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString("%1 •").arg(particle.type);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleListModel::setStreamId(const QString &streamId)
|
||||
{
|
||||
beginResetModel();
|
||||
m_currentStreamId = streamId;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int ParticleListModel::firstUnseenRow() const
|
||||
{
|
||||
if (m_currentStreamId.isEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const QList<Particle> &particles = m_data->particlesForStream(m_currentStreamId);
|
||||
for (int i = 0; i < particles.size(); ++i)
|
||||
{
|
||||
if (!particles.at(i).seen)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // All seen or empty
|
||||
}
|
||||
Reference in New Issue
Block a user