2018-06-06 16:05:30 +00:00
|
|
|
#include "ResultModel.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
ResultModel::ResultModel(QObject *parent)
|
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
{
|
2018-06-08 18:25:21 +00:00
|
|
|
m_results = { { "V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ",
|
|
|
|
"Genitiv", "Plural" } };
|
2018-06-06 16:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ResultModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2018-06-08 18:32:19 +00:00
|
|
|
return 5;
|
2018-06-06 16:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ResultModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ResultModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2018-06-14 17:19:53 +00:00
|
|
|
if (role == Qt::DisplayRole && index.column() < m_results.size())
|
2018-06-06 16:05:30 +00:00
|
|
|
{
|
2018-06-08 18:32:19 +00:00
|
|
|
switch (index.row())
|
2018-06-08 18:25:21 +00:00
|
|
|
{
|
2018-06-08 18:32:19 +00:00
|
|
|
case 0:
|
2018-06-14 17:19:53 +00:00
|
|
|
{
|
|
|
|
auto points = m_results[index.column()].points();
|
|
|
|
if (points != 0)
|
2018-06-08 18:32:19 +00:00
|
|
|
{
|
2018-06-14 17:19:53 +00:00
|
|
|
return static_cast<uint>(points);
|
2018-06-08 18:32:19 +00:00
|
|
|
}
|
2018-06-13 19:14:36 +00:00
|
|
|
break;
|
2018-06-14 17:19:53 +00:00
|
|
|
}
|
2018-06-13 19:14:36 +00:00
|
|
|
case 1:
|
2018-06-14 17:19:53 +00:00
|
|
|
{
|
|
|
|
auto pr = m_results[index.column()].pr();
|
|
|
|
if (pr >= 84)
|
2018-06-13 19:14:36 +00:00
|
|
|
{
|
2018-06-14 17:19:53 +00:00
|
|
|
return static_cast<uint>(pr);
|
2018-06-13 19:14:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-06-14 17:19:53 +00:00
|
|
|
}
|
2018-06-13 19:14:36 +00:00
|
|
|
case 2:
|
2018-06-14 17:19:53 +00:00
|
|
|
{
|
|
|
|
auto pr = m_results[index.column()].pr();
|
|
|
|
if (pr < 84 && pr > 16)
|
2018-06-13 19:14:36 +00:00
|
|
|
{
|
2018-06-14 17:19:53 +00:00
|
|
|
return static_cast<uint>(pr);
|
2018-06-13 19:14:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-06-14 17:19:53 +00:00
|
|
|
}
|
2018-06-13 19:14:36 +00:00
|
|
|
case 3:
|
2018-06-14 17:19:53 +00:00
|
|
|
{
|
|
|
|
auto pr = m_results[index.column()].pr();
|
|
|
|
if (pr <= 16)
|
2018-06-13 19:14:36 +00:00
|
|
|
{
|
2018-06-14 17:19:53 +00:00
|
|
|
return static_cast<uint>(pr);
|
2018-06-13 19:14:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-06-14 17:19:53 +00:00
|
|
|
}
|
2018-06-08 18:32:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-06-14 17:19:53 +00:00
|
|
|
};
|
2018-06-08 18:25:21 +00:00
|
|
|
|
|
|
|
return "-";
|
2018-06-06 16:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ResultModel::headerData(
|
|
|
|
int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (role != Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (orientation)
|
|
|
|
{
|
|
|
|
case Qt::Horizontal:
|
|
|
|
if (m_results.size() > section)
|
|
|
|
{
|
|
|
|
return m_results[section].name();
|
|
|
|
}
|
|
|
|
case Qt::Vertical:
|
|
|
|
switch (section)
|
|
|
|
{
|
|
|
|
case 0:
|
2018-06-08 18:32:19 +00:00
|
|
|
return "RP";
|
2018-06-06 16:05:30 +00:00
|
|
|
case 1:
|
2018-06-08 18:32:19 +00:00
|
|
|
return ">= PR 84";
|
2018-06-06 16:05:30 +00:00
|
|
|
case 2:
|
2018-06-08 18:32:19 +00:00
|
|
|
return "< PR 84";
|
|
|
|
case 3:
|
2018-06-06 16:05:30 +00:00
|
|
|
return "<= PR 16";
|
2018-06-08 18:32:19 +00:00
|
|
|
case 4:
|
|
|
|
return "T-Wert";
|
2018-06-06 16:05:30 +00:00
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 18:25:21 +00:00
|
|
|
|
2018-06-09 11:13:00 +00:00
|
|
|
void ResultModel::setAge(const Age &age)
|
2018-06-08 18:25:21 +00:00
|
|
|
{
|
2018-06-09 11:13:00 +00:00
|
|
|
qDebug() << "Age:" << age.years() << "years" << age.months() << "months";
|
2018-06-08 18:25:21 +00:00
|
|
|
m_age = age;
|
2018-06-13 19:14:36 +00:00
|
|
|
emit dataChanged(index(1, 0), index(4, 8));
|
2018-06-08 18:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultModel::setPluralResult(size_t points)
|
|
|
|
{
|
|
|
|
if (m_results[8].points() != points)
|
|
|
|
{
|
2018-06-14 17:19:53 +00:00
|
|
|
m_results[8].setPoints(points);
|
|
|
|
m_results[8].setPR(PluralPR().lookup(m_age, points));
|
2018-06-08 18:32:19 +00:00
|
|
|
emit dataChanged(index(0, 8), index(4, 8));
|
2018-06-08 18:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-13 19:14:36 +00:00
|
|
|
|