PC 端完成

This commit is contained in:
2026-04-30 22:45:57 +08:00
commit ebc49d1ac6
38 changed files with 5474 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
#include "FaceListModel.h"
FaceListModel::FaceListModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int FaceListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return m_items.size();
}
QVariant FaceListModel::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 FaceIdRole: return item.faceId;
case StudentIdRole: return item.studentId;
case HasPhotoRole: return item.hasPhoto;
case PhotoUrlRole: return item.photoUrl;
default: return {};
}
}
bool FaceListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size()) {
return false;
}
if (role == StudentIdRole) {
m_items[index.row()].studentId = value.toString().trimmed();
emit dataChanged(index, index, {role});
return true;
}
return false;
}
Qt::ItemFlags FaceListModel::flags(const QModelIndex &index) const
{
if (!index.isValid()) {
return Qt::NoItemFlags;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
QHash<int, QByteArray> FaceListModel::roleNames() const
{
return {
{FaceIdRole, "faceId"},
{StudentIdRole, "studentId"},
{HasPhotoRole, "hasPhoto"},
{PhotoUrlRole, "photoUrl"}
};
}
void FaceListModel::setItems(const QVector<Item> &items)
{
beginResetModel();
m_items = items;
endResetModel();
}
QVector<FaceListModel::Item> FaceListModel::items() const
{
return m_items;
}
void FaceListModel::updateStudentId(int index, const QString &studentId)
{
if (index < 0 || index >= m_items.size()) {
return;
}
m_items[index].studentId = studentId.trimmed();
emit dataChanged(this->index(index), this->index(index), {StudentIdRole});
}