added save as action to menu and toolbar, extended testdata
parent
dd269fdb84
commit
dd28d94043
|
@ -17,6 +17,10 @@ add_executable(${PROJECT_NAME}
|
|||
${UI_HEADERS}
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
PROPERTIES CXX_STANDARD 14
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
|
|
|
@ -1,24 +1,8 @@
|
|||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
#include "testdata.h"
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QFile>
|
||||
|
||||
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);
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include "testdata.h"
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow)
|
||||
{
|
||||
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()
|
||||
|
@ -13,4 +22,22 @@ MainWindow::~MainWindow()
|
|||
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>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
class MainWindow;
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
public slots:
|
||||
void saveAs();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
|
|
@ -115,8 +115,35 @@
|
|||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="actionSave_as"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
<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>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
void TestData::Meta::write(QJsonObject &json)
|
||||
{
|
||||
json["participant"] = m_participant;
|
||||
json["instructor"] = m_instructor;
|
||||
json["participant name"] = m_participant;
|
||||
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)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
#include <QDate>
|
||||
|
||||
class TestData
|
||||
{
|
||||
|
@ -11,6 +12,9 @@ private:
|
|||
private:
|
||||
QString m_participant;
|
||||
QString m_instructor;
|
||||
QDate m_dateOfBirth;
|
||||
QDate m_dateOfTest;
|
||||
QString m_remarks;
|
||||
|
||||
public:
|
||||
void write(QJsonObject &json);
|
||||
|
|
Loading…
Reference in New Issue