This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
ESGRAF48/source/mainwindow.cpp

71 lines
1.3 KiB
C++
Raw Normal View History

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"
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
#include <QFileDialog>
#include <QDataWidgetMapper>
2018-05-10 16:41:14 +00:00
MainWindow::MainWindow(QWidget *parent)
2018-05-18 17:51:48 +00:00
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_dataModel(new DataModel(parent))
2018-05-10 16:41:14 +00:00
{
ui->setupUi(this);
2018-05-16 05:02:12 +00:00
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
2018-05-18 18:12:48 +00:00
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(load()));
2018-05-18 17:51:48 +00:00
ui->metaDataWidget->setModel(&m_dataModel->m_metaData);
2018-05-10 16:41:14 +00:00
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::saveAs()
{
QString filename = QFileDialog::getSaveFileName(this);
if (filename.isEmpty())
{
return;
}
2018-05-10 16:41:14 +00:00
QJsonObject saveData;
2018-05-16 05:02:12 +00:00
m_dataModel->write(saveData);
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());
2018-05-18 17:51:48 +00:00
ui->metaDataWidget->toFirst();
2018-05-16 05:02:12 +00:00
}