Merge branch 'develop' into feature/print-as-qtextdocument

feature/print-as-qtextdocument
mandlm 2018-12-08 17:02:46 +01:00
commit e2237110cf
5 changed files with 72 additions and 38 deletions

View File

@ -34,7 +34,7 @@ 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
${LOGO_TEST_UI}

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

@ -1,8 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "DataModel.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
@ -21,16 +19,45 @@
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);
newFile();
connect(&m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
}
MainWindow::~MainWindow()
@ -42,21 +69,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 +84,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 + "[*]");
@ -142,7 +159,9 @@ void MainWindow::print() const
QTextDocument printDoc;
QTextCursor printCursor(&printDoc);
m_dataModel->printTo(printCursor);
m_dataModel.printTo(printCursor);
printDoc.print(&printer);
printDoc.print(&printer);
}
@ -162,7 +181,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;

View File

@ -1,8 +1,10 @@
#pragma once
#include <QMainWindow>
#include "DataModel.h"
#include <QMainWindow>
#include <QString>
#include <memory>
class DataModel;
class QDataWidgetMapper;
@ -17,17 +19,19 @@ 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();
@ -38,5 +42,6 @@ protected:
void closeEvent(QCloseEvent *event) override;
private:
void setupUi();
void saveFile(const QString &filename);
};