School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,77 @@
#include "PresenterModel.h"
PresenterModel::PresenterModel(QuestionRepo& repo, QObject* parent) : repo{ repo }, QAbstractTableModel{ parent }
{
}
int PresenterModel::rowCount(const QModelIndex& parent) const
{
return this->repo.size();
}
int PresenterModel::columnCount(const QModelIndex& parent) const
{
return 4;
}
QVariant PresenterModel::data(const QModelIndex& index, int role) const
{
int row = index.row();
int col = index.column();
std::vector<Question> questions = this->repo.get_all();
Question q = questions[row];
if (role == Qt::DisplayRole)
{
switch (col)
{
case 0:
return QString::number(q.id());
case 1:
return QString::fromStdString(q.text());
case 2:
return QString::fromStdString(q.correct_answer());
case 3:
return QString::number(q.score());
default:
break;
}
}
return QVariant();
}
QVariant PresenterModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
{
switch (section)
{
case 0:
return QString{ "ID" };
case 1:
return QString{ "Text" };
case 2:
return QString{ "Correct Answer" };
case 3:
return QString{ "Score" };
default:
break;
}
}
if(role == Qt::DisplayRole && orientation == Qt::Vertical)
{
return QString::number(section+1);
}
return QVariant();
}
void PresenterModel::addQuestion(const Question& q)
{
beginInsertRows(QModelIndex(), this->rowCount(), this->rowCount());
this->repo.add(q);
endInsertRows();
}