added save as action to menu and toolbar, extended testdata
This commit is contained in:
parent
dd269fdb84
commit
dd28d94043
@ -17,6 +17,10 @@ add_executable(${PROJECT_NAME}
|
|||||||
${UI_HEADERS}
|
${UI_HEADERS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set_target_properties(${PROJECT_NAME}
|
||||||
|
PROPERTIES CXX_STANDARD 14
|
||||||
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
@ -1,24 +1,8 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "testdata.h"
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QFile>
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
TestData testData;
|
|
||||||
QJsonObject saveData;
|
|
||||||
testData.write(saveData);
|
|
||||||
|
|
||||||
QJsonDocument saveDoc(saveData);
|
|
||||||
|
|
||||||
QFile saveFile("testdata.json");
|
|
||||||
saveFile.open(QFile::WriteOnly);
|
|
||||||
saveFile.write(saveDoc.toJson());
|
|
||||||
saveFile.close();
|
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
MainWindow mainWindow;
|
MainWindow mainWindow;
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#include "testdata.h"
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
, ui(new Ui::MainWindow)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->actionSave_as->setIcon(QIcon::fromTheme("document-save-as", QIcon("/usr/share/gtk-doc/html/gtk2/document-save-as.png")));
|
||||||
|
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -13,4 +22,22 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveAs()
|
||||||
|
{
|
||||||
|
QString filename = QFileDialog::getSaveFileName(this);
|
||||||
|
if (filename.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TestData testData;
|
||||||
|
QJsonObject saveData;
|
||||||
|
testData.write(saveData);
|
||||||
|
|
||||||
|
QJsonDocument saveDoc(saveData);
|
||||||
|
|
||||||
|
QFile saveFile(filename);
|
||||||
|
saveFile.open(QFile::WriteOnly);
|
||||||
|
saveFile.write(saveDoc.toJson());
|
||||||
|
saveFile.close();
|
||||||
|
}
|
||||||
|
@ -3,17 +3,20 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
public slots:
|
||||||
Ui::MainWindow *ui;
|
void saveAs();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::MainWindow *ui;
|
||||||
};
|
};
|
||||||
|
@ -115,8 +115,35 @@
|
|||||||
<height>19</height>
|
<height>19</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuFile">
|
||||||
|
<property name="title">
|
||||||
|
<string>&File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionSave_as"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuFile"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<widget class="QToolBar" name="toolBar">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>toolBar</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionSave_as"/>
|
||||||
|
</widget>
|
||||||
|
<action name="actionSave_as">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save as...</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Save as...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
void TestData::Meta::write(QJsonObject &json)
|
void TestData::Meta::write(QJsonObject &json)
|
||||||
{
|
{
|
||||||
json["participant"] = m_participant;
|
json["participant name"] = m_participant;
|
||||||
json["instructor"] = m_instructor;
|
json["instructor name"] = m_instructor;
|
||||||
|
json["date of birth"] = m_dateOfBirth.toString(Qt::TextDate);
|
||||||
|
json["date of test"] = m_dateOfTest.toString(Qt::TextDate);
|
||||||
|
json["remarks"] = m_remarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestData::SubTest1::write(QJsonObject &json)
|
void TestData::SubTest1::write(QJsonObject &json)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
class TestData
|
class TestData
|
||||||
{
|
{
|
||||||
@ -11,6 +12,9 @@ private:
|
|||||||
private:
|
private:
|
||||||
QString m_participant;
|
QString m_participant;
|
||||||
QString m_instructor;
|
QString m_instructor;
|
||||||
|
QDate m_dateOfBirth;
|
||||||
|
QDate m_dateOfTest;
|
||||||
|
QString m_remarks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void write(QJsonObject &json);
|
void write(QJsonObject &json);
|
||||||
|
Reference in New Issue
Block a user