Compare commits

..

No commits in common. "develop" and "main" have entirely different histories.

77 changed files with 2332 additions and 2443 deletions

View File

@ -1,118 +0,0 @@
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: '^(BEGIN|IMPLEMENT)_.*_MAP$'
MacroBlockEnd: '^END_.*_MAP$'
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 1000000
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never

View File

@ -9,58 +9,58 @@ Age::Age(unsigned int years, unsigned int months)
{ {
} }
Age::Age(const QDate& birth, const QDate& reference) Age::Age(const QDate &birth, const QDate &reference)
{ {
if (reference < birth) if (reference < birth)
{ {
qDebug() << "test (" << reference << ") before birth (" << birth << ")"; qDebug() << "test (" << reference << ") before birth (" << birth << ")";
m_years = 0; m_years = 0;
m_months = 0; m_months = 0;
return; return;
} }
int years = reference.year() - birth.year(); int years = reference.year() - birth.year();
int months = reference.month() - birth.month(); int months = reference.month() - birth.month();
if (months == 0 && reference.day() < birth.day()) if (months == 0 && reference.day() < birth.day())
{ {
months--; months--;
} }
if (months < 0) if (months < 0)
{ {
years--; years--;
months = (months + 12) % 12; months = (months + 12) % 12;
} }
m_years = years; m_years = years;
m_months = months; m_months = months;
} }
bool Age::operator<(const Age& cmp) const bool Age::operator<(const Age &cmp) const
{ {
if (m_years == cmp.m_years) if (m_years == cmp.m_years)
{ {
return m_months < cmp.m_months; return m_months < cmp.m_months;
} }
return m_years < cmp.m_years; return m_years < cmp.m_years;
} }
unsigned int Age::years() const unsigned int Age::years() const
{ {
return m_years; return m_years;
} }
unsigned int Age::months() const unsigned int Age::months() const
{ {
return m_months; return m_months;
} }
std::string Age::toString() const std::string Age::toString() const
{ {
std::ostringstream result; std::ostringstream result;
result << m_years << ";" << m_months; result << m_years << ";" << m_months;
return result.str(); return result.str();
} }

View File

@ -5,18 +5,18 @@
class Age class Age
{ {
private: private:
unsigned int m_years = 0; unsigned int m_years = 0;
unsigned int m_months = 0; unsigned int m_months = 0;
public: public:
Age() = default; Age() = default;
Age(unsigned int years, unsigned int months); Age(unsigned int years, unsigned int months);
Age(const QDate& birth, const QDate& reference); Age(const QDate &birth, const QDate &reference);
bool operator<(const Age& cmp) const; bool operator<(const Age &cmp) const;
unsigned int years() const; unsigned int years() const;
unsigned int months() const; unsigned int months() const;
std::string toString() const; std::string toString() const;
}; };

View File

@ -1,36 +1,36 @@
#include "CheckableItem.h" #include "CheckableItem.h"
CheckableItem::CheckableItem(const std::string& text) CheckableItem::CheckableItem(const std::string &text)
: m_text(text) : m_text(text)
{ {
} }
std::string CheckableItem::getText() const std::string CheckableItem::getText() const
{ {
return m_text; return m_text;
} }
bool CheckableItem::isChecked() const bool CheckableItem::isChecked() const
{ {
return m_checked; return m_checked;
} }
void CheckableItem::setState(bool checked) void CheckableItem::setState(bool checked)
{ {
m_checked = checked; m_checked = checked;
} }
unsigned int CheckableItem::value() const unsigned int CheckableItem::value() const
{ {
return m_value; return m_value;
} }
void CheckableItem::setValue(unsigned int value) void CheckableItem::setValue(unsigned int value)
{ {
m_value = value; m_value = value;
} }
unsigned int CheckableItem::points() const unsigned int CheckableItem::points() const
{ {
return m_checked ? m_value : 0; return m_checked ? m_value : 0;
} }

View File

@ -7,21 +7,21 @@
class CheckableItem class CheckableItem
{ {
private: private:
bool m_checked = false; bool m_checked = false;
std::string m_text; std::string m_text;
unsigned int m_value = 1; unsigned int m_value = 1;
public: public:
CheckableItem() = default; CheckableItem() = default;
CheckableItem(const std::string& text); CheckableItem(const std::string &text);
std::string getText() const; std::string getText() const;
bool isChecked() const; bool isChecked() const;
void setState(bool checked); void setState(bool checked);
unsigned int value() const; unsigned int value() const;
void setValue(unsigned int value); void setValue(unsigned int value);
unsigned int points() const; unsigned int points() const;
}; };

View File

@ -6,15 +6,15 @@
CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames) CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames)
{ {
for (const auto& itemName : itemNames) for (const auto &itemName : itemNames)
{ {
emplace_back(itemName); emplace_back(itemName);
} }
} }
unsigned int CheckableItems::getPoints() const unsigned int CheckableItems::getPoints() const
{ {
return std::accumulate(begin(), end(), 0, [](int base, const CheckableItem& item) { return std::accumulate(begin(), end(), 0, [](int base, const CheckableItem &item) {
return base + item.points(); return base + item.points();
}); });
} }

View File

@ -8,7 +8,7 @@
class CheckableItems : public std::vector<CheckableItem> class CheckableItems : public std::vector<CheckableItem>
{ {
public: public:
CheckableItems(std::initializer_list<std::string> itemNames); CheckableItems(std::initializer_list<std::string> itemNames);
unsigned int getPoints() const; unsigned int getPoints() const;
}; };

View File

@ -2,33 +2,34 @@
#include <numeric> #include <numeric>
CheckableTest::CheckableTest(const char* name, std::initializer_list<std::string> items) CheckableTest::CheckableTest(
: m_name(name) const char *name, std::initializer_list<std::string> items)
, m_items(items) : m_name(name)
, m_items(items)
{ {
} }
size_t CheckableTest::size() const size_t CheckableTest::size() const
{ {
return m_items.size(); return m_items.size();
} }
const QString& CheckableTest::name() const const QString &CheckableTest::name() const
{ {
return m_name; return m_name;
} }
const CheckableItems& CheckableTest::items() const const CheckableItems &CheckableTest::items() const
{ {
return m_items; return m_items;
} }
CheckableItems& CheckableTest::items() CheckableItems &CheckableTest::items()
{ {
return m_items; return m_items;
} }
unsigned int CheckableTest::getPoints() const unsigned int CheckableTest::getPoints() const
{ {
return m_items.getPoints(); return m_items.getPoints();
} }

View File

@ -7,18 +7,18 @@
class CheckableTest class CheckableTest
{ {
private: private:
CheckableItems m_items; CheckableItems m_items;
QString m_name; QString m_name;
public: public:
CheckableTest(const char* name, std::initializer_list<std::string> items); CheckableTest(const char *name, std::initializer_list<std::string> items);
size_t size() const; size_t size() const;
const QString& name() const; const QString &name() const;
const CheckableItems& items() const; const CheckableItems &items() const;
CheckableItems& items(); CheckableItems &items();
unsigned int getPoints() const; unsigned int getPoints() const;
}; };
using CheckableTests = std::vector<CheckableTest>; using CheckableTests = std::vector<CheckableTest>;

View File

@ -4,191 +4,191 @@
#include <QSize> #include <QSize>
#include <QDebug> #include <QDebug>
CheckableTestModel::CheckableTestModel(QObject* parent) CheckableTestModel::CheckableTestModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
{ {
} }
int CheckableTestModel::rowCount(const QModelIndex&) const int CheckableTestModel::rowCount(const QModelIndex &) const
{ {
return static_cast<int>(m_tests.size()); return static_cast<int>(m_tests.size());
} }
int CheckableTestModel::columnCount(const QModelIndex&) const int CheckableTestModel::columnCount(const QModelIndex &) const
{ {
int columnCount = 0; int columnCount = 0;
for (const auto& test : m_tests) for (const auto &test : m_tests)
{ {
columnCount = std::max(columnCount, static_cast<int>(test.size())); columnCount = std::max(columnCount, static_cast<int>(test.size()));
} }
return columnCount; return columnCount;
} }
QVariant CheckableTestModel::data(const QModelIndex& index, int role) const QVariant CheckableTestModel::data(const QModelIndex &index, int role) const
{ {
if (!isValidIndex(index)) if (!isValidIndex(index))
{ {
return {}; return {};
} }
try try
{ {
auto& item = getItem(index); auto &item = getItem(index);
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
{ {
return item.getText().c_str(); return item.getText().c_str();
} }
case Qt::CheckStateRole: case Qt::CheckStateRole:
{ {
return item.isChecked() ? Qt::Checked : Qt::Unchecked; return item.isChecked() ? Qt::Checked : Qt::Unchecked;
} }
} }
} }
catch (std::runtime_error& e) catch (std::runtime_error &e)
{ {
qDebug() << "CheckableTestModel::data" << index << e.what(); qDebug() << "CheckableTestModel::data" << index << e.what();
} }
return {}; return {};
} }
Qt::ItemFlags CheckableTestModel::flags(const QModelIndex& index) const Qt::ItemFlags CheckableTestModel::flags(const QModelIndex &index) const
{ {
if (isValidIndex(index)) if (isValidIndex(index))
{ {
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
} }
return Qt::NoItemFlags; return Qt::NoItemFlags;
} }
bool CheckableTestModel::setData(const QModelIndex& index, const QVariant& value, int role) bool CheckableTestModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if (!isValidIndex(index)) if (!isValidIndex(index))
{ {
return false; return false;
} }
try try
{ {
if (role == Qt::CheckStateRole) if (role == Qt::CheckStateRole)
{ {
auto& item = getItem(index); auto &item = getItem(index);
item.setState(value.toBool()); item.setState(value.toBool());
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} }
} }
catch (std::runtime_error& e) catch (std::runtime_error &e)
{ {
qDebug() << "CheckableTestModel::setData" << index << e.what(); qDebug() << "CheckableTestModel::setData" << index << e.what();
} }
return false; return false;
} }
QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
switch (orientation) switch (orientation)
{ {
case Qt::Vertical: case Qt::Vertical:
{ {
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
{ {
if (section < m_tests.size()) if (section < m_tests.size())
{ {
return m_tests.at(section).name(); return m_tests.at(section).name();
} }
} }
case Qt::SizeHintRole: case Qt::SizeHintRole:
{ {
return QSize(200, 0); return QSize(200, 0);
} }
} }
break; break;
} }
default: default:
break; break;
} }
return QAbstractTableModel::headerData(section, orientation, role); return QAbstractTableModel::headerData(section, orientation, role);
} }
bool CheckableTestModel::isValidIndex(const QModelIndex& index) const bool CheckableTestModel::isValidIndex(const QModelIndex &index) const
{ {
if (index.row() < m_tests.size()) if (index.row() < m_tests.size())
{ {
return index.column() < m_tests.at(index.row()).size(); return index.column() < m_tests.at(index.row()).size();
} }
return false; return false;
} }
CheckableItems& CheckableTestModel::getItems(const QModelIndex& index) CheckableItems &CheckableTestModel::getItems(const QModelIndex &index)
{ {
if (index.row() < m_tests.size()) if (index.row() < m_tests.size())
{ {
return m_tests.at(index.row()).items(); return m_tests.at(index.row()).items();
} }
throw std::runtime_error("invalid index"); throw std::runtime_error("invalid index");
} }
const CheckableItems& CheckableTestModel::getItems(const QModelIndex& index) const const CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) const
{ {
if (index.row() < m_tests.size()) if (index.row() < m_tests.size())
{ {
return m_tests.at(index.row()).items(); return m_tests.at(index.row()).items();
} }
throw std::runtime_error("invalid index"); throw std::runtime_error("invalid index");
} }
CheckableItem& CheckableTestModel::getItem(const QModelIndex& index) CheckableItem &CheckableTestModel::getItem(const QModelIndex &index)
{ {
auto& items = getItems(index); auto &items = getItems(index);
if (index.column() < items.size()) if (index.column() < items.size())
{ {
return items.at(index.column()); return items.at(index.column());
} }
throw std::runtime_error("invalid index"); throw std::runtime_error("invalid index");
} }
const CheckableItem& CheckableTestModel::getItem(const QModelIndex& index) const const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const
{ {
auto& items = getItems(index); auto &items = getItems(index);
if (index.column() < items.size()) if (index.column() < items.size())
{ {
return items.at(index.column()); return items.at(index.column());
} }
throw std::runtime_error("invalid index"); throw std::runtime_error("invalid index");
} }
unsigned int CheckableTestModel::getPoints() const unsigned int CheckableTestModel::getPoints() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (const auto& test : m_tests) for (const auto &test : m_tests)
{ {
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
points += item.points(); points += item.points();
} }
} }
return points; return points;
} }
QString CheckableTestModel::getTitle() const QString CheckableTestModel::getTitle() const
{ {
return m_title; return m_title;
} }

View File

@ -5,36 +5,37 @@
class CheckableTestModel : public QAbstractTableModel class CheckableTestModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
protected: protected:
QString m_title; QString m_title;
CheckableTests m_tests; CheckableTests m_tests;
public: public:
CheckableTestModel(QObject* parent); CheckableTestModel(QObject *parent);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(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;
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
QVariant headerData(int section, Qt::Orientation orientation, QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override; int role = Qt::DisplayRole) const override;
unsigned int getPoints() const; unsigned int getPoints() const;
QString getTitle() const; QString getTitle() const;
protected: protected:
virtual bool isValidIndex(const QModelIndex& index) const; virtual bool isValidIndex(const QModelIndex &index) const;
private: private:
CheckableItems& getItems(const QModelIndex& index); CheckableItems &getItems(const QModelIndex &index);
const CheckableItems& getItems(const QModelIndex& index) const; const CheckableItems &getItems(const QModelIndex &index) const;
CheckableItem& getItem(const QModelIndex& index); CheckableItem &getItem(const QModelIndex &index);
const CheckableItem& getItem(const QModelIndex& index) const; const CheckableItem &getItem(const QModelIndex &index) const;
}; };

View File

