added verb-end test
This commit is contained in:
parent
498abc873e
commit
8452054746
@ -36,9 +36,11 @@ target_include_directories(${PROJECT_NAME}
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
MetaData
|
||||
VerbEnd
|
||||
Genus
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
add_subdirectory(MetaData)
|
||||
add_subdirectory(VerbEnd)
|
||||
add_subdirectory(Genus)
|
||||
|
@ -3,6 +3,7 @@
|
||||
DataModel::DataModel(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_metaData(this)
|
||||
, m_verbEnd(this)
|
||||
, m_genus(this)
|
||||
{
|
||||
}
|
||||
@ -13,6 +14,10 @@ void DataModel::write(QJsonObject &target) const
|
||||
m_metaData.write(metaData);
|
||||
target["MetaData"] = metaData;
|
||||
|
||||
QJsonObject verbEnd;
|
||||
m_verbEnd.write(verbEnd);
|
||||
target["VerbEnd"] = verbEnd;
|
||||
|
||||
QJsonObject genus;
|
||||
m_genus.write(genus);
|
||||
target["Genus"] = genus;
|
||||
@ -26,6 +31,12 @@ void DataModel::read(const QJsonObject &source)
|
||||
m_metaData.read(metaData.toObject());
|
||||
}
|
||||
|
||||
const auto &verbEnd = source["VerbEnd"];
|
||||
if (verbEnd.isObject())
|
||||
{
|
||||
m_verbEnd.read(verbEnd.toObject());
|
||||
}
|
||||
|
||||
const auto &genus = source["Genus"];
|
||||
if (genus.isObject())
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "MetaData/MetaDataModel.h"
|
||||
#include "Genus/GenusModel.h"
|
||||
#include "VerbEnd/VerbEndModel.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
@ -11,6 +12,7 @@ class DataModel : public QObject
|
||||
|
||||
public:
|
||||
MetaDataModel m_metaData;
|
||||
VerbEndModel m_verbEnd;
|
||||
GenusModel m_genus;
|
||||
|
||||
public:
|
||||
|
@ -13,9 +13,9 @@ qt5_wrap_ui(UI_HEADERS
|
||||
add_library(${PROJECT_NAME}
|
||||
GenusWidget.cpp
|
||||
GenusModel.cpp
|
||||
CheckableItem.cpp
|
||||
CheckableItems.cpp
|
||||
${UI_HEADERS}
|
||||
../CheckableItem.cpp
|
||||
../CheckableItems.cpp
|
||||
${UI_HEADERS}
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CheckableItem.h"
|
||||
#include "CheckableItems.h"
|
||||
#include "../CheckableItem.h"
|
||||
#include "../CheckableItems.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
|
33
source/VerbEnd/CMakeLists.txt
Normal file
33
source/VerbEnd/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
project(VerbEnd LANGUAGES CXX)
|
||||
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
qt5_wrap_ui(UI_HEADERS
|
||||
VerbEndWidget.ui
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
VerbEndWidget.cpp
|
||||
VerbEndModel.cpp
|
||||
../CheckableItem.cpp
|
||||
../CheckableItems.cpp
|
||||
${UI_HEADERS}
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
PROPERTIES CXX_STANDARD 14
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
Qt5::Widgets
|
||||
)
|
208
source/VerbEnd/VerbEndModel.cpp
Normal file
208
source/VerbEnd/VerbEndModel.cpp
Normal file
@ -0,0 +1,208 @@
|
||||
#include "VerbEndModel.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
VerbEndModel::VerbEndModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int VerbEndModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
int VerbEndModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
QVariant VerbEndModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!isValidIndex(index))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto &item = getItem(index);
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return item.getText().c_str();
|
||||
}
|
||||
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
qDebug() << "VerbEndModel::data" << index << e.what();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Qt::ItemFlags VerbEndModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (isValidIndex(index))
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
||||
bool VerbEndModel::setData(
|
||||
const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!isValidIndex(index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
auto &item = getItem(index);
|
||||
item.setState(value.toBool());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
qDebug() << "VerbEndModel::setData" << index << e.what();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant VerbEndModel::headerData(
|
||||
int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Vertical)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return "Telefonat";
|
||||
case 1:
|
||||
return "Zaubertrick";
|
||||
case 2:
|
||||
return "Zauberregel";
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void VerbEndModel::write(QJsonObject &json) const
|
||||
{
|
||||
QJsonArray telefonat;
|
||||
m_telefonat.write(telefonat);
|
||||
json["Telefonat"] = telefonat;
|
||||
|
||||
QJsonArray zaubertrick;
|
||||
m_zaubertrick.write(zaubertrick);
|
||||
json["Zaubertrick"] = zaubertrick;
|
||||
|
||||
QJsonArray zauberregel;
|
||||
m_zauberregel.write(zauberregel);
|
||||
json["Zauberregel"] = zauberregel;
|
||||
}
|
||||
|
||||
void VerbEndModel::read(const QJsonObject &json)
|
||||
{
|
||||
if (json["Telefonat"].isArray())
|
||||
{
|
||||
m_telefonat.read(json["Telefonat"].toArray());
|
||||
}
|
||||
|
||||
if (json["Zaubertrick"].isArray())
|
||||
{
|
||||
m_zaubertrick.read(json["Zaubertrick"].toArray());
|
||||
}
|
||||
|
||||
if (json["Zauberregel"].isArray())
|
||||
{
|
||||
m_zauberregel.read(json["Zauberregel"].toArray());
|
||||
}
|
||||
}
|
||||
|
||||
bool VerbEndModel::isValidIndex(const QModelIndex &index) const
|
||||
{
|
||||
switch (index.row())
|
||||
{
|
||||
case 0:
|
||||
return index.column() < m_telefonat.size();
|
||||
case 1:
|
||||
return index.column() < m_zaubertrick.size();
|
||||
case 2:
|
||||
return index.column() < m_zauberregel.size();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CheckableItems &VerbEndModel::getItems(const QModelIndex &index)
|
||||
{
|
||||
switch (index.row())
|
||||
{
|
||||
case 0:
|
||||
return m_telefonat;
|
||||
case 1:
|
||||
return m_zaubertrick;
|
||||
case 2:
|
||||
return m_zauberregel;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
const CheckableItems &VerbEndModel::getItems(const QModelIndex &index) const
|
||||
{
|
||||
switch (index.row())
|
||||
{
|
||||
case 0:
|
||||
return m_telefonat;
|
||||
case 1:
|
||||
return m_zaubertrick;
|
||||
case 2:
|
||||
return m_zauberregel;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
CheckableItem &VerbEndModel::getItem(const QModelIndex &index)
|
||||
{
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
const CheckableItem &VerbEndModel::getItem(const QModelIndex &index) const
|
||||
{
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
44
source/VerbEnd/VerbEndModel.h
Normal file
44
source/VerbEnd/VerbEndModel.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "../CheckableItem.h"
|
||||
#include "../CheckableItems.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class VerbEndModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CheckableItems m_telefonat = { "Kausal (1)", "Kausal (2)", "Relativ",
|
||||
"Kausal (3)", "Final", "Temporal (1)", "Temporal (2)" };
|
||||
CheckableItems m_zaubertrick = { "Relativ", "Final (1)", "Kausal (1)",
|
||||
"Final (2)", "Temporal (1)", "Kausal (2)", "Temporal (2)" };
|
||||
CheckableItems m_zauberregel = { "Temporal (1)", "Kausal", "Final",
|
||||
"Relativ (1)", "Temporal (2)", "Relativ (2)" };
|
||||
|
||||
public:
|
||||
VerbEndModel(QObject *parent);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(
|
||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
void write(QJsonObject &json) const;
|
||||
void read(const QJsonObject &json);
|
||||
|
||||
private:
|
||||
bool isValidIndex(const QModelIndex &index) const;
|
||||
|
||||
CheckableItems &getItems(const QModelIndex &index);
|
||||
const CheckableItems &getItems(const QModelIndex &index) const;
|
||||
|
||||
CheckableItem &getItem(const QModelIndex &index);
|
||||
const CheckableItem &getItem(const QModelIndex &index) const;
|
||||
};
|
23
source/VerbEnd/VerbEndWidget.cpp
Normal file
23
source/VerbEnd/VerbEndWidget.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "VerbEndWidget.h"
|
||||
#include "ui_VerbEndWidget.h"
|
||||
|
||||
#include "VerbEndModel.h"
|
||||
|
||||
VerbEndWidget::VerbEndWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::VerbEndWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->verbEndTableView->horizontalHeader()->hide();
|
||||
}
|
||||
|
||||
VerbEndWidget::~VerbEndWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void VerbEndWidget::setModel(VerbEndModel *model)
|
||||
{
|
||||
ui->verbEndTableView->setModel(model);
|
||||
}
|
23
source/VerbEnd/VerbEndWidget.h
Normal file
23
source/VerbEnd/VerbEndWidget.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class VerbEndModel;
|
||||
|
||||
namespace Ui {
|
||||
class VerbEndWidget;
|
||||
};
|
||||
|
||||
class VerbEndWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Ui::VerbEndWidget *ui;
|
||||
|
||||
public:
|
||||
VerbEndWidget(QWidget *parent = nullptr);
|
||||
~VerbEndWidget();
|
||||
|
||||
void setModel(VerbEndModel *model);
|
||||
};
|
24
source/VerbEnd/VerbEndWidget.ui
Normal file
24
source/VerbEnd/VerbEndWidget.ui
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VerbEndWidget</class>
|
||||
<widget class="QWidget" name="VerbEndWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>556</width>
|
||||
<height>210</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="verbEndTableView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -31,6 +31,7 @@ void MainWindow::newFile()
|
||||
{
|
||||
m_dataModel = std::make_unique<DataModel>(this);
|
||||
ui->metaDataWidget->setModel(&m_dataModel->m_metaData);
|
||||
ui->verbEndWidget->setModel(&m_dataModel->m_verbEnd);
|
||||
ui->genusWidget->setModel(&m_dataModel->m_genus);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="MetaDataTab">
|
||||
<attribute name="title">
|
||||
@ -30,6 +30,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="VerbEndTab">
|
||||
<attribute name="title">
|
||||
<string>Subtest 2: Verbenstellungsregel (VE)</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="VerbEndWidget" name="verbEndWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="GenusTab">
|
||||
<attribute name="title">
|
||||
<string>Subtest 3: Genus</string>
|
||||
@ -140,6 +150,12 @@
|
||||
<header>Genus/GenusWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>VerbEndWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>VerbEnd/VerbEndWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="mainwindow.qrc"/>
|
||||
|
Reference in New Issue
Block a user