Merge pull request #18 from mandlm/develop

Develop
This commit is contained in:
mandlm 2019-01-24 20:21:06 +01:00 committed by GitHub
commit e5232aee9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 219 additions and 48 deletions

View file

@ -6,3 +6,4 @@ include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_subdirectory(source)
add_subdirectory(test)

View file

@ -1,5 +1,6 @@
[requires]
protobuf/3.6.1@bincrafters/stable
catch2/2.4.2@bincrafters/stable
[generators]
cmake

23
source/Age/CMakeLists.txt Normal file
View file

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.6)
project(Age LANGUAGES CXX)
find_package(Qt5Core REQUIRED)
add_library(${PROJECT_NAME}
Age.cpp
)
set_target_properties(${PROJECT_NAME}
PROPERTIES CXX_STANDARD 14
)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
)

View file

@ -34,10 +34,9 @@ protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS
${DataModel_PROTO_FILES})
add_executable(${PROJECT_NAME} WIN32
LogoTest.cpp
ESGRAF48.cpp
DataModel.cpp
mainwindow.cpp
Age.cpp
${LOGO_TEST_UI}
${LOGO_TEST_QRC}
${DataModel_PROTO_SRCS}
@ -57,6 +56,7 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
Age
CheckableItem
CheckableTest
CheckableTestModel
@ -73,6 +73,7 @@ target_link_libraries(${PROJECT_NAME}
${Protobuf_LIBRARIES}
)
add_subdirectory(Age)
add_subdirectory(CheckableItem)
add_subdirectory(CheckableTest)
add_subdirectory(CheckableTestModel)

21
source/ESGRAF48.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
std::unique_ptr<MainWindow> mainWindow;
if (argc < 2)
{
mainWindow = std::make_unique<MainWindow>(nullptr);
}
else
{
mainWindow = std::make_unique<MainWindow>(nullptr, argv[1]);
}
mainWindow->show();
return app.exec();
}

View file

@ -1,11 +0,0 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}

View file

@ -41,6 +41,7 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
Age
Qt5::Widgets
${Protobuf_LIBRARIES}
)

View file

@ -1,6 +1,6 @@
#pragma once
#include "../Age.h"
#include "Age.h"
#include "MetaDataModel.pb.h"

View file

@ -30,5 +30,6 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
Age
Qt5::Widgets
)

View file

@ -1,6 +1,6 @@
#pragma once
#include "../Age.h"
#include "Age.h"
#include <vector>
class PRMap

View file

@ -1,6 +1,6 @@
#pragma once
#include "../Age.h"
#include "Age.h"
#include <QAbstractTableModel>
class TestResult

View file