@ -5,7 +5,7 @@
#include <sstream> #include <sstream>
DataModel::DataModel(QObject* parent) DataModel::DataModel(QObject *parent)
: QObject(parent) : QObject(parent)
, m_metaData(this) , m_metaData(this)
, m_verbEnd(this) , m_verbEnd(this)
@ -21,186 +21,186 @@ DataModel::DataModel(QObject* parent)
, m_passiv(this) , m_passiv(this)
, m_genitiv(this) , m_genitiv(this)
{ {
connect(&m_plural, &PluralModel::dataChanged, this, &DataModel::pluralModelChanged); connect(&m_plural, &PluralModel::dataChanged, this, &DataModel::pluralModelChanged);
connect(&m_metaData, &MetaDataModel::dataChanged, this, &DataModel::metaDataChanged); connect(&m_metaData, &MetaDataModel::dataChanged, this, &DataModel::metaDataChanged);
connect(&m_genus, &GenusModel::dataChanged, this, &DataModel::genusModelChanged); connect(&m_genus, &GenusModel::dataChanged, this, &DataModel::genusModelChanged);
connect(&m_verbEnd, &VerbEndModel::dataChanged, this, &DataModel::verbEndModelChanged); connect(&m_verbEnd, &VerbEndModel::dataChanged, this, &DataModel::verbEndModelChanged);
connect(&m_akkusativ, &AkkusativModel::dataChanged, this, &DataModel::akkusativModelChanged); connect(&m_akkusativ, &AkkusativModel::dataChanged, this, &DataModel::akkusativModelChanged);
connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged); connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged);
connect(&m_wfModel, &WFModel::dataChanged, this, &DataModel::v2SvkModelChanged); connect(&m_wfModel, &WFModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_otModel, &OTModel::dataChanged, this, &DataModel::v2SvkModelChanged); connect(&m_otModel, &OTModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_tPrModel, &TPrModel::dataChanged, this, &DataModel::v2SvkModelChanged); connect(&m_tPrModel, &TPrModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_tPeModel, &TPeModel::dataChanged, this, &DataModel::v2SvkModelChanged); connect(&m_tPeModel, &TPeModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged); connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged);
connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged);
} }
void DataModel::write(const QString& filename) const void DataModel::write(const QString &filename) const
{ {
ESGRAF48::DataModel dataModel; ESGRAF48::DataModel dataModel;
m_metaData.write(*dataModel.mutable_metadata()); m_metaData.write(*dataModel.mutable_metadata());
m_wfModel.write(*dataModel.mutable_v2svk()); m_wfModel.write(*dataModel.mutable_v2svk());
m_otModel.write(*dataModel.mutable_v2svk()); m_otModel.write(*dataModel.mutable_v2svk());
m_tPrModel.write(*dataModel.mutable_v2svk()); m_tPrModel.write(*dataModel.mutable_v2svk());
m_tPeModel.write(*dataModel.mutable_v2svk()); m_tPeModel.write(*dataModel.mutable_v2svk());
m_verbEnd.write(*dataModel.mutable_verbend()); m_verbEnd.write(*dataModel.mutable_verbend());
m_genus.write(*dataModel.mutable_genus()); m_genus.write(*dataModel.mutable_genus());
m_akkusativ.write(*dataModel.mutable_akkusativ()); m_akkusativ.write(*dataModel.mutable_akkusativ());
m_dativ.write(*dataModel.mutable_dativ()); m_dativ.write(*dataModel.mutable_dativ());
m_plural.write(*dataModel.mutable_plural()); m_plural.write(*dataModel.mutable_plural());
m_genitiv.write(*dataModel.mutable_lateskillsgenitiv()); m_genitiv.write(*dataModel.mutable_lateskillsgenitiv());
m_passiv.write(*dataModel.mutable_lateskillspassiv()); m_passiv.write(*dataModel.mutable_lateskillspassiv());
QFile outFile(filename); QFile outFile(filename);
if (!outFile.open(QIODevice::WriteOnly)) if (!outFile.open(QIODevice::WriteOnly))
{ {
throw std::runtime_error("failed to open file"); throw std::runtime_error("failed to open file");
} }
bool success = dataModel.SerializeToFileDescriptor(outFile.handle()); bool success = dataModel.SerializeToFileDescriptor(outFile.handle());
if (success == false) if (success == false)
{ {
throw std::runtime_error("filed to write file"); throw std::runtime_error("filed to write file");
} }
} }
void DataModel::read(const QString& filename) void DataModel::read(const QString &filename)
{ {
QFile inFile(filename); QFile inFile(filename);
if (!inFile.open(QIODevice::ReadOnly)) if (!inFile.open(QIODevice::ReadOnly))
{ {
throw std::runtime_error("failed to read file"); throw std::runtime_error("failed to read file");
} }
ESGRAF48::DataModel dataModel; ESGRAF48::DataModel dataModel;
bool success = dataModel.ParseFromFileDescriptor(inFile.handle()); bool success = dataModel.ParseFromFileDescriptor(inFile.handle());
if (success == false) if (success == false)
{ {
throw std::runtime_error("invalid file format"); throw std::runtime_error("invalid file format");
} }
m_metaData.read(dataModel.metadata()); m_metaData.read(dataModel.metadata());
m_wfModel.read(dataModel.v2svk()); m_wfModel.read(dataModel.v2svk());
m_otModel.read(dataModel.v2svk()); m_otModel.read(dataModel.v2svk());
m_tPrModel.read(dataModel.v2svk()); m_tPrModel.read(dataModel.v2svk());
m_tPeModel.read(dataModel.v2svk()); m_tPeModel.read(dataModel.v2svk());
m_verbEnd.read(dataModel.verbend()); m_verbEnd.read(dataModel.verbend());
m_genus.read(dataModel.genus()); m_genus.read(dataModel.genus());
m_akkusativ.read(dataModel.akkusativ()); m_akkusativ.read(dataModel.akkusativ());
m_dativ.read(dataModel.dativ()); m_dativ.read(dataModel.dativ());
m_plural.read(dataModel.plural()); m_plural.read(dataModel.plural());
m_genitiv.read(dataModel.lateskillsgenitiv()); m_genitiv.read(dataModel.lateskillsgenitiv());
m_passiv.read(dataModel.lateskillspassiv()); m_passiv.read(dataModel.lateskillspassiv());
} }
void DataModel::printTo(QPrinter& printer) const void DataModel::printTo(QPrinter &printer) const
{ {
QPainter painter; QPainter painter;
painter.begin(&printer); painter.begin(&printer);
painter.setFont(PrintableModel::h1Font()); painter.setFont(PrintableModel::h1Font());
painter.drawText(0, painter.fontMetrics().lineSpacing(), "ESGRAF 4-8 Auswertungsbogen"); painter.drawText(0, painter.fontMetrics().lineSpacing(), "ESGRAF 4-8 Auswertungsbogen");
painter.translate(0, 3 * painter.fontMetrics().lineSpacing()); painter.translate(0, 3 * painter.fontMetrics().lineSpacing());
m_metaData.printTo(painter); m_metaData.printTo(painter);
m_wfModel.printTo(painter); m_wfModel.printTo(painter);
m_otModel.printTo(painter); m_otModel.printTo(painter);
m_tPrModel.printTo(painter); m_tPrModel.printTo(painter);
m_tPeModel.printTo(painter); m_tPeModel.printTo(painter);
V2SvkModel::printSummary(painter, V2SvkModel::printSummary(painter,
m_wfModel.getV2Points() + m_otModel.getV2Points() m_wfModel.getV2Points() + m_otModel.getV2Points()
+ m_tPrModel.getV2Points() + m_tPeModel.getV2Points(), + m_tPrModel.getV2Points() + m_tPeModel.getV2Points(),
m_wfModel.getSvkPoints() + m_otModel.getSvkPoints() m_wfModel.getSvkPoints() + m_otModel.getSvkPoints()
+ m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints()); + m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints());
m_verbEnd.printTo(painter); m_verbEnd.printTo(painter);
m_genus.printTo(painter); m_genus.printTo(painter);
printer.newPage(); printer.newPage();
painter.resetTransform(); painter.resetTransform();
m_akkusativ.printTo(painter); m_akkusativ.printTo(painter);
m_dativ.printTo(painter); m_dativ.printTo(painter);
m_plural.printTo(painter); m_plural.printTo(painter);
m_passiv.printTo(painter); m_passiv.printTo(painter);
m_genitiv.printTo(painter); m_genitiv.printTo(painter);
m_results.printTo(painter); m_results.printTo(painter);
painter.end(); painter.end();
} }
void DataModel::pluralModelChanged() void DataModel::pluralModelChanged()
{ {
m_results.setPluralResult(m_plural.getPoints()); m_results.setPluralResult(m_plural.getPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::metaDataChanged() void DataModel::metaDataChanged()
{ {
m_results.setAge(m_metaData.getAge()); m_results.setAge(m_metaData.getAge());
emit modelChanged(); emit modelChanged();
} }
void DataModel::genusModelChanged() void DataModel::genusModelChanged()
{ {
m_results.setGenusResult(m_genus.getPoints()); m_results.setGenusResult(m_genus.getPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::verbEndModelChanged() void DataModel::verbEndModelChanged()
{ {
m_results.setVerbEndResult(m_verbEnd.getPoints()); m_results.setVerbEndResult(m_verbEnd.getPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::akkusativModelChanged() void DataModel::akkusativModelChanged()
{ {
m_results.setAkkusativResult(m_akkusativ.getPoints()); m_results.setAkkusativResult(m_akkusativ.getPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::dativModelChanged() void DataModel::dativModelChanged()
{ {
m_results.setDativResult(m_dativ.getPoints()); m_results.setDativResult(m_dativ.getPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::v2SvkModelChanged() void DataModel::v2SvkModelChanged()
{ {
m_results.setV2Result(m_wfModel.getV2Points() + m_otModel.getV2Points() m_results.setV2Result(m_wfModel.getV2Points() + m_otModel.getV2Points()
+ m_tPrModel.getV2Points() + m_tPeModel.getV2Points()); + m_tPrModel.getV2Points() + m_tPeModel.getV2Points());
m_results.setSvkResult(m_wfModel.getSvkPoints() + m_otModel.getSvkPoints() m_results.setSvkResult(m_wfModel.getSvkPoints() + m_otModel.getSvkPoints()
+ m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints()); + m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::passivModelChanged() void DataModel::passivModelChanged()
{ {
m_results.setPassivResult(m_passiv.getPoints()); m_results.setPassivResult(m_passiv.getPoints());
emit modelChanged(); emit modelChanged();
} }
void DataModel::genitivModelChanged() void DataModel::genitivModelChanged()
{ {
m_results.setGenitivResult(m_genitiv.getPoints()); m_results.setGenitivResult(m_genitiv.getPoints());
emit modelChanged(); emit modelChanged();
} }

View File

@ -23,45 +23,45 @@
class DataModel : public QObject class DataModel : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
MetaDataModel m_metaData; MetaDataModel m_metaData;
VerbEndModel m_verbEnd; VerbEndModel m_verbEnd;
GenusModel m_genus; GenusModel m_genus;
PluralModel m_plural; PluralModel m_plural;
AkkusativModel m_akkusativ; AkkusativModel m_akkusativ;
DativModel m_dativ; DativModel m_dativ;
WFModel m_wfModel; WFModel m_wfModel;
OTModel m_otModel; OTModel m_otModel;
TPrModel m_tPrModel; TPrModel m_tPrModel;
TPeModel m_tPeModel; TPeModel m_tPeModel;
PassivModel m_passiv; PassivModel m_passiv;
GenitivModel m_genitiv; GenitivModel m_genitiv;
ResultModel m_results; ResultModel m_results;
public: public:
DataModel(QObject* parent); DataModel(QObject *parent);
void write(const QString& filename) const; void write(const QString &filename) const;
void read(const QString& filename); void read(const QString &filename);
void printTo(QPrinter& printer) const; void printTo(QPrinter &printer) const;
signals: signals:
void modelChanged(); void modelChanged();
private slots: private slots:
void pluralModelChanged(); void pluralModelChanged();
void metaDataChanged(); void metaDataChanged();
void genusModelChanged(); void genusModelChanged();
void verbEndModelChanged(); void verbEndModelChanged();
void akkusativModelChanged(); void akkusativModelChanged();
void dativModelChanged(); void dativModelChanged();
void v2SvkModelChanged(); void v2SvkModelChanged();
void passivModelChanged(); void passivModelChanged();
void genitivModelChanged(); void genitivModelChanged();
}; };

View File

@ -5,33 +5,33 @@
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
QCoreApplication::setApplicationName(ESGRAF48_DESCRIPTION); QCoreApplication::setApplicationName(ESGRAF48_DESCRIPTION);
QCoreApplication::setApplicationVersion(ESGRAF48_VERSION); QCoreApplication::setApplicationVersion(ESGRAF48_VERSION);
QCommandLineParser cmdParser; QCommandLineParser cmdParser;
cmdParser.setApplicationDescription(ESGRAF48_DESCRIPTION); cmdParser.setApplicationDescription(ESGRAF48_DESCRIPTION);
cmdParser.addHelpOption(); cmdParser.addHelpOption();
cmdParser.addVersionOption(); cmdParser.addVersionOption();
cmdParser.addPositionalArgument("filename", "file to open"); cmdParser.addPositionalArgument("filename", "file to open");
cmdParser.process(app); cmdParser.process(app);
const QStringList args = cmdParser.positionalArguments(); const QStringList args = cmdParser.positionalArguments();
std::unique_ptr<MainWindow> mainWindow; std::unique_ptr<MainWindow> mainWindow;
if (args.empty()) if (args.empty())
{ {
mainWindow = std::make_unique<MainWindow>(nullptr); mainWindow = std::make_unique<MainWindow>(nullptr);
} }
else else
{ {
mainWindow = std::make_unique<MainWindow>(nullptr, args.at(0)); mainWindow = std::make_unique<MainWindow>(nullptr, args.at(0));
} }
mainWindow->show(); mainWindow->show();
return app.exec(); return app.exec();
} }

View File

@ -4,170 +4,170 @@
#include <sstream> #include <sstream>
MetaDataModel::MetaDataModel(QObject* parent) MetaDataModel::MetaDataModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
m_dateOfBirth = QDate::currentDate().addYears(-9); m_dateOfBirth = QDate::currentDate().addYears(-9);
m_dateOfTest = QDate::currentDate(); m_dateOfTest = QDate::currentDate();
} }
int MetaDataModel::rowCount(const QModelIndex& parent) const int MetaDataModel::rowCount(const QModelIndex &parent) const
{ {
return 1; return 1;
} }
int MetaDataModel::columnCount(const QModelIndex& parent) const int MetaDataModel::columnCount(const QModelIndex &parent) const
{ {
return 6; return 6;
} }
QVariant MetaDataModel::data(const QModelIndex& modelIndex, int role) const QVariant MetaDataModel::data(const QModelIndex &modelIndex, int role) const
{ {
if (role == Qt::DisplayRole || role == Qt::EditRole) if (role == Qt::DisplayRole || role == Qt::EditRole)
{ {
switch (modelIndex.column()) switch (modelIndex.column())
{ {
case 0: case 0:
return m_participant; return m_participant;
case 1: case 1:
return m_instructor; return m_instructor;
case 2: case 2:
return m_dateOfBirth; return m_dateOfBirth;
case 3: case 3:
return m_dateOfTest; return m_dateOfTest;
case 4: case 4:
return m_remarks; return m_remarks;
case 5: case 5:
return QString::fromStdString(getAge().toString()); return QString::fromStdString(getAge().toString());
default: default:
return QVariant(); return QVariant();
} }
} }
return QVariant(); return QVariant();
} }
Qt::ItemFlags MetaDataModel::flags(const QModelIndex& modelIndex) const Qt::ItemFlags MetaDataModel::flags(const QModelIndex &modelIndex) const
{ {
return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable; return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable;
} }
bool MetaDataModel::setData(const QModelIndex& modelIndex, const QVariant& value, int role) bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
{ {
if (role != Qt::EditRole) if (role != Qt::EditRole)
{ {
return QAbstractTableModel::setData(modelIndex, value, role); return QAbstractTableModel::setData(modelIndex, value, role);
} }
bool valueChanged = false; bool valueChanged = false;
switch (modelIndex.column()) switch (modelIndex.column())
{ {
case 0: case 0:
if (value.toString() != m_participant) if (value.toString() != m_participant)
{ {
m_participant = value.toString(); m_participant = value.toString();
valueChanged = true; valueChanged = true;
} }
break; break;
case 1: case 1:
if (value.toString() != m_instructor) if (value.toString() != m_instructor)
{ {
m_instructor = value.toString(); m_instructor = value.toString();
valueChanged = true; valueChanged = true;
} }
break; break;
case 2: case 2:
if (value.toDate() != m_dateOfBirth) if (value.toDate() != m_dateOfBirth)
{ {
m_dateOfBirth = value.toDate(); m_dateOfBirth = value.toDate();
emit dataChanged(index(0, 5), index(0, 5)); emit dataChanged(index(0, 5), index(0, 5));
valueChanged = true; valueChanged = true;
} }
break; break;
case 3: case 3:
if (value.toDate() != m_dateOfTest) if (value.toDate() != m_dateOfTest)
{ {
m_dateOfTest = value.toDate(); m_dateOfTest = value.toDate();
emit dataChanged(index(0, 5), index(0, 5)); emit dataChanged(index(0, 5), index(0, 5));
valueChanged = true; valueChanged = true;
} }
break; break;
case 4: case 4:
if (value.toString() != m_remarks) if (value.toString() != m_remarks)
{ {
m_remarks = value.toString(); m_remarks = value.toString();
valueChanged = true; valueChanged = true;
} }
break; break;
default: default:
break; break;
} }
if (valueChanged) if (valueChanged)
{ {
emit dataChanged(modelIndex, modelIndex); emit dataChanged(modelIndex, modelIndex);
} }
return valueChanged; return valueChanged;
} }
void MetaDataModel::read(const ESGRAF48::MetaDataModel& model) void MetaDataModel::read(const ESGRAF48::MetaDataModel &model)
{ {
setData(index(0, 0), QString::fromStdString(model.participantname())); setData(index(0, 0), QString::fromStdString(model.participantname()));
setData(index(0, 1), QString::fromStdString(model.instructorname())); setData(index(0, 1), QString::fromStdString(model.instructorname()));
setData(index(0, 2), QString::fromStdString(model.dateofbirth())); setData(index(0, 2), QString::fromStdString(model.dateofbirth()));
setData(index(0, 3), QString::fromStdString(model.dateoftest())); setData(index(0, 3), QString::fromStdString(model.dateoftest()));
setData(index(0, 4), QString::fromStdString(model.remarks())); setData(index(0, 4), QString::fromStdString(model.remarks()));
} }
void MetaDataModel::write(ESGRAF48::MetaDataModel& model) const void MetaDataModel::write(ESGRAF48::MetaDataModel &model) const
{ {
model.set_participantname(m_participant.toStdString()); model.set_participantname(m_participant.toStdString());
model.set_instructorname(m_instructor.toStdString()); model.set_instructorname(m_instructor.toStdString());
model.set_dateofbirth(m_dateOfBirth.toString(Qt::ISODate).toStdString()); model.set_dateofbirth(m_dateOfBirth.toString(Qt::ISODate).toStdString());
model.set_dateoftest(m_dateOfTest.toString(Qt::ISODate).toStdString()); model.set_dateoftest(m_dateOfTest.toString(Qt::ISODate).toStdString());
model.set_remarks(m_remarks.toStdString()); model.set_remarks(m_remarks.toStdString());
} }
void MetaDataModel::printTo(QPainter& painter) const void MetaDataModel::printTo(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
auto hasRemarks = !m_remarks.trimmed().isEmpty(); auto hasRemarks = !m_remarks.trimmed().isEmpty();
painter.drawText(0, 0, "Name, Vorname"); painter.drawText(0, 0, "Name, Vorname");
painter.drawText(0.25 * width, 0, m_participant); painter.drawText(0.25 * width, 0, m_participant);
painter.drawText(0.5 * width, 0, "Untersucher(in)"); painter.drawText(0.5 * width, 0, "Untersucher(in)");
painter.drawText(0.75 * width, 0, m_instructor); painter.drawText(0.75 * width, 0, m_instructor);
painter.translate(0, height); painter.translate(0, height);
painter.drawText(0, 0, "Geburtsdatum"); painter.drawText(0, 0, "Geburtsdatum");
painter.drawText(0.25 * width, 0, m_dateOfBirth.toString("dd.MM.yyyy")); painter.drawText(0.25 * width, 0, m_dateOfBirth.toString("dd.MM.yyyy"));
if (hasRemarks) if (hasRemarks)
{ {
painter.drawText(0.5 * width, 0, "Bemerkungen:"); painter.drawText(0.5 * width, 0, "Bemerkungen:");
painter.drawText(QRect(0.5 * width, 0.5 * height, width, 2 * height), m_remarks); painter.drawText(QRect(0.5 * width, 0.5 * height, width, 2 * height), m_remarks);
} }
painter.translate(0, height); painter.translate(0, height);
painter.drawText(0, 0, "Untersuchungsdatum"); painter.drawText(0, 0, "Untersuchungsdatum");
painter.drawText(0.25 * width, 0, m_dateOfTest.toString("dd.MM.yyyy")); painter.drawText(0.25 * width, 0, m_dateOfTest.toString("dd.MM.yyyy"));
painter.translate(0, height); painter.translate(0, height);
painter.drawText(0, 0, "Alter am Testtag"); painter.drawText(0, 0, "Alter am Testtag");
painter.drawText(0.25 * width, 0, getAge().toString().c_str()); painter.drawText(0.25 * width, 0, getAge().toString().c_str());
painter.translate(0, 2 * height); painter.translate(0, 2 * height);
} }
Age MetaDataModel::getAge() const Age MetaDataModel::getAge() const
{ {
return {m_dateOfBirth, m_dateOfTest}; return {m_dateOfBirth, m_dateOfTest};
} }

View File

@ -12,27 +12,27 @@
class MetaDataModel : public PrintableModel class MetaDataModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
private: private:
QString m_participant; QString m_participant;
QString m_instructor; QString m_instructor;
QDate m_dateOfBirth; QDate m_dateOfBirth;
QDate m_dateOfTest; QDate m_dateOfTest;
QString m_remarks; QString m_remarks;
public: public:
MetaDataModel(QObject* parent); MetaDataModel(QObject *parent);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(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;
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void read(const ESGRAF48::MetaDataModel& model); void read(const ESGRAF48::MetaDataModel &model);
void write(ESGRAF48::MetaDataModel& model) const; void write(ESGRAF48::MetaDataModel &model) const;
void printTo(QPainter& painter) const override; void printTo(QPainter &painter) const override;
Age getAge() const; Age getAge() const;
}; };

View File

@ -6,37 +6,37 @@
#include <QDataWidgetMapper> #include <QDataWidgetMapper>
#include <QDebug> #include <QDebug>
MetaDataWidget::MetaDataWidget(QWidget* parent) MetaDataWidget::MetaDataWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::MetaDataWidget) , ui(new Ui::MetaDataWidget)
, m_widgetMapper(new QDataWidgetMapper(this)) , m_widgetMapper(new QDataWidgetMapper(this))
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->dateOfTestDateEdit, &QDateEdit::dateChanged, m_widgetMapper, connect(ui->dateOfTestDateEdit, &QDateEdit::dateChanged, m_widgetMapper,
&QDataWidgetMapper::submit); &QDataWidgetMapper::submit);
connect(ui->dateOfBirthDateEdit, &QDateEdit::dateChanged, m_widgetMapper, connect(ui->dateOfBirthDateEdit, &QDateEdit::dateChanged, m_widgetMapper,
&QDataWidgetMapper::submit); &QDataWidgetMapper::submit);
} }
MetaDataWidget::~MetaDataWidget() MetaDataWidget::~MetaDataWidget()
{ {
delete ui; delete ui;
} }
void MetaDataWidget::setModel(MetaDataModel* model) void MetaDataWidget::setModel(MetaDataModel *model)
{ {
m_widgetMapper->setModel(model); m_widgetMapper->setModel(model);
m_widgetMapper->addMapping(ui->participantLineEdit, 0); m_widgetMapper->addMapping(ui->participantLineEdit, 0);
m_widgetMapper->addMapping(ui->instructorLineEdit, 1); m_widgetMapper->addMapping(ui->instructorLineEdit, 1);
m_widgetMapper->addMapping(ui->dateOfBirthDateEdit, 2); m_widgetMapper->addMapping(ui->dateOfBirthDateEdit, 2);
m_widgetMapper->addMapping(ui->dateOfTestDateEdit, 3); m_widgetMapper->addMapping(ui->dateOfTestDateEdit, 3);
m_widgetMapper->addMapping(ui->remarksPlainTextEdit, 4); m_widgetMapper->addMapping(ui->remarksPlainTextEdit, 4);
m_widgetMapper->addMapping(ui->ageLineEdit, 5); m_widgetMapper->addMapping(ui->ageLineEdit, 5);
m_widgetMapper->toFirst(); m_widgetMapper->toFirst();
} }
void MetaDataWidget::toFirst() void MetaDataWidget::toFirst()
{ {
m_widgetMapper->toFirst(); m_widgetMapper->toFirst();
} }

View File

@ -6,21 +6,21 @@ class QDataWidgetMapper;
class MetaDataModel; class MetaDataModel;
namespace Ui { namespace Ui {
class MetaDataWidget; class MetaDataWidget;
}; };
class MetaDataWidget : public QWidget class MetaDataWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::MetaDataWidget* ui; Ui::MetaDataWidget *ui;
QDataWidgetMapper* m_widgetMapper; QDataWidgetMapper *m_widgetMapper;
public: public:
MetaDataWidget(QWidget* parent = nullptr); MetaDataWidget(QWidget *parent = nullptr);
~MetaDataWidget(); ~MetaDataWidget();
void setModel(MetaDataModel* model); void setModel(MetaDataModel *model);
void toFirst(); void toFirst();
}; };

View File

@ -2,183 +2,183 @@
#include <regex> #include <regex>
PrintableModel::PrintableModel(QObject* parent) PrintableModel::PrintableModel(QObject *parent)
: CheckableTestModel(parent) : CheckableTestModel(parent)
{ {
} }
void PrintableModel::printTo(QPainter& painter) const void PrintableModel::printTo(QPainter &painter) const
{ {
printHeader(painter); printHeader(painter);
printTests(painter); printTests(painter);
printSummary(painter); printSummary(painter);
} }
QFont PrintableModel::h1Font() QFont PrintableModel::h1Font()
{ {
return QFont("Helvetica", 16); return QFont("Helvetica", 16);
} }
QFont PrintableModel::h2Font() QFont PrintableModel::h2Font()
{ {
return QFont("Helvetica", 10); return QFont("Helvetica", 10);
} }
QFont PrintableModel::tableFont() QFont PrintableModel::tableFont()
{ {
return QFont("Helvetica", 8); return QFont("Helvetica", 8);
} }
QPen PrintableModel::tablePen() QPen PrintableModel::tablePen()
{ {
return QPen(Qt::black, 1, Qt::SolidLine); return QPen(Qt::black, 1, Qt::SolidLine);
} }
QPen PrintableModel::resultPen() QPen PrintableModel::resultPen()
{ {
return QPen(Qt::black, 2, Qt::SolidLine); return QPen(Qt::black, 2, Qt::SolidLine);
} }
double PrintableModel::headerWidthFactor() double PrintableModel::headerWidthFactor()
{ {
return 0.17; return 0.17;
} }
double PrintableModel::cellWidthFactor() double PrintableModel::cellWidthFactor()
{ {
return headerWidthFactor() / 2; return headerWidthFactor() / 2;
} }
void PrintableModel::drawTextSquare(QPainter& painter, const QRectF& cell, const QString& text) void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text)
{ {
auto prevPen = painter.pen(); auto prevPen = painter.pen();
painter.setPen(tablePen()); painter.setPen(tablePen());
painter.drawText(cell, Qt::AlignCenter, text); painter.drawText(cell, Qt::AlignCenter, text);
painter.drawLine(cell.topLeft(), cell.topRight()); painter.drawLine(cell.topLeft(), cell.topRight());
painter.drawLine(cell.topRight(), cell.bottomRight()); painter.drawLine(cell.topRight(), cell.bottomRight());
painter.drawLine(cell.bottomRight(), cell.bottomLeft()); painter.drawLine(cell.bottomRight(), cell.bottomLeft());
painter.drawLine(cell.bottomLeft(), cell.topLeft()); painter.drawLine(cell.bottomLeft(), cell.topLeft());
painter.setPen(prevPen); painter.setPen(prevPen);
} }
void PrintableModel::drawNumberSquare(QPainter& painter, double x, double y, int number) void PrintableModel::drawNumberSquare(QPainter &painter, double x, double y, int number)
{ {
QRectF cell = {x, y, 0.03 * painter.device()->width(), QRectF cell = {x, y, 0.03 * painter.device()->width(),
1.5 * painter.fontMetrics().lineSpacing()}; 1.5 * painter.fontMetrics().lineSpacing()};
painter.drawText(cell, Qt::AlignCenter, QString::number(number)); painter.drawText(cell, Qt::AlignCenter, QString::number(number));
painter.drawLine(cell.topLeft(), cell.topRight()); painter.drawLine(cell.topLeft(), cell.topRight());
painter.drawLine(cell.topRight(), cell.bottomRight()); painter.drawLine(cell.topRight(), cell.bottomRight());
painter.drawLine(cell.bottomRight(), cell.bottomLeft()); painter.drawLine(cell.bottomRight(), cell.bottomLeft());
painter.drawLine(cell.bottomLeft(), cell.topLeft()); painter.drawLine(cell.bottomLeft(), cell.topLeft());
} }
void PrintableModel::PrintableModel::drawCheckSquare(QPainter& painter, const QRectF& cell, void PrintableModel::PrintableModel::drawCheckSquare(QPainter &painter, const QRectF &cell,
bool checked) bool checked)
{ {
drawTextSquare(painter, cell, checked ? u8"\u2612" : u8"\u2610"); drawTextSquare(painter, cell, checked ? u8"\u2612" : u8"\u2610");
} }
void PrintableModel::drawResultSquare(QPainter& painter, double y, bool rightCell, void PrintableModel::drawResultSquare(QPainter &painter, double y, bool rightCell,
unsigned int value) unsigned int value)
{ {
double pageWidth = painter.device()->width(); double pageWidth = painter.device()->width();
double cellWidth = 0.03 * pageWidth; double cellWidth = 0.03 * pageWidth;
double cellHeight = 1.5 * painter.fontMetrics().lineSpacing(); double cellHeight = 1.5 * painter.fontMetrics().lineSpacing();
double x = pageWidth - cellWidth - (rightCell ? 0 : 0.04 * pageWidth); double x = pageWidth - cellWidth - (rightCell ? 0 : 0.04 * pageWidth);
drawTextSquare(painter, {x, y, cellWidth, cellHeight}, QString::number(value)); drawTextSquare(painter, {x, y, cellWidth, cellHeight}, QString::number(value));
} }
void PrintableModel::drawGreySquare(QPainter& painter, const QRectF& cell) void PrintableModel::drawGreySquare(QPainter &painter, const QRectF &cell)
{ {
auto prevBrush = painter.brush(); auto prevBrush = painter.brush();
auto prevPen = painter.pen(); auto prevPen = painter.pen();
painter.setBrush(QBrush(QColor(224, 224, 224))); painter.setBrush(QBrush(QColor(224, 224, 224)));
painter.setPen(QPen(Qt::NoPen)); painter.setPen(QPen(Qt::NoPen));
QPointF points[4] = {cell.topLeft(), cell.topRight(), cell.bottomRight(), cell.bottomLeft()}; QPointF points[4] = {cell.topLeft(), cell.topRight(), cell.bottomRight(), cell.bottomLeft()};
painter.drawPolygon(points, 4); painter.drawPolygon(points, 4);
painter.setPen(tablePen()); painter.setPen(tablePen());
painter.drawLine(cell.topLeft(), cell.topRight()); painter.drawLine(cell.topLeft(), cell.topRight());
painter.drawLine(cell.topRight(), cell.bottomRight()); painter.drawLine(cell.topRight(), cell.bottomRight());
painter.drawLine(cell.bottomRight(), cell.bottomLeft()); painter.drawLine(cell.bottomRight(), cell.bottomLeft());
painter.drawLine(cell.bottomLeft(), cell.topLeft()); painter.drawLine(cell.bottomLeft(), cell.topLeft());
painter.setBrush(prevBrush); painter.setBrush(prevBrush);
painter.setPen(prevPen); painter.setPen(prevPen);
} }
void PrintableModel::drawHeader2(QPainter& painter, const QString& text) void PrintableModel::drawHeader2(QPainter &painter, const QString &text)
{ {
painter.setFont(h2Font()); painter.setFont(h2Font());
painter.drawText(0, 0, text); painter.drawText(0, 0, text);
painter.translate(0, 0.5 * painter.fontMetrics().lineSpacing()); painter.translate(0, 0.5 * painter.fontMetrics().lineSpacing());
} }
void PrintableModel::printHeader(QPainter& painter) const void PrintableModel::printHeader(QPainter &painter) const
{ {
auto title = getTitle(); auto title = getTitle();
if (!title.isEmpty()) if (!title.isEmpty())
{ {
drawHeader2(painter, getTitle()); drawHeader2(painter, getTitle());
} }
} }
void PrintableModel::printTests(QPainter& painter) const void PrintableModel::printTests(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
painter.setPen(tablePen()); painter.setPen(tablePen());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
double headerWidth = headerWidthFactor() * width; double headerWidth = headerWidthFactor() * width;
double cellWidth = cellWidthFactor() * width; double cellWidth = cellWidthFactor() * width;
double rowHeight = height; double rowHeight = height;
double x = 0; double x = 0;
double y = 0; double y = 0;
for (const auto& test : m_tests) for (const auto &test : m_tests)
{ {
QString testName = QString::fromStdString( QString testName = QString::fromStdString(
std::regex_replace(test.name().toStdString(), std::regex("\\s"), "\n")); std::regex_replace(test.name().toStdString(), std::regex("\\s"), "\n"));
drawTextSquare(painter, {0, y, headerWidth, 2 * rowHeight}, testName); drawTextSquare(painter, {0, y, headerWidth, 2 * rowHeight}, testName);
x = headerWidth; x = headerWidth;
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
drawTextSquare(painter, {x, y, cellWidth, rowHeight}, item.getText().c_str()); drawTextSquare(painter, {x, y, cellWidth, rowHeight}, item.getText().c_str());
drawCheckSquare(painter, {x, y + rowHeight, cellWidth, rowHeight}, item.isChecked()); drawCheckSquare(painter, {x, y + rowHeight, cellWidth, rowHeight}, item.isChecked());
x += cellWidth; x += cellWidth;
} }
y += rowHeight; y += rowHeight;
drawResultSquare(painter, y, true, test.getPoints()); drawResultSquare(painter, y, true, test.getPoints());
y += rowHeight; y += rowHeight;
} }
painter.translate(0, y + rowHeight); painter.translate(0, y + rowHeight);
} }
void PrintableModel::printSummary(QPainter& painter) const void PrintableModel::printSummary(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter, painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter,
"Rohwertpunkte Total:"); "Rohwertpunkte Total:");
painter.setPen(resultPen()); painter.setPen(resultPen());
drawNumberSquare(painter, 0.97 * width, 0, getPoints()); drawNumberSquare(painter, 0.97 * width, 0, getPoints());
painter.translate(0, 3 * height); painter.translate(0, 3 * height);
} }

