2018-05-10 16:41:14 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
2018-05-16 05:02:12 +00:00
|
|
|
#include "DataModel.h"
|
2018-05-15 12:24:15 +00:00
|
|
|
#include "MetaDataModel.h"
|
2018-05-16 05:02:12 +00:00
|
|
|
|
2018-05-15 11:11:40 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileDialog>
|
2018-05-15 12:24:15 +00:00
|
|
|
#include <QDataWidgetMapper>
|
2018-05-15 11:11:40 +00:00
|
|
|
|
2018-05-10 16:41:14 +00:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2018-05-16 05:02:12 +00:00
|
|
|
: QMainWindow(parent), ui(new Ui::MainWindow),
|
|
|
|
m_dataModel(new DataModel(parent))
|
|
|
|
, m_widgetMapper(new QDataWidgetMapper(parent))
|
2018-05-10 16:41:14 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-05-15 11:11:40 +00:00
|
|
|
|
|
|
|
ui->actionSave_as->setIcon(QIcon::fromTheme("document-save-as", QIcon("/usr/share/gtk-doc/html/gtk2/document-save-as.png")));
|
2018-05-16 05:02:12 +00:00
|
|
|
ui->actionLoad->setIcon(QIcon::fromTheme("document-open", QIcon("/usr/share/gtk-doc/html/gtk2/document-open.png")));
|
2018-05-15 12:24:15 +00:00
|
|
|
|
2018-05-16 05:02:12 +00:00
|
|
|
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
|
|
|
|
connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(load()));
|
2018-05-15 12:24:15 +00:00
|
|
|
|
2018-05-16 05:02:12 +00:00
|
|
|
m_widgetMapper->setModel(&m_dataModel->m_metaData);
|
|
|
|
m_widgetMapper->addMapping(ui->lineEdit, 0);
|
|
|
|
m_widgetMapper->addMapping(ui->lineEdit_2, 1);
|
2018-05-17 07:22:52 +00:00
|
|
|
m_widgetMapper->addMapping(ui->dateEdit, 2);
|
|
|
|
m_widgetMapper->addMapping(ui->dateEdit_2, 3);
|
2018-05-17 17:42:35 +00:00
|
|
|
m_widgetMapper->addMapping(ui->plainTextEdit, 4);
|
2018-05-16 05:02:12 +00:00
|
|
|
m_widgetMapper->toFirst();
|
2018-05-10 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2018-05-15 11:11:40 +00:00
|
|
|
void MainWindow::saveAs()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getSaveFileName(this);
|
|
|
|
if (filename.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-05-10 16:41:14 +00:00
|
|
|
|
2018-05-15 11:11:40 +00:00
|
|
|
QJsonObject saveData;
|
2018-05-16 05:02:12 +00:00
|
|
|
m_dataModel->write(saveData);
|
2018-05-15 11:11:40 +00:00
|
|
|
|
|
|
|
QJsonDocument saveDoc(saveData);
|
|
|
|
|
|
|
|
QFile saveFile(filename);
|
|
|
|
saveFile.open(QFile::WriteOnly);
|
|
|
|
saveFile.write(saveDoc.toJson());
|
|
|
|
saveFile.close();
|
|
|
|
}
|
2018-05-16 05:02:12 +00:00
|
|
|
|
|
|
|
void MainWindow::load()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getOpenFileName(this);
|
|
|
|
if (filename.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile loadFile(filename);
|
|
|
|
if (!loadFile.open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
qWarning("Could not open file");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray byteData = loadFile.readAll();
|
|
|
|
QJsonDocument loadDoc = QJsonDocument::fromJson(byteData);
|
|
|
|
|
|
|
|
m_dataModel->read(loadDoc.object());
|
|
|
|
|
|
|
|
m_widgetMapper->toFirst();
|
|
|
|
}
|