Re-formatted all source files

This commit is contained in:
Michael Mandl 2019-10-05 16:14:45 +02:00
parent 5c6ed8191b
commit d0f64ef440
77 changed files with 2443 additions and 2332 deletions

View file

@ -5,9 +5,9 @@
class AkkusativPR : public PRMap
{
public:
AkkusativPR()
{
// clang-format off
AkkusativPR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 5, 0 },
@ -44,6 +44,6 @@ public:
{ 95, 89, 76, 74, 69 },
{ 100, 100, 100, 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -5,9 +5,9 @@
class DativPR : public PRMap
{
public:
DativPR()
{
// clang-format off
DativPR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 5, 0 },
@ -44,6 +44,6 @@ public:
{ 92, 87, 76, 68, 60 },
{ 100, 100, 100, 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -5,9 +5,9 @@
class GenitivPR : public PRMap
{
public:
GenitivPR()
{
// clang-format off
GenitivPR()
{
// clang-format off
m_ages = {
{ 7, 0 },
{ 7, 6 },
@ -34,6 +34,6 @@ public:
{ 96, 92, 87 },
{ 100, 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -5,9 +5,9 @@
class GenusPR : public PRMap
{
public:
GenusPR()
{
// clang-format off
GenusPR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 5, 0 },
@ -40,7 +40,6 @@ public:
{ 94, 75, 49, 37, 27 },
{ 100, 100, 100, 100, 100 },
};
// clang-format on
}
// clang-format on
}
};

View file

@ -1,43 +1,43 @@
#include "PRMap.h"
unsigned int PRMap::lookup(const Age &age, const unsigned int &points)
unsigned int PRMap::lookup(const Age& age, const unsigned int& points)
{
if (points >= m_PRs.size())
{
return 0;
}
if (points >= m_PRs.size())
{
return 0;
}
auto ageIndex = [&]() -> size_t {
if (m_ages.empty())
{
return 0;
}
auto ageIndex = [&]() -> size_t {
if (m_ages.empty())
{
return 0;
}
if (age < m_ages.front())
{
return 0;
}
if (age < m_ages.front())
{
return 0;
}
if (m_ages.back() < age)
{
return m_ages.size() - 2;
}
if (m_ages.back() < age)
{
return m_ages.size() - 2;
}
for (size_t index = 1; index < m_ages.size(); ++index)
{
if (age < m_ages.at(index))
{
return index - 1;
}
}
for (size_t index = 1; index < m_ages.size(); ++index)
{
if (age < m_ages.at(index))
{
return index - 1;
}
}
return 0;
}();
}();
if (ageIndex >= m_PRs.at(points).size())
{
return 0;
}
if (ageIndex >= m_PRs.at(points).size())
{
return 0;
}
return m_PRs.at(points).at(ageIndex);
return m_PRs.at(points).at(ageIndex);
}

View file

@ -6,9 +6,9 @@
class PRMap
{
protected:
std::vector<Age> m_ages;
std::vector<std::vector<unsigned int>> m_PRs;
std::vector<Age> m_ages;
std::vector<std::vector<unsigned int>> m_PRs;
public:
unsigned int lookup(const Age &age, const unsigned int &points);
unsigned int lookup(const Age& age, const unsigned int& points);
};

View file

@ -5,9 +5,9 @@
class PassivPR : public PRMap
{
public:
PassivPR()
{
// clang-format off
PassivPR()
{
// clang-format off
m_ages = {
{ 7, 0 },
{ 8, 6 },
@ -27,6 +27,6 @@ public:
{ 94, 84 },
{ 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -5,9 +5,9 @@
class PluralPR : public PRMap
{
public:
PluralPR()
{
// clang-format off
PluralPR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 4, 6 },
@ -27,6 +27,6 @@ public:
{ 79, 56, 27 },
{ 100, 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -14,246 +14,246 @@
#include <QDebug>
ResultModel::ResultModel(QObject *parent)
ResultModel::ResultModel(QObject* parent)
: QAbstractTableModel(parent)
{
m_results = {{"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"}};
m_results = {{"V2", "SVK", "VE", "Genus", "Akkusativ", "Dativ", "Plural", "Passiv", "Genitiv"}};
m_results = {{"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"}};
m_results = {{"V2", "SVK", "VE", "Genus", "Akkusativ", "Dativ", "Plural", "Passiv", "Genitiv"}};
}
int ResultModel::rowCount(const QModelIndex &parent) const
int ResultModel::rowCount(const QModelIndex& parent) const
{
return 4;
return 4;
}
int ResultModel::columnCount(const QModelIndex &parent) const
int ResultModel::columnCount(const QModelIndex& parent) const
{
return 9;
return 9;
}
QVariant ResultModel::data(const QModelIndex &index, int role) const
QVariant ResultModel::data(const QModelIndex& index, int role) const
{
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;
};
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 "-";
}
return {};
return {};
}
QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
{
return {};
}
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 {};
}
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 {};
}
}
void ResultModel::setAge(const Age &age)
void ResultModel::setAge(const Age& age)
{
m_age = age;
emit dataChanged(index(1, 0), index(4, 8));
m_age = age;
emit dataChanged(index(1, 0), index(4, 8));
}
void ResultModel::setPluralResult(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::setGenusResult(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::setVerbEndResult(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::setAkkusativResult(unsigned int points)
{
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));
}
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)
{
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));
}
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));
}
}
void ResultModel::setV2Result(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::setSvkResult(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::setPassivResult(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::setGenitivResult(unsigned int points)
{
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));
}
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));
}
}
void ResultModel::printTo(QPainter &painter) const
void ResultModel::printTo(QPainter& painter) const
{
PrintableModel::drawHeader2(painter, "Prozentränge (PR)");
PrintableModel::drawHeader2(painter, "Prozentränge (PR)");
painter.setFont(PrintableModel::tableFont());
painter.setPen(PrintableModel::tablePen());
painter.setFont(PrintableModel::tableFont());
painter.setPen(PrintableModel::tablePen());
auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing();
auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing();
double cellWidth = width / (m_results.size() + 1);
double rowHeight = 2 * height;
double cellWidth = width / (m_results.size() + 1);
double rowHeight = 2 * height;
double x = 0;
double y = 0;
double x = 0;
double y = 0;
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, "");
PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight},
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, "");
PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight},
u8"\u2265 PR 84");
PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
"< PR 84");
PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
"< PR 84");
PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight});
PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight});
PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
u8"\u2264 PR 16");
x += cellWidth;
for (const auto &result : m_results)
{
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight},
result.name());
const auto pr = result.pr();
x += cellWidth;
for (const auto& result : m_results)
{
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight},
result.name());
const auto pr = result.pr();
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) : "-");
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) : "-");
PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight});
PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
pr <= 16 ? QString::number(pr) : "-");
PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight});
PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
pr <= 16 ? QString::number(pr) : "-");
x += cellWidth;
}
x += cellWidth;
}
}