View File

@ -10,33 +10,33 @@
class PrintableModel : public CheckableTestModel class PrintableModel : public CheckableTestModel
{ {
Q_OBJECT Q_OBJECT
public: public:
PrintableModel(QObject* parent); PrintableModel(QObject *parent);
virtual void printTo(QPainter& painter) const; virtual void printTo(QPainter &painter) const;
static QFont h1Font(); static QFont h1Font();
static QFont h2Font(); static QFont h2Font();
static QFont tableFont(); static QFont tableFont();
static QPen tablePen(); static QPen tablePen();
static QPen resultPen(); static QPen resultPen();
static double headerWidthFactor(); static double headerWidthFactor();
static double cellWidthFactor(); static double cellWidthFactor();
static void drawTextSquare(QPainter& painter, const QRectF& cell, const QString& text); static void drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text);
static void drawNumberSquare(QPainter& painter, double x, double y, int number); static void drawNumberSquare(QPainter &painter, double x, double y, int number);
static void drawCheckSquare(QPainter& painter, const QRectF& cell, bool checked); static void drawCheckSquare(QPainter &painter, const QRectF &cell, bool checked);
static void drawResultSquare(QPainter& painter, double y, bool rightCell, unsigned int value); static void drawResultSquare(QPainter &painter, double y, bool rightCell, unsigned int value);
static void drawGreySquare(QPainter& painter, const QRectF& cell); static void drawGreySquare(QPainter &painter, const QRectF &cell);
static void drawHeader2(QPainter& painter, const QString& text); static void drawHeader2(QPainter &painter, const QString &text);
protected: protected:
virtual void printHeader(QPainter& painter) const; virtual void printHeader(QPainter &painter) const;
virtual void printTests(QPainter& painter) const; virtual void printTests(QPainter &painter) const;
virtual void printSummary(QPainter& painter) const; virtual void printSummary(QPainter &painter) const;
}; };

View File

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

View File

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

View File

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

View File

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

View File

@ -1,43 +1,43 @@
#include "PRMap.h" #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()) if (points >= m_PRs.size())
{ {
return 0; return 0;
} }
auto ageIndex = [&]() -> size_t { auto ageIndex = [&]() -> size_t {
if (m_ages.empty()) if (m_ages.empty())
{ {
return 0; return 0;
} }
if (age < m_ages.front()) if (age < m_ages.front())
{ {
return 0; return 0;
} }
if (m_ages.back() < age) if (m_ages.back() < age)
{ {
return m_ages.size() - 2; return m_ages.size() - 2;
} }
for (size_t index = 1; index < m_ages.size(); ++index) for (size_t index = 1; index < m_ages.size(); ++index)
{ {
if (age < m_ages.at(index)) if (age < m_ages.at(index))
{ {
return index - 1; return index - 1;
} }
} }
return 0; return 0;
}(); }();
if (ageIndex >= m_PRs.at(points).size()) if (ageIndex >= m_PRs.at(points).size())
{ {
return 0; return 0;
} }
return m_PRs.at(points).at(ageIndex); return m_PRs.at(points).at(ageIndex);
} }

View File

@ -6,9 +6,9 @@
class PRMap class PRMap
{ {
protected: protected:
std::vector<Age> m_ages; std::vector<Age> m_ages;
std::vector<std::vector<unsigned int>> m_PRs; std::vector<std::vector<unsigned int>> m_PRs;
public: 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 class PassivPR : public PRMap
{ {
public: public:
PassivPR() PassivPR()
{ {
// clang-format off // clang-format off
m_ages = { m_ages = {
{ 7, 0 }, { 7, 0 },
{ 8, 6 }, { 8, 6 },
@ -27,6 +27,6 @@ public:
{ 94, 84 }, { 94, 84 },
{ 100, 100 } { 100, 100 }
}; };
// clang-format on // clang-format on
} }
}; };

View File

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

View File

@ -14,246 +14,246 @@
#include <QDebug> #include <QDebug>
ResultModel::ResultModel(QObject* parent) ResultModel::ResultModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
{ {
m_results = {{"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"}}; 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", "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()) if (role == Qt::DisplayRole && index.column() < m_results.size())
{ {
switch (index.row()) switch (index.row())
{ {
case 0: case 0:
{ {
auto points = m_results[index.column()].points(); auto points = m_results[index.column()].points();
if (points != 0) if (points != 0)
{ {
return static_cast<uint>(points); return static_cast<uint>(points);
} }
break; break;
} }
case 1: case 1:
{ {
auto pr = m_results[index.column()].pr(); auto pr = m_results[index.column()].pr();
if (pr >= 84) if (pr >= 84)
{ {
return static_cast<uint>(pr); return static_cast<uint>(pr);
} }
break; break;
} }
case 2: case 2:
{ {
auto pr = m_results[index.column()].pr(); auto pr = m_results[index.column()].pr();
if (pr < 84 && pr > 16) if (pr < 84 && pr > 16)
{ {
return static_cast<uint>(pr); return static_cast<uint>(pr);
} }
break; break;
} }
case 3: case 3:
{ {
auto pr = m_results[index.column()].pr(); auto pr = m_results[index.column()].pr();
if (pr <= 16) if (pr <= 16)
{ {
return static_cast<uint>(pr); return static_cast<uint>(pr);
} }
break; break;
} }
default: default:
break; break;
}; };
return "-"; return "-";
} }
return {}; return {};
} }
QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
{ {
return {}; return {};
} }
switch (orientation) switch (orientation)
{ {
case Qt::Horizontal: case Qt::Horizontal:
if (m_results.size() > section) if (m_results.size() > section)
{ {
return m_results[section].name(); return m_results[section].name();
} }
case Qt::Vertical: case Qt::Vertical:
switch (section) switch (section)
{ {
case 0: case 0:
return "RP"; return "RP";
case 1: case 1:
return ">= PR 84"; return ">= PR 84";
case 2: case 2:
return "< PR 84"; return "< PR 84";
case 3: case 3:
return "<= PR 16"; return "<= PR 16";
default: default:
return {}; return {};
} }
default: default:
return {}; return {};
} }
} }
void ResultModel::setAge(const Age& age) void ResultModel::setAge(const Age &age)
{ {
m_age = age; m_age = age;
emit dataChanged(index(1, 0), index(4, 8)); emit dataChanged(index(1, 0), index(4, 8));
} }
void ResultModel::setPluralResult(unsigned int points) void ResultModel::setPluralResult(unsigned int points)
{ {
if (m_results[6].points() != points) if (m_results[6].points() != points)
{ {
m_results[6].setPoints(points); m_results[6].setPoints(points);
m_results[6].setPR(PluralPR().lookup(m_age, points)); m_results[6].setPR(PluralPR().lookup(m_age, points));
emit dataChanged(index(0, 6), index(4, 6)); emit dataChanged(index(0, 6), index(4, 6));
} }
} }
void ResultModel::setGenusResult(unsigned int points) void ResultModel::setGenusResult(unsigned int points)
{ {
if (m_results[3].points() != points) if (m_results[3].points() != points)
{ {
m_results[3].setPoints(points); m_results[3].setPoints(points);
m_results[3].setPR(GenusPR().lookup(m_age, points)); m_results[3].setPR(GenusPR().lookup(m_age, points));
emit dataChanged(index(0, 3), index(4, 3)); emit dataChanged(index(0, 3), index(4, 3));
} }
} }
void ResultModel::setVerbEndResult(unsigned int points) void ResultModel::setVerbEndResult(unsigned int points)
{ {
if (m_results[2].points() != points) if (m_results[2].points() != points)
{ {
m_results[2].setPoints(points); m_results[2].setPoints(points);
m_results[2].setPR(VerbEndPR().lookup(m_age, points)); m_results[2].setPR(VerbEndPR().lookup(m_age, points));
emit dataChanged(index(0, 2), index(4, 2)); emit dataChanged(index(0, 2), index(4, 2));
} }
} }
void ResultModel::setAkkusativResult(unsigned int points) void ResultModel::setAkkusativResult(unsigned int points)
{ {
if (m_results[4].points() != points) if (m_results[4].points() != points)
{ {
m_results[4].setPoints(points); m_results[4].setPoints(points);
m_results[4].setPR(AkkusativPR().lookup(m_age, points)); m_results[4].setPR(AkkusativPR().lookup(m_age, points));
emit dataChanged(index(0, 4), index(4, 4)); emit dataChanged(index(0, 4), index(4, 4));
} }
} }
void ResultModel::setDativResult(unsigned int points) void ResultModel::setDativResult(unsigned int points)
{ {
if (m_results[5].points() != points) if (m_results[5].points() != points)
{ {
m_results[5].setPoints(points); m_results[5].setPoints(points);
m_results[5].setPR(DativPR().lookup(m_age, points)); m_results[5].setPR(DativPR().lookup(m_age, points));
emit dataChanged(index(0, 5), index(4, 5)); emit dataChanged(index(0, 5), index(4, 5));
} }
} }
void ResultModel::setV2Result(unsigned int points) void ResultModel::setV2Result(unsigned int points)
{ {
if (m_results[0].points() != points) if (m_results[0].points() != points)
{ {
m_results[0].setPoints(points); m_results[0].setPoints(points);
m_results[0].setPR(V2PR().lookup(m_age, points)); m_results[0].setPR(V2PR().lookup(m_age, points));
emit dataChanged(index(0, 0), index(4, 0)); emit dataChanged(index(0, 0), index(4, 0));
} }
} }
void ResultModel::setSvkResult(unsigned int points) void ResultModel::setSvkResult(unsigned int points)
{ {
if (m_results[1].points() != points) if (m_results[1].points() != points)
{ {
m_results[1].setPoints(points); m_results[1].setPoints(points);
m_results[1].setPR(SvkPR().lookup(m_age, points)); m_results[1].setPR(SvkPR().lookup(m_age, points));
emit dataChanged(index(0, 1), index(4, 1)); emit dataChanged(index(0, 1), index(4, 1));
} }
} }
void ResultModel::setPassivResult(unsigned int points) void ResultModel::setPassivResult(unsigned int points)
{ {
if (m_results[7].points() != points) if (m_results[7].points() != points)
{ {
m_results[7].setPoints(points); m_results[7].setPoints(points);
m_results[7].setPR(PassivPR().lookup(m_age, points)); m_results[7].setPR(PassivPR().lookup(m_age, points));
emit dataChanged(index(0, 7), index(4, 7)); emit dataChanged(index(0, 7), index(4, 7));
} }
} }
void ResultModel::setGenitivResult(unsigned int points) void ResultModel::setGenitivResult(unsigned int points)
{ {
if (m_results[8].points() != points) if (m_results[8].points() != points)
{ {
m_results[8].setPoints(points); m_results[8].setPoints(points);
m_results[8].setPR(GenitivPR().lookup(m_age, points)); m_results[8].setPR(GenitivPR().lookup(m_age, points));
emit dataChanged(index(0, 8), index(4, 8)); 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.setFont(PrintableModel::tableFont());
painter.setPen(PrintableModel::tablePen()); painter.setPen(PrintableModel::tablePen());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
double cellWidth = width / (m_results.size() + 1); double cellWidth = width / (m_results.size() + 1);
double rowHeight = 2 * height; double rowHeight = 2 * height;
double x = 0; double x = 0;
double y = 0; double y = 0;
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, ""); PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, "");
PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight}, PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight},
u8"\u2265 PR 84"); u8"\u2265 PR 84");
PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight}, PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
"< PR 84"); "< PR 84");
PrintableModel::drawGreySquare(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}, PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
u8"\u2264 PR 16"); u8"\u2264 PR 16");
x += cellWidth; x += cellWidth;
for (const auto& result : m_results) for (const auto &result : m_results)
{ {
PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight},
result.name()); result.name());
const auto pr = result.pr(); const auto pr = result.pr();
PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight}, PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight},
pr >= 84 ? QString::number(pr) : "-"); pr >= 84 ? QString::number(pr) : "-");
PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight}, PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
pr < 84 && pr > 16 ? QString::number(pr) : "-"); pr < 84 && pr > 16 ? QString::number(pr) : "-");
PrintableModel::drawGreySquare(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}, PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight},
pr <= 16 ? QString::number(pr) : "-"); pr <= 16 ? QString::number(pr) : "-");
x += cellWidth; x += cellWidth;
} }
} }

View File

@ -8,71 +8,72 @@
class TestResult class TestResult
{ {
private: private:
QString m_name; QString m_name;
size_t m_points = 0; size_t m_points = 0;
size_t m_pr = 0; size_t m_pr = 0;
public: public:
TestResult(const char* name) TestResult(const char *name)
: m_name(name) : m_name(name)
{ {
} }
void setPoints(const size_t& points) void setPoints(const size_t &points)
{ {
m_points = points; m_points = points;
} }
void setPR(const unsigned int& pr) void setPR(const unsigned int &pr)
{ {
m_pr = pr; m_pr = pr;
} }
const QString& name() const const QString &name() const
{ {
return m_name; return m_name;
} }
const size_t points() const const size_t points() const
{ {
return m_points; return m_points;
} }
const size_t pr() const const size_t pr() const
{ {
return m_pr; return m_pr;
} }
}; };
class ResultModel : public QAbstractTableModel class ResultModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
private: private:
Age m_age; Age m_age;
std::vector<TestResult> m_results; std::vector<TestResult> m_results;
public: public:
ResultModel(QObject* parent); ResultModel(QObject *parent);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(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, QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override; int role = Qt::DisplayRole) const override;
void setAge(const Age& age); void setAge(const Age &age);
void setPluralResult(unsigned int points); void setPluralResult(unsigned int points);
void setGenusResult(unsigned int points); void setGenusResult(unsigned int points);
void setVerbEndResult(unsigned int points); void setVerbEndResult(unsigned int points);
void setAkkusativResult(unsigned int points); void setAkkusativResult(unsigned int points);
void setDativResult(unsigned int points); void setDativResult(unsigned int points);
void setV2Result(unsigned int points); void setV2Result(unsigned int points);
void setSvkResult(unsigned int points); void setSvkResult(unsigned int points);
void setPassivResult(unsigned int points); void setPassivResult(unsigned int points);
void setGenitivResult(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" #include "ResultModel.h"
ResultWidget::ResultWidget(QWidget* parent) ResultWidget::ResultWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::ResultWidget) , ui(new Ui::ResultWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
} }
ResultWidget::~ResultWidget() 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 class ResultWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::ResultWidget* ui; Ui::ResultWidget *ui;
public: public:
ResultWidget(QWidget* parent = nullptr); ResultWidget(QWidget *parent = nullptr);
~ResultWidget(); ~ResultWidget();
void setModel(ResultModel* model); void setModel(ResultModel *model);
}; };

