added result model

This commit is contained in:
mandlm 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_genus(this)
, m_plural(this)
, m_results(this)
{
}

View File

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

View File

@ -12,7 +12,7 @@ qt5_wrap_ui(GENUS_UI
add_library(${PROJECT_NAME}
ResultWidget.cpp
#ResultModel.cpp
ResultModel.cpp
${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 "ui_ResultWidget.h"
#include "ResultModel.h"
ResultWidget::ResultWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::ResultWidget)
@ -12,3 +14,8 @@ ResultWidget::~ResultWidget()
{
delete ui;
}
void ResultWidget::setModel(ResultModel *model)
{
ui->resultTableView->setModel(model);
}

View File

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

View File

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

View File

@ -35,6 +35,7 @@ void MainWindow::newFile()
ui->verbEndWidget->setModel(&m_dataModel->m_verbEnd);
ui->genusWidget->setModel(&m_dataModel->m_genus);
ui->pluralWidget->setModel(&m_dataModel->m_plural);
ui->resultWidget->setModel(&m_dataModel->m_results);
m_filename = "";
}

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>905</width>
<height>277</height>
<height>572</height>
</rect>
</property>
<property name="windowTitle">
@ -16,7 +16,7 @@
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QTabWidget" name="testTabWidget">
<property name="currentIndex">
<number>3</number>
</property>
@ -63,7 +63,24 @@
</widget>
</item>
<item>
<widget class="ResultWidget" name="resultWidget" native="true"/>
<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>
<widget class="ResultWidget" name="resultWidget" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
@ -73,7 +90,7 @@
<x>0</x>
<y>0</y>
<width>905</width>
<height>17</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">