You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.0 KiB
C++
111 lines
3.0 KiB
C++
#include "QExposureTimeDlg.h"
|
|
#include <QFileDialog>
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
QExposureTimeDlg::QExposureTimeDlg(QWidget* parent) : QWidget(parent)
|
|
{
|
|
ui.setupUi(this);
|
|
ui.appliedLabel->setVisible(false);
|
|
connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
}
|
|
QExposureTimeDlg::~QExposureTimeDlg()
|
|
{
|
|
}
|
|
|
|
Q_SLOT void QExposureTimeDlg::onButtonClicked()
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if (strObj == "m_pbApply")
|
|
{
|
|
QString strPath = QApplication::applicationDirPath();
|
|
savaParam(strPath);
|
|
ui.appliedLabel->setVisible(true);
|
|
m_timeID = startTimer(1000);
|
|
emit sgExpsParamChange();
|
|
}
|
|
else if (strObj == "m_pbExit")
|
|
{
|
|
close();
|
|
}
|
|
}
|
|
|
|
void QExposureTimeDlg::showEvent(QShowEvent *event)
|
|
{
|
|
QString strPath = QApplication::applicationDirPath();
|
|
if (!showParam(strPath))
|
|
{
|
|
}
|
|
}
|
|
void QExposureTimeDlg::timerEvent(QTimerEvent *event)
|
|
{
|
|
if (m_timeID == event->timerId())
|
|
{
|
|
killTimer(m_timeID);
|
|
m_timeID = 0;
|
|
ui.appliedLabel->setVisible(false);
|
|
}
|
|
}
|
|
|
|
bool QExposureTimeDlg::showParam(const QString& strPath)
|
|
{
|
|
QString filePath = strPath + "\\config\\exposure.json";
|
|
QJsonObject jsonObj = QZkJsonParser::ReadJsonAuto(filePath);
|
|
if (jsonObj.empty())
|
|
{
|
|
qDebug() << "Json file parsing failed!";
|
|
return false;
|
|
}
|
|
|
|
QJsonObject exposureObj = jsonObj.value("exposureTime").toObject();
|
|
|
|
QJsonObject::iterator objIterEnd = exposureObj.end();
|
|
std::vector<int> exposureTimeVec;
|
|
for (auto objIter = exposureObj.begin(); objIter != objIterEnd; objIter++)
|
|
{
|
|
int exposureTime = objIter.value().toInt();
|
|
exposureTimeVec.emplace_back(exposureTime);
|
|
}
|
|
const unsigned int nSize = exposureTimeVec.size();
|
|
if (nSize == 5)
|
|
{
|
|
ui.exposureTime1->setValue(exposureTimeVec[0]);
|
|
ui.exposureTime2->setValue(exposureTimeVec[1]);
|
|
ui.exposureTime3->setValue(exposureTimeVec[2]);
|
|
ui.exposureTime4->setValue(exposureTimeVec[3]);
|
|
ui.exposureTime5->setValue(exposureTimeVec[4]);
|
|
}
|
|
int switchFlag = jsonObj.value("switch").toInt();
|
|
ui.multiExpSwitch->setChecked(switchFlag > 0 ? true : false);
|
|
return true;
|
|
}
|
|
|
|
void QExposureTimeDlg::savaParam(const QString& strPath)
|
|
{
|
|
QString filePath = strPath + "\\config\\exposure.json";
|
|
QJsonObject jsonObj;
|
|
|
|
//QJsonArray jsonArr;
|
|
QJsonObject expsObj;
|
|
int exposureTime1 = ui.exposureTime1->value();
|
|
int exposureTime2 = ui.exposureTime2->value();
|
|
int exposureTime3 = ui.exposureTime3->value();
|
|
int exposureTime4 = ui.exposureTime4->value();
|
|
int exposureTime5 = ui.exposureTime5->value();
|
|
expsObj.insert("time1", exposureTime1);
|
|
expsObj.insert("time2", exposureTime2);
|
|
expsObj.insert("time3", exposureTime3);
|
|
expsObj.insert("time4", exposureTime4);
|
|
expsObj.insert("time5", exposureTime5);
|
|
|
|
jsonObj.insert("exposureTime", expsObj);
|
|
int switchFlag = ui.multiExpSwitch->isChecked();
|
|
jsonObj.insert("switch", switchFlag);
|
|
QJsonDocument jsonDoc(jsonObj);
|
|
QByteArray data = jsonDoc.toJson();
|
|
QFile jsonFile(filePath);
|
|
jsonFile.open(QIODevice::WriteOnly);
|
|
jsonFile.write(data);
|
|
jsonFile.close();
|
|
} |