View File

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

View File

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

View File

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

View File

@ -4,26 +4,26 @@
#include "AkkusativModel.h" #include "AkkusativModel.h"
#include "DativModel.h" #include "DativModel.h"
AkkusativDativWidget::AkkusativDativWidget(QWidget* parent) AkkusativDativWidget::AkkusativDativWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::AkkusativDativWidget) , ui(new Ui::AkkusativDativWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->akkusativTableView->horizontalHeader()->hide(); ui->akkusativTableView->horizontalHeader()->hide();
ui->dativTableView->horizontalHeader()->hide(); ui->dativTableView->horizontalHeader()->hide();
} }
AkkusativDativWidget::~AkkusativDativWidget() AkkusativDativWidget::~AkkusativDativWidget()
{ {
delete ui; delete ui;
} }
void AkkusativDativWidget::setAkkusativModel(AkkusativModel* model) void AkkusativDativWidget::setAkkusativModel(AkkusativModel *model)
{ {
ui->akkusativTableView->setModel(model); ui->akkusativTableView->setModel(model);
} }
void AkkusativDativWidget::setDativModel(DativModel* model) void AkkusativDativWidget::setDativModel(DativModel *model)
{ {
ui->dativTableView->setModel(model); ui->dativTableView->setModel(model);
} }

View File

@ -11,15 +11,15 @@ class AkkusativDativWidget;
class AkkusativDativWidget : public QWidget class AkkusativDativWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::AkkusativDativWidget* ui; Ui::AkkusativDativWidget *ui;
public: public:
AkkusativDativWidget(QWidget* parent = nullptr); AkkusativDativWidget(QWidget *parent = nullptr);
~AkkusativDativWidget(); ~AkkusativDativWidget();
void setAkkusativModel(AkkusativModel* model); void setAkkusativModel(AkkusativModel *model);
void setDativModel(DativModel* model); void setDativModel(DativModel *model);
}; };

View File

@ -1,112 +1,112 @@
#include "AkkusativModel.h" #include "AkkusativModel.h"
AkkusativModel::AkkusativModel(QObject* parent) AkkusativModel::AkkusativModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
m_tests = {{"Akkusativ Nominalphrase", m_tests = {{"Akkusativ Nominalphrase",
{"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}}, {"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}},
{"Präpositionalphrase (Verstecke)", {"Präpositionalphrase (Verstecke)",
{"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}}, {"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}},
{"Nominalphrase (Futter)", {"Nominalphrase (Futter)",
{"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}}; {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}};
} }
void AkkusativModel::read(const ESGRAF48::AkkusativModel& model) void AkkusativModel::read(const ESGRAF48::AkkusativModel &model)
{ {
const auto& tiereModel = model.tiere(); const auto &tiereModel = model.tiere();
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(tiereModel.tiger()); testItems[0].setState(tiereModel.tiger());
testItems[1].setState(tiereModel.katze()); testItems[1].setState(tiereModel.katze());
testItems[2].setState(tiereModel.affe()); testItems[2].setState(tiereModel.affe());
testItems[3].setState(tiereModel.gans()); testItems[3].setState(tiereModel.gans());
testItems[4].setState(tiereModel.baer()); testItems[4].setState(tiereModel.baer());
testItems[5].setState(tiereModel.pferd()); testItems[5].setState(tiereModel.pferd());
testItems[6].setState(tiereModel.hund()); testItems[6].setState(tiereModel.hund());
testItems[7].setState(tiereModel.elefant()); testItems[7].setState(tiereModel.elefant());
} }
const auto& versteckeModel = model.verstecke(); const auto &versteckeModel = model.verstecke();
{ {
auto& testItems = m_tests.at(1).items(); auto &testItems = m_tests.at(1).items();
testItems[0].setState(versteckeModel.vorhang1()); testItems[0].setState(versteckeModel.vorhang1());
testItems[1].setState(versteckeModel.kiste1()); testItems[1].setState(versteckeModel.kiste1());
testItems[2].setState(versteckeModel.holz1()); testItems[2].setState(versteckeModel.holz1());
testItems[3].setState(versteckeModel.kiste2()); testItems[3].setState(versteckeModel.kiste2());
testItems[4].setState(versteckeModel.baum1()); testItems[4].setState(versteckeModel.baum1());
testItems[5].setState(versteckeModel.vorhang2()); testItems[5].setState(versteckeModel.vorhang2());
testItems[6].setState(versteckeModel.holz2()); testItems[6].setState(versteckeModel.holz2());
testItems[7].setState(versteckeModel.baum2()); testItems[7].setState(versteckeModel.baum2());
} }
const auto& futterModel = model.futter(); const auto &futterModel = model.futter();
{ {
auto& testItems = m_tests.at(2).items(); auto &testItems = m_tests.at(2).items();
testItems[0].setState(futterModel.salat()); testItems[0].setState(futterModel.salat());
testItems[1].setState(futterModel.fleisch()); testItems[1].setState(futterModel.fleisch());
testItems[2].setState(futterModel.knochen()); testItems[2].setState(futterModel.knochen());
testItems[3].setState(futterModel.banane()); testItems[3].setState(futterModel.banane());
testItems[4].setState(futterModel.apfel()); testItems[4].setState(futterModel.apfel());
testItems[5].setState(futterModel.karotte()); testItems[5].setState(futterModel.karotte());
testItems[6].setState(futterModel.honig()); testItems[6].setState(futterModel.honig());
testItems[7].setState(futterModel.zucker()); testItems[7].setState(futterModel.zucker());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void AkkusativModel::write(ESGRAF48::AkkusativModel& model) const void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const
{ {
auto* tiereModel = model.mutable_tiere(); auto *tiereModel = model.mutable_tiere();
if (tiereModel != nullptr) if (tiereModel != nullptr)
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
tiereModel->set_tiger(testItems[0].isChecked()); tiereModel->set_tiger(testItems[0].isChecked());
tiereModel->set_katze(testItems[1].isChecked()); tiereModel->set_katze(testItems[1].isChecked());
tiereModel->set_affe(testItems[2].isChecked()); tiereModel->set_affe(testItems[2].isChecked());
tiereModel->set_gans(testItems[3].isChecked()); tiereModel->set_gans(testItems[3].isChecked());
tiereModel->set_baer(testItems[4].isChecked()); tiereModel->set_baer(testItems[4].isChecked());
tiereModel->set_pferd(testItems[5].isChecked()); tiereModel->set_pferd(testItems[5].isChecked());
tiereModel->set_hund(testItems[6].isChecked()); tiereModel->set_hund(testItems[6].isChecked());
tiereModel->set_elefant(testItems[7].isChecked()); tiereModel->set_elefant(testItems[7].isChecked());
} }
auto* versteckeModel = model.mutable_verstecke(); auto *versteckeModel = model.mutable_verstecke();
if (versteckeModel != nullptr) if (versteckeModel != nullptr)
{ {
const auto& testItems = m_tests.at(1).items(); const auto &testItems = m_tests.at(1).items();
versteckeModel->set_vorhang1(testItems[0].isChecked()); versteckeModel->set_vorhang1(testItems[0].isChecked());
versteckeModel->set_kiste1(testItems[1].isChecked()); versteckeModel->set_kiste1(testItems[1].isChecked());
versteckeModel->set_holz1(testItems[2].isChecked()); versteckeModel->set_holz1(testItems[2].isChecked());
versteckeModel->set_kiste2(testItems[3].isChecked()); versteckeModel->set_kiste2(testItems[3].isChecked());
versteckeModel->set_baum1(testItems[4].isChecked()); versteckeModel->set_baum1(testItems[4].isChecked());
versteckeModel->set_vorhang2(testItems[5].isChecked()); versteckeModel->set_vorhang2(testItems[5].isChecked());
versteckeModel->set_holz2(testItems[6].isChecked()); versteckeModel->set_holz2(testItems[6].isChecked());
versteckeModel->set_baum2(testItems[7].isChecked()); versteckeModel->set_baum2(testItems[7].isChecked());
} }
auto* futterModel = model.mutable_futter(); auto *futterModel = model.mutable_futter();
if (futterModel != nullptr) if (futterModel != nullptr)
{ {
const auto& testItems = m_tests.at(2).items(); const auto &testItems = m_tests.at(2).items();
futterModel->set_salat(testItems[0].isChecked()); futterModel->set_salat(testItems[0].isChecked());
futterModel->set_fleisch(testItems[1].isChecked()); futterModel->set_fleisch(testItems[1].isChecked());
futterModel->set_knochen(testItems[2].isChecked()); futterModel->set_knochen(testItems[2].isChecked());
futterModel->set_banane(testItems[3].isChecked()); futterModel->set_banane(testItems[3].isChecked());
futterModel->set_apfel(testItems[4].isChecked()); futterModel->set_apfel(testItems[4].isChecked());
futterModel->set_karotte(testItems[5].isChecked()); futterModel->set_karotte(testItems[5].isChecked());
futterModel->set_honig(testItems[6].isChecked()); futterModel->set_honig(testItems[6].isChecked());
futterModel->set_zucker(testItems[7].isChecked()); futterModel->set_zucker(testItems[7].isChecked());
} }
} }
void AkkusativModel::printHeader(QPainter& painter) const void AkkusativModel::printHeader(QPainter &painter) const
{ {
drawHeader2(painter, "Subtest 4: Akkusativ und Dativ"); drawHeader2(painter, "Subtest 4: Akkusativ und Dativ");
} }

View File

@ -5,14 +5,14 @@
class AkkusativModel : public PrintableModel class AkkusativModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
AkkusativModel(QObject* parent); AkkusativModel(QObject *parent);
void read(const ESGRAF48::AkkusativModel& model); void read(const ESGRAF48::AkkusativModel &model);
void write(ESGRAF48::AkkusativModel& model) const; void write(ESGRAF48::AkkusativModel &model) const;
protected: protected:
void printHeader(QPainter& painter) const override; void printHeader(QPainter &painter) const override;
}; };

View File

@ -1,112 +1,112 @@
#include "DativModel.h" #include "DativModel.h"
DativModel::DativModel(QObject* parent) DativModel::DativModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
m_tests = {{"Dativ Nominalphrase", m_tests = {{"Dativ Nominalphrase",
{"Affe", "Gans", "Tiger", "Hund", "Elefant", "Pferd", "Bär", "Katze"}}, {"Affe", "Gans", "Tiger", "Hund", "Elefant", "Pferd", "Bär", "Katze"}},
{"Präpositionalphrase (Verstecke)", {"Präpositionalphrase (Verstecke)",
{"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}}, {"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}},
{"Nominalphrase (Tiere)", {"Nominalphrase (Tiere)",
{"Gans", "Tiger", "Hund", "Affe", "Elefant", "Pferd", "Bär", "Katze"}}}; {"Gans", "Tiger", "Hund", "Affe", "Elefant", "Pferd", "Bär", "Katze"}}};
} }
void DativModel::read(const ESGRAF48::DativModel& model) void DativModel::read(const ESGRAF48::DativModel &model)
{ {
const auto& tiereModel = model.tiere(); const auto &tiereModel = model.tiere();
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(tiereModel.affe()); testItems[0].setState(tiereModel.affe());
testItems[1].setState(tiereModel.gans()); testItems[1].setState(tiereModel.gans());
testItems[2].setState(tiereModel.tiger()); testItems[2].setState(tiereModel.tiger());
testItems[3].setState(tiereModel.hund()); testItems[3].setState(tiereModel.hund());
testItems[4].setState(tiereModel.elefant()); testItems[4].setState(tiereModel.elefant());
testItems[5].setState(tiereModel.pferd()); testItems[5].setState(tiereModel.pferd());
testItems[6].setState(tiereModel.baer()); testItems[6].setState(tiereModel.baer());
testItems[7].setState(tiereModel.katze()); testItems[7].setState(tiereModel.katze());
} }
const auto& versteckeModel = model.verstecke(); const auto &versteckeModel = model.verstecke();
{ {
auto& testItems = m_tests.at(1).items(); auto &testItems = m_tests.at(1).items();
testItems[0].setState(versteckeModel.vorhang1()); testItems[0].setState(versteckeModel.vorhang1());
testItems[1].setState(versteckeModel.kiste1()); testItems[1].setState(versteckeModel.kiste1());
testItems[2].setState(versteckeModel.holz1()); testItems[2].setState(versteckeModel.holz1());
testItems[3].setState(versteckeModel.kiste2()); testItems[3].setState(versteckeModel.kiste2());
testItems[4].setState(versteckeModel.baum1()); testItems[4].setState(versteckeModel.baum1());
testItems[5].setState(versteckeModel.vorhang2()); testItems[5].setState(versteckeModel.vorhang2());
testItems[6].setState(versteckeModel.holz2()); testItems[6].setState(versteckeModel.holz2());
testItems[7].setState(versteckeModel.baum2()); testItems[7].setState(versteckeModel.baum2());
} }
const auto& nomTiereModel = model.nomtiere(); const auto &nomTiereModel = model.nomtiere();
{ {
auto& testItems = m_tests.at(2).items(); auto &testItems = m_tests.at(2).items();
testItems[0].setState(nomTiereModel.gans()); testItems[0].setState(nomTiereModel.gans());
testItems[1].setState(nomTiereModel.tiger()); testItems[1].setState(nomTiereModel.tiger());
testItems[2].setState(nomTiereModel.hund()); testItems[2].setState(nomTiereModel.hund());
testItems[3].setState(nomTiereModel.affe()); testItems[3].setState(nomTiereModel.affe());
testItems[4].setState(nomTiereModel.elefant()); testItems[4].setState(nomTiereModel.elefant());
testItems[5].setState(nomTiereModel.pferd()); testItems[5].setState(nomTiereModel.pferd());
testItems[6].setState(nomTiereModel.baer()); testItems[6].setState(nomTiereModel.baer());
testItems[7].setState(nomTiereModel.katze()); testItems[7].setState(nomTiereModel.katze());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void DativModel::write(ESGRAF48::DativModel& model) const void DativModel::write(ESGRAF48::DativModel &model) const
{ {
auto* tiereModel = model.mutable_tiere(); auto *tiereModel = model.mutable_tiere();
if (tiereModel != nullptr) if (tiereModel != nullptr)
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
tiereModel->set_affe(testItems[0].isChecked()); tiereModel->set_affe(testItems[0].isChecked());
tiereModel->set_gans(testItems[1].isChecked()); tiereModel->set_gans(testItems[1].isChecked());
tiereModel->set_tiger(testItems[2].isChecked()); tiereModel->set_tiger(testItems[2].isChecked());
tiereModel->set_hund(testItems[3].isChecked()); tiereModel->set_hund(testItems[3].isChecked());
tiereModel->set_elefant(testItems[4].isChecked()); tiereModel->set_elefant(testItems[4].isChecked());
tiereModel->set_pferd(testItems[5].isChecked()); tiereModel->set_pferd(testItems[5].isChecked());
tiereModel->set_baer(testItems[6].isChecked()); tiereModel->set_baer(testItems[6].isChecked());
tiereModel->set_katze(testItems[7].isChecked()); tiereModel->set_katze(testItems[7].isChecked());
} }
auto* versteckeModel = model.mutable_verstecke(); auto *versteckeModel = model.mutable_verstecke();
if (versteckeModel != nullptr) if (versteckeModel != nullptr)
{ {
const auto& testItems = m_tests.at(1).items(); const auto &testItems = m_tests.at(1).items();
versteckeModel->set_vorhang1(testItems[0].isChecked()); versteckeModel->set_vorhang1(testItems[0].isChecked());
versteckeModel->set_kiste1(testItems[1].isChecked()); versteckeModel->set_kiste1(testItems[1].isChecked());
versteckeModel->set_holz1(testItems[2].isChecked()); versteckeModel->set_holz1(testItems[2].isChecked());
versteckeModel->set_kiste2(testItems[3].isChecked()); versteckeModel->set_kiste2(testItems[3].isChecked());
versteckeModel->set_baum1(testItems[4].isChecked()); versteckeModel->set_baum1(testItems[4].isChecked());
versteckeModel->set_vorhang2(testItems[5].isChecked()); versteckeModel->set_vorhang2(testItems[5].isChecked());
versteckeModel->set_holz2(testItems[6].isChecked()); versteckeModel->set_holz2(testItems[6].isChecked());
versteckeModel->set_baum2(testItems[7].isChecked()); versteckeModel->set_baum2(testItems[7].isChecked());
} }
auto* nomTiereModel = model.mutable_nomtiere(); auto *nomTiereModel = model.mutable_nomtiere();
if (nomTiereModel != nullptr) if (nomTiereModel != nullptr)
{ {
const auto& testItems = m_tests.at(2).items(); const auto &testItems = m_tests.at(2).items();
nomTiereModel->set_gans(testItems[0].isChecked()); nomTiereModel->set_gans(testItems[0].isChecked());
nomTiereModel->set_tiger(testItems[1].isChecked()); nomTiereModel->set_tiger(testItems[1].isChecked());
nomTiereModel->set_hund(testItems[2].isChecked()); nomTiereModel->set_hund(testItems[2].isChecked());
nomTiereModel->set_affe(testItems[3].isChecked()); nomTiereModel->set_affe(testItems[3].isChecked());
nomTiereModel->set_elefant(testItems[4].isChecked()); nomTiereModel->set_elefant(testItems[4].isChecked());
nomTiereModel->set_pferd(testItems[5].isChecked()); nomTiereModel->set_pferd(testItems[5].isChecked());
nomTiereModel->set_baer(testItems[6].isChecked()); nomTiereModel->set_baer(testItems[6].isChecked());
nomTiereModel->set_katze(testItems[7].isChecked()); nomTiereModel->set_katze(testItems[7].isChecked());
} }
} }
void DativModel::printHeader(QPainter& painter) const void DativModel::printHeader(QPainter &painter) const
{ {
painter.translate(0, -1.5 * painter.fontMetrics().lineSpacing()); painter.translate(0, -1.5 * painter.fontMetrics().lineSpacing());
} }

View File

@ -5,14 +5,14 @@
class DativModel : public PrintableModel class DativModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
DativModel(QObject* parent); DativModel(QObject *parent);
void read(const ESGRAF48::DativModel& model); void read(const ESGRAF48::DativModel &model);
void write(ESGRAF48::DativModel& model) const; void write(ESGRAF48::DativModel &model) const;
protected: protected:
void printHeader(QPainter& painter) const override; void printHeader(QPainter &painter) const override;
}; };

View File

