|
|
@@ -7,6 +7,8 @@
|
|
|
#include <QSqlDatabase>
|
|
|
#include <QSqlQuery>
|
|
|
#include <QSqlError>
|
|
|
+#include <QTextStream>
|
|
|
+#include <QRegularExpression>
|
|
|
#define READ_INI_STR(key, default_value) (settings.contains(key) ? settings.value(key).toString() : default_value)
|
|
|
#define READ_INI_INT(key, default_value) (settings.contains(key) ? settings.value(key).toInt() : default_value)
|
|
|
|
|
|
@@ -25,6 +27,7 @@ pdu_Ctrl::pdu_Ctrl(QObject *parent) : QObject(parent)
|
|
|
nChidPHIndex=0;
|
|
|
m_nAngle=0;
|
|
|
isT_ACType=0;
|
|
|
+ m_nSaveAngle=0;
|
|
|
memset(nButtonStatus,0,sizeof(nButtonStatus));
|
|
|
//
|
|
|
}
|
|
|
@@ -37,6 +40,11 @@ void pdu_Ctrl::slot_setAngel(int nAngle)
|
|
|
//m_pAngleCtrl->transform(width() / 2, height() / 2);
|
|
|
m_pAngleCtrl->setRotation(nAngle);
|
|
|
m_nAngle=nAngle;
|
|
|
+ if(m_nAngle!=m_nSaveAngle)
|
|
|
+ {
|
|
|
+ m_nSaveAngle=m_nAngle;
|
|
|
+ SetPDUInit();
|
|
|
+ }
|
|
|
if(nAngle==0||nAngle==180)
|
|
|
{
|
|
|
m_pWidget->resize(m_nWidth, m_nHeight);
|
|
|
@@ -97,7 +105,7 @@ void pdu_Ctrl::InitData(Widget *pWidget, QGraphicsProxyWidget *pProxy, QGraphics
|
|
|
|
|
|
void pdu_Ctrl::ReadModbusInit()
|
|
|
{
|
|
|
- QSettings settings("./AppConfig.ini",QSettings::IniFormat);
|
|
|
+ QSettings settings("/root/run/app/smartPDU.ini",QSettings::IniFormat);
|
|
|
m_nModbusAddress=READ_INI_INT("MODBUS/address",0);
|
|
|
if(m_nModbusAddress>255||m_nModbusAddress<0)
|
|
|
{
|
|
|
@@ -137,13 +145,17 @@ void pdu_Ctrl::ReadModbusInit()
|
|
|
}
|
|
|
m_db.close();
|
|
|
qDebug()<<"modbus m_nModbusMSType="<<m_nModbusMSType<<" m_nModbusAddress="<<m_nModbusAddress;
|
|
|
+
|
|
|
+ ReadPDUinit();
|
|
|
}
|
|
|
|
|
|
void pdu_Ctrl::SaveModbusInit()
|
|
|
{
|
|
|
- QSettings settings("./AppConfig.ini",QSettings::IniFormat);
|
|
|
- settings.setValue("MODBUS/address",m_nModbusAddress);
|
|
|
- settings.setValue("MODBUS/MSType",m_nModbusMSType);//0:主机,1:从机
|
|
|
+ //QSettings settings("/root/run/app/smartPDU.ini",QSettings::IniFormat);
|
|
|
+ updateIniValue("/root/run/app/smartPDU.ini","MODBUS","address",QString::number(m_nModbusAddress));
|
|
|
+ updateIniValue("/root/run/app/smartPDU.ini","MODBUS","MSType",QString::number(m_nModbusMSType));
|
|
|
+ //settings.setValue("MODBUS/address",m_nModbusAddress);
|
|
|
+ //settings.setValue("MODBUS/MSType",m_nModbusMSType);//0:主机,1:从机
|
|
|
QSqlDatabase m_db;
|
|
|
m_db=QSqlDatabase::addDatabase("QSQLITE");
|
|
|
m_db.setDatabaseName(strSqliteAddress);
|
|
|
@@ -173,6 +185,73 @@ void pdu_Ctrl::SaveModbusInit()
|
|
|
|
|
|
}
|
|
|
|
|
|
+void pdu_Ctrl::ReadPDUinit()
|
|
|
+{
|
|
|
+ qDebug()<<"Read misc/rotate";
|
|
|
+ QSettings settings("/root/run/app/smartPDU.ini",QSettings::IniFormat);
|
|
|
+ QString strRotate=READ_INI_STR("misc/rotate","0");
|
|
|
+ qDebug()<<"misc/rotate="<<strRotate;
|
|
|
+ if(!strRotate.isEmpty())
|
|
|
+ {
|
|
|
+ m_nSaveAngle=strRotate.toInt();
|
|
|
+ qDebug()<<"InitAngleStr="<<strRotate<<"InitAngleToint="<<m_nSaveAngle;
|
|
|
+ m_nAngle=m_nSaveAngle;
|
|
|
+ slot_setAngel(m_nAngle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug()<<"InitAngleStr="<<strRotate;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void pdu_Ctrl::SetPDUInit()
|
|
|
+{
|
|
|
+ //QSettings settings("/root/run/app/smartPDU.ini",QSettings::IniFormat);
|
|
|
+ QString strValue="\""+QString::number(m_nSaveAngle)+"\"";
|
|
|
+ //settings.setValue("misc/rotate",strValue);
|
|
|
+ updateIniValue("/root/run/app/smartPDU.ini","misc","rotate",strValue);
|
|
|
+}
|
|
|
+
|
|
|
+bool pdu_Ctrl::updateIniValue(const QString &filePath, const QString §ion, const QString &key, const QString &newValue)
|
|
|
+{
|
|
|
+ QFile file(filePath);
|
|
|
+ if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ QTextStream in(&file);
|
|
|
+ QStringList lines;
|
|
|
+ bool inTargetSection = false;
|
|
|
+ QRegularExpression sectionRe(R"(^\[(.*)\]\s*$)");
|
|
|
+ QRegularExpression keyRe(R"(^\s*([^=]+)\s*=\s*(.*)\s*$)");
|
|
|
+
|
|
|
+ // 逐行读取并处理
|
|
|
+ while (!in.atEnd()) {
|
|
|
+ QString line = in.readLine();
|
|
|
+ QRegularExpressionMatch sectionMatch = sectionRe.match(line);
|
|
|
+ if (sectionMatch.hasMatch()) {
|
|
|
+ inTargetSection = (sectionMatch.captured(1) == section);
|
|
|
+ } else if (inTargetSection) {
|
|
|
+ QRegularExpressionMatch keyMatch = keyRe.match(line);
|
|
|
+ if (keyMatch.hasMatch() && keyMatch.captured(1).trimmed() == key) {
|
|
|
+ // 替换目标键的值,保留原格式(如双引号)
|
|
|
+ line = QString("%1 = %2").arg(key, newValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lines.append(line);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写回文件
|
|
|
+ file.resize(0); // 清空原内容
|
|
|
+ QTextStream out(&file);
|
|
|
+ for (const QString& line : lines) {
|
|
|
+ out << line << "\n";
|
|
|
+ }
|
|
|
+ file.close();
|
|
|
+ return true;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
void pdu_Ctrl::Main_UPBtnSet(BtnDownType nbtnType)
|
|
|
{
|
|
|
qDebug()<<"Main_UPBtnSet";
|