From 1aa0fdfd2205fe578e7b8d3cdfa148214189855d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 20 May 2018 12:04:21 +0200 Subject: [PATCH] Added new-file function --- source/MetaData/MetaDataModel.cpp | 2 ++ source/images/document-new.png | Bin 0 -> 736 bytes source/mainwindow.cpp | 48 +++++++++++++++++------------- source/mainwindow.h | 9 ++++-- source/mainwindow.qrc | 1 + source/mainwindow.ui | 43 +++++++++++++++++++++++++- 6 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 source/images/document-new.png diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index eaabd04..cd70d41 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -4,6 +4,8 @@ MetaDataModel::MetaDataModel(QObject *parent) : QAbstractTableModel(parent) { + m_dateOfBirth.setDate(2010, 01, 01); + m_dateOfTest = QDate::currentDate(); } int MetaDataModel::rowCount(const QModelIndex &parent) const diff --git a/source/images/document-new.png b/source/images/document-new.png new file mode 100644 index 0000000000000000000000000000000000000000..c89e797b729c004345d7e50960764724b65539b5 GIT binary patch literal 736 zcmV<60w4W}P)%u~Y(r zXb}_|8`BG=c%ukX-$4{9q76doLzp{zV@x*PwAt}u&t}hl#Z3GlB7)KAFFf)5O^6;q@Ed~j={Z&#>!se0@Ao_1wrp*-9>)b( zH#Q9uXJ=D@e0^d95rMVPpZ^&SVcRy=SDWRPl`E}Ix4pdxpz6vXVlXq9{2)Cz{Oven zl*?t*>vddT+bGp)ms*`}`_V!G6M@wY6A?3V90wwTN~HqZwsE6*t87`-2c2&FPLR)t z1BeNbzuU}rxG+-h<4b)|0w*W}lR4ps~${?^TE3$Q=fuAMBk!B-^8wGo# zD+NIFTdGQgY0_+BM)?5Rf#{(KF2g7XfK+?4N-)P{87%@tOtg#ZMw!iD1`t4qDB0As z=Bsio1<0~VG=G6nEPx3&R7$SoHaUZ5(_JVhYhzJpR zgI|NYhlgMGK7IbUft>#;QkIy8c{CUd?g8*bL`ao|0TfgO#k~+f#SFkqM7)1JxOeC1 SEjfSy0000setupUi(this); - connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs())); - connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(load())); + connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newFile())); + connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile())); + connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveFileAs())); - ui->metaDataWidget->setModel(&m_dataModel->m_metaData); + newFile(); } MainWindow::~MainWindow() @@ -27,26 +27,13 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::saveAs() +void MainWindow::newFile() { - QString filename = QFileDialog::getSaveFileName(this); - if (filename.isEmpty()) - { - return; - } - - QJsonObject saveData; - m_dataModel->write(saveData); - - QJsonDocument saveDoc(saveData); - - QFile saveFile(filename); - saveFile.open(QFile::WriteOnly); - saveFile.write(saveDoc.toJson()); - saveFile.close(); + m_dataModel = std::make_unique(this); + ui->metaDataWidget->setModel(&m_dataModel->m_metaData); } -void MainWindow::load() +void MainWindow::openFile() { QString filename = QFileDialog::getOpenFileName(this); if (filename.isEmpty()) @@ -68,3 +55,22 @@ void MainWindow::load() ui->metaDataWidget->toFirst(); } + +void MainWindow::saveFileAs() +{ + QString filename = QFileDialog::getSaveFileName(this); + if (filename.isEmpty()) + { + return; + } + + QJsonObject saveData; + m_dataModel->write(saveData); + + QJsonDocument saveDoc(saveData); + + QFile saveFile(filename); + saveFile.open(QFile::WriteOnly); + saveFile.write(saveDoc.toJson()); + saveFile.close(); +} diff --git a/source/mainwindow.h b/source/mainwindow.h index c15576c..96c572b 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -2,6 +2,8 @@ #include +#include + class DataModel; class QDataWidgetMapper; @@ -15,13 +17,14 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; - DataModel *m_dataModel; + std::unique_ptr m_dataModel; public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); public slots: - void saveAs(); - void load(); + void newFile(); + void openFile(); + void saveFileAs(); }; diff --git a/source/mainwindow.qrc b/source/mainwindow.qrc index 5459d85..b8f23c7 100644 --- a/source/mainwindow.qrc +++ b/source/mainwindow.qrc @@ -1,5 +1,6 @@ + images/document-new.png images/document-open.png images/document-save-as.png diff --git a/source/mainwindow.ui b/source/mainwindow.ui index da44e69..d114134 100644 --- a/source/mainwindow.ui +++ b/source/mainwindow.ui @@ -52,8 +52,11 @@ &File + + + @@ -67,6 +70,7 @@ false + @@ -97,6 +101,26 @@ Ctrl+O + + + + :/images/document-new.png:/images/document-new.png + + + New + + + Ctrl+N + + + + + Quit + + + Ctrl+Q + + @@ -109,5 +133,22 @@ - + + + actionQuit + triggered() + MainWindow + close() + + + -1 + -1 + + + 399 + 177 + + + +