@ -1,99 +1,99 @@
#include "GenusModel.h" #include "GenusModel.h"
GenusModel::GenusModel(QObject* parent) GenusModel::GenusModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
m_title = "Subtest 3: Genus"; m_title = "Subtest 3: Genus";
m_tests = {{"Tiere", {"Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Affe", "Hund"}}, m_tests = {{"Tiere", {"Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Affe", "Hund"}},
{"Futter", {"Futter",
{"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}, {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}},
{"Zirkus", {"Kiste", "Holz", "Vorhang", "Baum"}}}; {"Zirkus", {"Kiste", "Holz", "Vorhang", "Baum"}}};
} }
void GenusModel::read(const ESGRAF48::GenusModel& model) void GenusModel::read(const ESGRAF48::GenusModel &model)
{ {
const auto& tiereModel = model.tiere(); const auto &tiereModel = model.tiere();
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(tiereModel.tiger()); testItems[0].setState(tiereModel.tiger());
testItems[1].setState(tiereModel.baer()); testItems[1].setState(tiereModel.baer());
testItems[2].setState(tiereModel.katze()); testItems[2].setState(tiereModel.katze());
testItems[3].setState(tiereModel.pferd()); testItems[3].setState(tiereModel.pferd());
testItems[4].setState(tiereModel.gans()); testItems[4].setState(tiereModel.gans());
testItems[5].setState(tiereModel.elefant()); testItems[5].setState(tiereModel.elefant());
testItems[6].setState(tiereModel.affe()); testItems[6].setState(tiereModel.affe());
testItems[7].setState(tiereModel.hund()); testItems[7].setState(tiereModel.hund());
} }
const auto& futterModel = model.futter(); const auto &futterModel = model.futter();
{ {
auto& testItems = m_tests.at(1).items(); auto &testItems = m_tests.at(1).items();
testItems[0].setState(futterModel.salat()); testItems[0].setState(futterModel.salat());
testItems[1].setState(futterModel.fleisch()); testItems[1].setState(futterModel.fleisch());
testItems[2].setState(futterModel.knochen()); testItems[2].setState(futterModel.knochen());
testItems[3].setState(futterModel.banane()); testItems[3].setState(futterModel.banane());
testItems[4].setState(futterModel.apfel()); testItems[4].setState(futterModel.apfel());
testItems[5].setState(futterModel.karotte()); testItems[5].setState(futterModel.karotte());
testItems[6].setState(futterModel.honig()); testItems[6].setState(futterModel.honig());
testItems[7].setState(futterModel.zucker()); testItems[7].setState(futterModel.zucker());
} }
const auto& zirkusModel = model.zirkus(); const auto &zirkusModel = model.zirkus();
{ {
auto& testItems = m_tests.at(2).items(); auto &testItems = m_tests.at(2).items();
testItems[0].setState(zirkusModel.kiste()); testItems[0].setState(zirkusModel.kiste());
testItems[1].setState(zirkusModel.holz()); testItems[1].setState(zirkusModel.holz());
testItems[2].setState(zirkusModel.vorhang()); testItems[2].setState(zirkusModel.vorhang());
testItems[3].setState(zirkusModel.baum()); testItems[3].setState(zirkusModel.baum());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void GenusModel::write(ESGRAF48::GenusModel& model) const void GenusModel::write(ESGRAF48::GenusModel &model) const
{ {
auto* tiereModel = model.mutable_tiere(); auto *tiereModel = model.mutable_tiere();
if (tiereModel != nullptr) if (tiereModel != nullptr)
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
tiereModel->set_tiger(testItems[0].isChecked()); tiereModel->set_tiger(testItems[0].isChecked());
tiereModel->set_baer(testItems[1].isChecked()); tiereModel->set_baer(testItems[1].isChecked());
tiereModel->set_katze(testItems[2].isChecked()); tiereModel->set_katze(testItems[2].isChecked());
tiereModel->set_pferd(testItems[3].isChecked()); tiereModel->set_pferd(testItems[3].isChecked());
tiereModel->set_gans(testItems[4].isChecked()); tiereModel->set_gans(testItems[4].isChecked());
tiereModel->set_elefant(testItems[5].isChecked()); tiereModel->set_elefant(testItems[5].isChecked());
tiereModel->set_affe(testItems[6].isChecked()); tiereModel->set_affe(testItems[6].isChecked());
tiereModel->set_hund(testItems[7].isChecked()); tiereModel->set_hund(testItems[7].isChecked());
} }
auto* futterModel = model.mutable_futter(); auto *futterModel = model.mutable_futter();
if (futterModel != nullptr) if (futterModel != nullptr)
{ {
const auto& testItems = m_tests.at(1).items(); const auto &testItems = m_tests.at(1).items();
futterModel->set_salat(testItems[0].isChecked()); futterModel->set_salat(testItems[0].isChecked());
futterModel->set_fleisch(testItems[1].isChecked()); futterModel->set_fleisch(testItems[1].isChecked());
futterModel->set_knochen(testItems[2].isChecked()); futterModel->set_knochen(testItems[2].isChecked());
futterModel->set_banane(testItems[3].isChecked()); futterModel->set_banane(testItems[3].isChecked());
futterModel->set_apfel(testItems[4].isChecked()); futterModel->set_apfel(testItems[4].isChecked());
futterModel->set_karotte(testItems[5].isChecked()); futterModel->set_karotte(testItems[5].isChecked());
futterModel->set_honig(testItems[6].isChecked()); futterModel->set_honig(testItems[6].isChecked());
futterModel->set_zucker(testItems[7].isChecked()); futterModel->set_zucker(testItems[7].isChecked());
} }
auto* zirkusModel = model.mutable_zirkus(); auto *zirkusModel = model.mutable_zirkus();
if (zirkusModel != nullptr) if (zirkusModel != nullptr)
{ {
const auto& testItems = m_tests.at(2).items(); const auto &testItems = m_tests.at(2).items();
zirkusModel->set_kiste(testItems[0].isChecked()); zirkusModel->set_kiste(testItems[0].isChecked());
zirkusModel->set_holz(testItems[1].isChecked()); zirkusModel->set_holz(testItems[1].isChecked());
zirkusModel->set_vorhang(testItems[2].isChecked()); zirkusModel->set_vorhang(testItems[2].isChecked());
zirkusModel->set_baum(testItems[3].isChecked()); zirkusModel->set_baum(testItems[3].isChecked());
} }
} }

View File

@ -5,11 +5,11 @@
class GenusModel : public PrintableModel class GenusModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
GenusModel(QObject* parent); GenusModel(QObject *parent);
void read(const ESGRAF48::GenusModel& model); void read(const ESGRAF48::GenusModel &model);
void write(ESGRAF48::GenusModel& model) const; void write(ESGRAF48::GenusModel &model) const;
}; };

View File

@ -3,21 +3,21 @@
#include "GenusModel.h" #include "GenusModel.h"
GenusWidget::GenusWidget(QWidget* parent) GenusWidget::GenusWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::GenusWidget) , ui(new Ui::GenusWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->genusTableView->horizontalHeader()->hide(); ui->genusTableView->horizontalHeader()->hide();
} }
GenusWidget::~GenusWidget() GenusWidget::~GenusWidget()
{ {
delete ui; delete ui;
} }
void GenusWidget::setModel(GenusModel* model) void GenusWidget::setModel(GenusModel *model)
{ {
ui->genusTableView->setModel(model); ui->genusTableView->setModel(model);
} }

View File

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

View File

@ -1,114 +1,114 @@
#include "GenitivModel.h" #include "GenitivModel.h"
GenitivModel::GenitivModel(QObject* parent) GenitivModel::GenitivModel(QObject *parent)
: LateSkillsModel(parent) : LateSkillsModel(parent)
{ {
m_tests = { m_tests = {
{"Genitiv Präpositionen", {"Genitiv Präpositionen",
{"anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", "mithilfe (1)", {"anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", "mithilfe (1)",
"mithilfe (2)"}}, "mithilfe (2)"}},
{"Attributierung", {"Attributierung",
{"Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", "Hut (1)", "Hut (2)", {"Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", "Hut (1)", "Hut (2)",
"Brille (1)", "Brille (2)", "Gürtel (1)", "Gürtel (2)"}}, "Brille (1)", "Brille (2)", "Gürtel (1)", "Gürtel (2)"}},
}; };
for (auto index : {1, 3, 5}) for (auto index : {1, 3, 5})
{ {
m_tests[0].items()[index].setValue(2); m_tests[0].items()[index].setValue(2);
} }
for (auto index : {1, 3, 5, 7, 9}) for (auto index : {1, 3, 5, 7, 9})
{ {
m_tests[1].items()[index].setValue(2); m_tests[1].items()[index].setValue(2);
} }
} }
bool GenitivModel::setData(const QModelIndex& modelIndex, const QVariant& value, int role) bool GenitivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
{ {
if (role == Qt::CheckStateRole && value.toBool() == true) if (role == Qt::CheckStateRole && value.toBool() == true)
{ {
if (modelIndex.column() % 2 == 0) if (modelIndex.column() % 2 == 0)
{ {
CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false, CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false,
role); role);
} }
else else
{ {
CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false, CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false,
role); role);
} }
} }
return CheckableTestModel::setData(modelIndex, value, role); return CheckableTestModel::setData(modelIndex, value, role);
} }
void GenitivModel::read(const ESGRAF48::LateSkillsGenitivModel& model) void GenitivModel::read(const ESGRAF48::LateSkillsGenitivModel &model)
{ {
const auto& praepositionenModel = model.praepositionen(); const auto &praepositionenModel = model.praepositionen();
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(praepositionenModel.anstelle1()); testItems[0].setState(praepositionenModel.anstelle1());
testItems[1].setState(praepositionenModel.anstelle2()); testItems[1].setState(praepositionenModel.anstelle2());
testItems[2].setState(praepositionenModel.ausserhalb1()); testItems[2].setState(praepositionenModel.ausserhalb1());
testItems[3].setState(praepositionenModel.ausserhalb2()); testItems[3].setState(praepositionenModel.ausserhalb2());
testItems[4].setState(praepositionenModel.mithilfe1()); testItems[4].setState(praepositionenModel.mithilfe1());
testItems[5].setState(praepositionenModel.mithilfe2()); testItems[5].setState(praepositionenModel.mithilfe2());
} }
const auto& attributierungModel = model.attributierung(); const auto &attributierungModel = model.attributierung();
{ {
auto& testItems = m_tests.at(1).items(); auto &testItems = m_tests.at(1).items();
testItems[0].setState(attributierungModel.schuhe1()); testItems[0].setState(attributierungModel.schuhe1());
testItems[1].setState(attributierungModel.schuhe2()); testItems[1].setState(attributierungModel.schuhe2());
testItems[2].setState(attributierungModel.zauberstab1()); testItems[2].setState(attributierungModel.zauberstab1());
testItems[3].setState(attributierungModel.zauberstab2()); testItems[3].setState(attributierungModel.zauberstab2());
testItems[4].setState(attributierungModel.hut1()); testItems[4].setState(attributierungModel.hut1());
testItems[5].setState(attributierungModel.hut2()); testItems[5].setState(attributierungModel.hut2());
testItems[6].setState(attributierungModel.brille1()); testItems[6].setState(attributierungModel.brille1());
testItems[7].setState(attributierungModel.brille2()); testItems[7].setState(attributierungModel.brille2());
testItems[8].setState(attributierungModel.guertel1()); testItems[8].setState(attributierungModel.guertel1());
testItems[9].setState(attributierungModel.guertel2()); testItems[9].setState(attributierungModel.guertel2());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel& model) const void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const
{ {
auto* praepositionenModel = model.mutable_praepositionen(); auto *praepositionenModel = model.mutable_praepositionen();
if (praepositionenModel != nullptr) if (praepositionenModel != nullptr)
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
praepositionenModel->set_anstelle1(testItems[0].isChecked()); praepositionenModel->set_anstelle1(testItems[0].isChecked());
praepositionenModel->set_anstelle2(testItems[1].isChecked()); praepositionenModel->set_anstelle2(testItems[1].isChecked());
praepositionenModel->set_ausserhalb1(testItems[2].isChecked()); praepositionenModel->set_ausserhalb1(testItems[2].isChecked());
praepositionenModel->set_ausserhalb2(testItems[3].isChecked()); praepositionenModel->set_ausserhalb2(testItems[3].isChecked());
praepositionenModel->set_mithilfe1(testItems[4].isChecked()); praepositionenModel->set_mithilfe1(testItems[4].isChecked());
praepositionenModel->set_mithilfe2(testItems[5].isChecked()); praepositionenModel->set_mithilfe2(testItems[5].isChecked());
} }
auto* attributierungModel = model.mutable_attributierung(); auto *attributierungModel = model.mutable_attributierung();
if (attributierungModel != nullptr) if (attributierungModel != nullptr)
{ {
const auto& testItems = m_tests.at(1).items(); const auto &testItems = m_tests.at(1).items();
attributierungModel->set_schuhe1(testItems[0].isChecked()); attributierungModel->set_schuhe1(testItems[0].isChecked());
attributierungModel->set_schuhe2(testItems[1].isChecked()); attributierungModel->set_schuhe2(testItems[1].isChecked());
attributierungModel->set_zauberstab1(testItems[2].isChecked()); attributierungModel->set_zauberstab1(testItems[2].isChecked());
attributierungModel->set_zauberstab2(testItems[3].isChecked()); attributierungModel->set_zauberstab2(testItems[3].isChecked());
attributierungModel->set_hut1(testItems[4].isChecked()); attributierungModel->set_hut1(testItems[4].isChecked());
attributierungModel->set_hut2(testItems[5].isChecked()); attributierungModel->set_hut2(testItems[5].isChecked());
attributierungModel->set_brille1(testItems[6].isChecked()); attributierungModel->set_brille1(testItems[6].isChecked());
attributierungModel->set_brille2(testItems[7].isChecked()); attributierungModel->set_brille2(testItems[7].isChecked());
attributierungModel->set_guertel1(testItems[8].isChecked()); attributierungModel->set_guertel1(testItems[8].isChecked());
attributierungModel->set_guertel2(testItems[9].isChecked()); attributierungModel->set_guertel2(testItems[9].isChecked());
} }
} }
void GenitivModel::printHeader(QPainter& painter) const void GenitivModel::printHeader(QPainter &painter) const
{ {
painter.translate(0, -1.5 * painter.fontMetrics().lineSpacing()); painter.translate(0, -1.5 * painter.fontMetrics().lineSpacing());
} }

View File

@ -5,15 +5,16 @@
class GenitivModel : public LateSkillsModel class GenitivModel : public LateSkillsModel
{ {
Q_OBJECT Q_OBJECT
public: public:
GenitivModel(QObject* parent); GenitivModel(QObject *parent);
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
void read(const ESGRAF48::LateSkillsGenitivModel& model); void read(const ESGRAF48::LateSkillsGenitivModel &model);
void write(ESGRAF48::LateSkillsGenitivModel& model) const; void write(ESGRAF48::LateSkillsGenitivModel &model) const;
protected: protected:
void printHeader(QPainter& painter) const override; void printHeader(QPainter &painter) const override;
}; };

View File

@ -2,63 +2,63 @@
#include <regex> #include <regex>
LateSkillsModel::LateSkillsModel(QObject* parent) LateSkillsModel::LateSkillsModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
} }
void LateSkillsModel::printTests(QPainter& painter) const void LateSkillsModel::printTests(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
painter.setPen(tablePen()); painter.setPen(tablePen());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
double headerWidth = headerWidthFactor() * width; double headerWidth = headerWidthFactor() * width;
double cellHeaderWidth = cellWidthFactor() * width; double cellHeaderWidth = cellWidthFactor() * width;
double cellWidth = 0.5 * cellHeaderWidth; double cellWidth = 0.5 * cellHeaderWidth;
double rowHeight = height; double rowHeight = height;
double x = 0; double x = 0;
double y = 0; double y = 0;
for (const auto& test : m_tests) for (const auto &test : m_tests)
{ {
QString testName = QString::fromStdString( QString testName = QString::fromStdString(
std::regex_replace(test.name().toStdString(), std::regex("\\s"), "\n")); std::regex_replace(test.name().toStdString(), std::regex("\\s"), "\n"));
drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, testName); drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, testName);
const auto& items = test.items(); const auto &items = test.items();
x = headerWidth; x = headerWidth;
for (unsigned int i = 0; i < items.size(); i += 2) for (unsigned int i = 0; i < items.size(); i += 2)
{ {
const auto& item = test.items().at(i); const auto &item = test.items().at(i);
QString itemText = QString::fromStdString(item.getText()).split(" ").at(0); QString itemText = QString::fromStdString(item.getText()).split(" ").at(0);
drawTextSquare(painter, {x, y, cellHeaderWidth, rowHeight}, itemText); drawTextSquare(painter, {x, y, cellHeaderWidth, rowHeight}, itemText);
x += cellHeaderWidth; x += cellHeaderWidth;
} }
y += rowHeight; y += rowHeight;
x = headerWidth; x = headerWidth;
for (const auto& item : items) for (const auto &item : items)
{ {
drawTextSquare(painter, {x, y, cellWidth, rowHeight}, QString::number(item.value())); drawTextSquare(painter, {x, y, cellWidth, rowHeight}, QString::number(item.value()));
drawCheckSquare(painter, {x, y + rowHeight, cellWidth, rowHeight}, item.isChecked()); drawCheckSquare(painter, {x, y + rowHeight, cellWidth, rowHeight}, item.isChecked());
x += cellWidth; x += cellWidth;
} }
if (m_tests.size() > 1) if (m_tests.size() > 1)
{ {
drawResultSquare(painter, y + rowHeight, true, test.getPoints()); drawResultSquare(painter, y + rowHeight, true, test.getPoints());
} }
y += 2 * rowHeight; y += 2 * rowHeight;
} }
painter.translate(0, y + rowHeight); painter.translate(0, y + rowHeight);
} }

View File

@ -5,11 +5,11 @@
class LateSkillsModel : public PrintableModel class LateSkillsModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
LateSkillsModel(QObject* parent); LateSkillsModel(QObject *parent);
protected: protected:
void printTests(QPainter& painter) const override; void printTests(QPainter &painter) const override;
}; };

View File

@ -4,26 +4,26 @@
#include "PassivModel.h" #include "PassivModel.h"
#include "GenitivModel.h" #include "GenitivModel.h"
LateSkillsWidget::LateSkillsWidget(QWidget* parent) LateSkillsWidget::LateSkillsWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::LateSkillsWidget) , ui(new Ui::LateSkillsWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->passivTableView->horizontalHeader()->hide(); ui->passivTableView->horizontalHeader()->hide();
ui->genitivTableView->horizontalHeader()->hide(); ui->genitivTableView->horizontalHeader()->hide();
} }
LateSkillsWidget::~LateSkillsWidget() LateSkillsWidget::~LateSkillsWidget()
{ {
delete ui; delete ui;
} }
void LateSkillsWidget::setPassivModel(PassivModel* model) void LateSkillsWidget::setPassivModel(PassivModel *model)
{ {
ui->passivTableView->setModel(model); ui->passivTableView->setModel(model);
} }
void LateSkillsWidget::setGenitivModel(GenitivModel* model) void LateSkillsWidget::setGenitivModel(GenitivModel *model)
{ {
ui->genitivTableView->setModel(model); ui->genitivTableView->setModel(model);
} }

View File

@ -11,15 +11,15 @@ class LateSkillsWidget;
class LateSkillsWidget : public QWidget class LateSkillsWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::LateSkillsWidget* ui; Ui::LateSkillsWidget *ui;
public: public:
LateSkillsWidget(QWidget* parent = nullptr); LateSkillsWidget(QWidget *parent = nullptr);
~LateSkillsWidget(); ~LateSkillsWidget();
void setPassivModel(PassivModel* model); void setPassivModel(PassivModel *model);
void setGenitivModel(GenitivModel* model); void setGenitivModel(GenitivModel *model);
}; };

View File

@ -1,72 +1,72 @@
#include "PassivModel.h" #include "PassivModel.h"
PassivModel::PassivModel(QObject* parent) PassivModel::PassivModel(QObject *parent)
: LateSkillsModel(parent) : LateSkillsModel(parent)
{ {
m_tests = {{"Passiv", m_tests = {{"Passiv",
{"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)", {"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)",
"Ball (1)", "Ball (2)", "Fleisch (1)", "Fleisch (2)"}}}; "Ball (1)", "Ball (2)", "Fleisch (1)", "Fleisch (2)"}}};
for (auto index : {1, 3, 5, 7, 9}) for (auto index : {1, 3, 5, 7, 9})
{ {
m_tests[0].items()[index].setValue(2); m_tests[0].items()[index].setValue(2);
} }
} }
bool PassivModel::setData(const QModelIndex& modelIndex, const QVariant& value, int role) bool PassivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
{ {
if (role == Qt::CheckStateRole && value.toBool() == true) if (role == Qt::CheckStateRole && value.toBool() == true)
{ {
if (modelIndex.column() % 2 == 0) if (modelIndex.column() % 2 == 0)
{ {
CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false, CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false,
role); role);
} }
else else
{ {
CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false, CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false,
role); role);
} }
} }
return CheckableTestModel::setData(modelIndex, value, role); return CheckableTestModel::setData(modelIndex, value, role);
} }
void PassivModel::read(const ESGRAF48::LateSkillsPassivModel& model) void PassivModel::read(const ESGRAF48::LateSkillsPassivModel &model)
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(model.elefant1()); testItems[0].setState(model.elefant1());
testItems[1].setState(model.elefant2()); testItems[1].setState(model.elefant2());
testItems[2].setState(model.pferde1()); testItems[2].setState(model.pferde1());
testItems[3].setState(model.pferde2()); testItems[3].setState(model.pferde2());
testItems[4].setState(model.baelle1()); testItems[4].setState(model.baelle1());
testItems[5].setState(model.baelle2()); testItems[5].setState(model.baelle2());
testItems[6].setState(model.ball1()); testItems[6].setState(model.ball1());
testItems[7].setState(model.ball2()); testItems[7].setState(model.ball2());
testItems[8].setState(model.fleisch1()); testItems[8].setState(model.fleisch1());
testItems[9].setState(model.fleisch2()); testItems[9].setState(model.fleisch2());
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void PassivModel::write(ESGRAF48::LateSkillsPassivModel& model) const void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
model.set_elefant1(testItems[0].isChecked()); model.set_elefant1(testItems[0].isChecked());
model.set_elefant2(testItems[1].isChecked()); model.set_elefant2(testItems[1].isChecked());
model.set_pferde1(testItems[2].isChecked()); model.set_pferde1(testItems[2].isChecked());
model.set_pferde2(testItems[3].isChecked()); model.set_pferde2(testItems[3].isChecked());
model.set_baelle1(testItems[4].isChecked()); model.set_baelle1(testItems[4].isChecked());
model.set_baelle2(testItems[5].isChecked()); model.set_baelle2(testItems[5].isChecked());
model.set_ball1(testItems[6].isChecked()); model.set_ball1(testItems[6].isChecked());
model.set_ball2(testItems[7].isChecked()); model.set_ball2(testItems[7].isChecked());
model.set_fleisch1(testItems[8].isChecked()); model.set_fleisch1(testItems[8].isChecked());
model.set_fleisch2(testItems[9].isChecked()); model.set_fleisch2(testItems[9].isChecked());
} }
void PassivModel::printHeader(QPainter& painter) const void PassivModel::printHeader(QPainter &painter) const
{ {
drawHeader2(painter, "Subtest 6: Späte Fähigkeiten (7;0-8;11)"); drawHeader2(painter, "Subtest 6: Späte Fähigkeiten (7;0-8;11)");
} }

