ESGRAF48/source/ResultWidget/ResultModel.cpp

260 lines
7.1 KiB
C++
Raw Permalink Normal View History

2018-06-06 16:05:30 +00:00
#include "ResultModel.h"
2018-06-15 15:53:43 +00:00
#include "PluralPR.h"
#include "GenusPR.h"
2018-06-15 16:36:58 +00:00
#include "VerbEndPR.h"
2018-06-17 17:40:10 +00:00
#include "AkkusativPR.h"
#include "DativPR.h"
2018-06-25 21:04:32 +00:00
#include "V2PR.h"
#include "SvkPR.h"
2018-06-26 14:59:51 +00:00
#include "PassivPR.h"
#include "GenitivPR.h"
2018-06-15 15:53:43 +00:00
2019-02-07 21:36:39 +00:00
#include "PrintableModel.h"
2018-06-06 16:05:30 +00:00
#include <QDebug>
2019-10-05 14:14:45 +00:00
ResultModel::ResultModel(QObject* parent)
2019-02-07 21:36:39 +00:00
: QAbstractTableModel(parent)
2018-06-06 16:05:30 +00:00
{
2019-10-05 14:14:45 +00:00
m_results = {{"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"}};
m_results = {{"V2", "SVK", "VE", "Genus", "Akkusativ", "Dativ", "Plural", "Passiv", "Genitiv"}};
2018-06-06 16:05:30 +00:00
}
2019-10-05 14:14:45 +00:00
int ResultModel::rowCount(const QModelIndex& parent) const
2018-06-06 16:05:30 +00:00
{
2019-10-05 14:14:45 +00:00
return 4;
2018-06-06 16:05:30 +00:00
}
2019-10-05 14:14:45 +00:00
int ResultModel::columnCount(const QModelIndex& parent) const
2018-06-06 16:05:30 +00:00
{
2019-10-05 14:14:45 +00:00
return 9;
2018-06-06 16:05:30 +00:00
}
2019-10-05 14:14:45 +00:00
QVariant ResultModel::data(const QModelIndex& index, int role) const
2018-06-06 16:05:30 +00:00
{
2019-10-05 14:14:45 +00:00
if (role == Qt::DisplayRole && index.column() < m_results.size())
{
switch (index.row())
{
case 0:
{
auto points = m_results[index.column()].points();
if (points != 0)
{
return static_cast<uint>(points);
}
break;
}
case 1:
{
auto pr = m_results[index.column()].pr();
if (pr >= 84)
{
return static_cast<uint>(pr);
}
break;
}
case 2:
{
auto pr = m_results[index.column()].pr();
if (pr < 84 && pr > 16)
{
return static_cast<uint>(pr);
}
break;
}
case 3:
{
auto pr = m_results[index.column()].pr();
if (pr <= 16)
{
return static_cast<uint>(pr);
}
break;
}
default:
break;
};
return "-";
}
return {};
2018-06-06 16:05:30 +00:00
}
2019-02-07 21:36:39 +00:00
QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const
2018-06-06 16:05:30 +00:00
{
2019-10-05 14:14:45 +00:00
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:
return "RP";
case 1:
return ">= PR 84";
case 2:
return "< PR 84";
case 3:
return "<= PR 16";
default:
return {};
}
default:
return {};
}
2018-06-06 16:05:30 +00:00
}
2019-10-05 14:14:45 +00:00
void ResultModel::setAge(const Age& age)
{
2019-10-05 14:14:45 +00:00
m_age = age;
emit dataChanged(index(1, 0), index(4, 8));
}
2018-06-15 15:53:43 +00:00
void ResultModel::setPluralResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[6].points() != points)
{
m_results[6].setPoints(points);
m_results[6].setPR(PluralPR().lookup(m_age, points));
emit dataChanged(index(0, 6), index(4, 6));
}
}
2018-06-15 15:53:43 +00:00
void ResultModel::setGenusResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[3].points() != points)
{
m_results[3].setPoints(points);
m_results[3].setPR(GenusPR().lookup(m_age, points));
emit dataChanged(index(0, 3), index(4, 3));
}
2018-06-15 15:53:43 +00:00
}
2018-06-15 16:36:58 +00:00
void ResultModel::setVerbEndResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[2].points() != points)
{
m_results[2].setPoints(points);
m_results[2].setPR(VerbEndPR().lookup(m_age, points));
emit dataChanged(index(0, 2), index(4, 2));
}
2018-06-15 16:36:58 +00:00
}
void ResultModel::setAkkusativResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[4].points() != points)
{
m_results[4].setPoints(points);
m_results[4].setPR(AkkusativPR().lookup(m_age, points));
emit dataChanged(index(0, 4), index(4, 4));
}
}
void ResultModel::setDativResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[5].points() != points)
{
m_results[5].setPoints(points);
m_results[5].setPR(DativPR().lookup(m_age, points));
emit dataChanged(index(0, 5), index(4, 5));
}
}
2019-02-07 21:36:39 +00:00
2018-06-25 21:04:32 +00:00
void ResultModel::setV2Result(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[0].points() != points)
{
m_results[0].setPoints(points);
m_results[0].setPR(V2PR().lookup(m_age, points));
emit dataChanged(index(0, 0), index(4, 0));
}
2018-06-25 21:04:32 +00:00
}
void ResultModel::setSvkResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[1].points() != points)
{
m_results[1].setPoints(points);
m_results[1].setPR(SvkPR().lookup(m_age, points));
emit dataChanged(index(0, 1), index(4, 1));
}
2018-06-25 21:04:32 +00:00
}
2018-06-26 14:59:51 +00:00
void ResultModel::setPassivResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[7].points() != points)
{
m_results[7].setPoints(points);
m_results[7].setPR(PassivPR().lookup(m_age, points));
emit dataChanged(index(0, 7), index(4, 7));
}
2018-06-26 14:59:51 +00:00
}
void ResultModel::setGenitivResult(unsigned int points)
{
2019-10-05 14:14:45 +00:00
if (m_results[8].points() != points)
{
m_results[8].setPoints(points);
m_results[8].setPR(GenitivPR().lookup(m_age, points));
emit dataChanged(index(0, 8), index(4, 8));
}
2019-02-07 21:36:39 +00:00
}
2019-10-05 14:14:45 +00:00
void ResultModel::printTo(QPainter& painter) const
2019-02-07 21:36:39 +00:00
{
2019-10-05 14:14:45 +00:00
PrintableModel::drawHeader2(painter, "Prozentränge (PR)");
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
painter.setFont(PrintableModel::tableFont());
painter.setPen(PrintableModel::tablePen());
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing();
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
double cellWidth = width / (m_results.size() + 1);
double rowHeight = 2 * height;
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
double x = 0;
double y = 0;
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, "");
PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight},
2019-02-08 20:03:52 +00:00
u8"\u2265 PR 84");
2019-10-05 14:14:45 +00:00
PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
"< PR 84");
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight});
PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
2019-02-08 20:03:52 +00:00
u8"\u2264 PR 16");
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
x += cellWidth;
for (const auto& result : m_results)
{
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight},
result.name());
const auto pr = result.pr();
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight},
pr >= 84 ? QString::number(pr) : "-");
PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
pr < 84 && pr > 16 ? QString::number(pr) : "-");
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight});
PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
pr <= 16 ? QString::number(pr) : "-");
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
x += cellWidth;
}
2018-06-26 14:59:51 +00:00
}