@ -1,8 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "DataModel.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
@ -21,16 +19,46 @@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_dataModel(this)
{
ui->setupUi(this);
setupUi();
newFile();
}
MainWindow::MainWindow(QWidget *parent, const QString &filename)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_dataModel(this)
{
ui->setupUi(this);
setupUi();
openFile(filename);
}
void MainWindow::setupUi()
{
ui->metaDataWidget->setModel(&m_dataModel.m_metaData);
ui->verbEndWidget->setModel(&m_dataModel.m_verbEnd);
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->lateSkillsWidget->setPassivModel(&m_dataModel.m_passiv);
ui->lateSkillsWidget->setGenitivModel(&m_dataModel.m_genitiv);
ui->resultWidget->setModel(&m_dataModel.m_results);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile);
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openFile);
connect(ui->actionOpen, &QAction::triggered, this, qOverload<>(&MainWindow::openFile));
connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile));
connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs);
connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print);
connect(ui->actionExport_PDF, &QAction::triggered, this, qOverload<>(&MainWindow::savePdf));
newFile();
connect(&m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
}
MainWindow::~MainWindow()
@ -42,21 +70,6 @@ void MainWindow::newFile()
{
closeFile();
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);
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->lateSkillsWidget->setPassivModel(&m_dataModel->m_passiv);
ui->lateSkillsWidget->setGenitivModel(&m_dataModel->m_genitiv);
ui->resultWidget->setModel(&m_dataModel->m_results);
connect(&*m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
setWindowModified(false);
setWindowTitle("untitled[*]");
m_filename = "";
@ -72,10 +85,15 @@ void MainWindow::openFile()
return;
}
openFile(filename);
}
void MainWindow::openFile(const QString &filename)
{
closeFile();
std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary);
m_dataModel->read(protoInFile);
m_dataModel.read(protoInFile);
setWindowModified(false);
setWindowTitle(filename + "[*]");
@ -133,7 +151,7 @@ void MainWindow::closeFile()
void MainWindow::print() const
{
//std::ofstream htmlfile("print.html");
//htmlfile << m_dataModel->toHtml();
//htmlfile << m_dataModel.toHtml();
QPrinter printer;
@ -144,7 +162,7 @@ void MainWindow::print() const
}
QTextDocument printDoc;
printDoc.setHtml(QString::fromStdString(m_dataModel->toHtml()));
printDoc.setHtml(QString::fromStdString(m_dataModel.toHtml()));
printDoc.print(&printer);
}
@ -155,6 +173,22 @@ void MainWindow::dataModelChanged()
setWindowModified(true);
}
void MainWindow::savePdf()
{
QFileDialog saveFilenameDialog(this);
saveFilenameDialog.setDefaultSuffix("pdf");
saveFilenameDialog.setFileMode(QFileDialog::AnyFile);
saveFilenameDialog.setNameFilter("PDF File (*.pdf)");
saveFilenameDialog.setWindowTitle("Save file");
if (!saveFilenameDialog.exec())
{
return;
}
savePdf(saveFilenameDialog.selectedFiles().first());
}
void MainWindow::closeEvent(QCloseEvent *event)
{
closeFile();
@ -164,7 +198,7 @@ void MainWindow::saveFile(const QString &filename)
{
std::fstream protoOutFile(filename.toStdString(),
std::ios::out | std::ios::trunc | std::ios::binary);
m_dataModel->write(protoOutFile);
m_dataModel.write(protoOutFile);
qDebug() << "Wrote" << filename;
@ -173,3 +207,16 @@ void MainWindow::saveFile(const QString &filename)
m_filename = filename;
m_saveOnClose = false;
}
void MainWindow::savePdf(const QString &filename)
{
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(filename);
QTextDocument printDoc;
printDoc.setHtml(QString::fromStdString(m_dataModel.toHtml()));
printDoc.print(&printer);
}

View file

@ -1,8 +1,10 @@
#pragma once
#include <QMainWindow>
#include "DataModel.h"
#include <QMainWindow>
#include <QString>
#include <memory>
class DataModel;
class QDataWidgetMapper;
@ -17,26 +19,31 @@ class MainWindow : public QMainWindow
private:
Ui::MainWindow *ui;
std::unique_ptr<DataModel> m_dataModel;
DataModel m_dataModel;
QString m_filename;
bool m_saveOnClose = false;
public:
MainWindow(QWidget *parent = nullptr);
MainWindow(QWidget *parent);
MainWindow(QWidget *parent, const QString &filename);
~MainWindow();
public slots:
void newFile();
void openFile();
void openFile(const QString &filename);
void saveFile();
void saveFileAs();
void closeFile();
void print() const;
void dataModelChanged();
void savePdf();
protected:
void closeEvent(QCloseEvent *event) override;
private:
void setupUi();
void saveFile(const QString &filename);
void savePdf(const QString &filename);
};

View file

@ -133,6 +133,7 @@
<addaction name="actionSave_as"/>
<addaction name="separator"/>
<addaction name="actionPrint"/>
<addaction name="actionExport_PDF"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
@ -228,6 +229,14 @@
<string>Ctrl+P</string>
</property>
</action>
<action name="actionExport_PDF">
<property name="text">
<string>Export PDF</string>
</property>
<property name="toolTip">
<string>Export as PDF file</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

40
test/Age.cpp Normal file
View file

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

21
test/CMakeLists.txt Normal file
View file

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.5)
project(run-tests)
find_package(Catch2 REQUIRED)
add_executable(${PROJECT_NAME}
main.cpp
dummy.cpp
Age.cpp
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
Catch2::Catch2
Age
)
include(CTest)
include(Catch)
catch_discover_tests(${PROJECT_NAME})

7
test/dummy.cpp Normal file
View file

@ -0,0 +1,7 @@
#include <catch2/catch.hpp>
TEST_CASE("Dummy")
{
REQUIRE(true == true);
}

2
test/main.cpp Normal file
View file

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>