View File

@ -5,15 +5,15 @@
class PassivModel : public LateSkillsModel class PassivModel : public LateSkillsModel
{ {
Q_OBJECT Q_OBJECT
public: public:
PassivModel(QObject* parent); PassivModel(QObject *parent);
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void read(const ESGRAF48::LateSkillsPassivModel& model); void read(const ESGRAF48::LateSkillsPassivModel &model);
void write(ESGRAF48::LateSkillsPassivModel& model) const; void write(ESGRAF48::LateSkillsPassivModel &model) const;
protected: protected:
void printHeader(QPainter& painter) const override; void printHeader(QPainter &painter) const override;
}; };

View File

@ -4,80 +4,80 @@
#include <regex> #include <regex>
PluralModel::PluralModel(QObject* parent) PluralModel::PluralModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
m_title = "Subtest 5: Plural"; m_title = "Subtest 5: Plural";
m_tests = {{"Plural", m_tests = {{"Plural",
{"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/", {"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/",
"Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML"}}}; "Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML"}}};
} }
void PluralModel::read(const ESGRAF48::PluralModel& model) void PluralModel::read(const ESGRAF48::PluralModel &model)
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(model.fisch()); testItems[0].setState(model.fisch());
testItems[1].setState(model.banane()); testItems[1].setState(model.banane());
testItems[2].setState(model.bonbon()); testItems[2].setState(model.bonbon());
testItems[3].setState(model.ei()); testItems[3].setState(model.ei());
testItems[4].setState(model.eimer()); testItems[4].setState(model.eimer());
testItems[5].setState(model.korn()); testItems[5].setState(model.korn());
testItems[6].setState(model.nuss()); testItems[6].setState(model.nuss());
testItems[7].setState(model.baer()); testItems[7].setState(model.baer());
testItems[8].setState(model.apfel()); testItems[8].setState(model.apfel());
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void PluralModel::write(ESGRAF48::PluralModel& model) const void PluralModel::write(ESGRAF48::PluralModel &model) const
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
model.set_fisch(testItems[0].isChecked()); model.set_fisch(testItems[0].isChecked());
model.set_banane(testItems[1].isChecked()); model.set_banane(testItems[1].isChecked());
model.set_bonbon(testItems[2].isChecked()); model.set_bonbon(testItems[2].isChecked());
model.set_ei(testItems[3].isChecked()); model.set_ei(testItems[3].isChecked());
model.set_eimer(testItems[4].isChecked()); model.set_eimer(testItems[4].isChecked());
model.set_korn(testItems[5].isChecked()); model.set_korn(testItems[5].isChecked());
model.set_nuss(testItems[6].isChecked()); model.set_nuss(testItems[6].isChecked());
model.set_baer(testItems[7].isChecked()); model.set_baer(testItems[7].isChecked());
model.set_apfel(testItems[8].isChecked()); model.set_apfel(testItems[8].isChecked());
} }
void PluralModel::printTests(QPainter& painter) const void PluralModel::printTests(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
painter.setPen(tablePen()); painter.setPen(tablePen());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
double headerWidth = headerWidthFactor() * width; double headerWidth = headerWidthFactor() * width;
double cellWidth = cellWidthFactor() * width; double cellWidth = cellWidthFactor() * width;
double rowHeight = height; double rowHeight = height;
double x = 0; double x = 0;
double y = 0; double y = 0;
for (const auto& test : m_tests) for (const auto &test : m_tests)
{ {
drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, test.name()); drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, test.name());
x = headerWidth; x = headerWidth;
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
QString itemText = QString itemText =
QString::fromStdString(std::regex_replace(item.getText(), std::regex("\\s"), "\n")); QString::fromStdString(std::regex_replace(item.getText(), std::regex("\\s"), "\n"));
drawTextSquare(painter, {x, y, cellWidth, 2 * rowHeight}, itemText); drawTextSquare(painter, {x, y, cellWidth, 2 * rowHeight}, itemText);
drawCheckSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight}, drawCheckSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight},
item.isChecked()); item.isChecked());
x += cellWidth; x += cellWidth;
} }
y += 2 * rowHeight; y += 2 * rowHeight;
} }
painter.translate(0, y + 2 * rowHeight); painter.translate(0, y + 2 * rowHeight);
} }

View File

@ -5,14 +5,14 @@
class PluralModel : public PrintableModel class PluralModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
PluralModel(QObject* parent); PluralModel(QObject *parent);
void read(const ESGRAF48::PluralModel& model); void read(const ESGRAF48::PluralModel &model);
void write(ESGRAF48::PluralModel& model) const; void write(ESGRAF48::PluralModel &model) const;
protected: protected:
virtual void printTests(QPainter& painter) const; virtual void printTests(QPainter &painter) const;
}; };

View File

@ -3,21 +3,21 @@
#include "PluralModel.h" #include "PluralModel.h"
PluralWidget::PluralWidget(QWidget* parent) PluralWidget::PluralWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::PluralWidget) , ui(new Ui::PluralWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->pluralTableView->horizontalHeader()->hide(); ui->pluralTableView->horizontalHeader()->hide();
} }
PluralWidget::~PluralWidget() PluralWidget::~PluralWidget()
{ {
delete ui; delete ui;
} }
void PluralWidget::setModel(PluralModel* model) void PluralWidget::setModel(PluralModel *model)
{ {
ui->pluralTableView->setModel(model); ui->pluralTableView->setModel(model);
} }

View File

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

View File

@ -1,115 +1,115 @@
#include "OTModel.h" #include "OTModel.h"
OTModel::OTModel(QObject* parent) OTModel::OTModel(QObject *parent)
: V2SvkModel(parent) : V2SvkModel(parent)
{ {
m_tests = { m_tests = {
{"Objekt-Topikalisierung", {"Objekt-Topikalisierung",
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
"Gans", "Gans", "Gans"}}, "Gans", "Gans", "Gans"}},
{"SVK: Stamm", {"SVK: Stamm",
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
"Gans", "Gans", "Gans"}}, "Gans", "Gans", "Gans"}},
}; };
} }
unsigned int OTModel::getV2Points() const unsigned int OTModel::getV2Points() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {0}) for (auto testIndex : {0})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
unsigned int OTModel::getSvkPoints() const unsigned int OTModel::getSvkPoints() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {1}) for (auto testIndex : {1})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
void OTModel::write(ESGRAF48::V2SvkModel& model) const void OTModel::write(ESGRAF48::V2SvkModel &model) const
{ {
auto writeFourVals = [&](ESGRAF48::V2SvkModel::FourEach* modelData, int testIndex) { auto writeFourVals = [&](ESGRAF48::V2SvkModel::FourEach *modelData, int testIndex) {
if (modelData != nullptr) if (modelData != nullptr)
{ {
const auto& testItems = m_tests.at(testIndex).items(); const auto &testItems = m_tests.at(testIndex).items();
modelData->set_affe1(testItems[0].isChecked()); modelData->set_affe1(testItems[0].isChecked());
modelData->set_affe2(testItems[1].isChecked()); modelData->set_affe2(testItems[1].isChecked());
modelData->set_affe3(testItems[2].isChecked()); modelData->set_affe3(testItems[2].isChecked());
modelData->set_affe4(testItems[3].isChecked()); modelData->set_affe4(testItems[3].isChecked());
modelData->set_schwein1(testItems[4].isChecked()); modelData->set_schwein1(testItems[4].isChecked());
modelData->set_schwein2(testItems[5].isChecked()); modelData->set_schwein2(testItems[5].isChecked());
modelData->set_schwein3(testItems[6].isChecked()); modelData->set_schwein3(testItems[6].isChecked());
modelData->set_schwein4(testItems[7].isChecked()); modelData->set_schwein4(testItems[7].isChecked());
modelData->set_gans1(testItems[8].isChecked()); modelData->set_gans1(testItems[8].isChecked());
modelData->set_gans2(testItems[9].isChecked()); modelData->set_gans2(testItems[9].isChecked());
modelData->set_gans3(testItems[10].isChecked()); modelData->set_gans3(testItems[10].isChecked());
modelData->set_gans4(testItems[11].isChecked()); modelData->set_gans4(testItems[11].isChecked());
} }
}; };
writeFourVals(model.mutable_objtop(), 0); writeFourVals(model.mutable_objtop(), 0);
writeFourVals(model.mutable_svkstamm(), 1); writeFourVals(model.mutable_svkstamm(), 1);
} }
void OTModel::read(const ESGRAF48::V2SvkModel& model) void OTModel::read(const ESGRAF48::V2SvkModel &model)
{ {
auto readFourVals = [&](const ESGRAF48::V2SvkModel::FourEach& modelData, int testIndex) { auto readFourVals = [&](const ESGRAF48::V2SvkModel::FourEach &modelData, int testIndex) {
auto& testItems = m_tests.at(testIndex).items(); auto &testItems = m_tests.at(testIndex).items();
testItems[0].setState(modelData.affe1()); testItems[0].setState(modelData.affe1());
testItems[1].setState(modelData.affe2()); testItems[1].setState(modelData.affe2());
testItems[2].setState(modelData.affe3()); testItems[2].setState(modelData.affe3());
testItems[3].setState(modelData.affe4()); testItems[3].setState(modelData.affe4());
testItems[4].setState(modelData.schwein1()); testItems[4].setState(modelData.schwein1());
testItems[5].setState(modelData.schwein2()); testItems[5].setState(modelData.schwein2());
testItems[6].setState(modelData.schwein3()); testItems[6].setState(modelData.schwein3());
testItems[7].setState(modelData.schwein4()); testItems[7].setState(modelData.schwein4());
testItems[8].setState(modelData.gans1()); testItems[8].setState(modelData.gans1());
testItems[9].setState(modelData.gans2()); testItems[9].setState(modelData.gans2());
testItems[10].setState(modelData.gans3()); testItems[10].setState(modelData.gans3());
testItems[11].setState(modelData.gans4()); testItems[11].setState(modelData.gans4());
}; };
readFourVals(model.objtop(), 0); readFourVals(model.objtop(), 0);
readFourVals(model.svkstamm(), 1); readFourVals(model.svkstamm(), 1);
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
std::set<int> OTModel::v2Tests() const std::set<int> OTModel::v2Tests() const
{ {
return {0}; return {0};
}; };
std::set<int> OTModel::svkTests() const std::set<int> OTModel::svkTests() const
{ {
return {1}; return {1};
}; };

View File

@ -5,20 +5,20 @@
class OTModel : public V2SvkModel class OTModel : public V2SvkModel
{ {
Q_OBJECT Q_OBJECT
public: public:
OTModel(QObject* parent); OTModel(QObject *parent);
unsigned int getV2Points() const override; unsigned int getV2Points() const override;
unsigned int getSvkPoints() const override; unsigned int getSvkPoints() const override;
void write(ESGRAF48::V2SvkModel& model) const override; void write(ESGRAF48::V2SvkModel &model) const override;
void read(const ESGRAF48::V2SvkModel& model) override; void read(const ESGRAF48::V2SvkModel &model) override;
protected: protected:
void printHeader(QPainter&) const override{}; void printHeader(QPainter &) const override {};
std::set<int> v2Tests() const override; std::set<int> v2Tests() const override;
std::set<int> svkTests() const override; std::set<int> svkTests() const override;
}; };

View File

@ -1,105 +1,105 @@
#include "TPeModel.h" #include "TPeModel.h"
TPeModel::TPeModel(QObject* parent) TPeModel::TPeModel(QObject *parent)
: V2SvkModel(parent) : V2SvkModel(parent)
{ {
m_tests = { m_tests = {
{"Temporaladverb Perfekt", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"Temporaladverb Perfekt", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}},
{"Verbtrennung", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"Verbtrennung", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}},
{"SVK: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"SVK: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}},
{"Partizip", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"Partizip", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}},
}; };
} }
unsigned int TPeModel::getV2Points() const unsigned int TPeModel::getV2Points() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {0, 1}) for (auto testIndex : {0, 1})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
unsigned int TPeModel::getSvkPoints() const unsigned int TPeModel::getSvkPoints() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {2, 3}) for (auto testIndex : {2, 3})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
void TPeModel::write(ESGRAF48::V2SvkModel& model) const void TPeModel::write(ESGRAF48::V2SvkModel &model) const
{ {
auto writeTwoVals = [&](ESGRAF48::V2SvkModel::TwoEach* modelData, int testIndex) { auto writeTwoVals = [&](ESGRAF48::V2SvkModel::TwoEach *modelData, int testIndex) {
if (modelData != nullptr) if (modelData != nullptr)
{ {
const auto& testItems = m_tests.at(testIndex).items(); const auto &testItems = m_tests.at(testIndex).items();
modelData->set_affe1(testItems[0].isChecked()); modelData->set_affe1(testItems[0].isChecked());
modelData->set_affe2(testItems[1].isChecked()); modelData->set_affe2(testItems[1].isChecked());
modelData->set_schwein1(testItems[2].isChecked()); modelData->set_schwein1(testItems[2].isChecked());
modelData->set_schwein2(testItems[3].isChecked()); modelData->set_schwein2(testItems[3].isChecked());
modelData->set_gans1(testItems[4].isChecked()); modelData->set_gans1(testItems[4].isChecked());
modelData->set_gans2(testItems[5].isChecked()); modelData->set_gans2(testItems[5].isChecked());
} }
}; };
writeTwoVals(model.mutable_tempperf(), 0); writeTwoVals(model.mutable_tempperf(), 0);
writeTwoVals(model.mutable_verbtrennung2(), 1); writeTwoVals(model.mutable_verbtrennung2(), 1);
writeTwoVals(model.mutable_svke2(), 2); writeTwoVals(model.mutable_svke2(), 2);
writeTwoVals(model.mutable_partizip(), 3); writeTwoVals(model.mutable_partizip(), 3);
} }
void TPeModel::read(const ESGRAF48::V2SvkModel& model) void TPeModel::read(const ESGRAF48::V2SvkModel &model)
{ {
auto readTwoVals = [&](const ESGRAF48::V2SvkModel::TwoEach& modelData, int testIndex) { auto readTwoVals = [&](const ESGRAF48::V2SvkModel::TwoEach &modelData, int testIndex) {
auto& testItems = m_tests.at(testIndex).items(); auto &testItems = m_tests.at(testIndex).items();
testItems[0].setState(modelData.affe1()); testItems[0].setState(modelData.affe1());
testItems[1].setState(modelData.affe2()); testItems[1].setState(modelData.affe2());
testItems[2].setState(modelData.schwein1()); testItems[2].setState(modelData.schwein1());
testItems[3].setState(modelData.schwein2()); testItems[3].setState(modelData.schwein2());
testItems[4].setState(modelData.gans1()); testItems[4].setState(modelData.gans1());
testItems[5].setState(modelData.gans2()); testItems[5].setState(modelData.gans2());
}; };
readTwoVals(model.tempperf(), 0); readTwoVals(model.tempperf(), 0);
readTwoVals(model.verbtrennung2(), 1); readTwoVals(model.verbtrennung2(), 1);
readTwoVals(model.svke2(), 2); readTwoVals(model.svke2(), 2);
readTwoVals(model.partizip(), 3); readTwoVals(model.partizip(), 3);
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
std::set<int> TPeModel::v2Tests() const std::set<int> TPeModel::v2Tests() const
{ {
return {0, 1}; return {0, 1};
}; };
std::set<int> TPeModel::svkTests() const std::set<int> TPeModel::svkTests() const
{ {
return {2, 3}; return {2, 3};
}; };

View File

@ -5,20 +5,20 @@
class TPeModel : public V2SvkModel class TPeModel : public V2SvkModel
{ {
Q_OBJECT Q_OBJECT
public: public:
TPeModel(QObject* parent); TPeModel(QObject *parent);
unsigned int getV2Points() const override; unsigned int getV2Points() const override;
unsigned int getSvkPoints() const override; unsigned int getSvkPoints() const override;
void write(ESGRAF48::V2SvkModel& model) const override; void write(ESGRAF48::V2SvkModel &model) const override;
void read(const ESGRAF48::V2SvkModel& model) override; void read(const ESGRAF48::V2SvkModel &model) override;
protected: protected:
void printHeader(QPainter&) const override{}; void printHeader(QPainter &) const override {};
std::set<int> v2Tests() const override; std::set<int> v2Tests() const override;
std::set<int> svkTests() const override; std::set<int> svkTests() const override;
}; };

View File

@ -1,99 +1,99 @@
#include "TPrModel.h" #include "TPrModel.h"
TPrModel::TPrModel(QObject* parent) TPrModel::TPrModel(QObject *parent)
: V2SvkModel(parent) : V2SvkModel(parent)
{ {
m_tests = { m_tests = {
{"Temporaladverb Präsens", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"Temporaladverb Präsens", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}},
{"SKV: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"SKV: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}},
}; };
} }
unsigned int TPrModel::getV2Points() const unsigned int TPrModel::getV2Points() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {0}) for (auto testIndex : {0})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
unsigned int TPrModel::getSvkPoints() const unsigned int TPrModel::getSvkPoints() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {1}) for (auto testIndex : {1})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
void TPrModel::write(ESGRAF48::V2SvkModel& model) const void TPrModel::write(ESGRAF48::V2SvkModel &model) const
{ {
auto writeTwoVals = [&](ESGRAF48::V2SvkModel::TwoEach* modelData, int testIndex) { auto writeTwoVals = [&](ESGRAF48::V2SvkModel::TwoEach *modelData, int testIndex) {
if (modelData != nullptr) if (modelData != nullptr)
{ {
const auto& testItems = m_tests.at(testIndex).items(); const auto &testItems = m_tests.at(testIndex).items();
modelData->set_affe1(testItems[0].isChecked()); modelData->set_affe1(testItems[0].isChecked());
modelData->set_affe2(testItems[1].isChecked()); modelData->set_affe2(testItems[1].isChecked());
modelData->set_schwein1(testItems[2].isChecked()); modelData->set_schwein1(testItems[2].isChecked());
modelData->set_schwein2(testItems[3].isChecked()); modelData->set_schwein2(testItems[3].isChecked());
modelData->set_gans1(testItems[4].isChecked()); modelData->set_gans1(testItems[4].isChecked());
modelData->set_gans2(testItems[5].isChecked()); modelData->set_gans2(testItems[5].isChecked());
} }
}; };
writeTwoVals(model.mutable_temppraes(), 0); writeTwoVals(model.mutable_temppraes(), 0);
writeTwoVals(model.mutable_svke1(), 1); writeTwoVals(model.mutable_svke1(), 1);
} }
void TPrModel::read(const ESGRAF48::V2SvkModel& model) void TPrModel::read(const ESGRAF48::V2SvkModel &model)
{ {
auto readTwoVals = [&](const ESGRAF48::V2SvkModel::TwoEach& modelData, int testIndex) { auto readTwoVals = [&](const ESGRAF48::V2SvkModel::TwoEach &modelData, int testIndex) {
auto& testItems = m_tests.at(testIndex).items(); auto &testItems = m_tests.at(testIndex).items();
testItems[0].setState(modelData.affe1()); testItems[0].setState(modelData.affe1());
testItems[1].setState(modelData.affe2()); testItems[1].setState(modelData.affe2());
testItems[2].setState(modelData.schwein1()); testItems[2].setState(modelData.schwein1());
testItems[3].setState(modelData.schwein2()); testItems[3].setState(modelData.schwein2());
testItems[4].setState(modelData.gans1()); testItems[4].setState(modelData.gans1());
testItems[5].setState(modelData.gans2()); testItems[5].setState(modelData.gans2());
}; };
readTwoVals(model.temppraes(), 0); readTwoVals(model.temppraes(), 0);
readTwoVals(model.svke1(), 1); readTwoVals(model.svke1(), 1);
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
std::set<int> TPrModel::v2Tests() const std::set<int> TPrModel::v2Tests() const
{ {
return {0}; return {0};
}; };
std::set<int> TPrModel::svkTests() const std::set<int> TPrModel::svkTests() const
{ {
return {1}; return {1};
}; };

View File

@ -5,20 +5,20 @@
class TPrModel : public V2SvkModel class TPrModel : public V2SvkModel
{ {
Q_OBJECT Q_OBJECT
public: public:
TPrModel(QObject* parent); TPrModel(QObject *parent);
unsigned int getV2Points() const override; unsigned int getV2Points() const override;
unsigned int getSvkPoints() const override; unsigned int getSvkPoints() const override;
void write(ESGRAF48::V2SvkModel& model) const override; void write(ESGRAF48::V2SvkModel &model) const override;
void read(const ESGRAF48::V2SvkModel& model) override; void read(const ESGRAF48::V2SvkModel &model) override;
protected: protected:
void printHeader(QPainter&) const override{}; void printHeader(QPainter &) const override{};
std::set<int> v2Tests() const override; std::set<int> v2Tests() const override;
std::set<int> svkTests() const override; std::set<int> svkTests() const override;
}; };

View File

@ -2,137 +2,136 @@
#include <regex> #include <regex>
V2SvkModel::V2SvkModel(QObject* parent) V2SvkModel::V2SvkModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
} }
void V2SvkModel::printTests(QPainter& painter) const void V2SvkModel::printTests(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
painter.setPen(tablePen()); painter.setPen(tablePen());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
auto v2TestIndices = v2Tests(); auto v2TestIndices = v2Tests();
auto svkTestIndices = svkTests(); auto svkTestIndices = svkTests();
double x = 0; double x = 0;
double y = 0; double y = 0;
auto testIndex = 0; auto testIndex = 0;
for (const auto& test : m_tests) for (const auto &test : m_tests)
{ {
double rowHeaderWidth = headerWidthFactor() * width; double rowHeaderWidth = headerWidthFactor() * width;
double resultCellWidth = (test.size() > 8 ? 0.5 : 1) * cellWidthFactor() * width; double resultCellWidth = (test.size() > 8 ? 0.5 : 1) * cellWidthFactor() * width;
double rowHeight = height; double rowHeight = height;
QString testName = test.name(); QString testName = test.name();
if (testName.length() > 20) if (testName.length() > 20)
{ {
testName = QString::fromStdString( testName = QString::fromStdString(
std::regex_replace(testName.toStdString(), std::regex("[\\s-]"), "\n")); std::regex_replace(testName.toStdString(), std::regex("[\\s-]"), "\n"));
} }
if (testIndex == 0) if (testIndex == 0)
{ {
drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, testName); drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, testName);
x += rowHeaderWidth; x += rowHeaderWidth;
std::vector<std::pair<std::string, unsigned int>> columnHeaders; std::vector<std::pair<std::string, unsigned int>> columnHeaders;
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
const auto& itemText = item.getText(); const auto &itemText = item.getText();
if (!columnHeaders.empty() && columnHeaders.back().first == itemText) if (!columnHeaders.empty() && columnHeaders.back().first == itemText)
{ {
columnHeaders.back().second++; columnHeaders.back().second++;
} }
else else
{ {
columnHeaders.emplace_back(itemText, 1); columnHeaders.emplace_back(itemText, 1);
} }
} }
for (const auto& columnHeader : columnHeaders) for (const auto &columnHeader : columnHeaders)
{ {
double cellWidth = columnHeader.second * resultCellWidth; double cellWidth = columnHeader.second * resultCellWidth;
drawTextSquare(painter, {x, y, cellWidth, rowHeight}, columnHeader.first.c_str()); drawTextSquare(painter, {x, y, cellWidth, rowHeight}, columnHeader.first.c_str());
x += cellWidth; x += cellWidth;
} }
x = rowHeaderWidth; x = rowHeaderWidth;
y += rowHeight; y += rowHeight;
} }
else else
{ {
drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, testName); drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, testName);
x += rowHeaderWidth; x += rowHeaderWidth;
} }
unsigned int emptyItemsStack = 0; unsigned int emptyItemsStack = 0;
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.getText().empty()) if (item.getText().empty())
{ {
emptyItemsStack++; emptyItemsStack++;
} }
else else
{ {
if (emptyItemsStack > 0) if (emptyItemsStack > 0)
{ {
drawGreySquare(painter, drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y,
{x - emptyItemsStack * resultCellWidth, y, emptyItemsStack * resultCellWidth, rowHeight});
emptyItemsStack * resultCellWidth, rowHeight}); emptyItemsStack = 0;
emptyItemsStack = 0; }
}
drawCheckSquare(painter, {x, y, resultCellWidth, rowHeight}, item.isChecked()); drawCheckSquare(painter, {x, y, resultCellWidth, rowHeight}, item.isChecked());
} }
x += resultCellWidth; x += resultCellWidth;
} }
if (emptyItemsStack > 0) if (emptyItemsStack > 0)
{ {
drawGreySquare(painter, drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y,
{x - emptyItemsStack * resultCellWidth, y, emptyItemsStack * resultCellWidth, rowHeight});
emptyItemsStack * resultCellWidth, rowHeight}); emptyItemsStack = 0;
emptyItemsStack = 0; }
}
if (v2TestIndices.find(testIndex) != v2TestIndices.end()) if (v2TestIndices.find(testIndex) != v2TestIndices.end())
{ {
drawResultSquare(painter, y, false, test.getPoints()); drawResultSquare(painter, y, false, test.getPoints());
} }
if (svkTestIndices.find(testIndex) != svkTestIndices.end()) if (svkTestIndices.find(testIndex) != svkTestIndices.end())
{ {
drawResultSquare(painter, y, true, test.getPoints()); drawResultSquare(painter, y, true, test.getPoints());
} }
x = 0; x = 0;
y += rowHeight; y += rowHeight;
testIndex++; testIndex++;
} }
x = 0; x = 0;
y += height; y += height;
painter.translate(0, y); painter.translate(0, y);
} }
void V2SvkModel::printSummary(QPainter& painter, unsigned int v2Points, unsigned int svkPoints) void V2SvkModel::printSummary(QPainter &painter, unsigned int v2Points, unsigned int svkPoints)
{ {
painter.setFont(PrintableModel::tableFont()); painter.setFont(PrintableModel::tableFont());
painter.setPen(PrintableModel::tablePen()); painter.setPen(PrintableModel::tablePen());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
painter.drawText(0, 0, 0.91 * width, height, Qt::AlignRight | Qt::AlignVCenter, painter.drawText(0, 0, 0.91 * width, height, Qt::AlignRight | Qt::AlignVCenter,
"Rohwertpunkte Total:"); "Rohwertpunkte Total:");
painter.setPen(resultPen()); painter.setPen(resultPen());
drawNumberSquare(painter, 0.93 * width, 0, v2Points); drawNumberSquare(painter, 0.93 * width, 0, v2Points);
drawNumberSquare(painter, 0.97 * width, 0, svkPoints); drawNumberSquare(painter, 0.97 * width, 0, svkPoints);
painter.translate(0, 3 * height); painter.translate(0, 3 * height);
} }

