#include "question_item.h"
QuestionItem::QuestionItem()
{
q_name = "";
q_flag = -1;
q_difficulty = 0;
q_text = "";
q_answers << "" << "false" << "" << "false" << "" << "false" << "" << "false";
q_incorrectanscount = 0;
q_correctanscount = 0;
}
QuestionItem::QuestionItem(QString name)
{
q_name = name;
q_flag = -1;
q_difficulty = 0;
q_text = "";
q_answers << "" << "false" << "" << "false" << "" << "false" << "" << "false";
q_incorrectanscount = 0;
q_correctanscount = 0;
}
QuestionItem::QuestionItem(QString name, int flag, int difficulty, QString text, QStringList answers, unsigned int inccount, unsigned int ccount)
{
q_name = name;
q_flag = flag;
q_difficulty = difficulty;
q_text = text;
q_answers = answers;
q_incorrectanscount = inccount;
q_correctanscount = ccount;
}
QString QuestionItem::name() { return q_name; }
int QuestionItem::flag() { return q_flag; }
int QuestionItem::difficulty() { return q_difficulty; }
QString QuestionItem::text() { return q_text; }
QString QuestionItem::ansA() { return q_answers.at(0); }
QString QuestionItem::ansB() { return q_answers.at(2); }
QString QuestionItem::ansC() { return q_answers.at(4); }
QString QuestionItem::ansD() { return q_answers.at(6); }
bool QuestionItem::isAnsACorrect()
{
if (q_answers.at(1) == "true") {return true;} else {return false;}
}
bool QuestionItem::isAnsBCorrect()
{
if (q_answers.at(3) == "true") {return true;} else {return false;}
}
bool QuestionItem::isAnsCCorrect()
{
if (q_answers.at(5) == "true") {return true;} else {return false;}
}
bool QuestionItem::isAnsDCorrect()
{
if (q_answers.at(7) == "true") {return true;} else {return false;}
}
QStringList QuestionItem::answers() { return q_answers; }
QString QuestionItem::allProperties()
{
QString out;
out.append("[Q_NAME]\n");
out.append(q_name);
out.append("\n[Q_FLAG]\n");
out.append(QString("%1").arg(q_flag));
out.append("\n[Q_DIFFICULTY]\n");
out.append(QString("%1").arg(q_difficulty));
out.append("\n[Q_TEXT]\n");
out.append(q_text);
out.append("\n[Q_ANSA]\n");
out.append(q_answers.at(0));
out.append("\n[Q_ANSA_C]\n");
out.append(q_answers.at(1));
out.append("\n[Q_ANSB]\n");
out.append(q_answers.at(2));
out.append("\n[Q_ANSB_C]\n");
out.append(q_answers.at(3));
out.append("\n[Q_ANSC]\n");
out.append(q_answers.at(4));
out.append("\n[Q_ANSC_C]\n");
out.append(q_answers.at(5));
out.append("\n[Q_ANSD]\n");
out.append(q_answers.at(6));
out.append("\n[Q_ANSD_C]\n");
out.append(q_answers.at(7));
out.append("\n[Q_ICNT]\n");
out.append(QString("%1").arg(q_incorrectanscount));
out.append("\n[Q_CCNT]\n");
out.append(QString("%1").arg(q_correctanscount));
out.append("\n[Q_END]");
return out;
}
QString QuestionItem::allPublicProperties()
{
QString out;
out.append("[Q_NAME]\n");
out.append(q_name);
out.append("\n[Q_FLAG]\n");
out.append(QString("%1").arg(q_flag));
out.append("\n[Q_DIFFICULTY]\n");
out.append(QString("%1").arg(q_difficulty));
out.append("\n[Q_TEXT]\n");
out.append(q_text);
out.append("\n[Q_ANSA]\n");
out.append(q_answers.at(0));
out.append("\n[Q_ANSB]\n");
out.append(q_answers.at(2));
out.append("\n[Q_ANSC]\n");
out.append(q_answers.at(4));
out.append("\n[Q_ANSD]\n");
out.append(q_answers.at(6));
out.append("\n[Q_END]");
return out;
}
void QuestionItem::setName(QString name) { q_name = name; }
void QuestionItem::setFlag(int flag) { q_flag = flag; }
void QuestionItem::setDifficulty(int difficulty) { q_difficulty = difficulty; }
void QuestionItem::setText(QString text) { q_text = text; }
void QuestionItem::setAnsA(QString ans) { q_answers.replace(0, ans); }
void QuestionItem::setAnsB(QString ans) { q_answers.replace(2, ans); }
void QuestionItem::setAnsC(QString ans) { q_answers.replace(4, ans); }
void QuestionItem::setAnsD(QString ans) { q_answers.replace(6, ans); }
void QuestionItem::setAnsACorrect(bool correct)
{
if (correct) {q_answers.replace(1, "true");} else {q_answers.replace(1, "false");}
}
void QuestionItem::setAnsBCorrect(bool correct)
{
if (correct) {q_answers.replace(3, "true");} else {q_answers.replace(3, "false");}
}
void QuestionItem::setAnsCCorrect(bool correct)
{
if (correct) {q_answers.replace(5, "true");} else {q_answers.replace(5, "false");}
}
void QuestionItem::setAnsDCorrect(bool correct)
{
if (correct) {q_answers.replace(7, "true");} else {q_answers.replace(7, "false");}
}
void QuestionItem::setAnswers(QStringList answers) { q_answers = answers; }
bool QuestionItem::hasCorrectAnswer()
{
if ((q_answers.at(1) == "true") || (q_answers.at(3) == "true") ||
(q_answers.at(5) == "true") || (q_answers.at(7) == "true"))
{ return true; }
return false;
}
void QuestionItem::setIncorrectAnsCount(unsigned int count) { q_incorrectanscount = count; }
void QuestionItem::setCorrectAnsCount(unsigned int count) { q_correctanscount = count; }
unsigned int QuestionItem::incorrectAnsCount() { return q_incorrectanscount; }
unsigned int QuestionItem::correctAnsCount() { return q_correctanscount; }
void QuestionItem::addIncorrectAns() { q_incorrectanscount++; }
void QuestionItem::addCorrectAns() { q_correctanscount++; }
int QuestionItem::recommendedDifficulty()
{
if (q_correctanscount == 0 && q_incorrectanscount == 0) { return -1; }
else if (q_correctanscount == 0 && q_incorrectanscount > 0) { return 2; }
long double ansratio = (long double)q_incorrectanscount / (long double)q_correctanscount;
if (ansratio <= 0.5) { return 0; }
else if (ansratio > 0.5 && ansratio < 2.0) { return 1; }
else if (ansratio >= 2.0) { return 2; }
return -1;
}