Initial QT project upload
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include "StatisticsListModel.h"
|
||||
|
||||
StatisticsListModel::StatisticsListModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int StatisticsListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
QVariant StatisticsListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const Item &item = m_items.at(index.row());
|
||||
switch (role) {
|
||||
case StudentIdRole: return item.studentId;
|
||||
case NameRole: return item.name;
|
||||
case TotalCountRole: return item.totalCount;
|
||||
case TodayCountRole: return item.todayCount;
|
||||
case LastCheckInRole: return item.lastCheckIn;
|
||||
case AverageConfidenceRole: return item.averageConfidence;
|
||||
case AverageConfidenceTextRole: return QString::number(item.averageConfidence * 100.0, 'f', 2) + "%";
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> StatisticsListModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{StudentIdRole, "studentId"},
|
||||
{NameRole, "name"},
|
||||
{TotalCountRole, "totalCount"},
|
||||
{TodayCountRole, "todayCount"},
|
||||
{LastCheckInRole, "lastCheckIn"},
|
||||
{AverageConfidenceRole, "averageConfidence"},
|
||||
{AverageConfidenceTextRole, "averageConfidenceText"}
|
||||
};
|
||||
}
|
||||
|
||||
void StatisticsListModel::setItems(const QVector<Item> &items)
|
||||
{
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
}
|
||||
Reference in New Issue
Block a user