View File

@ -5,23 +5,23 @@
class V2SvkModel : public PrintableModel class V2SvkModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
V2SvkModel(QObject* parent); V2SvkModel(QObject *parent);
virtual unsigned int getV2Points() const = 0; virtual unsigned int getV2Points() const = 0;
virtual unsigned int getSvkPoints() const = 0; virtual unsigned int getSvkPoints() const = 0;
virtual void write(ESGRAF48::V2SvkModel& model) const = 0; virtual void write(ESGRAF48::V2SvkModel &model) const = 0;
virtual void read(const ESGRAF48::V2SvkModel& model) = 0; virtual void read(const ESGRAF48::V2SvkModel &model) = 0;
static void printSummary(QPainter& painter, unsigned int v2Points, unsigned int svkPoints); static void printSummary(QPainter &painter, unsigned int v2Points, unsigned int svkPoints);
protected: protected:
void printTests(QPainter& painter) const override; void printTests(QPainter &painter) const override;
void printSummary(QPainter& painter) const override{}; void printSummary(QPainter &painter) const override {};
virtual std::set<int> v2Tests() const = 0; virtual std::set<int> v2Tests() const = 0;
virtual std::set<int> svkTests() const = 0; virtual std::set<int> svkTests() const = 0;
}; };

View File

@ -6,38 +6,38 @@
#include "TPrModel.h" #include "TPrModel.h"
#include "TPeModel.h" #include "TPeModel.h"
V2SvkWidget::V2SvkWidget(QWidget* parent) V2SvkWidget::V2SvkWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::V2SvkWidget) , ui(new Ui::V2SvkWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->wfTableView->horizontalHeader()->hide(); ui->wfTableView->horizontalHeader()->hide();
ui->otTableView->horizontalHeader()->hide(); ui->otTableView->horizontalHeader()->hide();
ui->tprTableView->horizontalHeader()->hide(); ui->tprTableView->horizontalHeader()->hide();
ui->tpeTableView->horizontalHeader()->hide(); ui->tpeTableView->horizontalHeader()->hide();
} }
V2SvkWidget::~V2SvkWidget() V2SvkWidget::~V2SvkWidget()
{ {
delete ui; delete ui;
} }
void V2SvkWidget::setWFModel(WFModel* model) void V2SvkWidget::setWFModel(WFModel *model)
{ {
ui->wfTableView->setModel(model); ui->wfTableView->setModel(model);
} }
void V2SvkWidget::setOTModel(OTModel* model) void V2SvkWidget::setOTModel(OTModel *model)
{ {
ui->otTableView->setModel(model); ui->otTableView->setModel(model);
} }
void V2SvkWidget::setTPrModel(TPrModel* model) void V2SvkWidget::setTPrModel(TPrModel *model)
{ {
ui->tprTableView->setModel(model); ui->tprTableView->setModel(model);
} }
void V2SvkWidget::setTPeModel(TPeModel* model) void V2SvkWidget::setTPeModel(TPeModel *model)
{ {
ui->tpeTableView->setModel(model); ui->tpeTableView->setModel(model);
} }

View File

@ -13,17 +13,17 @@ class V2SvkWidget;
class V2SvkWidget : public QWidget class V2SvkWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::V2SvkWidget* ui; Ui::V2SvkWidget *ui;
public: public:
V2SvkWidget(QWidget* parent = nullptr); V2SvkWidget(QWidget *parent = nullptr);
~V2SvkWidget(); ~V2SvkWidget();
void setWFModel(WFModel* model); void setWFModel(WFModel *model);
void setOTModel(OTModel* model); void setOTModel(OTModel *model);
void setTPrModel(TPrModel* model); void setTPrModel(TPrModel *model);
void setTPeModel(TPeModel* model); void setTPeModel(TPeModel *model);
}; };

View File

@ -1,147 +1,147 @@
#include "WFModel.h" #include "WFModel.h"
WFModel::WFModel(QObject* parent) WFModel::WFModel(QObject *parent)
: V2SvkModel(parent) : V2SvkModel(parent)
{ {
m_title = "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"; m_title = "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)";
m_tests = { m_tests = {
{"W-Frage", {"W-Frage",
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
"Gans", "Gans", "Gans"}}, "Gans", "Gans", "Gans"}},
{"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}}, {"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}},
{"SVK: /-st/", {"SVK: /-st/",
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
"Gans", "Gans", "Gans"}}, "Gans", "Gans", "Gans"}},
}; };
} }
unsigned int WFModel::getV2Points() const unsigned int WFModel::getV2Points() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {0, 1}) for (auto testIndex : {0, 1})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
unsigned int WFModel::getSvkPoints() const unsigned int WFModel::getSvkPoints() const
{ {
unsigned int points = 0; unsigned int points = 0;
for (auto testIndex : {2}) for (auto testIndex : {2})
{ {
const auto& test = m_tests.at(testIndex); const auto &test = m_tests.at(testIndex);
for (const auto& item : test.items()) for (const auto &item : test.items())
{ {
if (item.isChecked()) if (item.isChecked())
{ {
points++; points++;
} }
} }
} }
return points; return points;
} }
bool WFModel::isValidIndex(const QModelIndex& index) const bool WFModel::isValidIndex(const QModelIndex &index) const
{ {
if (index.row() == 1) if (index.row() == 1)
{ {
return index.column() == 1 || index.column() == 7 || index.column() == 10; return index.column() == 1 || index.column() == 7 || index.column() == 10;
} }
return CheckableTestModel::isValidIndex(index); return CheckableTestModel::isValidIndex(index);
} }
void WFModel::write(ESGRAF48::V2SvkModel& model) const void WFModel::write(ESGRAF48::V2SvkModel &model) const
{ {
auto writeOneVal = [&](ESGRAF48::V2SvkModel::OneEach* modelData, int testIndex) { auto writeOneVal = [&](ESGRAF48::V2SvkModel::OneEach *modelData, int testIndex) {
if (modelData != nullptr) if (modelData != nullptr)
{ {
const auto& testItems = m_tests.at(testIndex).items(); const auto &testItems = m_tests.at(testIndex).items();
modelData->set_affe(testItems[1].isChecked()); modelData->set_affe(testItems[1].isChecked());
modelData->set_schwein(testItems[7].isChecked()); modelData->set_schwein(testItems[7].isChecked());
modelData->set_gans(testItems[10].isChecked()); modelData->set_gans(testItems[10].isChecked());
} }
}; };
auto writeFourVals = [&](ESGRAF48::V2SvkModel::FourEach* modelData, int testIndex) { auto writeFourVals = [&](ESGRAF48::V2SvkModel::FourEach *modelData, int testIndex) {
if (modelData != nullptr) if (modelData != nullptr)
{ {
const auto& testItems = m_tests.at(testIndex).items(); const auto &testItems = m_tests.at(testIndex).items();
modelData->set_affe1(testItems[0].isChecked()); modelData->set_affe1(testItems[0].isChecked());
modelData->set_affe2(testItems[1].isChecked()); modelData->set_affe2(testItems[1].isChecked());
modelData->set_affe3(testItems[2].isChecked()); modelData->set_affe3(testItems[2].isChecked());
modelData->set_affe4(testItems[3].isChecked()); modelData->set_affe4(testItems[3].isChecked());
modelData->set_schwein1(testItems[4].isChecked()); modelData->set_schwein1(testItems[4].isChecked());
modelData->set_schwein2(testItems[5].isChecked()); modelData->set_schwein2(testItems[5].isChecked());
modelData->set_schwein3(testItems[6].isChecked()); modelData->set_schwein3(testItems[6].isChecked());
modelData->set_schwein4(testItems[7].isChecked()); modelData->set_schwein4(testItems[7].isChecked());
modelData->set_gans1(testItems[8].isChecked()); modelData->set_gans1(testItems[8].isChecked());
modelData->set_gans2(testItems[9].isChecked()); modelData->set_gans2(testItems[9].isChecked());
modelData->set_gans3(testItems[10].isChecked()); modelData->set_gans3(testItems[10].isChecked());
modelData->set_gans4(testItems[11].isChecked()); modelData->set_gans4(testItems[11].isChecked());
} }
}; };
writeFourVals(model.mutable_wfrage(), 0); writeFourVals(model.mutable_wfrage(), 0);
writeOneVal(model.mutable_verbtrennung1(), 1); writeOneVal(model.mutable_verbtrennung1(), 1);
} }
void WFModel::read(const ESGRAF48::V2SvkModel& model) void WFModel::read(const ESGRAF48::V2SvkModel &model)
{ {
auto readOneVal = [&](const ESGRAF48::V2SvkModel::OneEach& modelData, int testIndex) { auto readOneVal = [&](const ESGRAF48::V2SvkModel::OneEach &modelData, int testIndex) {
auto& testItems = m_tests.at(testIndex).items(); auto &testItems = m_tests.at(testIndex).items();
testItems[1].setState(modelData.affe()); testItems[1].setState(modelData.affe());
testItems[7].setState(modelData.schwein()); testItems[7].setState(modelData.schwein());
testItems[10].setState(modelData.gans()); testItems[10].setState(modelData.gans());
}; };
auto readFourVals = [&](const ESGRAF48::V2SvkModel::FourEach& modelData, int testIndex) { auto readFourVals = [&](const ESGRAF48::V2SvkModel::FourEach &modelData, int testIndex) {
auto& testItems = m_tests.at(testIndex).items(); auto &testItems = m_tests.at(testIndex).items();
testItems[0].setState(modelData.affe1()); testItems[0].setState(modelData.affe1());
testItems[1].setState(modelData.affe2()); testItems[1].setState(modelData.affe2());
testItems[2].setState(modelData.affe3()); testItems[2].setState(modelData.affe3());
testItems[3].setState(modelData.affe4()); testItems[3].setState(modelData.affe4());
testItems[4].setState(modelData.schwein1()); testItems[4].setState(modelData.schwein1());
testItems[5].setState(modelData.schwein2()); testItems[5].setState(modelData.schwein2());
testItems[6].setState(modelData.schwein3()); testItems[6].setState(modelData.schwein3());
testItems[7].setState(modelData.schwein4()); testItems[7].setState(modelData.schwein4());
testItems[8].setState(modelData.gans1()); testItems[8].setState(modelData.gans1());
testItems[9].setState(modelData.gans2()); testItems[9].setState(modelData.gans2());
testItems[10].setState(modelData.gans3()); testItems[10].setState(modelData.gans3());
testItems[11].setState(modelData.gans4()); testItems[11].setState(modelData.gans4());
}; };
readFourVals(model.wfrage(), 0); readFourVals(model.wfrage(), 0);
readOneVal(model.verbtrennung1(), 1); readOneVal(model.verbtrennung1(), 1);
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
std::set<int> WFModel::v2Tests() const std::set<int> WFModel::v2Tests() const
{ {
return {0, 1}; return {0, 1};
}; };
std::set<int> WFModel::svkTests() const std::set<int> WFModel::svkTests() const
{ {
return {2}; return {2};
}; };

View File

@ -5,20 +5,20 @@
class WFModel : public V2SvkModel class WFModel : public V2SvkModel
{ {
Q_OBJECT Q_OBJECT
public: public:
WFModel(QObject* parent); WFModel(QObject *parent);
unsigned int getV2Points() const override; unsigned int getV2Points() const override;
unsigned int getSvkPoints() const override; unsigned int getSvkPoints() const override;
void write(ESGRAF48::V2SvkModel& model) const override; void write(ESGRAF48::V2SvkModel &model) const override;
void read(const ESGRAF48::V2SvkModel& model) override; void read(const ESGRAF48::V2SvkModel &model) override;
protected: protected:
std::set<int> v2Tests() const override; std::set<int> v2Tests() const override;
std::set<int> svkTests() const override; std::set<int> svkTests() const override;
bool isValidIndex(const QModelIndex& index) const override; bool isValidIndex(const QModelIndex &index) const override;
}; };

View File

@ -1,128 +1,128 @@
#include "VerbEndModel.h" #include "VerbEndModel.h"
VerbEndModel::VerbEndModel(QObject* parent) VerbEndModel::VerbEndModel(QObject *parent)
: PrintableModel(parent) : PrintableModel(parent)
{ {
m_title = "Subtest 2: Verbendstellungsregel (VE)"; m_title = "Subtest 2: Verbendstellungsregel (VE)";
m_tests = { m_tests = {
{"Telefonat", {"Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal"}}, {"Telefonat", {"Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal"}},
{"Zaubertrick", {"Relativ", "Final", "Kausal", "Final", "Temporal", "Kausal", "Temporal"}}, {"Zaubertrick", {"Relativ", "Final", "Kausal", "Final", "Temporal", "Kausal", "Temporal"}},
{"Zauberregel", {"Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ"}}}; {"Zauberregel", {"Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ"}}};
} }
void VerbEndModel::write(ESGRAF48::VerbEndModel& model) const void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const
{ {
auto* telefonatModel = model.mutable_telefonat(); auto *telefonatModel = model.mutable_telefonat();
if (telefonatModel != nullptr) if (telefonatModel != nullptr)
{ {
const auto& testItems = m_tests.at(0).items(); const auto &testItems = m_tests.at(0).items();
telefonatModel->set_kausal1(testItems[0].isChecked()); telefonatModel->set_kausal1(testItems[0].isChecked());
telefonatModel->set_kausal2(testItems[1].isChecked()); telefonatModel->set_kausal2(testItems[1].isChecked());
telefonatModel->set_relativ(testItems[2].isChecked()); telefonatModel->set_relativ(testItems[2].isChecked());
telefonatModel->set_kausal3(testItems[3].isChecked()); telefonatModel->set_kausal3(testItems[3].isChecked());
telefonatModel->set_final(testItems[4].isChecked()); telefonatModel->set_final(testItems[4].isChecked());
telefonatModel->set_temporal1(testItems[5].isChecked()); telefonatModel->set_temporal1(testItems[5].isChecked());
telefonatModel->set_temporal2(testItems[6].isChecked()); telefonatModel->set_temporal2(testItems[6].isChecked());
} }
auto* zaubertrickModel = model.mutable_zaubertrick(); auto *zaubertrickModel = model.mutable_zaubertrick();
if (zaubertrickModel != nullptr) if (zaubertrickModel != nullptr)
{ {
const auto& testItems = m_tests.at(1).items(); const auto &testItems = m_tests.at(1).items();
zaubertrickModel->set_relativ(testItems[0].isChecked()); zaubertrickModel->set_relativ(testItems[0].isChecked());
zaubertrickModel->set_final1(testItems[1].isChecked()); zaubertrickModel->set_final1(testItems[1].isChecked());
zaubertrickModel->set_kausal1(testItems[2].isChecked()); zaubertrickModel->set_kausal1(testItems[2].isChecked());
zaubertrickModel->set_final2(testItems[3].isChecked()); zaubertrickModel->set_final2(testItems[3].isChecked());
zaubertrickModel->set_temporal1(testItems[4].isChecked()); zaubertrickModel->set_temporal1(testItems[4].isChecked());
zaubertrickModel->set_kausal2(testItems[5].isChecked()); zaubertrickModel->set_kausal2(testItems[5].isChecked());
zaubertrickModel->set_temporal2(testItems[6].isChecked()); zaubertrickModel->set_temporal2(testItems[6].isChecked());
} }
auto* zauberregelModel = model.mutable_zauberregel(); auto *zauberregelModel = model.mutable_zauberregel();
if (zauberregelModel != nullptr) if (zauberregelModel != nullptr)
{ {
const auto& testItems = m_tests.at(2).items(); const auto &testItems = m_tests.at(2).items();
zauberregelModel->set_temporal1(testItems[0].isChecked()); zauberregelModel->set_temporal1(testItems[0].isChecked());
zauberregelModel->set_kausal(testItems[1].isChecked()); zauberregelModel->set_kausal(testItems[1].isChecked());
zauberregelModel->set_final(testItems[2].isChecked()); zauberregelModel->set_final(testItems[2].isChecked());
zauberregelModel->set_relativ1(testItems[3].isChecked()); zauberregelModel->set_relativ1(testItems[3].isChecked());
zauberregelModel->set_temporal2(testItems[4].isChecked()); zauberregelModel->set_temporal2(testItems[4].isChecked());
zauberregelModel->set_relativ2(testItems[5].isChecked()); zauberregelModel->set_relativ2(testItems[5].isChecked());
} }
} }
void VerbEndModel::read(const ESGRAF48::VerbEndModel& model) void VerbEndModel::read(const ESGRAF48::VerbEndModel &model)
{ {
const auto& telefonatModel = model.telefonat(); const auto &telefonatModel = model.telefonat();
{ {
auto& testItems = m_tests.at(0).items(); auto &testItems = m_tests.at(0).items();
testItems[0].setState(telefonatModel.kausal1()); testItems[0].setState(telefonatModel.kausal1());
testItems[1].setState(telefonatModel.kausal2()); testItems[1].setState(telefonatModel.kausal2());
testItems[2].setState(telefonatModel.relativ()); testItems[2].setState(telefonatModel.relativ());
testItems[3].setState(telefonatModel.kausal3()); testItems[3].setState(telefonatModel.kausal3());
testItems[4].setState(telefonatModel.final()); testItems[4].setState(telefonatModel.final());
testItems[5].setState(telefonatModel.temporal1()); testItems[5].setState(telefonatModel.temporal1());
testItems[6].setState(telefonatModel.temporal2()); testItems[6].setState(telefonatModel.temporal2());
} }
const auto& zaubertrickModel = model.zaubertrick(); const auto &zaubertrickModel = model.zaubertrick();
{ {
auto& testItems = m_tests.at(1).items(); auto &testItems = m_tests.at(1).items();
testItems[0].setState(zaubertrickModel.relativ()); testItems[0].setState(zaubertrickModel.relativ());
testItems[1].setState(zaubertrickModel.final1()); testItems[1].setState(zaubertrickModel.final1());
testItems[2].setState(zaubertrickModel.kausal1()); testItems[2].setState(zaubertrickModel.kausal1());
testItems[3].setState(zaubertrickModel.final2()); testItems[3].setState(zaubertrickModel.final2());
testItems[4].setState(zaubertrickModel.temporal1()); testItems[4].setState(zaubertrickModel.temporal1());
testItems[5].setState(zaubertrickModel.kausal2()); testItems[5].setState(zaubertrickModel.kausal2());
testItems[6].setState(zaubertrickModel.temporal2()); testItems[6].setState(zaubertrickModel.temporal2());
} }
const auto& zauberregelModel = model.zauberregel(); const auto &zauberregelModel = model.zauberregel();
{ {
auto& testItems = m_tests.at(2).items(); auto &testItems = m_tests.at(2).items();
testItems[0].setState(zauberregelModel.temporal1()); testItems[0].setState(zauberregelModel.temporal1());
testItems[1].setState(zauberregelModel.kausal()); testItems[1].setState(zauberregelModel.kausal());
testItems[2].setState(zauberregelModel.final()); testItems[2].setState(zauberregelModel.final());
testItems[3].setState(zauberregelModel.relativ1()); testItems[3].setState(zauberregelModel.relativ1());
testItems[4].setState(zauberregelModel.temporal2()); testItems[4].setState(zauberregelModel.temporal2());
testItems[5].setState(zauberregelModel.relativ2()); testItems[5].setState(zauberregelModel.relativ2());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
unsigned int VerbEndModel::getKausalPoints() const unsigned int VerbEndModel::getKausalPoints() const
{ {
auto points = [&](unsigned int testId, unsigned int itemId) { auto points = [&](unsigned int testId, unsigned int itemId) {
return m_tests.at(testId).items().at(itemId).points(); return m_tests.at(testId).items().at(itemId).points();
}; };
return points(0, 0) + points(0, 1) + points(0, 3) + points(1, 2) + points(1, 5) + points(2, 1); return points(0, 0) + points(0, 1) + points(0, 3) + points(1, 2) + points(1, 5) + points(2, 1);
} }
void VerbEndModel::printSummary(QPainter& painter) const void VerbEndModel::printSummary(QPainter &painter) const
{ {
painter.setFont(tableFont()); painter.setFont(tableFont());
auto width = painter.device()->width(); auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing(); auto height = 1.5 * painter.fontMetrics().lineSpacing();
painter.drawText(0, 0, 0.71 * width, height, Qt::AlignRight | Qt::AlignVCenter, painter.drawText(0, 0, 0.71 * width, height, Qt::AlignRight | Qt::AlignVCenter,
"Rohwertpunkte Kausalsätze:"); "Rohwertpunkte Kausalsätze:");
painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter, painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter,
"Rohwertpunkte Total:"); "Rohwertpunkte Total:");
drawNumberSquare(painter, 0.73 * width, 0, getKausalPoints()); drawNumberSquare(painter, 0.73 * width, 0, getKausalPoints());
painter.setPen(resultPen()); painter.setPen(resultPen());
drawNumberSquare(painter, 0.97 * width, 0, getKausalPoints()); drawNumberSquare(painter, 0.97 * width, 0, getKausalPoints());
painter.translate(0, 3 * height); painter.translate(0, 3 * height);
} }

View File

@ -5,16 +5,16 @@
class VerbEndModel : public PrintableModel class VerbEndModel : public PrintableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
VerbEndModel(QObject* parent); VerbEndModel(QObject *parent);
void write(ESGRAF48::VerbEndModel& model) const; void write(ESGRAF48::VerbEndModel &model) const;
void read(const ESGRAF48::VerbEndModel& model); void read(const ESGRAF48::VerbEndModel &model);
unsigned int getKausalPoints() const; unsigned int getKausalPoints() const;
protected: protected:
void printSummary(QPainter& painter) const override; void printSummary(QPainter &painter) const override;
}; };

View File

@ -3,21 +3,21 @@
#include "VerbEndModel.h" #include "VerbEndModel.h"
VerbEndWidget::VerbEndWidget(QWidget* parent) VerbEndWidget::VerbEndWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::VerbEndWidget) , ui(new Ui::VerbEndWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->verbEndTableView->horizontalHeader()->hide(); ui->verbEndTableView->horizontalHeader()->hide();
} }
VerbEndWidget::~VerbEndWidget() VerbEndWidget::~VerbEndWidget()
{ {
delete ui; delete ui;
} }
void VerbEndWidget::setModel(VerbEndModel* model) void VerbEndWidget::setModel(VerbEndModel *model)
{ {
ui->verbEndTableView->setModel(model); ui->verbEndTableView->setModel(model);
} }

