Scan Json create and save.
This commit is contained in:
20
src/json/ScanJson.cpp
Normal file
20
src/json/ScanJson.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by Krad on 2022/5/11.
|
||||
//
|
||||
|
||||
#include "ScanJson.h"
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
void ScanJson::save() {
|
||||
if (!root) return;
|
||||
QFile f(QString("%1/%2.json").arg(QCoreApplication::applicationDirPath(),scanID.c_str()));
|
||||
f.open(QFileDevice::ReadWrite);
|
||||
cJSON_AddItemToObject(root, "EmptyScanID", cJSON_CreateString(emptyScanID.c_str()));
|
||||
cJSON_AddItemToObject(root, "ScanID", cJSON_CreateString(scanID.c_str()));
|
||||
char* content = cJSON_Print(root);
|
||||
f.write(content);
|
||||
f.flush();
|
||||
f.close();
|
||||
free(content);
|
||||
}
|
||||
44
src/json/ScanJson.h
Normal file
44
src/json/ScanJson.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// Created by Krad on 2022/5/11.
|
||||
//
|
||||
|
||||
#ifndef GUI_SCANJSON_H
|
||||
#define GUI_SCANJSON_H
|
||||
|
||||
#include <string>
|
||||
#include "cJSON.h"
|
||||
|
||||
class ScanJson {
|
||||
public:
|
||||
~ScanJson(){
|
||||
if(root)cJSON_Delete(root);
|
||||
}
|
||||
void store(cJSON* json){
|
||||
if(root){
|
||||
cJSON_Delete(root);
|
||||
root = nullptr;
|
||||
}
|
||||
root = json;
|
||||
}
|
||||
void setScanID(const char * id){
|
||||
scanID.clear();
|
||||
scanID.append(id);
|
||||
}
|
||||
void setEmptyScanID(const char * id){
|
||||
emptyScanID.clear();
|
||||
emptyScanID.append(id);
|
||||
setScanID(id);
|
||||
}
|
||||
void save();
|
||||
static ScanJson* Current(){
|
||||
static ScanJson instance;
|
||||
return &instance;
|
||||
}
|
||||
private:
|
||||
std::string emptyScanID;
|
||||
std::string scanID;
|
||||
cJSON* root = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //GUI_SCANJSON_H
|
||||
Reference in New Issue
Block a user