初始化毕业设计项目
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#include "RecordListModel.h"
|
||||
|
||||
RecordListModel::RecordListModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int RecordListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
QVariant RecordListModel::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 TimestampRole: return item.timestamp;
|
||||
case ClassIdRole: return item.classId;
|
||||
case ClassNameRole: return item.className;
|
||||
case StudentIdRole: return item.studentId;
|
||||
case NameRole: return item.name;
|
||||
case ConfidenceRole: return item.confidence;
|
||||
case ConfidenceTextRole: return QString::number(item.confidence * 100.0, 'f', 2) + "%";
|
||||
case StatusRole: return item.status;
|
||||
case StatusTextRole: return item.success ? QStringLiteral("成功") : QStringLiteral("失败");
|
||||
case SuccessRole: return item.success;
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> RecordListModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{TimestampRole, "timestamp"},
|
||||
{ClassIdRole, "classId"},
|
||||
{ClassNameRole, "className"},
|
||||
{StudentIdRole, "studentId"},
|
||||
{NameRole, "name"},
|
||||
{ConfidenceRole, "confidence"},
|
||||
{ConfidenceTextRole, "confidenceText"},
|
||||
{StatusRole, "status"},
|
||||
{StatusTextRole, "statusText"},
|
||||
{SuccessRole, "success"}
|
||||
};
|
||||
}
|
||||
|
||||
void RecordListModel::setItems(const QVector<Item> &items)
|
||||
{
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
}
|
||||
Reference in New Issue
Block a user