View File

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

View File

@ -19,230 +19,230 @@
#include <fstream> #include <fstream>
MainWindow::MainWindow(QWidget* parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, m_dataModel(this) , m_dataModel(this)
{ {
ui->setupUi(this); ui->setupUi(this);
setupUi(); setupUi();
newFile(); newFile();
} }
MainWindow::MainWindow(QWidget* parent, const QString& filename) MainWindow::MainWindow(QWidget *parent, const QString &filename)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, m_dataModel(this) , m_dataModel(this)
{ {
ui->setupUi(this); ui->setupUi(this);
setupUi(); setupUi();
openFile(filename); openFile(filename);
} }
void MainWindow::setupUi() void MainWindow::setupUi()
{ {
ui->metaDataWidget->setModel(&m_dataModel.m_metaData); ui->metaDataWidget->setModel(&m_dataModel.m_metaData);
ui->verbEndWidget->setModel(&m_dataModel.m_verbEnd); ui->verbEndWidget->setModel(&m_dataModel.m_verbEnd);
ui->genusWidget->setModel(&m_dataModel.m_genus); ui->genusWidget->setModel(&m_dataModel.m_genus);
ui->pluralWidget->setModel(&m_dataModel.m_plural); ui->pluralWidget->setModel(&m_dataModel.m_plural);
ui->akkusativDativWidget->setAkkusativModel(&m_dataModel.m_akkusativ); ui->akkusativDativWidget->setAkkusativModel(&m_dataModel.m_akkusativ);
ui->akkusativDativWidget->setDativModel(&m_dataModel.m_dativ); ui->akkusativDativWidget->setDativModel(&m_dataModel.m_dativ);
ui->v2SvkWidget->setWFModel(&m_dataModel.m_wfModel); ui->v2SvkWidget->setWFModel(&m_dataModel.m_wfModel);
ui->v2SvkWidget->setOTModel(&m_dataModel.m_otModel); ui->v2SvkWidget->setOTModel(&m_dataModel.m_otModel);
ui->v2SvkWidget->setTPrModel(&m_dataModel.m_tPrModel); ui->v2SvkWidget->setTPrModel(&m_dataModel.m_tPrModel);
ui->v2SvkWidget->setTPeModel(&m_dataModel.m_tPeModel); ui->v2SvkWidget->setTPeModel(&m_dataModel.m_tPeModel);
ui->lateSkillsWidget->setPassivModel(&m_dataModel.m_passiv); ui->lateSkillsWidget->setPassivModel(&m_dataModel.m_passiv);
ui->lateSkillsWidget->setGenitivModel(&m_dataModel.m_genitiv); ui->lateSkillsWidget->setGenitivModel(&m_dataModel.m_genitiv);
ui->resultWidget->setModel(&m_dataModel.m_results); ui->resultWidget->setModel(&m_dataModel.m_results);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile);
connect(ui->actionOpen, &QAction::triggered, this, qOverload<>(&MainWindow::openFile)); connect(ui->actionOpen, &QAction::triggered, this, qOverload<>(&MainWindow::openFile));
connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile)); connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile));
connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs); connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs);
connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print); connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print);
connect(ui->actionExport_PDF, &QAction::triggered, this, qOverload<>(&MainWindow::savePdf)); connect(ui->actionExport_PDF, &QAction::triggered, this, qOverload<>(&MainWindow::savePdf));
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::aboutDialog); connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::aboutDialog);
connect(&m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged); connect(&m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
} }
void MainWindow::newFile() void MainWindow::newFile()
{ {
closeFile(); closeFile();
setWindowModified(false); setWindowModified(false);
setWindowTitle("untitled[*]"); setWindowTitle("untitled[*]");
m_filename = ""; m_filename = "";
m_saveOnClose = false; m_saveOnClose = false;
} }
void MainWindow::openFile() void MainWindow::openFile()
{ {
QString filename = QString filename =
QFileDialog::getOpenFileName(this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)"); QFileDialog::getOpenFileName(this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)");
if (filename.isEmpty()) if (filename.isEmpty())
{ {
return; return;
} }
try try
{ {
openFile(filename); openFile(filename);
} }
catch (std::exception& e) catch (std::exception &e)
{ {
QString errorMessage = QString("Error loading \"") + filename + "\": " + e.what(); QString errorMessage = QString("Error loading \"") + filename + "\": " + e.what();
QMessageBox::critical(this, "Error", errorMessage); QMessageBox::critical(this, "Error", errorMessage);
} }
} }
void MainWindow::openFile(const QString& filename) void MainWindow::openFile(const QString &filename)
{ {
closeFile(); closeFile();
m_dataModel.read(filename); m_dataModel.read(filename);
setWindowModified(false); setWindowModified(false);
setWindowTitle(filename + "[*]"); setWindowTitle(filename + "[*]");
m_saveOnClose = false; m_saveOnClose = false;
m_filename = filename; m_filename = filename;
ui->metaDataWidget->toFirst(); ui->metaDataWidget->toFirst();
} }
void MainWindow::saveFile() void MainWindow::saveFile()
{ {
if (m_filename.isEmpty()) if (m_filename.isEmpty())
{ {
saveFileAs(); saveFileAs();
} }
else else
{ {
saveFile(m_filename); saveFile(m_filename);
} }
} }
void MainWindow::saveFileAs() void MainWindow::saveFileAs()
{ {
QFileDialog saveFilenameDialog(this); QFileDialog saveFilenameDialog(this);
saveFilenameDialog.setAcceptMode(QFileDialog::AcceptSave); saveFilenameDialog.setAcceptMode(QFileDialog::AcceptSave);
saveFilenameDialog.setDefaultSuffix("esgraf48"); saveFilenameDialog.setDefaultSuffix("esgraf48");
saveFilenameDialog.setFileMode(QFileDialog::AnyFile); saveFilenameDialog.setFileMode(QFileDialog::AnyFile);
saveFilenameDialog.setNameFilter("ESGRAF 4-8 (*.esgraf48)"); saveFilenameDialog.setNameFilter("ESGRAF 4-8 (*.esgraf48)");
saveFilenameDialog.setWindowTitle("Save file"); saveFilenameDialog.setWindowTitle("Save file");
if (!saveFilenameDialog.exec()) if (!saveFilenameDialog.exec())
{ {
return; return;
} }
saveFile(saveFilenameDialog.selectedFiles().first()); saveFile(saveFilenameDialog.selectedFiles().first());
} }
void MainWindow::closeFile() void MainWindow::closeFile()
{ {
if (m_saveOnClose == true) if (m_saveOnClose == true)
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText("The document has been modified."); msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?"); msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
msgBox.setDefaultButton(QMessageBox::Save); msgBox.setDefaultButton(QMessageBox::Save);
if (msgBox.exec() == QMessageBox::Save) if (msgBox.exec() == QMessageBox::Save)
{ {
saveFile(); saveFile();
} }
} }
} }
void MainWindow::print() const void MainWindow::print() const
{ {
QPrinter printer; QPrinter printer;
printer.setPaperSize(QPrinter::A4); printer.setPaperSize(QPrinter::A4);
printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter);
QPrintDialog dialog(&printer); QPrintDialog dialog(&printer);
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
{ {
return; return;
} }
m_dataModel.printTo(printer); m_dataModel.printTo(printer);
} }
void MainWindow::dataModelChanged() void MainWindow::dataModelChanged()
{ {
m_saveOnClose = true; m_saveOnClose = true;
setWindowModified(true); setWindowModified(true);
} }
void MainWindow::savePdf() void MainWindow::savePdf()
{ {
QFileDialog saveFilenameDialog(this); QFileDialog saveFilenameDialog(this);
saveFilenameDialog.setDefaultSuffix("pdf"); saveFilenameDialog.setDefaultSuffix("pdf");
saveFilenameDialog.setFileMode(QFileDialog::AnyFile); saveFilenameDialog.setFileMode(QFileDialog::AnyFile);
saveFilenameDialog.setNameFilter("PDF File (*.pdf)"); saveFilenameDialog.setNameFilter("PDF File (*.pdf)");
saveFilenameDialog.setWindowTitle("Save file"); saveFilenameDialog.setWindowTitle("Save file");
if (!saveFilenameDialog.exec()) if (!saveFilenameDialog.exec())
{ {
return; return;
} }
savePdf(saveFilenameDialog.selectedFiles().first()); savePdf(saveFilenameDialog.selectedFiles().first());
} }
void MainWindow::closeEvent(QCloseEvent* event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
closeFile(); closeFile();
} }
void MainWindow::saveFile(const QString& filename) void MainWindow::saveFile(const QString &filename)
{ {
try try
{ {
m_dataModel.write(filename); m_dataModel.write(filename);
} }
catch (std::exception& e) catch (std::exception &e)
{ {
QString errorMessage = QString("Error saving \"") + filename + "\": " + e.what(); QString errorMessage = QString("Error saving \"") + filename + "\": " + e.what();
QMessageBox::critical(this, "Error", errorMessage); QMessageBox::critical(this, "Error", errorMessage);
return; return;
} }
qDebug() << "Wrote" << filename; qDebug() << "Wrote" << filename;
setWindowTitle(filename + "[*]"); setWindowTitle(filename + "[*]");
setWindowModified(false); setWindowModified(false);
m_filename = filename; m_filename = filename;
m_saveOnClose = false; m_saveOnClose = false;
} }
void MainWindow::savePdf(const QString& filename) void MainWindow::savePdf(const QString &filename)
{ {
QPrinter printer; QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4); printer.setPaperSize(QPrinter::A4);
printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter);
printer.setOutputFileName(filename); printer.setOutputFileName(filename);
m_dataModel.printTo(printer); m_dataModel.printTo(printer);
} }
void MainWindow::aboutDialog() void MainWindow::aboutDialog()
{ {
QString infoString = QString infoString =
QString::fromUtf8(ESGRAF48_DESCRIPTION) + " Version " + QString::fromUtf8(ESGRAF48_VERSION); QString::fromUtf8(ESGRAF48_DESCRIPTION) + " Version " + QString::fromUtf8(ESGRAF48_VERSION);
QMessageBox::information(this, ESGRAF48_DESCRIPTION, infoString); QMessageBox::information(this, ESGRAF48_DESCRIPTION, infoString);
} }

View File

@ -6,6 +6,7 @@
#include <QString> #include <QString>
#include <QFont> #include <QFont>
class DataModel; class DataModel;
class QDataWidgetMapper; class QDataWidgetMapper;
@ -15,36 +16,36 @@ class MainWindow;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
private: private:
Ui::MainWindow* ui; Ui::MainWindow *ui;
DataModel m_dataModel; DataModel m_dataModel;
QString m_filename; QString m_filename;
bool m_saveOnClose = false; bool m_saveOnClose = false;
public: public:
MainWindow(QWidget* parent); MainWindow(QWidget *parent);
MainWindow(QWidget* parent, const QString& filename); MainWindow(QWidget *parent, const QString &filename);
~MainWindow(); ~MainWindow();
public slots: public slots:
void newFile(); void newFile();
void openFile(); void openFile();
void openFile(const QString& filename); void openFile(const QString &filename);
void saveFile(); void saveFile();
void saveFileAs(); void saveFileAs();
void closeFile(); void closeFile();
void print() const; void print() const;
void dataModelChanged(); void dataModelChanged();
void savePdf(); void savePdf();
void aboutDialog(); void aboutDialog();
protected: protected:
void closeEvent(QCloseEvent* event) override; void closeEvent(QCloseEvent *event) override;
private: private:
void setupUi(); void setupUi();
void saveFile(const QString& filename); void saveFile(const QString &filename);
void savePdf(const QString& filename); void savePdf(const QString &filename);
}; };

View File

@ -4,37 +4,37 @@
TEST_CASE("default initialization") TEST_CASE("default initialization")
{ {
Age age; Age age;
REQUIRE(age.years() == 0); REQUIRE(age.years() == 0);
REQUIRE(age.months() == 0); REQUIRE(age.months() == 0);
REQUIRE(age.toString() == "0;0"); REQUIRE(age.toString() == "0;0");
Age age2; Age age2;
REQUIRE(!(age < age)); REQUIRE(!(age < age));
REQUIRE(!(age < age2)); REQUIRE(!(age < age2));
} }
TEST_CASE("year/month initialization") TEST_CASE("year/month initialization")
{ {
for (unsigned int year = 0; year <= 100; ++year) for (unsigned int year = 0; year <= 100; ++year)
{ {
for (unsigned int month = 0; month < 12; ++month) for (unsigned int month = 0; month < 12; ++month)
{ {
Age age(year, month); Age age(year, month);
REQUIRE(age.years() == year); REQUIRE(age.years() == year);
REQUIRE(age.months() == month); REQUIRE(age.months() == month);
} }
} }
} }
TEST_CASE("age by reference") TEST_CASE("age by reference")
{ {
QDate birth(1970, 1, 1); QDate birth(1970, 1, 1);
QDate reference(1980, 1, 1); QDate reference(1980, 1, 1);
Age age(birth, reference); Age age(birth, reference);
REQUIRE(age.years() == 10); REQUIRE(age.years() == 10);
REQUIRE(age.months() == 0); REQUIRE(age.months() == 0);
} }

View File

@ -2,5 +2,6 @@
TEST_CASE("Dummy") TEST_CASE("Dummy")
{ {
REQUIRE(true == true); REQUIRE(true == true);
} }