added result model

This commit is contained in:
Michael Mandl 2018-06-06 18:05:30 +02:00
parent 1614d4b409
commit 1f9a051382
10 changed files with 146 additions and 6 deletions

View file

@ -6,6 +6,7 @@ DataModel::DataModel(QObject *parent)
, m_verbEnd(this) , m_verbEnd(this)
, m_genus(this) , m_genus(this)
, m_plural(this) , m_plural(this)
, m_results(this)
{ {
} }

View file

@ -5,6 +5,8 @@
#include "VerbEndModel.h" #include "VerbEndModel.h"
#include "PluralModel.h" #include "PluralModel.h"
#include "ResultModel.h"
#include <QJsonObject> #include <QJsonObject>
class DataModel : public QObject class DataModel : public QObject
@ -17,6 +19,8 @@ public:
GenusModel m_genus; GenusModel m_genus;
PluralModel m_plural; PluralModel m_plural;
ResultModel m_results;
public: public:
DataModel(QObject *parent); DataModel(QObject *parent);

View file

@ -12,7 +12,7 @@ qt5_wrap_ui(GENUS_UI
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
ResultWidget.cpp ResultWidget.cpp
#ResultModel.cpp ResultModel.cpp
${GENUS_UI} ${GENUS_UI}
) )

View file

@ -0,0 +1,61 @@
#include "ResultModel.h"
#include <QDebug>
ResultModel::ResultModel(QObject *parent)
: QAbstractTableModel(parent)
{
m_results = {{ "V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural" }};
}
int ResultModel::rowCount(const QModelIndex &parent) const
{
return 3;
}
int ResultModel::columnCount(const QModelIndex &parent) const
{
return 9;
}
QVariant ResultModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
return "data";
}
return {};
}
QVariant ResultModel::headerData(
int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
{
return {};
}
switch (orientation)
{
case Qt::Horizontal:
if (m_results.size() > section)
{
return m_results[section].name();
}
case Qt::Vertical:
switch (section)
{
case 0:
return ">= PR 84";
case 1:
return "< PR 84";
case 2:
return "<= PR 16";
default:
return {};
}
default:
return {};
}
}

View file

@ -0,0 +1,41 @@
#pragma once
#include <vector>
#include <QAbstractTableModel>
class TestResult
{
private:
QString m_name;
public:
TestResult(const char *name)
: m_name(name)
{
}
const QString &name() const
{
return m_name;
}
};
class ResultModel : public QAbstractTableModel
{
Q_OBJECT
private:
std::vector<TestResult> m_results;
public:
ResultModel(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;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
};

View file

@ -1,6 +1,8 @@
#include "ResultWidget.h" #include "ResultWidget.h"
#include "ui_ResultWidget.h" #include "ui_ResultWidget.h"
#include "ResultModel.h"
ResultWidget::ResultWidget(QWidget *parent) ResultWidget::ResultWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::ResultWidget) , ui(new Ui::ResultWidget)
@ -12,3 +14,8 @@ ResultWidget::~ResultWidget()
{ {
delete ui; delete ui;
} }
void ResultWidget::setModel(ResultModel *model)
{
ui->resultTableView->setModel(model);
}

View file

@ -2,6 +2,8 @@
#include <QWidget> #include <QWidget>
class ResultModel;
namespace Ui { namespace Ui {
class ResultWidget; class ResultWidget;
}; };
@ -16,4 +18,6 @@ private:
public: public:
ResultWidget(QWidget *parent = nullptr); ResultWidget(QWidget *parent = nullptr);
~ResultWidget(); ~ResultWidget();
void setModel(ResultModel *model);
}; };

View file

@ -13,7 +13,11 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"/> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="resultTableView"/>
</item>
</layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

View file

@ -35,6 +35,7 @@ void MainWindow::newFile()
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->resultWidget->setModel(&m_dataModel->m_results);
m_filename = ""; m_filename = "";
} }

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>905</width> <width>905</width>
<height>277</height> <height>572</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -16,7 +16,7 @@
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="testTabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>3</number>
</property> </property>
@ -62,18 +62,35 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="QTabWidget" name="resultTabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<property name="tabBarAutoHide">
<bool>false</bool>
</property>
<widget class="QWidget" name="prTab">
<attribute name="title">
<string>Prozentränge (PR)</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item> <item>
<widget class="ResultWidget" name="resultWidget" native="true"/> <widget class="ResultWidget" name="resultWidget" native="true"/>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>905</width> <width>905</width>
<height>17</height> <height>19</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">