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 0000000..c89e797 Binary files /dev/null and b/source/images/document-new.png differ diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 15d470f..348e1c5 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -12,14 +12,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) - , m_dataModel(new DataModel(parent)) { ui->setupUi(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 + + + +