From b8c869ff39ee3de17bbe92265fcff9f5caf3d26b Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 25 Jun 2018 23:04:32 +0200 Subject: [PATCH] implemented V2/SVK test --- source/CMakeLists.txt | 1 + source/DataModel.cpp | 11 ++++ source/DataModel.h | 3 ++ source/ResultWidget/ResultModel.cpp | 22 ++++++++ source/ResultWidget/ResultModel.h | 2 + source/ResultWidget/SvkPR.h | 65 ++++++++++++++++++++++ source/ResultWidget/V2PR.h | 68 +++++++++++++++++++++++ source/SubTests/CMakeLists.txt | 1 + source/SubTests/V2Svk/CMakeLists.txt | 36 +++++++++++++ source/SubTests/V2Svk/V2SvkModel.cpp | 77 +++++++++++++++++++++++++++ source/SubTests/V2Svk/V2SvkModel.h | 14 +++++ source/SubTests/V2Svk/V2SvkWidget.cpp | 21 ++++++++ source/SubTests/V2Svk/V2SvkWidget.h | 23 ++++++++ source/SubTests/V2Svk/V2SvkWidget.ui | 24 +++++++++ source/mainwindow.cpp | 55 +++++++++---------- source/mainwindow.ui | 38 ++++++++++++- 16 files changed, 432 insertions(+), 29 deletions(-) create mode 100644 source/ResultWidget/SvkPR.h create mode 100644 source/ResultWidget/V2PR.h create mode 100644 source/SubTests/V2Svk/CMakeLists.txt create mode 100644 source/SubTests/V2Svk/V2SvkModel.cpp create mode 100644 source/SubTests/V2Svk/V2SvkModel.h create mode 100644 source/SubTests/V2Svk/V2SvkWidget.cpp create mode 100644 source/SubTests/V2Svk/V2SvkWidget.h create mode 100644 source/SubTests/V2Svk/V2SvkWidget.ui diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index c6de361..383d65e 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -44,6 +44,7 @@ target_link_libraries(${PROJECT_NAME} Plural Genus AkkusativDativ + V2Svk ResultWidget Qt5::Widgets ) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 78fa623..6c19b25 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -11,6 +11,7 @@ DataModel::DataModel(QObject *parent) , m_results(this) , m_akkusativ(this) , m_dativ(this) + , m_v2Svk(this) { connect(&m_plural, &PluralModel::dataChanged, this, &DataModel::pluralModelChanged); @@ -24,6 +25,8 @@ DataModel::DataModel(QObject *parent) &DataModel::akkusativModelChanged); connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged); + connect(&m_v2Svk, &V2SvkModel::dataChanged, this, + &DataModel::v2SvkModelChanged); } void DataModel::write(QJsonObject &target) const @@ -34,6 +37,7 @@ void DataModel::write(QJsonObject &target) const write(m_plural, target, "Plural"); write(m_akkusativ, target, "Akkusativ"); write(m_dativ, target, "Dativ"); + write(m_v2Svk, target, "V2Svk"); } void DataModel::read(const QJsonObject &source) @@ -44,6 +48,7 @@ void DataModel::read(const QJsonObject &source) read(m_plural, source, "Plural"); read(m_akkusativ, source, "Akkusativ"); read(m_dativ, source, "Dativ"); + read(m_v2Svk, source, "V2Svk"); } void DataModel::pluralModelChanged() @@ -75,3 +80,9 @@ void DataModel::dativModelChanged() { m_results.setDativResult(m_dativ.getPoints()); } + +void DataModel::v2SvkModelChanged() +{ + m_results.setV2Result(m_v2Svk.getV2Points()); + m_results.setSvkResult(m_v2Svk.getSvkPoints()); +} diff --git a/source/DataModel.h b/source/DataModel.h index 830b614..df37aeb 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -6,6 +6,7 @@ #include "PluralModel.h" #include "AkkusativModel.h" #include "DativModel.h" +#include "V2SvkModel.h" #include "ResultModel.h" @@ -22,6 +23,7 @@ public: PluralModel m_plural; AkkusativModel m_akkusativ; DativModel m_dativ; + V2SvkModel m_v2Svk; ResultModel m_results; @@ -59,4 +61,5 @@ private slots: void verbEndModelChanged(); void akkusativModelChanged(); void dativModelChanged(); + void v2SvkModelChanged(); }; diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index bad17df..15c3244 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -5,6 +5,8 @@ #include "VerbEndPR.h" #include "AkkusativPR.h" #include "DativPR.h" +#include "V2PR.h" +#include "SvkPR.h" #include @@ -166,3 +168,23 @@ void ResultModel::setDativResult(unsigned int points) emit dataChanged(index(0, 6), index(4, 6)); } } + +void ResultModel::setV2Result(unsigned int points) +{ + if (m_results[0].points() != points) + { + m_results[0].setPoints(points); + m_results[0].setPR(V2PR().lookup(m_age, points)); + emit dataChanged(index(0, 0), index(4, 0)); + } +} + +void ResultModel::setSvkResult(unsigned int points) +{ + if (m_results[1].points() != points) + { + m_results[1].setPoints(points); + m_results[1].setPR(SvkPR().lookup(m_age, points)); + emit dataChanged(index(0, 1), index(4, 1)); + } +} diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index 4befa81..918f325 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -68,4 +68,6 @@ public: void setVerbEndResult(unsigned int points); void setAkkusativResult(unsigned int points); void setDativResult(unsigned int points); + void setV2Result(unsigned int points); + void setSvkResult(unsigned int points); }; diff --git a/source/ResultWidget/SvkPR.h b/source/ResultWidget/SvkPR.h new file mode 100644 index 0000000..87a3563 --- /dev/null +++ b/source/ResultWidget/SvkPR.h @@ -0,0 +1,65 @@ +#pragma once + +#include "PRMap.h" + +class SvkPR : public PRMap +{ +public: + SvkPR() + { + // clang-format off + m_ages = { + { 4, 0 }, + { 5, 0 }, + { 6, 0 }, + { 9, 0 } + }; + + m_PRs = { + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 1, 0 }, + { 3, 1, 0 }, + { 4, 1, 1 }, + { 4, 1, 1 }, + { 7, 2, 1 }, + { 8, 3, 3 }, + { 8, 5, 3 }, + { 9, 5, 3 }, + { 12, 6, 4 }, + { 17, 6, 4 }, + { 18, 7, 5 }, + { 21, 7, 6 }, + { 21, 8, 7 }, + { 24, 10, 7 }, + { 28, 11, 7 }, + { 32, 12, 9 }, + { 34, 14, 9 }, + { 37, 19, 11 }, + { 42, 25, 13 }, + { 51, 28, 16 }, + { 53, 31, 19 }, + { 59, 38, 25 }, + { 71, 50, 36 }, + { 100, 100, 100 } + }; + // clang-format on + } +}; diff --git a/source/ResultWidget/V2PR.h b/source/ResultWidget/V2PR.h new file mode 100644 index 0000000..b060a73 --- /dev/null +++ b/source/ResultWidget/V2PR.h @@ -0,0 +1,68 @@ +#pragma once + +#include "PRMap.h" + +class V2PR : public PRMap +{ +public: + V2PR() + { + // clang-format off + m_ages = { + { 4, 0 }, + { 5, 0 }, + { 6, 0 }, + { 9, 0 } + }; + + m_PRs = { + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 1, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 0, 0 }, + { 2, 1, 0 }, + { 2, 1, 0 }, + { 2, 1, 0 }, + { 2, 1, 0 }, + { 3, 1, 0 }, + { 3, 1, 0 }, + { 3, 1, 1 }, + { 3, 1, 1 }, + { 3, 1, 1 }, + { 4, 1, 1 }, + { 5, 2, 1 }, + { 7, 2, 1 }, + { 8, 2, 1 }, + { 9, 3, 2 }, + { 14, 5, 4 }, + { 17, 6, 4 }, + { 18, 7, 5 }, + { 21, 9, 5 }, + { 21, 10, 6 }, + { 22, 10, 6 }, + { 24, 11, 7 }, + { 25, 11, 8 }, + { 27, 14, 9 }, + { 29, 14, 10 }, + { 32, 16, 10 }, + { 37, 19, 12 }, + { 42, 22, 13 }, + { 47, 26, 15 }, + { 52, 29, 19 }, + { 55, 32, 21 }, + { 60, 41, 27 }, + { 69, 52, 37 }, + { 100, 100, 100 } + }; + // clang-format on + } +}; diff --git a/source/SubTests/CMakeLists.txt b/source/SubTests/CMakeLists.txt index 5eabd7e..6ef8db8 100644 --- a/source/SubTests/CMakeLists.txt +++ b/source/SubTests/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(VerbEnd) add_subdirectory(Genus) add_subdirectory(Plural) add_subdirectory(AkkusativDativ) +add_subdirectory(V2Svk) diff --git a/source/SubTests/V2Svk/CMakeLists.txt b/source/SubTests/V2Svk/CMakeLists.txt new file mode 100644 index 0000000..495e5ca --- /dev/null +++ b/source/SubTests/V2Svk/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.6) + +project(V2Svk LANGUAGES CXX) + +find_package(Qt5Widgets REQUIRED) + +set(CMAKE_AUTOMOC ON) + +qt5_wrap_ui(UI_HEADERS + V2SvkWidget.ui +) + +add_library(${PROJECT_NAME} + V2SvkWidget.cpp + V2SvkModel.cpp + ${UI_HEADERS} +) + +set_target_properties(${PROJECT_NAME} + PROPERTIES CXX_STANDARD 14 +) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + CheckableItem + CheckableTest + CheckableTestModel + Qt5::Widgets +) diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp new file mode 100644 index 0000000..d86b883 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -0,0 +1,77 @@ +#include "V2SvkModel.h" + +V2SvkModel::V2SvkModel(QObject *parent) + : CheckableTestModel(parent) +{ + m_tests = { + { "W-Frage", + { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", + "Gans" , "Gans", "Gans", "Gans"} }, + { "Verbtrennung", + { "", "Affe", "", "", "", "", "", "Schwein", "" , "", "Gans", ""} }, + { "SVK: /-st/", + { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", + "Gans" , "Gans", "Gans", "Gans"} }, + + { "Objekt-Topikalisierung", + { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", + "Gans" , "Gans", "Gans", "Gans"} }, + { "SVK: Stamm", + { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", + "Gans" , "Gans", "Gans", "Gans"} }, + + { "Temporaladverb Präsens", + { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + { "SKV: /-e/ o. Stamm", + { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + + { "Temporaladverb Perfekt", + { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + { "Verbtrennung", + { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + { "SVK: /-e/ o. Stamm", + { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + { "Partizip", + { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + }; +} + +unsigned int V2SvkModel::getV2Points() +{ + size_t points = 0; + + for (auto testIndex : { 0, 1, 3, 5, 7, 8 }) + { + const auto &test = m_tests.at(testIndex); + + for (const auto &item : test.items()) + { + if (item.isChecked()) + { + points++; + } + } + } + + return points; +} + +unsigned int V2SvkModel::getSvkPoints() +{ + size_t points = 0; + + for (auto testIndex : { 2, 4, 6, 9, 10 }) + { + const auto &test = m_tests.at(testIndex); + + for (const auto &item : test.items()) + { + if (item.isChecked()) + { + points++; + } + } + } + + return points; +} diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h new file mode 100644 index 0000000..456c572 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -0,0 +1,14 @@ +#pragma once + +#include "CheckableTestModel.h" + +class V2SvkModel : public CheckableTestModel +{ + Q_OBJECT + +public: + V2SvkModel(QObject *parent); + + unsigned int getV2Points(); + unsigned int getSvkPoints(); +}; diff --git a/source/SubTests/V2Svk/V2SvkWidget.cpp b/source/SubTests/V2Svk/V2SvkWidget.cpp new file mode 100644 index 0000000..e9793c5 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkWidget.cpp @@ -0,0 +1,21 @@ +#include "V2SvkWidget.h" +#include "ui_V2SvkWidget.h" + +#include "V2SvkModel.h" + +V2SvkWidget::V2SvkWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::V2SvkWidget) +{ + ui->setupUi(this); +} + +V2SvkWidget::~V2SvkWidget() +{ + delete ui; +} + +void V2SvkWidget::setV2SvkModel(V2SvkModel *model) +{ + ui->v2SvkTableView->setModel(model); +} diff --git a/source/SubTests/V2Svk/V2SvkWidget.h b/source/SubTests/V2Svk/V2SvkWidget.h new file mode 100644 index 0000000..e23cac5 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkWidget.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +class V2SvkModel; + +namespace Ui { +class V2SvkWidget; +}; + +class V2SvkWidget : public QWidget +{ + Q_OBJECT + +private: + Ui::V2SvkWidget *ui; + +public: + V2SvkWidget(QWidget *parent = nullptr); + ~V2SvkWidget(); + + void setV2SvkModel(V2SvkModel *model); +}; diff --git a/source/SubTests/V2Svk/V2SvkWidget.ui b/source/SubTests/V2Svk/V2SvkWidget.ui new file mode 100644 index 0000000..73ee028 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkWidget.ui @@ -0,0 +1,24 @@ + + + V2SvkWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 4887656..c0b2c0f 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -17,8 +17,8 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newFile())); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile())); - connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveFileAs())); + connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFile())); + connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveFileAs())); newFile(); } @@ -33,20 +33,21 @@ void MainWindow::newFile() m_dataModel = std::make_unique(this); ui->metaDataWidget->setModel(&m_dataModel->m_metaData); 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->akkusativDativWidget->setAkkusativModel(&m_dataModel->m_akkusativ); ui->akkusativDativWidget->setDativModel(&m_dataModel->m_dativ); + ui->v2SvkWidget->setV2SvkModel(&m_dataModel->m_v2Svk); ui->resultWidget->setModel(&m_dataModel->m_results); - m_filename = ""; + m_filename = ""; } void MainWindow::openFile() { - QString filename = QFileDialog::getOpenFileName(this, "Open file", - "", "ESGRAF 4-8 (*.esgraf48)"); + QString filename = QFileDialog::getOpenFileName( + this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)"); if (filename.isEmpty()) { return; @@ -64,46 +65,46 @@ void MainWindow::openFile() m_dataModel->read(loadDoc.object()); - m_filename = filename; + m_filename = filename; - ui->metaDataWidget->toFirst(); + ui->metaDataWidget->toFirst(); } void MainWindow::saveFile() { - if (m_filename.isEmpty()) - { - saveFileAs(); - } - else - { - saveFile(m_filename); - } + if (m_filename.isEmpty()) + { + saveFileAs(); + } + else + { + saveFile(m_filename); + } } void MainWindow::saveFileAs() { - QString filename = QFileDialog::getSaveFileName(this, "Save file", "", - "ESGRAF 4-8 (*.esgraf48)"); + QString filename = QFileDialog::getSaveFileName( + this, "Save file", "", "ESGRAF 4-8 (*.esgraf48)"); if (filename.isEmpty()) { return; } - saveFile(filename); + saveFile(filename); } void MainWindow::saveFile(const QString &filename) { - QJsonObject saveData; - m_dataModel->write(saveData); + QJsonObject saveData; + m_dataModel->write(saveData); - QJsonDocument saveDoc(saveData); + QJsonDocument saveDoc(saveData); - QFile saveFile(filename); - saveFile.open(QFile::WriteOnly); - saveFile.write(saveDoc.toJson()); - saveFile.close(); + QFile saveFile(filename); + saveFile.open(QFile::WriteOnly); + saveFile.write(saveDoc.toJson()); + saveFile.close(); - m_filename = filename; + m_filename = filename; } diff --git a/source/mainwindow.ui b/source/mainwindow.ui index 9ec7130..0b5ebe8 100644 --- a/source/mainwindow.ui +++ b/source/mainwindow.ui @@ -18,7 +18,7 @@ - 3 + 1 @@ -30,6 +30,16 @@ + + + Subtest 1: V2/SVK + + + + + + + Subtest 2: Verbendstellungsregel (VE) @@ -74,6 +84,24 @@ + + + 0 + 0 + + + + + 0 + 220 + + + + + 16777215 + 220 + + 0 @@ -100,7 +128,7 @@ 0 0 1125 - 17 + 19 @@ -227,6 +255,12 @@
AkkusativDativWidget.h
1 + + V2SvkWidget + QWidget +
V2SvkWidget.h
+ 1 +