View file

@ -8,72 +8,71 @@
class TestResult
{
private:
QString m_name;
size_t m_points = 0;
size_t m_pr = 0;
QString m_name;
size_t m_points = 0;
size_t m_pr = 0;
public:
TestResult(const char *name)
: m_name(name)
{
}
TestResult(const char* name)
: m_name(name)
{
}
void setPoints(const size_t &points)
{
m_points = points;
}
void setPoints(const size_t& points)
{
m_points = points;
}
void setPR(const unsigned int &pr)
{
m_pr = pr;
}
void setPR(const unsigned int& pr)
{
m_pr = pr;
}
const QString &name() const
{
return m_name;
}
const QString& name() const
{
return m_name;
}
const size_t points() const
{
return m_points;
}
const size_t pr() const
{
return m_pr;
}
const size_t points() const
{
return m_points;
}
const size_t pr() const
{
return m_pr;
}
};
class ResultModel : public QAbstractTableModel
{
Q_OBJECT
Q_OBJECT
private:
Age m_age;
std::vector<TestResult> m_results;
Age m_age;
std::vector<TestResult> m_results;
public:
ResultModel(QObject *parent);
ResultModel(QObject* parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(
const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
void setAge(const Age &age);
void setPluralResult(unsigned int points);
void setGenusResult(unsigned int points);
void setVerbEndResult(unsigned int points);
void setAkkusativResult(unsigned int points);
void setDativResult(unsigned int points);
void setV2Result(unsigned int points);
void setSvkResult(unsigned int points);
void setAge(const Age& age);
void setPluralResult(unsigned int points);
void setGenusResult(unsigned int points);
void setVerbEndResult(unsigned int points);
void setAkkusativResult(unsigned int points);
void setDativResult(unsigned int points);
void setV2Result(unsigned int points);
void setSvkResult(unsigned int points);
void setPassivResult(unsigned int points);
void setGenitivResult(unsigned int points);
void printTo(QPainter &painter) const;
void printTo(QPainter& painter) const;
};

View file

@ -3,19 +3,19 @@
#include "ResultModel.h"
ResultWidget::ResultWidget(QWidget *parent)
: QWidget(parent)
ResultWidget::ResultWidget(QWidget* parent)
: QWidget(parent)
, ui(new Ui::ResultWidget)
{
ui->setupUi(this);
ui->setupUi(this);
}
ResultWidget::~ResultWidget()
{
delete ui;
delete ui;
}
void ResultWidget::setModel(ResultModel *model)
void ResultWidget::setModel(ResultModel* model)
{
ui->resultTableView->setModel(model);
ui->resultTableView->setModel(model);
}

View file

@ -10,14 +10,14 @@ class ResultWidget;
class ResultWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
private:
Ui::ResultWidget *ui;
Ui::ResultWidget* ui;
public:
ResultWidget(QWidget *parent = nullptr);
~ResultWidget();
ResultWidget(QWidget* parent = nullptr);
~ResultWidget();
void setModel(ResultModel *model);
void setModel(ResultModel* model);
};

View file

@ -5,9 +5,9 @@
class SvkPR : public PRMap
{
public:
SvkPR()
{
// clang-format off
SvkPR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 5, 0 },
@ -60,6 +60,6 @@ public:
{ 71, 50, 36 },
{ 100, 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -5,9 +5,9 @@
class V2PR : public PRMap
{
public:
V2PR()
{
// clang-format off
V2PR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 5, 0 },
@ -63,6 +63,6 @@ public:
{ 69, 52, 37 },
{ 100, 100, 100 }
};
// clang-format on
}
// clang-format on
}
};

View file

@ -5,9 +5,9 @@
class VerbEndPR : public PRMap
{
public:
VerbEndPR()
{
// clang-format off
VerbEndPR()
{
// clang-format off
m_ages = {
{ 4, 0 },
{ 4, 6 },
@ -39,7 +39,6 @@ public:
{ 85, 79, 74, 65 },
{ 100, 100, 100, 100, 100 },
};
// clang-format on
}
// clang-format on
}
};