|
|
|
|
#include "lpGlobalConfig.h"
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
|
|
|
|
lpGlobalConfig::lpGlobalConfig(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
m_rootPath = QApplication::applicationDirPath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lpGlobalConfig::~lpGlobalConfig()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lpGlobalConfig::readConfig()
|
|
|
|
|
{
|
|
|
|
|
QString strPath = m_rootPath + "/user/globalConfig.json";
|
|
|
|
|
QFile file(strPath);
|
|
|
|
|
if (true == file.open(QIODevice::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
QByteArray readData = file.readAll();
|
|
|
|
|
QJsonObject rootObj = QJsonDocument::fromJson(readData).object();
|
|
|
|
|
if (!rootObj.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QString strCam1 = rootObj.value("station_camkey_1").toString();
|
|
|
|
|
QString strCam2 = rootObj.value("station_camkey_2").toString();
|
|
|
|
|
QString strSolution1 = rootObj.value("station_solution_1").toString();
|
|
|
|
|
QString strSolution2 = rootObj.value("station_solution_2").toString();
|
|
|
|
|
QString strRunModel1 = rootObj.value("station_runModel_1").toString();
|
|
|
|
|
QString strRunModel2 = rootObj.value("station_runModel_2").toString();
|
|
|
|
|
m_StationCamKey_1 = strCam1;
|
|
|
|
|
m_StationCamKey_2 = strCam2;
|
|
|
|
|
m_StationSolution_1 = strSolution1;
|
|
|
|
|
m_StationSolution_2 = strSolution2;
|
|
|
|
|
m_StationRunModel_1 = strRunModel1;
|
|
|
|
|
m_StationRunModel_2 = strRunModel2;
|
|
|
|
|
|
|
|
|
|
m_bOnlineMode = rootObj.value("onlineMode").toBool(false);
|
|
|
|
|
|
|
|
|
|
int p1x_1 = rootObj.value("point1_x_1").toInt(0);
|
|
|
|
|
int p1y_1 = rootObj.value("point1_y_1").toInt(0);
|
|
|
|
|
int p2x_1 = rootObj.value("point2_x_1").toInt(100);
|
|
|
|
|
int p2y_1 = rootObj.value("point2_y_1").toInt(100);
|
|
|
|
|
double length_1 = rootObj.value("length_1").toDouble(1000);
|
|
|
|
|
point1_1.setX(p1x_1);
|
|
|
|
|
point1_1.setY(p1y_1);
|
|
|
|
|
point2_1.setX(p2x_1);
|
|
|
|
|
point2_1.setY(p2y_1);
|
|
|
|
|
fLength_1 = length_1;
|
|
|
|
|
m_StationScale_1 = rootObj.value("StationScale_1").toDouble(1.0);
|
|
|
|
|
m_StationXOffset_1 = rootObj.value("StationXOffset_1").toDouble(0.0);
|
|
|
|
|
m_StationYOffset_1 = rootObj.value("StationYOffset_1").toDouble(0.0);
|
|
|
|
|
|
|
|
|
|
int p1x_2 = rootObj.value("point1_x_2").toInt(0);
|
|
|
|
|
int p1y_2 = rootObj.value("point1_y_2").toInt(0);
|
|
|
|
|
int p2x_2 = rootObj.value("point2_x_2").toInt(100);
|
|
|
|
|
int p2y_2 = rootObj.value("point2_y_2").toInt(100);
|
|
|
|
|
double length_2 = rootObj.value("length_2").toDouble(1000);
|
|
|
|
|
point1_2.setX(p1x_2);
|
|
|
|
|
point1_2.setY(p1y_2);
|
|
|
|
|
point2_2.setX(p2x_2);
|
|
|
|
|
point2_2.setY(p2y_2);
|
|
|
|
|
fLength_2 = length_2;
|
|
|
|
|
m_StationScale_2 = rootObj.value("StationScale_2").toDouble(1.0);
|
|
|
|
|
m_StationXOffset_2 = rootObj.value("StationXOffset_2").toDouble(0.0);
|
|
|
|
|
m_StationYOffset_2 = rootObj.value("StationYOffset_2").toDouble(0.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lpGlobalConfig::writeConfig()
|
|
|
|
|
{
|
|
|
|
|
QString strPath = m_rootPath + "/user/globalConfig.json";
|
|
|
|
|
QFile file(strPath);
|
|
|
|
|
if (true == file.open(QIODevice::WriteOnly))
|
|
|
|
|
{
|
|
|
|
|
QJsonObject rootObj;
|
|
|
|
|
rootObj.insert("station_camkey_1", m_StationCamKey_1);
|
|
|
|
|
rootObj.insert("station_camkey_2", m_StationCamKey_2);
|
|
|
|
|
rootObj.insert("station_solution_1", m_StationSolution_1);
|
|
|
|
|
rootObj.insert("station_solution_2", m_StationSolution_2);
|
|
|
|
|
rootObj.insert("station_runModel_1", m_StationRunModel_1);
|
|
|
|
|
rootObj.insert("station_runModel_2", m_StationRunModel_2);
|
|
|
|
|
|
|
|
|
|
rootObj.insert("onlineMode", m_bOnlineMode);
|
|
|
|
|
|
|
|
|
|
rootObj.insert("point1_x_1", point1_1.x());
|
|
|
|
|
rootObj.insert("point1_y_1", point1_1.y());
|
|
|
|
|
rootObj.insert("point2_x_1", point2_1.x());
|
|
|
|
|
rootObj.insert("point2_y_1", point2_1.y());
|
|
|
|
|
rootObj.insert("length_1", fLength_1);
|
|
|
|
|
|
|
|
|
|
rootObj.insert("StationScale_1",m_StationScale_1);
|
|
|
|
|
rootObj.insert("StationXOffset_1",m_StationXOffset_1);
|
|
|
|
|
rootObj.insert("StationYOffset_1",m_StationYOffset_1);
|
|
|
|
|
|
|
|
|
|
rootObj.insert("point1_x_2", point1_2.x());
|
|
|
|
|
rootObj.insert("point1_y_2", point1_2.y());
|
|
|
|
|
rootObj.insert("point2_x_2", point2_2.x());
|
|
|
|
|
rootObj.insert("point2_y_2", point2_2.y());
|
|
|
|
|
rootObj.insert("length_2", fLength_2);
|
|
|
|
|
|
|
|
|
|
rootObj.insert("StationScale_2",m_StationScale_2);
|
|
|
|
|
rootObj.insert("StationXOffset_2",m_StationXOffset_2);
|
|
|
|
|
rootObj.insert("StationYOffset_2",m_StationYOffset_2);
|
|
|
|
|
|
|
|
|
|
QJsonDocument doc(rootObj);
|
|
|
|
|
QByteArray writeData = doc.toJson();
|
|
|
|
|
file.write(writeData);
|
|
|
|
|
}
|
|
|
|
|
file.close();
|
|
|
|
|
}
|