增加MQTT,优化功能

This commit is contained in:
Zhang0626 2023-04-27 19:48:15 +08:00
parent fd972af89c
commit 3c5d149e78
90 changed files with 4190 additions and 354 deletions

View File

@ -87,6 +87,28 @@ color: rgb(27, 30, 35);</string>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton_confirm">
<property name="minimumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#pushButton_confirm { border-image: url(:/image/Btn/normal_Btn.png);
color:#1f5188 }
#pushButton_confirm:hover { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_confirm:pressed { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_confirm:checked { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}</string>
</property>
<property name="text">
<string>确认</string>
</property>
@ -94,6 +116,28 @@ color: rgb(27, 30, 35);</string>
</item>
<item>
<widget class="QPushButton" name="pushButton_cancel">
<property name="minimumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#pushButton_cancel { border-image: url(:/image/Btn/normal_Btn.png);
color:#1f5188 }
#pushButton_cancel:hover { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_cancel:pressed { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_cancel:checked { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}</string>
</property>
<property name="text">
<string>取消</string>
</property>

66
AlarmDetails.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "AlarmDetails.h"
#include "ui_AlarmDetails.h"
#include <QDateTime>
CAlarmDetails::CAlarmDetails(QWidget *parent) :
QWidget(parent),
ui(new Ui::CAlarmDetails)
{
ui->setupUi(this);
headerStr = QObject::tr("属性,值");
model = new QStandardItemModel(ui->tableView);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行
QStringList headerList = headerStr.split(",");
model->setHorizontalHeaderLabels(headerList);
model->setColumnCount(headerList.size());
ui->tableView->setModel(model);
ui->tableView->setColumnWidth(0, 200);
ui->tableView->setColumnWidth(1, 300);
model->setRowCount(12);
}
CAlarmDetails::~CAlarmDetails()
{
delete ui;
}
void CAlarmDetails::ViewData(TriggerEvent_t& m_vecTriggerEvent)
{
model->setData(model->index(0,0,QModelIndex()),"触发通道名称");
model->setData(model->index(0,1,QModelIndex()),m_vecTriggerEvent.triggeredChannelName);
model->setData(model->index(1,0,QModelIndex()),"触发通道类型");
model->setData(model->index(1,1,QModelIndex()),m_vecTriggerEvent.triggeredType);
model->setData(model->index(2,0,QModelIndex()),"触发值");
model->setData(model->index(2,1,QModelIndex()),m_vecTriggerEvent.triggeredValue);
model->setData(model->index(3,0,QModelIndex()),"触发实际值");
model->setData(model->index(3,1,QModelIndex()),m_vecTriggerEvent.triggeredValue);
model->setData(model->index(4,0,QModelIndex()),"触发提示");
model->setData(model->index(4,1,QModelIndex()),m_vecTriggerEvent.triggeredNotification);
model->setData(model->index(5,0,QModelIndex()),"触发设备号");
model->setData(model->index(5,1,QModelIndex()),m_vecTriggerEvent.triggeredDataWatchNo);
model->setData(model->index(6,0,QModelIndex()),"触发设备名称");
model->setData(model->index(6,1,QModelIndex()),m_vecTriggerEvent.triggeredDataWatchName);
model->setData(model->index(7,0,QModelIndex()),"触发通道号");
model->setData(model->index(7,1,QModelIndex()),m_vecTriggerEvent.triggeredChannelID);
model->setData(model->index(8,0,QModelIndex()),"触发时间");
QString TStr = QDateTime::fromSecsSinceEpoch(m_vecTriggerEvent.triggeredTime).toString("yyyy-MM-dd hh:mm:ss");
model->setData(model->index(8,1,QModelIndex()),TStr);
model->setData(model->index(9,0,QModelIndex()),"设备ID");
model->setData(model->index(9,1,QModelIndex()),m_vecTriggerEvent.triggeredEquipmentID);
model->setData(model->index(10,0,QModelIndex()),"事件名称");
model->setData(model->index(10,1,QModelIndex()),m_vecTriggerEvent.triggeredEventName);
model->setData(model->index(11,0,QModelIndex()),"触发特征值名称");
model->setData(model->index(11,1,QModelIndex()),m_vecTriggerEvent.triggeredFeatureName);
}

32
AlarmDetails.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef ALARMDETAILS_H
#define ALARMDETAILS_H
#include <QWidget>
#include <QStandardItemModel> //数据模型类
#include "TableHeaderView.h"
#include "global.h"
namespace Ui {
class CAlarmDetails;
}
class CAlarmDetails : public QWidget
{
Q_OBJECT
public:
explicit CAlarmDetails(QWidget *parent = nullptr);
~CAlarmDetails();
void ViewData(TriggerEvent_t& m_vecTriggerEvent);
private:
Ui::CAlarmDetails *ui;
TableHeaderView *myHeader;
QStandardItemModel *model;
QString headerStr ;
};
#endif // ALARMDETAILS_H

39
AlarmDetails.ui Normal file
View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CAlarmDetails</class>
<widget class="QWidget" name="CAlarmDetails">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>802</width>
<height>578</height>
</rect>
</property>
<property name="windowTitle">
<string>报警详情</string>
</property>
<property name="styleSheet">
<string notr="true">font: 16pt &quot;黑体&quot;;
color: rgb(27, 30, 35);
</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="tableView">
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -291,8 +291,8 @@ void CBoardSetting::on_Btn_Confirm_clicked()
'%68','%69','%70',%71,%72,%73,'%74','%75','%76','%77','%78','%79','%80','%81','%82','%83','%84',%85,'%86','%87','%88','%89','%90','%91','%92','%93','%94','%95');").\
arg("NULL").arg(2).arg("true").arg("ACCELEROMETER").arg("0").arg("Bottom").arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg(0).arg(0).arg("false").
arg(0).arg("false").arg(0).arg("false").arg(0).arg(strChannelID).arg("NONE").arg(strChannelName).arg("false").arg(0).arg("false").arg(0).arg("RMSValue").arg("").arg(0).arg("false").arg(0).arg("CTC-AC102").arg("false").arg(0).arg("false").arg(0).arg("").\
arg("true").arg(strMAC).arg(0).arg(1000).arg(0).arg("Hamming").arg("").arg("").arg(10).arg("5000").arg("").arg(1).arg(1).arg("0").arg("60000").arg(0).arg("NONE").arg("").arg("0").arg(8192).arg("").arg("").arg(timeStamp).\
arg("m/s^2").arg("").arg("").arg(0).arg(BoardNo).arg(i+1).arg("").arg("false").arg("-2").arg("-20").arg("10.2").arg("").arg("").arg("").arg("").arg("true").arg("").arg(0).arg("").arg("").arg("").arg("").arg("").arg("").arg("").arg(tempOptions.at(ii)["BoardTypeNo"].toInt()).arg("").arg("");
arg("true").arg(strMAC).arg(0).arg(1000).arg(0).arg("Hamming").arg("15000").arg("0.5").arg(10).arg("5000").arg("").arg(0).arg(0).arg("0").arg("60000").arg(0).arg("NONE").arg("").arg("0").arg(1024).arg("").arg("").arg(timeStamp).\
arg("m/s^2").arg("").arg("").arg(0).arg(BoardNo).arg(i+1).arg("2032").arg("false").arg("-2").arg("-20").arg("10.2").arg("").arg("").arg("").arg("").arg("true").arg("").arg(0).arg("").arg("").arg("").arg("").arg("").arg("").arg("").arg(tempOptions.at(ii)["BoardTypeNo"].toInt()).arg("").arg("峰峰值");
qDebug() << "str" << str << endl;
g_SqliteDB->InsertData(taleName,str);
@ -312,8 +312,8 @@ void CBoardSetting::on_Btn_Confirm_clicked()
'%68','%69','%70',%71,%72,%73,'%74','%75','%76','%77','%78','%79','%80','%81','%82','%83','%84',%85,'%86','%87','%88','%89','%90','%91','%92','%93','%94','%95');").\
arg("NULL").arg(2).arg("true").arg("PULSE_CURRENT").arg("0").arg("Bottom").arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg(0).arg(0).arg("false").
arg(0).arg("false").arg(0).arg("false").arg(0).arg(strChannelID).arg("NONE").arg(strChannelName).arg("false").arg(0).arg("false").arg(0).arg("RMSValue").arg("").arg(0).arg("false").arg(0).arg("电流变送器").arg("false").arg(0).arg("false").arg(0).arg("").\
arg("true").arg(MAC).arg(0).arg(1000).arg(0).arg("Hamming").arg("").arg("").arg(20).arg("5000").arg("").arg(1).arg(1).arg("0").arg("60000").arg(0).arg("NONE").arg("").arg("0").arg(8192).arg("").arg("").arg(timeStamp).\
arg("mA").arg("").arg("").arg(0).arg(BoardNo).arg(i+1).arg("").arg("false").arg("-2").arg("-20").arg("0").arg("").arg("").arg("").arg("").arg("true").arg("").arg(0).arg("").arg("").arg("").arg("20").arg("").arg("4").arg("4").arg(tempOptions.at(ii)["BoardTypeNo"].toInt()).arg("").arg("");
arg("true").arg(MAC).arg(0).arg(1000).arg(0).arg("Hamming").arg("").arg("").arg(20).arg("5000").arg("").arg(0).arg(0).arg("0").arg("60000").arg(0).arg("NONE").arg("").arg("0").arg(1024).arg("").arg("").arg(timeStamp).\
arg("mA").arg("").arg("").arg(0).arg(BoardNo).arg(i+1).arg("").arg("false").arg("-2").arg("-20").arg("0").arg("").arg("").arg("").arg("").arg("true").arg("").arg(0).arg("").arg("").arg("").arg("20").arg("").arg("4").arg("4").arg(tempOptions.at(ii)["BoardTypeNo"].toInt()).arg("").arg("平均值");
qDebug() << "str" << str << endl;
g_SqliteDB->InsertData(taleName,str);
@ -332,7 +332,7 @@ void CBoardSetting::on_Btn_Confirm_clicked()
'%68','%69','%70',%71,%72,%73,'%74','%75','%76','%77','%78','%79','%80','%81','%82','%83','%84',%85,'%86','%87','%88','%89','%90','%91','%92','%93','%94','%95');").\
arg("NULL").arg(2).arg("true").arg("SLOW_CURRENT").arg("0").arg("Bottom").arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg("false").arg(0).arg(0).arg(0).arg("false").
arg(0).arg("false").arg(0).arg("false").arg(0).arg(strChannelID).arg("NONE").arg(strChannelName).arg("false").arg(0).arg("false").arg(0).arg("RMSValue").arg("").arg(0).arg("false").arg(0).arg("电流变送器").arg("false").arg(0).arg("false").arg(0).arg("").\
arg("true").arg(MAC).arg(0).arg(1000).arg(0).arg("Hamming").arg("").arg("").arg(20).arg("5000").arg("").arg(1).arg(1).arg("0").arg("60000").arg(0).arg("NONE").arg("").arg("0").arg(64).arg("").arg("").arg(timeStamp).\
arg("true").arg(MAC).arg(0).arg(1000).arg(0).arg("Hamming").arg("").arg("").arg(20).arg("5000").arg("").arg(0).arg(0).arg("0").arg("60000").arg(0).arg("NONE").arg("").arg("0").arg(64).arg("").arg("").arg(timeStamp).\
arg("mA").arg("").arg("").arg(0).arg(BoardNo).arg(i+1).arg("").arg("false").arg("-2").arg("-20").arg("0").arg("").arg("").arg("").arg("").arg("true").arg("").arg(0).arg("").arg("").arg("").arg("20").arg("").arg("4").arg("4").arg(tempOptions.at(ii)["BoardTypeNo"].toInt()).arg("").arg("");
qDebug() << "str" << str << endl;
@ -361,7 +361,7 @@ void CBoardSetting::on_Btn_Confirm_clicked()
'%68','%69','%70',%71,%72,%73,'%74','%75','%76','%77','%78','%79','%80','%81','%82','%83','%84',%85,'%86','%87','%88','%89','%90','%91','%92','%93','%94','%95');").\
arg("NULL").arg(2).arg("false").arg(strchannelType).arg("0").arg("").arg("").arg(0).arg("").arg(0).arg("").arg(0).arg("").arg(0).arg("").arg(0).arg("").arg(0).arg(0).arg(0).arg("").
arg(0).arg("").arg(0).arg("").arg(0).arg(strChannelID).arg("").arg(strChannelName).arg("").arg(0).arg("").arg(0).arg("").arg("").arg(0).arg("").arg(0).arg("").arg("").arg(0).arg("").arg(0).arg("").\
arg("true").arg(MAC).arg(0).arg(1000).arg(0).arg("").arg("").arg("").arg(10).arg("").arg("").arg(1).arg(1).arg("0").arg("").arg(0).arg("").arg("").arg("0").arg(0).arg("").arg("").arg(timeStamp).\
arg("true").arg(MAC).arg(0).arg(1000).arg(0).arg("").arg("").arg("").arg(10).arg("").arg("").arg(0).arg(0).arg("0").arg("").arg(0).arg("").arg("").arg("0").arg(0).arg("").arg("").arg(timeStamp).\
arg("").arg("").arg("").arg(0).arg(BoardNo).arg(i+1).arg("").arg("false").arg("-2").arg("-20").arg("0").arg("").arg("").arg("").arg("").arg("").arg("").arg(2).arg("").arg("").arg("").arg("").arg("").arg("").arg("").arg(tempOptions.at(ii)["BoardTypeNo"].toInt()).arg("").arg("");
qDebug() << "str" << str << endl;

View File

@ -493,12 +493,12 @@ void CChannelList::slotRowDoubleClicked(const QModelIndex &index)
{
if(g_channelSetting[m_nCurRow].boardType.toInt() == 1 && g_channelSetting[i].channelId == g_channelSetting[m_nCurRow].channelId){//开入开出板卡
CSlowSpeedChannelSetting *dialog = new CSlowSpeedChannelSetting();
connect(dialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting)));
dialog->channelSetting = g_channelSetting[i];
dialog->setWindowModality(Qt::ApplicationModal);
dialog->displayChannelSetting();
dialog->show();
CSlowSpeedChannelSetting *dialog = new CSlowSpeedChannelSetting();
connect(dialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting)));
dialog->channelSetting = g_channelSetting[i];
dialog->setWindowModality(Qt::ApplicationModal);
dialog->displayChannelSetting();
dialog->show();
}
else if(g_channelSetting[m_nCurRow].boardType.toInt() > 1 && g_channelSetting[m_nCurRow].boardType.toInt() < 5 && g_channelSetting[i].channelId == g_channelSetting[m_nCurRow].channelId){//高速板卡
@ -572,7 +572,7 @@ void CChannelList::on_pushButton_open_clicked()
//model->setData(model->index(i,4),QBrush(Qt::red), Qt::BackgroundRole);
model->setItem(i,4,new QStandardItem("启用"));
QString strChannelID = model->data(model->index(i,38)).toString();
QString strUpdateSql = QString(" set isEnable = %1 where channelId = '%2' ").arg(1).arg(g_channelSetting[i].channelId);
QString strUpdateSql = QString(" set isEnable = %1 , isWork = %2 where channelId = '%3' ").arg(1).arg(1).arg(g_channelSetting[i].channelId);
QString tableName = "t_ChannelSetting ";
g_SqliteDB->UpdateDataSql(tableName,strUpdateSql);
g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting");

View File

@ -49,7 +49,7 @@ CChannelSetting::CChannelSetting(QWidget *parent) :
ui->lineEdit_tachTriggerPerRev->setValidator(Validator);
ui->lineEdit_tachTriggerHysteresis->setValidator(Validator);
connect(ui->channelTypeCombox,SIGNAL(currentTextChanged(QString)),this,SLOT(on_channelTypeCombox_currentTextChanged(const QString&)));
connect(ui->channelTypeCombox,SIGNAL(currentTextChanged(const QString&)),this,SLOT(on_channelTypeCombox_currentTextChanged(const QString&)));
}
@ -60,6 +60,17 @@ CChannelSetting::~CChannelSetting()
void CChannelSetting::displayChannelSetting()
{
ui->channelTypeCombox->addItems(ChannelTypeList);
qDebug() <<"channelSetting.sensorType" << channelSetting.sensorType <<endl;
QMap<QString,QString>::Iterator iter = g_MapChannelType.begin();
for (; iter != g_MapChannelType.end(); iter++) {
if(iter.key() == channelSetting.sensorType){
ui->channelTypeCombox->setCurrentText(iter.value());
break;
}
}
m_itemList << "" << "" ;
m_DisPlayerList << "峰峰值" << "有效值" << "峰值" <<"平均值";
@ -67,7 +78,7 @@ void CChannelSetting::displayChannelSetting()
ui->label_modelNo->setText(string_modelNo);
QString string_sensorNo = QString("%1").arg(channelSetting.sensorNo);
ui->label_channelNo->setText(string_sensorNo);
ui->channelTypeCombox->addItems(ChannelTypeList);
ui->comboBox_coupling->clear();
ui->comboBox_coupling->addItem("AC");
@ -77,21 +88,15 @@ void CChannelSetting::displayChannelSetting()
ui->comboBox_defaultDisplay->addItems(m_DisPlayerList);
ui->comboBox_defaultDisplay->setCurrentText(channelSetting.defaultDisplay);
ui->lineEdit_sensorRange->setText(channelSetting.sensorRange);
ui->lineEdit_sensorRange_2->setText(channelSetting.sensorRange);
if(channelSetting.couplingACDC)
ui->comboBox_coupling->setCurrentText("AC");
else
ui->comboBox_coupling->setCurrentText("DC");
qDebug() <<"channelSetting.sensorType" << channelSetting.sensorType <<endl;
QMap<QString,QString>::Iterator iter = g_MapChannelType.begin();
for (; iter != g_MapChannelType.end(); iter++) {
if(iter.key() == channelSetting.sensorType){
ui->channelTypeCombox->setCurrentText(iter.value());
}
}
ui->RPMComBox->addItem("- -");
ui->pairChannelComBox->addItem("- -");
QMap<QString,QMap<QString,QString>>::iterator iterChannel = g_MapChannel.begin();
@ -143,6 +148,7 @@ void CChannelSetting::displayChannelSetting()
ui->comboBox_sensorICP->setCurrentText("");
else
ui->comboBox_sensorICP->setCurrentText("");
ui->lineEdit_frequencyRangeMax->setText(channelSetting.frequencyRangeMax);
ui->lineEdit_frequencyRangeMin->setText(channelSetting.frequencyRangeMin);
@ -159,7 +165,7 @@ void CChannelSetting::displayChannelSetting()
ui->lineEdit_vMin->setText(sensorRangeMin);
strListFs << "1kHz"<<"2kHz"<<"4kHz"<<"8kHz" << "16kHz";
strListFs << "1kHz"<<"2kHz"<<"4kHz"<<"8kHz";
ui->comboBox_samplingRate->addItems(strListFs);
if(channelSetting.samplingRate == 1024)
ui->comboBox_samplingRate->setCurrentText("1kHz");
@ -169,8 +175,8 @@ void CChannelSetting::displayChannelSetting()
ui->comboBox_samplingRate->setCurrentText("4kHz");
if(channelSetting.samplingRate == 8192)
ui->comboBox_samplingRate->setCurrentText("8kHz");
if(channelSetting.samplingRate == 16384)
ui->comboBox_samplingRate->setCurrentText("16kHz");
// if(channelSetting.samplingRate == 16384)
// ui->comboBox_samplingRate->setCurrentText("16kHz");
QString envelopeLowpassband = QString("%1").arg(channelSetting.envelopeLowpassband);
ui->lineEdit_envelopeLowpassband->setText(envelopeLowpassband);
@ -242,18 +248,21 @@ void CChannelSetting::displayChannelSetting()
if(channelSetting.samplingRate == 131072)
ui->comboBox_samplingRate_2->setCurrentText("128kHz");
ui->lineEdit_sensorLeftOrRight->setText(channelSetting.sensorLeftOrRight);
ui->comboBox_tachAutoTach->addItems(m_itemList);
if(channelSetting.tachAutoTach )
ui->comboBox_tachAutoTach->setCurrentText("");
else
ui->comboBox_tachAutoTach->setCurrentText("");
ui->comboBox_tachTriggerEdge->addItem("rising");
ui->comboBox_tachTriggerEdge->addItem("falling");
if(channelSetting.tachTriggerEdge == "rising")
ui->comboBox_tachTriggerEdge->setCurrentText("rising");
else
ui->comboBox_tachTriggerEdge->setCurrentText("falling");
QString tachTriggerVoltageLevel = QString("%1").arg(channelSetting.tachTriggerVoltageLevel);
ui->lineEdit_tachTriggerVoltageLevel->setText(tachTriggerVoltageLevel);
ui->lineEdit_tachTriggerPerRev->setText(channelSetting.tachTriggerPerRev);
QString tachTriggerHysteresis = QString("%1").arg(channelSetting.tachTriggerHysteresis);
ui->lineEdit_tachTriggerHysteresis->setText(tachTriggerHysteresis);
ui->comboBox_tachTriggerEdge->addItem("上升沿");
ui->comboBox_tachTriggerEdge->addItem("下降沿");
ui->comboBox_tachTriggerEdge->setCurrentText(channelSetting.tachTriggerEdge);
}
@ -280,15 +289,26 @@ void CChannelSetting::on_pushButton_submit_clicked()
channelSetting.defaultDisplay = ui->comboBox_defaultDisplay->currentText();
channelSetting.pairChannelName = ui->pairChannelComBox->currentText();
for (int i = 0; i < g_ChannelBaseInfo.size(); i++) {
if(g_ChannelBaseInfo[i].channelName == ui->RPMComBox->currentText()){
channelSetting.speedRefChannelId = g_ChannelBaseInfo[i].channelID;
channelSetting.speedRefChannelName = g_ChannelBaseInfo[i].channelName;
}else if(ui->RPMComBox->currentText() == "- -")
{
channelSetting.speedRefChannelId = "";
channelSetting.speedRefChannelName = "";
}
if(g_ChannelBaseInfo[i].channelName == ui->pairChannelComBox->currentText()){
channelSetting.pairChannelId = g_ChannelBaseInfo[i].channelID;
channelSetting.pairChannelName = g_ChannelBaseInfo[i].channelName;
}else if(ui->pairChannelComBox->currentText() == "- -")
{
channelSetting.pairChannelId = "";
channelSetting.pairChannelId = "";
}
}
channelSetting.rpmMultiplier = ui->lineEdit_rpmMultiplier->text();
@ -328,19 +348,25 @@ void CChannelSetting::on_pushButton_submit_clicked()
channelSetting.samplingRate = 4096;
else if(strSamplingRate == "8kHz")
channelSetting.samplingRate = 8192;
else if(strSamplingRate == "16kHz")
channelSetting.samplingRate = 16384;
// else if(strSamplingRate == "16kHz")
// channelSetting.samplingRate = 16384;
channelSetting.channelName = ui->lineEdit_ChannelName->text();
// channelSetting.isEnable = 1;
// channelSetting.isWork = 1;
channelSetting.isEnable = 1;
channelSetting.isWork = 1;
channelSetting.ChUnitCoeff = ui->lineEdit_ChUnitCoeff->text().toDouble();
channelSetting.ChUnitDot = ui->lineEdit_ChUnitDot->text().toInt();
channelSetting.sensorGapVoltage = ui->lineEdit_sensorGapVoltage->text();
channelSetting.bearingClearance = ui->lineEdit_bearingClearance->text();
channelSetting.sensorLocationInDegree = ui->lineEdit_sensorLocationInDegree->text().toInt();
channelSetting.sensorLeftOrRight = ui->lineEdit_sensorLeftOrRight->text();
channelSetting.sensor1xPhaseRunout = ui->lineEdit_sensor1xPhaseRunout->text();
channelSetting.sensor1xAmplitudeRunout = ui->lineEdit_sensor1xAmplitudeRunout->text();
channelSetting.envelopeHighpassband = ui->lineEdit_envelopeHighpassband->text().toDouble();
channelSetting.envelopeLowpassband = ui->lineEdit_envelopeLowpassband->text().toDouble();
if(ui->tabWidget->currentIndex() == 1){
channelSetting.sensorEngineeringUnit = ui->lineEdit_sensorEngineeringUnit_2->text();
channelSetting.channelSensorType = ui->lineEdit_SensorType_2->text();
@ -380,12 +406,17 @@ void CChannelSetting::on_pushButton_submit_clicked()
channelSetting.samplingRate = 4096;
else if(strSamplingRate == "8kHz")
channelSetting.samplingRate = 8192;
else if(strSamplingRate == "16kHz")
channelSetting.samplingRate = 16384;
// else if(strSamplingRate == "16kHz")
// channelSetting.samplingRate = 16384;
channelSetting.tachTriggerEdge = ui->comboBox_tachTriggerEdge->currentText();
if(ui->comboBox_tachTriggerEdge->currentText() == "上升沿")
channelSetting.tachTriggerEdge = "rising";
else
channelSetting.tachTriggerEdge = "falling";
channelSetting.sensorSensitivity ="0";
channelSetting.defaultDisplay = "转速";
}
QDateTime timeNow = QDateTime::currentDateTime();
@ -397,9 +428,14 @@ void CChannelSetting::on_pushButton_submit_clicked()
void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg1)
{
qDebug() << arg1 << endl;
if(arg1 == "转速"){
ui->tabWidget->setCurrentIndex(1);
ui->comboBox_samplingRate_2->setCurrentText("128kHz");
ui->comboBox_samplingRate_2->setCurrentText("8kHz");
ui->lineEdit_tachTriggerVoltageLevel->setText("-10");
ui->lineEdit_tachTriggerPerRev->setText("1");
ui->lineEdit_tachTriggerHysteresis->setText("2");
ui->lineEdit_sensorRange_2->setText("20000");
}else{
ui->tabWidget->setCurrentIndex(0);
if(arg1 == "加速度"){
@ -418,7 +454,9 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->lineEdit_vMin->setText("-20");
ui->comboBox_samplingRate->clear();
ui->comboBox_samplingRate->addItems(strListFs);
ui->comboBox_samplingRate->setCurrentText("16kHz");
ui->comboBox_samplingRate->setCurrentText("1kHz");
ui->pairChannelComBox->setCurrentText("- -");
ui->RPMComBox->setCurrentText("- -");
QString str = QString("%1").arg(16*1024/2.56);
ui->lineEdit_analyseRate->setText(str);
ui->lineEdit_RateRatio->setText("1");
@ -427,6 +465,7 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
// ui->comboBox_coupling->addItem("DC");
ui->lineEdit_envelopeLowpassband->setText("10");
ui->lineEdit_envelopeHighpassband->setText("3500");
ui->lineEdit_sensorRange->setText("2032");
}else if(arg1 == "速度"){
ui->lineEdit_SensorType->setText("CTC-VE102");
@ -442,7 +481,7 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->lineEdit_vMin->setText("-20");
ui->comboBox_samplingRate->clear();
ui->comboBox_samplingRate->addItems(strListFs);
ui->comboBox_samplingRate->setCurrentText("8kHz");
ui->comboBox_samplingRate->setCurrentText("1kHz");
QString str = QString("%1").arg(8*1024/2.56);
ui->lineEdit_analyseRate->setText(str);
ui->lineEdit_RateRatio->setText("1");
@ -451,6 +490,9 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->comboBox_coupling->addItem("DC");
ui->lineEdit_envelopeLowpassband->setText("4.5");
ui->lineEdit_envelopeHighpassband->setText("5000");
ui->pairChannelComBox->setCurrentText("- -");
ui->RPMComBox->setCurrentText("- -");
ui->lineEdit_sensorRange->setText("2054");
}else if(arg1 == "声音"){
ui->lineEdit_SensorType->setText("378B02");
@ -466,7 +508,7 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->lineEdit_vMin->setText("-20");
ui->comboBox_samplingRate->clear();
ui->comboBox_samplingRate->addItems(strListFs);
ui->comboBox_samplingRate->setCurrentText("16kHz");
ui->comboBox_samplingRate->setCurrentText("1kHz");
QString str = QString("%1").arg(16*1024/2.56);
ui->lineEdit_analyseRate->setText(str);
ui->lineEdit_RateRatio->setText("1");
@ -475,6 +517,9 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->comboBox_coupling->addItem("DC");
ui->lineEdit_envelopeLowpassband->setText("350");
ui->lineEdit_envelopeHighpassband->setText("12000");
ui->pairChannelComBox->setCurrentText("- -");
ui->RPMComBox->setCurrentText("- -");
ui->lineEdit_sensorRange->setText("2000");
}else if(arg1 == "径向振动位移"){
ui->lineEdit_SensorType->setText("CTC-DP1001");
@ -491,7 +536,7 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->lineEdit_vMin->setText("-20");
ui->comboBox_samplingRate->clear();
ui->comboBox_samplingRate->addItems(strListFs);
ui->comboBox_samplingRate->setCurrentText("8kHz");
ui->comboBox_samplingRate->setCurrentText("1kHz");
QString str = QString("%1").arg(8*1024/2.56);
ui->lineEdit_analyseRate->setText(str);
ui->lineEdit_RateRatio->setText("1");
@ -500,6 +545,9 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->comboBox_coupling->addItem("AC");
ui->lineEdit_envelopeLowpassband->setText("1");
ui->lineEdit_envelopeHighpassband->setText("4000");
ui->pairChannelComBox->setCurrentText("- -");
ui->RPMComBox->setCurrentText("- -");
ui->lineEdit_sensorRange->setText("2000");
}else if(arg1 == "轴向位移"){
ui->lineEdit_SensorType->setText("CTC-DP1001");
@ -516,7 +564,7 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->lineEdit_vMin->setText("-20");
ui->comboBox_samplingRate->clear();
ui->comboBox_samplingRate->addItems(strListFs);
ui->comboBox_samplingRate->setCurrentText("8kHz");
ui->comboBox_samplingRate->setCurrentText("1kHz");
QString str = QString("%1").arg(8*1024/2.56);
ui->lineEdit_analyseRate->setText(str);
ui->lineEdit_RateRatio->setText("1");
@ -525,6 +573,9 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->comboBox_coupling->addItem("AC");
ui->lineEdit_envelopeLowpassband->setText("1");
ui->lineEdit_envelopeHighpassband->setText("4000");
ui->pairChannelComBox->setCurrentText("- -");
ui->RPMComBox->setCurrentText("- -");
ui->lineEdit_sensorRange->setText("2");
}else if(arg1 == "动态电压"){
ui->lineEdit_SensorType->setText("");
ui->lineEdit_sensorEngineeringUnit->setText("");
@ -539,7 +590,7 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->lineEdit_vMin->setText("-20");
ui->comboBox_samplingRate->clear();
ui->comboBox_samplingRate->addItems(strListFs);
ui->comboBox_samplingRate->setCurrentText("8kHz");
ui->comboBox_samplingRate->setCurrentText("1kHz");
QString str = QString("%1").arg(8*1024/2.56);
ui->lineEdit_analyseRate->setText(str);
ui->lineEdit_RateRatio->setText("1");
@ -548,6 +599,9 @@ void CChannelSetting::on_channelTypeCombox_currentTextChanged(const QString &arg
ui->comboBox_coupling->addItem("AC");
ui->lineEdit_envelopeLowpassband->setText("0");
ui->lineEdit_envelopeHighpassband->setText("5000");
ui->pairChannelComBox->setCurrentText("- -");
ui->RPMComBox->setCurrentText("- -");
ui->lineEdit_sensorRange->setText("2000");
}
}
}
@ -630,6 +684,7 @@ void CChannelSetting::slotSetChannelData(QStringList& listChannelName)
g_SqliteDB->UpdateDataSql(tableName,strUpdateSql);
}
}
void CChannelSetting::on_pushButton_copy_clicked()
{
//sensorModuleNo

View File

@ -74,7 +74,14 @@ void CCharacteristicList::DisPlayCharacteristic()
model->setData(model->index(j,2,QModelIndex()),g_Charateristic[j].DerivedPeak);
}else if(g_ChannelBaseInfo[i].defaultDisplay == "平均值"){
model->setData(model->index(j,2,QModelIndex()),g_Charateristic[j].DCValues);
}else if(g_ChannelBaseInfo[i].defaultDisplay == "转速"){
model->setData(model->index(j,2,QModelIndex()),g_Charateristic[j].speedRPM);
}
//qDebug() << g_ChannelBaseInfo[i].boardType << g_Charateristic[j].DCValues <<endl;
if(g_ChannelBaseInfo[i].boardType == "5"){
model->setData(model->index(j,2,QModelIndex()),g_Charateristic[j].DCValues);
}
model->setData(model->index(j,3,QModelIndex()),QString::number(g_Charateristic[j].MonitorPk2Pk,'f',2));
model->setData(model->index(j,4,QModelIndex()),g_Charateristic[j].Amp1x);

View File

@ -24,7 +24,7 @@ CConfiguration::CConfiguration(QWidget *parent) :
Init();
connect(ui->comboBox_WC,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(on_comboBox_WC_currentTextChanged(const QString&)));
connect(ui->comboBox_WC,SIGNAL(currentTextChanged(const QString &)),this,SLOT(on_comboBox_WC_currentTextChanged2(const QString&)));
}
@ -75,6 +75,7 @@ void CConfiguration::Init()
model_Available->appendRow(item2);
QStandardItem *itemAnd = new QStandardItem(QString("logicAND(1)"));
itemAnd->setData(1,Qt::UserRole+1);
QStandardItem *itemOr = new QStandardItem(QString("logicOR"));
item1->appendRow(itemAnd);
item1->appendRow(itemOr);
@ -98,6 +99,7 @@ void CConfiguration::Init()
ui->comboBox_WC->clear();
ui->comboBox_WC->addItems(strWorkConditionList);
QString strWC = ui->comboBox_WC->currentText();
qDebug() << strWC;
arrayTriggerConfig = document.array();
for (int i = 0; i < arrayTriggerConfig.size(); i++) {
if(strWC == arrayTriggerConfig.at(i)["workConditionName"].toString()){
@ -113,7 +115,6 @@ void CConfiguration::Init()
QString channelName = TriggerSettings.at(j)["channelName"].toString();
QStandardItem *itemChannel = new QStandardItem(QString(channelName));
QJsonArray arrayConfig = TriggerSettings.at(j)["triggerConfig"].toArray();
qDebug() << "arrayConfig size" <<arrayConfig.size() <<endl;
if(arrayConfig.size() > 0){
item2->appendRow(itemChannel);
@ -345,6 +346,7 @@ QJsonObject CConfiguration::SelectChannel(int channelNo)
}
return ConfiguraitonsObj;
}
void CConfiguration::on_pushButton_confirm_clicked()
{
@ -469,8 +471,9 @@ void CConfiguration::on_pushButton_confirm_clicked()
}
void CConfiguration::on_comboBox_WC_currentTextChanged(const QString &arg1)
void CConfiguration::on_comboBox_WC_currentTextChanged2(const QString &arg1)
{
qDebug() << "on_comboBox_WC_currentTextChanged" << endl;
for(int i = 0;i < model_Available->rowCount() ;i++){
QStandardItem *item = model_Available->item(i);
if(item->text() == "Operand"){
@ -844,13 +847,13 @@ void CConfiguration::on_radioButton_6_clicked()
void CConfiguration::on_radioButton_8_clicked()
{
ViewRelay(9);
ViewRelay(10);
}
void CConfiguration::on_radioButton_7_clicked()
{
ViewRelay(10);
ViewRelay(9);
}

View File

@ -26,7 +26,7 @@ private slots:
void slotModifyItem();
void on_pushButton_confirm_clicked();
void on_comboBox_WC_currentTextChanged(const QString &arg1);
void on_comboBox_WC_currentTextChanged2(const QString &arg1);
void on_pushButton_save_clicked();

View File

@ -220,6 +220,19 @@ color: rgb(27, 30, 35);</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_7">
<property name="geometry">
<rect>
<x>0</x>
<y>220</y>
<width>177</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>继电器9</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_8">
<property name="geometry">
<rect>
<x>0</x>
@ -232,19 +245,6 @@ color: rgb(27, 30, 35);</string>
<string>继电器10</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_8">
<property name="geometry">
<rect>
<x>0</x>
<y>223</y>
<width>177</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>继电器9</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_9">
<property name="geometry">
<rect>

View File

@ -26,15 +26,19 @@ CONFIG += c++11
SOURCES += \
AddChannel.cpp \
AlarmDetails.cpp \
CharacteristicList.cpp \
Configuration.cpp \
CopyChannelSetting.cpp \
DIO_Board.cpp \
FileServerConfig.cpp \
HistoryAlarm.cpp \
Mqttclient.cpp \
NTPServerConfig.cpp \
NetMgr.cpp \
PSConfig.cpp \
QGraphicsMovieItem.cpp \
QMyTableViewBtnDelegate.cpp \
RealTimeAlarm.cpp \
SlowSpeedChannelSetting.cpp \
SystemSelfcheck.cpp \
@ -48,6 +52,7 @@ SOURCES += \
ftpclient.cpp \
global.cpp \
headerView.cpp \
log.cpp \
mainwindow.cpp \
main.cpp \
qcustomplot.cpp \
@ -64,15 +69,19 @@ SOURCES += \
HEADERS += \
AddChannel.h \
AlarmDetails.h \
CharacteristicList.h \
Configuration.h \
CopyChannelSetting.h \
DIO_Board.h \
FileServerConfig.h \
HistoryAlarm.h \
Mqttclient.h \
NTPServerConfig.h \
NetMgr.h \
PSConfig.h \
QGraphicsMovieItem.h \
QMyTableViewBtnDelegate.h \
RealTimeAlarm.h \
SlowSpeedChannelSetting.h \
SystemSelfcheck.h \
@ -86,6 +95,7 @@ HEADERS += \
ftpclient.h \
global.h \
headerView.h \
log.h \
mainwindow.h \
qcustomplot.h \
quihelper.h \
@ -101,6 +111,7 @@ HEADERS += \
FORMS += \
AddChannel.ui \
AlarmDetails.ui \
CharacteristicList.ui \
Configuration.ui \
CopyChannelSetting.ui \
@ -137,3 +148,9 @@ RESOURCES += \
DISTFILES += \
image/Btn/btn.png \
image/Btn/btn_p.png
INCLUDEPATH += $$PWD/include/mqtt
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/mqtt/ -lQt5Qmqtt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/mqtt/ -lQt5Qmqttd
else:unix: LIBS += -L$$PWD/lib/MQTT/ -lQt5Qmqtt

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.0, 2023-04-17T09:23:44. -->
<!-- Written by QtCreator 4.15.0, 2023-04-27T09:56:22. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -94,7 +94,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.11 MinGW 32-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.11 MinGW 32-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.51211.win32_mingw73_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@ -301,7 +301,7 @@
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/WorkSpace/3500/build-DataWatch3500_GUI-Desktop_Qt_5_12_11_MinGW_32_bit-Release</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/WorkSpace/3500/build-DataWatch3500_GUI-Desktop_Qt_5_12_11_MinGW_32_bit-Debug</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>

View File

@ -164,9 +164,9 @@ void CFileServerConfig::on_pushButtonPush_clicked()
fileName = QCoreApplication::applicationDirPath() + "\\config\\ServerConfig.json";
QFile file2(fileName);
file.open(QIODevice::WriteOnly);
file.write(jsonDoc.toJson());
file.close();
file2.open(QIODevice::WriteOnly);
file2.write(jsonDoc.toJson());
file2.close();
QString str3 = QString("ftp://%1/CIDW/qtconfig/%2").arg(IP).arg("ServerConfig.json");
g_FtpClient->SetServerInfo(str3);
@ -177,6 +177,15 @@ void CFileServerConfig::on_pushButtonPush_clicked()
void CFileServerConfig::slotNetMgr(QString sAddr, const QVariant &msg)
{
QJsonObject objec = msg.value<QJsonObject>();
bool Status = objec.take("success").toBool();
QString strMessage = objec.take("message").toString();
if(Status){
//QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("获取成功!"));
}else{
QMessageBox::information(this, QStringLiteral("提示"), strMessage);
return;
}
if(objec.contains("cmd"))
{
QJsonValue arrays_value = objec.take("cmd");

View File

@ -1,5 +1,10 @@
#include "HistoryAlarm.h"
#include "ui_HistoryAlarm.h"
#include <QListView>
#include "sqlitedb.h"
#include "QMyTableViewBtnDelegate.h"
#include "AlarmDetails.h"
CHistoryAlarm::CHistoryAlarm(QWidget *parent) :
QWidget(parent),
@ -16,11 +21,27 @@ CHistoryAlarm::CHistoryAlarm(QWidget *parent) :
ui->tableView->setModel(model);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
ui->tableView->setColumnWidth(2, 300);
ui->tableView->setColumnWidth(3, 300);
ui->tableView->setColumnWidth(4, 300);
ui->tableView->setAlternatingRowColors(true);
model->setRowCount(10);
ui->tableView->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(5,QHeaderView::ResizeToContents);
ui->dateTimeEdit_start->setCalendarPopup(true);
ui->dateTimeEdit_end->setCalendarPopup(true);
QDateTime curDateTime=QDateTime::currentDateTime();//通过QDateTime的currentDateTime获得当前的日期时间并赋值给curDateTime
ui->dateTimeEdit_start->setDateTime(curDateTime);
ui->dateTimeEdit_end->setDateTime(curDateTime);
ui->comboBox_channel->setView(new QListView());
connect(ui->comboBox_channel,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(on_comboBox_channel_currentTextChanged(const QString&)));
for (int i = 0; i < g_ChannelBaseInfo.size(); i++) {
ui->comboBox_channel->insertItem(i,g_ChannelBaseInfo[i].channelName);
}
}
@ -28,3 +49,64 @@ CHistoryAlarm::~CHistoryAlarm()
{
delete ui;
}
void CHistoryAlarm::on_comboBox_channel_currentTextChanged(const QString& strChannelName)
{
int i = 0;
for (i = 0; i < g_ChannelBaseInfo.size(); i++) {
if(strChannelName == g_ChannelBaseInfo[i].channelName){
m_strChannelID = g_ChannelBaseInfo[i].channelID;
break;
}
}
}
void CHistoryAlarm::createRowItem(int Row,QVariantList RowItem)
{
model->setRowCount(Row+1);
for (int j = 0; j < RowItem.size(); ++j)
{
model->setData(model->index(Row,j,QModelIndex()),RowItem.at(j));
}
}
void CHistoryAlarm::on_pushButton_search_clicked()
{
model->removeRows(0, model->rowCount());
QDateTime dateTimeStart =ui->dateTimeEdit_start->dateTime();
QDateTime dateTimeEnd =ui->dateTimeEdit_end->dateTime();
int timestampStart = dateTimeStart.toTime_t();
int timestampEnd = dateTimeEnd.toTime_t();
QString strTableName = "t_TriggerEvent",strSql;
strSql = QString(" triggeredTime > %1 and triggeredTime < %2 order by triggeredTime ").arg(timestampStart).arg(timestampEnd);
m_vecTriggerEvent = g_SqliteDB->GetTriggerEvent(strTableName,strSql);
if(m_vecTriggerEvent.size() > 0){
for (int i = 0; i < m_vecTriggerEvent.size(); i++) {
QVariantList strRowItem ;
QString TStr = QDateTime::fromSecsSinceEpoch(m_vecTriggerEvent[i].triggeredTime).toString("yyyy-MM-dd hh:mm:ss");
strRowItem << i + 1 << m_vecTriggerEvent[i].triggeredNotification << m_vecTriggerEvent[i].triggeredFeatureName << TStr;
createRowItem(i,strRowItem);
}
QMyTableViewBtnDelegate *m_btnDelegate = new QMyTableViewBtnDelegate(QStringList()<<"详情", this);
ui->tableView->setItemDelegateForColumn(5, m_btnDelegate);
connect(m_btnDelegate, SIGNAL(editData(const QModelIndex &)), this,SLOT(Details(const QModelIndex &)));
}else{
QMessageBox::information(this, "提示", QString("未查询到数据!"));
}
}
void CHistoryAlarm::Details(const QModelIndex &index)
{
int row = index.row();
CAlarmDetails *dialog = new CAlarmDetails();
dialog->ViewData(m_vecTriggerEvent[row]);
dialog->setWindowModality(Qt::ApplicationModal);
dialog->show();
}

View File

@ -20,12 +20,21 @@ public:
explicit CHistoryAlarm(QWidget *parent = nullptr);
~CHistoryAlarm();
private slots:
void on_comboBox_channel_currentTextChanged(const QString&);
void on_pushButton_search_clicked();
void Details(const QModelIndex &index);
private:
Ui::CHistoryAlarm *ui;
TableHeaderView *myHeader;
QStandardItemModel *model;
QString headerStr ;
QString m_strChannelID;
QVector<TriggerEvent_t> m_vecTriggerEvent;
void createRowItem(int Row,QVariantList RowItem);
};
#endif // HISTORYALARM_H

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1054</width>
<width>1148</width>
<height>533</height>
</rect>
</property>
@ -58,20 +58,7 @@ color: rgb(27, 30, 35);</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QDateTimeEdit" name="dateTimeEdit_start"/>
</item>
</layout>
</item>
@ -85,23 +72,7 @@ color: rgb(27, 30, 35);</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QDateTimeEdit" name="dateTimeEdit_end"/>
</item>
</layout>
</item>
@ -115,7 +86,7 @@ color: rgb(27, 30, 35);</string>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<widget class="QComboBox" name="comboBox_channel">
<property name="minimumSize">
<size>
<width>230</width>
@ -146,7 +117,29 @@ color: rgb(27, 30, 35);</string>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="pushButton_search">
<property name="minimumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#pushButton_search { border-image: url(:/image/Btn/normal_Btn.png);
color:#1f5188 }
#pushButton_search:hover { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_search:pressed { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_search:checked { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}</string>
</property>
<property name="text">
<string>查询</string>
</property>

159
Mqttclient.cpp Normal file
View File

@ -0,0 +1,159 @@
#include "MqttClient.h"
MqttClient::MqttClient(QObject *parent) : QObject(parent)
{
}
void MqttClient::onMQTT_Connected()
{
qDebug()<< "doConnected" <<endl;
}
void MqttClient::onMQTT_disconnected()
{
qDebug()<< "doDisconnected" <<endl;
}
void MqttClient::onMQTT_Connacked(quint8 ack)
{
//todo: should emit on server suback
/*
QString ackStatus;
switch(ack) {
case QMQTT::CONNACK_ACCEPT:
ui->pushButtonPusblish->setEnabled(true);
ui->pushButtonSubscribe->setEnabled(true);
ackStatus = "Connection Accepted";
break;
case QMQTT::CONNACK_PROTO_VER:
ackStatus = "Connection Refused: unacceptable protocol version";
break;
case QMQTT::CONNACK_INVALID_ID:
ackStatus = "Connection Refused: identifier rejected";
break;
case QMQTT::CONNACK_SERVER:
ackStatus = "Connection Refused: server unavailable";
break;
case QMQTT::CONNACK_CREDENTIALS:
ackStatus = "Connection Refused: bad user name or password";
break;
case QMQTT::CONNACK_AUTH:
ackStatus = "Connection Refused: not authorized";
break;
}
log(tr("connacked: %1, %2").arg(ack).arg(ackStatus));
*/
}
void MqttClient::onMQTT_error(QMQTT::ClientError err)
{
//todo: should emit on server suback
QString errInfo;
switch(err) {
// 0 The connection was refused by the peer (or timed out).
case QAbstractSocket::ConnectionRefusedError:
errInfo = tr("Connection Refused");
// 1 The remote host closed the connection. Note that the client socket (i.e., this socket) will be closed after the remote close notification has been sent.
case QAbstractSocket::RemoteHostClosedError:
errInfo = tr("Remote Host Closed");
// 2 The host address was not found.
case QAbstractSocket::HostNotFoundError:
errInfo = tr("Host Not Found Error");
// 3 The socket operation failed because the application lacked the required privileges.
case QAbstractSocket::SocketAccessError:
errInfo = tr("Socket Access Error");
// 4 The local system ran out of resources (e.g., too many sockets).
case QAbstractSocket::SocketResourceError:
errInfo = tr("Socket Resource Error");
// 5 The socket operation timed out.
case QAbstractSocket::SocketTimeoutError:
errInfo = tr("Socket Timeout Error");
default:
errInfo = tr("Socket Error");
}
qDebug()<< errInfo <<endl;;
}
void MqttClient::onMQTT_Published(const QMQTT::Message &message)
{
qDebug()<< "onMQTT_Published" <<endl;
}
void MqttClient::onMQTT_Pubacked(quint8 type, quint16 msgid)
{
}
void MqttClient::onMQTT_Received(const QMQTT::Message &message)
{
QString mes = QString(message.id())+" "+QString(message.qos())+" "+message.topic()+" "+message.payload()+"";
emit Recevive_sig(message.topic(),message.payload());
}
void MqttClient::onMQTT_subscribed(const QString &topic)
{
qDebug() << "onMQTT_subscribed" << topic << endl;
}
void MqttClient::onMQTT_subacked(quint16 msgid, quint8 qos)
{
}
void MqttClient::onMQTT_unsubscribed(const QString &topic)
{
}
void MqttClient::onMQTT_unsubacked(quint16 msgid)
{
}
void MqttClient::Push(const QMQTT::Message &message)
{
qDebug()<< "onMQTT_Published" <<endl;
m_client->publish(message);
}
void MqttClient::subscribed(QString strTopic)
{
qDebug()<< "subscribed" <<endl;
m_client->subscribe(strTopic);
}
void MqttClient::ConnectMQTT(QString strIP)
{
m_client = new QMQTT::Client(QHostAddress(strIP),1883);
//m_client->setHost(QHostAddress("192.168.1.156"));
//m_client->setPort(51613);
//m_client->setUsername("chaos");
//m_client->setPassword("HSD272*#xkd");
m_client->connectToHost();
connect(m_client, SIGNAL(connected()), this, SLOT(onMQTT_Connected()));
//todo: should emit on server suback
//connect(_client, SIGNAL(connacked(quint8)), this, SLOT(onMQTT_Connacked(quint8)));
connect(m_client, SIGNAL(error(QMQTT::ClientError)), this, SLOT(onMQTT_error(QMQTT::ClientError)));
//slots changes
//API: void published(const QMQTT::Message& message);
connect(m_client,SIGNAL(published(const QMQTT::Message &)),this,SLOT(onMQTT_Published(const QMQTT::Message &)));
//todo: should emit on server suback
//connect(_client, SIGNAL(pubacked(quint8, quint16)), this, SLOT(onMQTT_Pubacked(quint8, quint16)));
connect(m_client, SIGNAL(received(const QMQTT::Message &)), this, SLOT(onMQTT_Received(const QMQTT::Message &)));
connect(m_client, SIGNAL(subscribed(const QString &)), this, SLOT(onMQTT_subscribed(const QString &)));
}

34
Mqttclient.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef MQTTCLIENT_H
#define MQTTCLIENT_H
#include <QObject>
#include "qmqtt.h"
#include "global.h"
class MqttClient : public QObject
{
Q_OBJECT
public:
explicit MqttClient(QObject *parent = nullptr);
void ConnectMQTT(QString strIP);
QMQTT::Client *m_client;
void Push(const QMQTT::Message &message);
void subscribed(QString strTopic);
public slots:
void onMQTT_Connected();
void onMQTT_Connacked(quint8 ack);
void onMQTT_error(QMQTT::ClientError err);
void onMQTT_Published(const QMQTT::Message &message);
void onMQTT_Pubacked(quint8 type, quint16 msgid);
void onMQTT_Received(const QMQTT::Message &message);
void onMQTT_subscribed(const QString &topic);
void onMQTT_subacked(quint16 msgid, quint8 qos);
void onMQTT_unsubscribed(const QString &topic);
void onMQTT_unsubacked(quint16 msgid);
void onMQTT_disconnected();
signals:
void Recevive_sig(QString,QByteArray);
};
#endif // MQTTCLIENT_H

View File

@ -2,6 +2,8 @@
#include "ui_NTPServerConfig.h"
#include "NetMgr.h"
#include <QTime>
#include <QRegExpValidator>
#include "ftpclient.h"
CNTPServerConfig::CNTPServerConfig(QWidget *parent) :
QWidget(parent),
@ -10,6 +12,14 @@ CNTPServerConfig::CNTPServerConfig(QWidget *parent) :
ui->setupUi(this);
ui->widget_3->setProperty("flag", "Title");
ui->widget->setProperty("flag", "normal");
QString exp = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.)"
"{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
QRegExp rege(exp);
QValidator *Validator = new QRegExpValidator(rege);
ui->lineEdit_NTP_IP->setValidator(Validator);
Init();
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
}
@ -57,3 +67,100 @@ void CNTPServerConfig::on_pushButton_manual_clicked()
g_NetMgr->PostJson(req,allObj);
}
void CNTPServerConfig::Init()
{
QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ServerConfig.json";
if(!fileName.isEmpty())
{
qDebug() << "打开" << fileName ;
QFile file(fileName);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString value = file.readAll();
file.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
QMessageBox::about(NULL, "提示", "读取文件错误!");
return;
}
m_ServerObject = document.object();
if(m_ServerObject.contains(QStringLiteral("NTP_Server"))){
QJsonObject tempObject = m_ServerObject.value(QStringLiteral("NTP_Server")).toObject();
QJsonObject OptionObject = tempObject["option"].toObject();
ui->lineEdit_NTP_IP->setText(OptionObject["ntpNetworkStation"].toString());
if(OptionObject["ntpSwitch"].toString() == "0"){
ui->radioButton_switch->setChecked(false);
ui->radioButton_switch->setText("关闭");
}else if(OptionObject["ntpSwitch"].toString() == "1"){
ui->radioButton_switch->setChecked(true);
ui->radioButton_switch->setText("启动");
}
}
}
}
void CNTPServerConfig::slotReplyStatus(int result)
{
qDebug()<< "Result" << result << endl;
if(!result){
QJsonObject NTPServerObj,itemObj;
itemObj["ntpNetworkStation"] = ui->lineEdit_NTP_IP->text();
if(ui->radioButton_switch->isChecked()){
ui->radioButton_switch->setChecked(false);
itemObj["ntpSwitch"] = "0";
ui->radioButton_switch->setText("关闭");
}
else{
ui->radioButton_switch->setChecked(true);
itemObj["ntpSwitch"] = "1";
ui->radioButton_switch->setText("启动");
}
NTPServerObj["option"] = itemObj;
m_ServerObject["NTP_Server"] = NTPServerObj;
QJsonDocument jsonDoc;
jsonDoc.setObject(m_ServerObject);
QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ServerConfig.json";
QFile file(fileName);
file.open(QIODevice::WriteOnly);
file.write(jsonDoc.toJson());
file.close();
}
}
void CNTPServerConfig::on_radioButton_switch_clicked()
{
connect(g_FtpClient, SIGNAL(sigReplyStatus(int)), this, SLOT(slotReplyStatus(int)));
QJsonObject NTPServerObj,itemObj;
itemObj["ntpNetworkStation"] = ui->lineEdit_NTP_IP->text();
if(ui->radioButton_switch->isChecked()){
itemObj["ntpSwitch"] = "1";
ui->radioButton_switch->setText("启动");
}
else{
itemObj["ntpSwitch"] = "0";
ui->radioButton_switch->setText("关闭");
}
NTPServerObj["option"] = itemObj;
m_ServerObject["NTP_Server"] = NTPServerObj;
QJsonDocument jsonDoc;
jsonDoc.setObject(m_ServerObject);
QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ServerConfig.json";
QFile file(fileName);
file.open(QIODevice::WriteOnly);
file.write(jsonDoc.toJson());
file.close();
QString str = QString("ftp://%1/CIDW/qtconfig/%2").arg(IP).arg("ServerConfig.json");
g_FtpClient->SetServerInfo(str);
g_FtpClient->SetUserInfo("root","@#cidw!@123456");
g_FtpClient->UpLoadFile(fileName,"ServerConfig.json",4);
}

View File

@ -25,9 +25,17 @@ private slots:
void on_pushButton_manual_clicked();
void slotNetMgr(QString sAddr,const QVariant& msg);
void on_pushButton_NTP_clicked();
void on_radioButton_switch_clicked();
void slotReplyStatus(int );
private:
Ui::CNTPServerConfig *ui;
NetMgr *m_pNetMgr;
void Init();
QJsonObject m_ServerObject;
};
#endif // NTPSERVERCONFIG_H

View File

@ -88,15 +88,37 @@
<property name="title">
<string>B码对时</string>
</property>
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="pushButton_B">
<property name="geometry">
<rect>
<x>30</x>
<y>60</y>
<width>103</width>
<width>120</width>
<height>35</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#pushButton_B { border-image: url(:/image/Btn/normal_Btn.png);
color:#1f5188 }
#pushButton_B:hover { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_B:pressed { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_B:checked { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}</string>
</property>
<property name="text">
<string>B码对时</string>
</property>
@ -111,10 +133,10 @@
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<x>11</x>
<y>41</y>
<width>410</width>
<height>82</height>
<height>81</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -135,12 +157,12 @@
</size>
</property>
<property name="text">
<string>NTP对时地址</string>
<string>NTP对时IP</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="lineEdit_NTP_IP">
<property name="minimumSize">
<size>
<width>200</width>
@ -158,43 +180,11 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>时间间隔:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
<widget class="QRadioButton" name="radioButton_switch">
<property name="text">
<string>启动</string>
</property>
</widget>
</item>
</layout>
</widget>

View File

@ -341,7 +341,7 @@ void NetMgr::httpFinished(QNetworkReply *reply)
void NetMgr::parseData(const QByteArray &szData, const QString &sUrlPath, QString sAddr)
{
qDebug() << sUrlPath << szData;
//qDebug() << sUrlPath << szData;
QJsonDocument doc = QJsonDocument::fromJson(szData);
QJsonObject obj = doc.object();
QVariant var;

26
QGraphicsMovieItem.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "QGraphicsMovieItem.h"
QGraphicsMovieItem::QGraphicsMovieItem(QGraphicsItem *parent) : QGraphicsItem(parent) {}
void QGraphicsMovieItem::setMovie(QMovie* movie) {
prepareGeometryChange();
QObject::disconnect(mConnection);
mMovie = movie;
if (mMovie) {
mConnection = QObject::connect(mMovie, &QMovie::frameChanged, [=]{ update(); });
}
}
QRectF QGraphicsMovieItem::boundingRect() const {
if (mMovie) { return mMovie->frameRect(); }
else { return QRectF(); }
}
void QGraphicsMovieItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
Q_UNUSED(option)
Q_UNUSED(widget)
if (mMovie) {
painter->drawPixmap(mMovie->frameRect(), mMovie->currentPixmap(), mMovie->frameRect());
}
}

24
QGraphicsMovieItem.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef QGRAPHICSMOVIEITEM_H
#define QGRAPHICSMOVIEITEM_H
#include <QGraphicsItem>
#include <QObject>
#include <QMovie>
#include <QPainter>
class QGraphicsMovieItem : public QGraphicsItem
{
//Q_OBJECT
public:
QGraphicsMovieItem(QGraphicsItem *parent = nullptr);
void setMovie(QMovie* movie);
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
private:
QPointer<QMovie> mMovie;
QMetaObject::Connection mConnection;
};
#endif // QGRAPHICSMOVIEITEM_H

177
QMyTableViewBtnDelegate.cpp Normal file
View File

@ -0,0 +1,177 @@
#include "qmytableviewbtndelegate.h"
#include <QApplication>
#include <QMouseEvent>
#include <QMessageBox>
#include <QPainter>
#include <QStyleOption>
#include <QDesktopWidget>
#include <QToolTip>
#include <QDebug>
QMyTableViewBtnDelegate::QMyTableViewBtnDelegate(QStringList btnNames, QWidget *parent)
: QStyledItemDelegate(parent),
m_btnNames(btnNames)
{
}
QMyTableViewBtnDelegate::~QMyTableViewBtnDelegate()
{
}
// 绘制按钮
void QMyTableViewBtnDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem viewOption(option);
initStyleOption(&viewOption, index);
if (option.state.testFlag(QStyle::State_HasFocus))
viewOption.state = viewOption.state ^ QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, viewOption, index);
// 计算按钮显示区域
int nCount = m_btnNames.count();
int w = nCount != 0 ? option.rect.width() / nCount : 0;
if(w < 0) {
return;
}
for (int i = 0; i < nCount; ++i)
{
// 绘制按钮
QStyleOptionButton button;
button.rect = option.rect.adjusted(1 + i*w , 1, -(w * ( nCount - i -1 ) + 1) , -1);
button.text = m_btnNames.at(i);
button.state |= QStyle::State_Enabled;
if (button.rect.contains(m_mousePoint))
{
if (m_nType == 0)
{
button.state |= QStyle::State_MouseOver;
}
else if (m_nType == 1)
{
button.state |= QStyle::State_Sunken;
}
}
QPushButton pushBtn;
//if (i == nCount - 1)
{
pushBtn.setStyleSheet("QPushButton{border-width: 0px;\
position: absolute;\
left: 0px;\
top: 0px;\
max-width: 80px;\
width:80px;\
height: 30px;\
background: inherit;\
background-color: rgba(255, 255, 255, 0);\
border-width: 1px;\
border-style: solid;\
border-color: red;\
border-radius: 10px;\
font-size: 11px;\
color: red;}\
QPushButton:hover{background-color:red; color:#FFFFFF;}");
}
// else
// {
// pushBtn.setStyleSheet("QPushButton{border-width: 0px;\
// position: absolute;\
// left: 0px;\
// top: 0px;\
// max-width:120px; \
// width:120px;\
// height: 30px;\
// background: inherit;\
// background-color: rgba(255, 255, 255, 0);\
// border-width: 1px;\
// border-style: solid;\
// border-color: rgba(2, 182, 212, 1);\
// border-radius: 10px;\
// font-size: 11px;\
// color: #000000;}\
// QPushButton:hover{background-color:rgba(2, 182, 212, 1); color:#FFFFFF;}");
// }
pushBtn.style()->drawControl(QStyle::CE_PushButton, &button, painter, &pushBtn);
}
}
// 响应按钮事件 - 划过、按下
bool QMyTableViewBtnDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
{
m_nType = -1;
bool bRepaint = false;
QMouseEvent *pEvent = static_cast<QMouseEvent *> (event);
m_mousePoint = pEvent->pos();
int nCount = m_btnNames.count();
int w = nCount != 0 ? option.rect.width() / nCount : 0;
if(w < 0) {
return false;
}
// 还原鼠标样式
QApplication::restoreOverrideCursor();
for (int i = 0; i < nCount; ++i)
{
QStyleOptionButton button;
button.rect = option.rect.adjusted(1 + i*w , 1, -(w * ( nCount - i -1 ) + 1) , -1);
// 鼠标位于按钮之上
if (!button.rect.contains(m_mousePoint))
continue;
bRepaint = true;
switch (event->type())
{
// 鼠标滑过
case QEvent::MouseMove:
{
// 设置鼠标样式为手型
//QApplication::setOverrideCursor(Qt::PointingHandCursor);
m_nType = 0;
//QToolTip::showText(pEvent->globalPos(), m_btnNames.at(i));
break;
}
// 鼠标按下
case QEvent::MouseButtonPress:
{
m_nType = 1;
break;
}
// 鼠标释放
case QEvent::MouseButtonRelease:
{
switch (i)
{
case 0:
{
emit editData(index);
break;
}
case 1:
{
emit deleteData(index);
break;
}
default:
break;
}
}
default:
break;
}
}
return bRepaint;
}

30
QMyTableViewBtnDelegate.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef QMYTABLEVIEWBTNDELEGATE_H
#define QMYTABLEVIEWBTNDELEGATE_H
#include <QObject>
#include <QPushButton>
#include<QStyledItemDelegate>
class QMyTableViewBtnDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
explicit QMyTableViewBtnDelegate(QStringList btnNames, QWidget *parent = 0);
~QMyTableViewBtnDelegate();
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index);
signals:
void editData(const QModelIndex &index);
void deleteData(const QModelIndex &index);
private:
QPoint m_mousePoint; // 鼠标位置
int m_nType; // 按钮状态0-划过 1-按下
QStringList m_btnNames;
};
#endif // QMYTABLEVIEWBTNDELEGATE_H

View File

@ -1,11 +1,16 @@
#include "RealTimeAlarm.h"
#include "ui_RealTimeAlarm.h"
#include <QPushButton>
#include "QMyTableViewBtnDelegate.h"
#include "AlarmDetails.h"
#include "sqlitedb.h"
CRealTimeAlarm::CRealTimeAlarm(QWidget *parent) :
QWidget(parent),
ui(new Ui::CRealTimeAlarm)
{
ui->setupUi(this);
ui->widget_alarm->setProperty("flag", "Button");
headerStr = QObject::tr("序号,报警级别,报警内容,报警时间,报警详情");
model = new QStandardItemModel(ui->tableView);
@ -15,15 +20,61 @@ CRealTimeAlarm::CRealTimeAlarm(QWidget *parent) :
model->setColumnCount(headerList.size());
ui->tableView->setModel(model);
ui->tableView->setColumnWidth(2, 300);
ui->tableView->setColumnWidth(3, 300);
ui->tableView->setAlternatingRowColors(true);
model->setRowCount(10);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
ui->tableView->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(4,QHeaderView::ResizeToContents);
// 必须要设置此项否则样式表的hover无法生效
ui->tableView->setMouseTracking(true);
initTable();
}
CRealTimeAlarm::~CRealTimeAlarm()
{
delete ui;
}
void CRealTimeAlarm::createRowItem(int Row,QVariantList RowItem)
{
model->setRowCount(Row+1);
for (int j = 0; j < RowItem.size(); ++j)
{
model->setData(model->index(Row,j,QModelIndex()),RowItem.at(j));
}
}
void CRealTimeAlarm::initTable()
{
QString strTableName = "t_TriggerEvent",strSql;
strSql = QString(" triggeredTime <> '' order by triggeredTime limit 0,10");
m_vecTriggerEvent = g_SqliteDB->GetTriggerEvent(strTableName,strSql);
if(m_vecTriggerEvent.size() > 0){
for (int i = 0; i < m_vecTriggerEvent.size(); i++) {
QVariantList strRowItem ;
QString TStr = QDateTime::fromSecsSinceEpoch(m_vecTriggerEvent[i].triggeredTime).toString("yyyy-MM-dd hh:mm:ss");
strRowItem << i + 1 << m_vecTriggerEvent[i].triggeredNotification << m_vecTriggerEvent[i].triggeredFeatureName << TStr;
createRowItem(i,strRowItem);
}
QMyTableViewBtnDelegate *m_btnDelegate = new QMyTableViewBtnDelegate(QStringList()<<"详情", this);
ui->tableView->setItemDelegateForColumn(4, m_btnDelegate);
connect(m_btnDelegate, SIGNAL(editData(const QModelIndex &)), this,SLOT(Details(const QModelIndex &)));
}else{
QMessageBox::information(this, "提示", QString("未查询到数据!"));
}
}
void CRealTimeAlarm::Details(const QModelIndex &index)
{
int row = index.row();
CAlarmDetails *dialog = new CAlarmDetails();
dialog->ViewData(m_vecTriggerEvent[row]);
dialog->setWindowModality(Qt::ApplicationModal);
dialog->show();
}

View File

@ -3,7 +3,6 @@
#include <QWidget>
#include <QStandardItemModel> //数据模型类
#include "HeaderView.h"
#include "TableHeaderView.h"
#include "global.h"
@ -19,6 +18,9 @@ public:
explicit CRealTimeAlarm(QWidget *parent = nullptr);
~CRealTimeAlarm();
private slots:
void Details(const QModelIndex &index);
private:
Ui::CRealTimeAlarm *ui;
@ -26,6 +28,11 @@ private:
QStandardItemModel *model;
QString headerStr ;
QVector<TriggerEvent_t> m_vecTriggerEvent;
void initTable();
void createRowItem(int Row,QVariantList RowItem);
};
#endif // REALTIMEALARM_H

View File

@ -15,11 +15,15 @@
</property>
<property name="styleSheet">
<string notr="true">font: 16pt &quot;黑体&quot;;
color: rgb(27, 30, 35);</string>
color: rgb(27, 30, 35);
</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<widget class="QWidget" name="widget_alarm" native="true">
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="tableView">

View File

@ -1,5 +1,8 @@
#include "SystemSelfcheck.h"
#include "ui_SystemSelfcheck.h"
#include "NetMgr.h"
#include <QNetworkRequest>
#include "global.h"
CSystemSelfcheck::CSystemSelfcheck(QWidget *parent) :
QWidget(parent),
@ -14,8 +17,11 @@ CSystemSelfcheck::CSystemSelfcheck(QWidget *parent) :
"font-size:20px; color:#409CE1; font-weight:900;"));
m_centerLabel->hide();
//绑定HTTP消息响应
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
initPieChart();
bulidPieChart(75);
bulidPieChart(0);
}
@ -36,7 +42,191 @@ void CSystemSelfcheck::resizeEvent(QResizeEvent *event)
// ui->chartView->height() - m_bottomLabel->height() - 15);
}
void CSystemSelfcheck::slotNetMgr(QString sAddr,const QVariant& msg)
{
QJsonObject objec = msg.value<QJsonObject>();
if(!objec["success"].toBool()){
QString strMessage = objec["message"].toString();
if(strMessage.isEmpty())
QMessageBox::information(this, QStringLiteral("提示"), "连接失败!");
else
QMessageBox::information(this, QStringLiteral("提示"), strMessage);
return;
}
if(objec.contains("cmd")){
bulidPieChart(100);
ui->label_CPU->setText("正常");
ui->label_Power->setText("正常");
ui->label_CPU->setStyleSheet("color:green");
ui->label_Power->setStyleSheet("color:green");
QJsonValue arrays_value = objec.take("cmd");
qDebug()<<"cmd ="<<arrays_value.toString();
if(arrays_value.toString() == "42"){
QJsonArray contentArray = objec["content"].toArray();
if(contentArray.at(0)["state"] == 0){
ui->label_Board1->setText("待检");
}
if(contentArray.at(0)["state"] == 1){
ui->label_Board1->setText("检验失败");
ui->label_Board1->setStyleSheet("color:#ff0000");
}
if(contentArray.at(0)["state"] == 2){
ui->label_Board1->setText("无板卡");
ui->label_Board1->setStyleSheet("color:#ff9900");
}
if(contentArray.at(0)["state"] == 3){
ui->label_Board1->setText("板卡正常");
ui->label_Board1->setStyleSheet("color:green");
}
if(contentArray.at(1)["state"] == 0){
ui->label_Board2->setText("待检");
}
if(contentArray.at(1)["state"] == 1){
ui->label_Board2->setText("检验失败");
ui->label_Board2->setStyleSheet("color:#ff0000");
}
if(contentArray.at(1)["state"] == 2){
ui->label_Board2->setText("无板卡");
ui->label_Board2->setStyleSheet("color:#ff9900");
}
if(contentArray.at(1)["state"] == 3){
ui->label_Board2->setText("板卡正常");
ui->label_Board2->setStyleSheet("color:green");
}
if(contentArray.at(2)["state"] == 0){
ui->label_Board3->setText("待检");
}
if(contentArray.at(2)["state"] == 1){
ui->label_Board3->setText("检验失败");
ui->label_Board3->setStyleSheet("color:#ff0000");
}
if(contentArray.at(2)["state"] == 2){
ui->label_Board3->setText("无板卡");
ui->label_Board3->setStyleSheet("color:#ff9900");
}
if(contentArray.at(2)["state"] == 3){
ui->label_Board3->setText("板卡正常");
ui->label_Board3->setStyleSheet("color:green");
}
if(contentArray.at(3)["state"] == 0){
ui->label_Board4->setText("待检");
}
if(contentArray.at(3)["state"] == 1){
ui->label_Board4->setText("检验失败");
ui->label_Board4->setStyleSheet("color:#ff0000");
}
if(contentArray.at(3)["state"] == 2){
ui->label_Board4->setText("无板卡");
ui->label_Board4->setStyleSheet("color:#ff9900");
}
if(contentArray.at(3)["state"] == 3){
ui->label_Board4->setText("板卡正常");
ui->label_Board4->setStyleSheet("color:green");
}
if(contentArray.at(4)["state"] == 0){
ui->label_Board5->setText("待检");
}
if(contentArray.at(4)["state"] == 1){
ui->label_Board5->setText("检验失败");
ui->label_Board5->setStyleSheet("color:#ff0000");
}
if(contentArray.at(4)["state"] == 2){
ui->label_Board5->setText("无板卡");
ui->label_Board5->setStyleSheet("color:#ff9900");
}
if(contentArray.at(4)["state"] == 3){
ui->label_Board5->setText("板卡正常");
ui->label_Board5->setStyleSheet("color:green");
}
if(contentArray.at(5)["state"] == 0){
ui->label_Board6->setText("待检");
}
if(contentArray.at(5)["state"] == 1){
ui->label_Board6->setText("检验失败");
ui->label_Board6->setStyleSheet("color:#ff0000");
}
if(contentArray.at(5)["state"] == 2){
ui->label_Board6->setText("无板卡");
ui->label_Board6->setStyleSheet("color:#ff9900");
}
if(contentArray.at(5)["state"] == 3){
ui->label_Board6->setText("板卡正常");
ui->label_Board6->setStyleSheet("color:green");
}
if(contentArray.at(6)["state"] == 0){
ui->label_Board7->setText("待检");
}
if(contentArray.at(6)["state"] == 1){
ui->label_Board7->setText("检验失败");
ui->label_Board7->setStyleSheet("color:#ff0000");
}
if(contentArray.at(6)["state"] == 2){
ui->label_Board7->setText("无板卡");
ui->label_Board7->setStyleSheet("color:#ff9900");
}
if(contentArray.at(6)["state"] == 3){
ui->label_Board7->setText("板卡正常");
ui->label_Board7->setStyleSheet("color:green");
}
if(contentArray.at(7)["state"] == 0){
ui->label_Board8->setText("待检");
}
if(contentArray.at(7)["state"] == 1){
ui->label_Board8->setText("检验失败");
ui->label_Board8->setStyleSheet("color:#ff0000");
}
if(contentArray.at(7)["state"] == 2){
ui->label_Board8->setText("无板卡");
ui->label_Board8->setStyleSheet("color:#ff9900");
}
if(contentArray.at(7)["state"] == 3){
ui->label_Board8->setText("板卡正常");
ui->label_Board8->setStyleSheet("color:green");
}
if(contentArray.at(8)["state"] == 0){
ui->label_Board9->setText("待检");
}
if(contentArray.at(8)["state"] == 1){
ui->label_Board9->setText("检验失败");
ui->label_Board9->setStyleSheet("color:#ff0000");
}
if(contentArray.at(8)["state"] == 2){
ui->label_Board9->setText("无板卡");
ui->label_Board9->setStyleSheet("color:#ff9900");
}
if(contentArray.at(8)["state"] == 3){
ui->label_Board9->setText("板卡正常");
ui->label_Board9->setStyleSheet("color:green");
}
if(contentArray.at(9)["state"] == 0){
ui->label_Board10->setText("待检");
}
if(contentArray.at(9)["state"] == 1){
ui->label_Board10->setText("检验失败");
ui->label_Board10->setStyleSheet("color:#ff0000");
}
if(contentArray.at(9)["state"] == 2){
ui->label_Board10->setText("无板卡");
ui->label_Board10->setStyleSheet("color:#ff9900");
}
if(contentArray.at(9)["state"] == 3){
ui->label_Board10->setText("板卡正常");
ui->label_Board10->setStyleSheet("color:green");
}
}
}
}
void CSystemSelfcheck::initPieChart()
{
QChart *chart = new QChart();
@ -77,3 +267,14 @@ void CSystemSelfcheck::bulidPieChart(int percent)
m_centerLabel->show();
resizeEvent(NULL);
}
void CSystemSelfcheck::on_pushButton_check_clicked()
{
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "42");
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
g_NetMgr->PostJson(req,allObj);
}

View File

@ -23,7 +23,9 @@ private:
QChartView * m_ChartView;
QLabel * m_centerLabel;
private slots:
//网络请求数据响应
void slotNetMgr(QString sAddr,const QVariant& msg);
void initPieChart();
@ -31,6 +33,7 @@ private:
void resizeEvent(QResizeEvent *event);
void on_pushButton_check_clicked();
};
#endif // SYSTEMSELFCHECK_H

View File

@ -146,7 +146,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<widget class="QLabel" name="label_Power">
<property name="text">
<string>待检</string>
</property>
@ -162,21 +162,21 @@
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>CPU自检状态</string>
<string>CPU自检状态 </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<widget class="QLabel" name="label_CPU">
<property name="minimumSize">
<size>
<width>55</width>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>55</width>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
@ -200,7 +200,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_14">
<widget class="QLabel" name="label_Board1">
<property name="text">
<string>待检</string>
</property>
@ -218,7 +218,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<widget class="QLabel" name="label_Board2">
<property name="text">
<string>待检</string>
</property>
@ -236,7 +236,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<widget class="QLabel" name="label_Board3">
<property name="text">
<string>待检</string>
</property>
@ -254,7 +254,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_17">
<widget class="QLabel" name="label_Board4">
<property name="text">
<string>待检</string>
</property>
@ -318,7 +318,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_22">
<widget class="QLabel" name="label_Board5">
<property name="text">
<string>待检</string>
</property>
@ -336,7 +336,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_21">
<widget class="QLabel" name="label_Board6">
<property name="text">
<string>待检</string>
</property>
@ -354,7 +354,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_20">
<widget class="QLabel" name="label_Board7">
<property name="text">
<string>待检</string>
</property>
@ -372,7 +372,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
<widget class="QLabel" name="label_Board8">
<property name="text">
<string>待检</string>
</property>
@ -390,7 +390,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_18">
<widget class="QLabel" name="label_Board9">
<property name="text">
<string>待检</string>
</property>
@ -408,7 +408,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_24">
<widget class="QLabel" name="label_Board10">
<property name="text">
<string>待检</string>
</property>

View File

@ -253,16 +253,37 @@ QChart * CTerminalInfo::bulidPieChart(int percent,QString& strTitle )
void CTerminalInfo::on_pushButton_Update_clicked()
{
QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*.tar.gz"));
QStringList items;//ComboBox控件的内容
items<<QStringLiteral("系统")<<QStringLiteral("后端主程序")<<QStringLiteral("后端辅助程序");
QString dlgTitle=QStringLiteral("更新内容选择对话框");//对话框标题
QString txtLabel=QStringLiteral("请选择更新类别:");//对话框Label显示内容
int curIndex = 0;//ComboBox控件默认哪个索引的内容
bool editable = true;//ComboBox控件内容是否可被编辑
bool ok = false;
QString text = QInputDialog::getItem(this,dlgTitle,txtLabel,items,curIndex,editable,&ok);
if(!ok || text.isEmpty())
{
return;
}
QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*"));
qDebug() << filepath << endl;
QFileInfo fileinfo;
fileinfo = QFileInfo(filepath);
QString file_suffix = fileinfo.suffix();
QString FileName = fileinfo.fileName();
if(FileName.isEmpty())
return;
QString str = QString("ftp://%1/var/%2").arg(IP).arg(FileName);
g_FtpClient->SetServerInfo(str);
g_FtpClient->SetUserInfo("root","@#cidw!@123456");
g_FtpClient->UpLoadFile(filepath,FileName);
if(text == "系统")
curIndex = 0;
else if(text == "后端主程序")
curIndex = 1;
else if(text == "后端辅助程序")
curIndex = 2;
g_FtpClient->UpLoadFile(filepath,FileName,curIndex);
}

View File

@ -133,7 +133,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">color: rgb(0, 255, 0);</string>
<string notr="true">color: rgb(0, 170, 0);</string>
</property>
<property name="text">
<string>在线</string>

View File

@ -1,14 +1,46 @@
#include "TrendGraph.h"
#include "ui_TrendGraph.h"
#include <QListView>
#include "global.h"
CTrendGraph::CTrendGraph(QWidget *parent) :
QWidget(parent),
ui(new Ui::CTrendGraph)
{
ui->setupUi(this);
QDateTime curDateTime=QDateTime::currentDateTime();//通过QDateTime的currentDateTime获得当前的日期时间并赋值给curDateTime
ui->dateTimeEdit_start->setDateTime(curDateTime);
ui->dateTimeEdit_end->setDateTime(curDateTime);
ui->comboBox_channel->setView(new QListView());
for (int i = 0; i < g_ChannelBaseInfo.size(); i++) {
ui->comboBox_channel->insertItem(i,g_ChannelBaseInfo[i].channelName);
}
connect(ui->comboBox_channel,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(on_comboBox_channel_currentTextChanged(const QString&)));
}
CTrendGraph::~CTrendGraph()
{
delete ui;
}
void CTrendGraph::on_comboBox_channel_currentTextChanged(const QString& strChannelName)
{
int i = 0;
for (i = 0; i < g_ChannelBaseInfo.size(); i++) {
if(strChannelName == g_ChannelBaseInfo[i].channelName){
m_strChannelID = g_ChannelBaseInfo[i].channelID;
break;
}
}
}
void CTrendGraph::on_pushButton_search_clicked()
{
}

View File

@ -15,8 +15,14 @@ public:
explicit CTrendGraph(QWidget *parent = nullptr);
~CTrendGraph();
private slots:
void on_pushButton_search_clicked();
void on_comboBox_channel_currentTextChanged(const QString&);
private:
Ui::CTrendGraph *ui;
QString m_strChannelID;
};
#endif // TRENDGRAPH_H

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1054</width>
<width>1148</width>
<height>561</height>
</rect>
</property>
@ -58,20 +58,7 @@ color: rgb(27, 30, 35);</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
<widget class="QDateTimeEdit" name="dateTimeEdit_start"/>
</item>
</layout>
</item>
@ -85,23 +72,7 @@ color: rgb(27, 30, 35);</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QDateTimeEdit" name="dateTimeEdit_end"/>
</item>
</layout>
</item>
@ -115,7 +86,7 @@ color: rgb(27, 30, 35);</string>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<widget class="QComboBox" name="comboBox_channel">
<property name="minimumSize">
<size>
<width>230</width>
@ -146,7 +117,29 @@ color: rgb(27, 30, 35);</string>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="pushButton_search">
<property name="minimumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>35</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#pushButton_search { border-image: url(:/image/Btn/normal_Btn.png);
color:#1f5188 }
#pushButton_search:hover { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_search:pressed { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}
#pushButton_search:checked { border-image: url(:/image/Btn/normal_Btn_p.png);
color:#ffffff}</string>
</property>
<property name="text">
<string>查询</string>
</property>

View File

@ -110,6 +110,8 @@ void CTriggerConfig::LoadTriggerConfig(QString& strChannelID)
trgStatus.append("单次触发");
trgStatus.append("连续触发");
if(m_vecTriggerConfig.size() > 0){
model->setRowCount(m_vecTriggerConfig.size());
for (int i = 0; i < m_vecTriggerConfig.size(); i++) {
@ -335,7 +337,7 @@ void CTriggerConfig::on_comboBox_channelConfig_currentTextChanged(const QString
}
}else if(g_ChannelBaseInfo[ii].channelType =="SLOW_CURRENT"){
}else if(g_ChannelBaseInfo[ii].channelType =="SLOW_CURRENT" || g_ChannelBaseInfo[ii].channelType =="PULSE_CURRENT"){
LoadTriggerConfig(g_ChannelBaseInfo[ii].channelID);
if(m_vecTriggerConfig.size() < 1){
@ -570,7 +572,7 @@ void CTriggerConfig::on_pushButton_save_clicked()
rowObj["triggerFeatureName"] = "MinValues";
else if(triggerConfig[j].Characteristic == "最大值")
rowObj["triggerFeatureName"] = "MaxValues";
else if(triggerConfig[j].Characteristic == "平均值")
else if(triggerConfig[j].Characteristic == "平均值" || triggerConfig[j].Characteristic == "偏执电压")
rowObj["triggerFeatureName"] = "DCValues";
else if(triggerConfig[j].Characteristic == "有效值")
rowObj["triggerFeatureName"] = "RMSValues";
@ -582,7 +584,7 @@ void CTriggerConfig::on_pushButton_save_clicked()
rowObj["triggerFeatureName"] = "IntegratPk2Pk";
else if(triggerConfig[j].Characteristic == "转速")
rowObj["triggerFeatureName"] = "SpeedProfileSpeed";
else if(triggerConfig[j].Characteristic == "速度峰值")//积分
else if(triggerConfig[j].Characteristic == "速度峰值" || triggerConfig[j].Characteristic == "位移峰值")//积分
rowObj["triggerFeatureName"] = "IntegratPk2Pk/2";
else if(triggerConfig[j].Characteristic == "峰值")
rowObj["triggerFeatureName"] = "DiagnosisPeak";
@ -629,6 +631,11 @@ void CTriggerConfig::on_pushButton_save_clicked()
file.write(jsonDoc.toJson());
file.close();
QVector<WorkCondition_t>().swap(m_WorkCondition);
QString wherecon = "";
wherecon = QString("Enable = \"1\" ");
m_WorkCondition = g_SqliteDB->GetWorkCondition("t_WorkCondition",wherecon);
QString str = QString("ftp://%1/CIDW/qtconfig/%2").arg(IP).arg("TriggerSettings.json");
g_FtpClient->SetServerInfo(str);
g_FtpClient->SetUserInfo("root","@#cidw!@123456");

View File

@ -250,6 +250,7 @@ void CUnitSetting::on_Btn_Confirm_clicked()
array.append("可逆式机组");
array.append("灯泡式机组");
array.append("冲击式机组");
array.append("贯流式机组");
tempObj["Options"] = array;
paramsObj.insert("UnitStyle",tempObj);
tempObj.remove("content");
@ -277,7 +278,21 @@ void CUnitSetting::on_Btn_Confirm_clicked()
g_FtpClient->SetUserInfo("root","@#cidw!@123456");
g_FtpClient->UpLoadFile(fileName,"UnitParameters.json");
}
void CUnitSetting::on_UnitStyle_currentTextChanged(const QString &arg1)
{
if(arg1 == "贯流式机组"){
ui->UpperGuideVaneWattage->setEnabled(false);
ui->LowerGuideVaneWattage->setEnabled(false);
ui->WaterGuideVaneWattage->setEnabled(false);
ui->ThrustWattage->setEnabled(false);
}else{
ui->UpperGuideVaneWattage->setEnabled(true);
ui->LowerGuideVaneWattage->setEnabled(true);
ui->WaterGuideVaneWattage->setEnabled(true);
ui->ThrustWattage->setEnabled(true);
}
}

View File

@ -18,6 +18,8 @@ public:
private slots:
void on_Btn_Confirm_clicked();
void on_UnitStyle_currentTextChanged(const QString &arg1);
private:
Ui::CUnitSetting *ui;

View File

@ -13,6 +13,8 @@ CWaveDisPlay::CWaveDisPlay(QWidget *parent) :
m_PackgNum = 1;
bFlag = false;
m_Times = 0;
m_Count = 0;
OneSecond = true;
ui->widget->setProperty("flag", "Title");
ui->widget_4->setProperty("flag", "normal");
// QAbstractItemView* view = ui->comboBox_channel_2->view();
@ -101,6 +103,7 @@ void CWaveDisPlay::on_Btn_Hand_clicked()
if(ui->Btn_Hand->isChecked()){
//交互设置
ui->widget_wave->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iMultiSelect);
ui->Btn_Zoom->setChecked(false);
}else if(!ui->Btn_Hand->isChecked()){
ui->widget_wave->setInteractions(QCP::iNone);
}
@ -109,9 +112,15 @@ void CWaveDisPlay::on_Btn_Hand_clicked()
void CWaveDisPlay::on_Btn_Zoom_clicked()
{
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmZoom);
ui->widget_wave->selectionRect()->setPen(QPen(Qt::black,1,Qt::DashLine));//虚线
ui->widget_wave->selectionRect()->setBrush(QBrush(QColor(255, 222, 173,50)));//NavajoWhite
if(ui->Btn_Zoom->isChecked()){
ui->Btn_Hand->setChecked(false);
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmZoom);
ui->widget_wave->selectionRect()->setPen(QPen(Qt::black,1,Qt::DashLine));//虚线
ui->widget_wave->selectionRect()->setBrush(QBrush(QColor(255, 222, 173,50)));//NavajoWhite
}
else if(!ui->Btn_Zoom->isChecked()){
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmNone);
}
}
@ -148,30 +157,83 @@ void CWaveDisPlay::ParseDataTimeWave(QJsonObject & objContent)
}
QString data = objContent["Data"].toString();
m_WaveData = m_WaveData + data + ",";
if(package + 1 == packageMax){
qDebug() << "package" <<package << "packageMax" <<packageMax << endl;
m_PackgNum = 1;
bFlag = true;
m_ListWaveData = m_WaveData.split(",");
//qDebug() << m_ListWaveData << endl;
ui->widget_wave->xAxis->setRange(0, 1);
ui->widget_wave->xAxis->setLabel("Time(s)");
double gap = (double)1/(double)m_ListWaveData.size();
double f = 0.0;
QVector<double> x,y;
QCPGraph* graph = ui->widget_wave->addGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
for(int i = 0; i < m_ListWaveData.size();i++){
f += gap;
x.push_back(f);
y.push_back(m_ListWaveData[i].toDouble());
}
qDebug() << "x" <<x.size() << "y" << y.size() << endl;
graph->setData(x,y);
ui->widget_wave->xAxis->setRange(0, 1);
on_Btn_Scales_clicked();
ui->widget_wave->replot();
if(package + 1 == packageMax){
if(!OneSecond){
m_Count ++;
m_WaveData = m_WaveData + data ;
qDebug() << "4S" <<"package" <<package << "packageMax" <<packageMax << endl;
m_PackgNum = 1;
QStringList waveData;
waveData = m_WaveData.split(",");
m_ListWaveData.append(waveData);
if(m_Count == 4){
ui->widget_wave->xAxis->setRange(0, 4);
ui->widget_wave->xAxis->setLabel("Time(s)");
double gap = (double)4/(double)m_ListWaveData.size();
QVector<double> x,y;
double f = 0.0;
QCPGraph* graph = ui->widget_wave->addGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
for(int i = 0; i < m_ListWaveData.size();i++){
x.push_back(f);
y.push_back(m_ListWaveData[i].toDouble());
f += gap;
}
qDebug() << "x" <<x.size() << "y" << y.size() << endl;
graph->setData(x,y);
ui->widget_wave->xAxis->setRange(0, 1);
on_Btn_Scales_clicked();
ui->widget_wave->replot();
m_ListWaveData.clear();
m_Count = 0;
}
m_WaveData = "";
}else {
m_WaveData = m_WaveData + data;
qDebug() << "package" <<package << "packageMax" <<packageMax << endl;
m_PackgNum = 1;
bFlag = true;
m_ListWaveData = m_WaveData.split(",");
ui->widget_wave->xAxis->setRange(0, 1);
ui->widget_wave->xAxis->setLabel("Time(s)");
double gap = (double)1/(double)m_ListWaveData.size();
double f = 0.0;
QVector<double> x,y,x2,y2;
QCPGraph* graph = ui->widget_wave->addGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
for(int i = 0; i < m_ListWaveData.size();i++){
x.push_back(f);
y.push_back(m_ListWaveData[i].toDouble());
f += gap;
for(int j = 0; j < m_ListKeyPhaseData.size();j++){
if(m_ListKeyPhaseData[j].toInt() == i){
x2.push_back(f);
y2.push_back(m_ListWaveData[i].toDouble());
}
}
}
QCPGraph* dwPoints = new QCPGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
dwPoints->setAdaptiveSampling(false);
dwPoints->setLineStyle(QCPGraph::lsNone);
dwPoints->setScatterStyle(QCPScatterStyle::ssDot);
dwPoints->setPen(QPen(QBrush(Qt::red), 5));
dwPoints->addData(x2, y2);
QVector<double>::iterator max = std::max_element(std::begin(y), std::end(y));
double biggest = *max;
qDebug() << "x" << x.size() << "y" << y.size() << endl;
qDebug() << "x2" << x2.size() << "y2" << y2.size() << endl;
graph->setData(x,y);
ui->widget_wave->xAxis->setRange(0, 1);
ui->widget_wave->yAxis->setRange(-1,biggest+2);
//on_Btn_Scales_clicked();
ui->widget_wave->replot();
}
}else{
m_WaveData = m_WaveData + data + ",";
}
}
@ -218,9 +280,24 @@ void CWaveDisPlay::ParseDataFsWave(QJsonObject & objContent)
}
}
void CWaveDisPlay::ParseDataKeyPhase(QJsonObject& objContent)
{
QString data = objContent["Data"].toString();
m_ListKeyPhaseData = data.split(",");
qDebug() << "m_ListKeyPhaseData" << m_ListKeyPhaseData << endl;
}
void CWaveDisPlay::slotNetMgr(QString sAddr, const QVariant &msg)
{
QJsonObject objec = msg.value<QJsonObject>();
if(!objec["success"].toBool()){
QString strMessage = objec["message"].toString();
if(strMessage.isEmpty())
QMessageBox::information(this, QStringLiteral("提示"), "连接失败!");
else
QMessageBox::information(this, QStringLiteral("提示"), strMessage);
return;
}
if(objec.contains("cmd"))
{
QJsonValue arrays_value = objec.take("cmd");
@ -228,9 +305,12 @@ void CWaveDisPlay::slotNetMgr(QString sAddr, const QVariant &msg)
if(arrays_value.toString() == "30"){
QJsonObject objValue = objec["content"].toObject();
ParseDataTimeWave(objValue);
} if(arrays_value.toString() == "32"){
}else if(arrays_value.toString() == "32"){
QJsonObject objValue = objec["content"].toObject();
ParseDataFsWave(objValue);
}else if(arrays_value.toString() == "92"){
QJsonObject objValue = objec["content"].toObject();
ParseDataKeyPhase(objValue);
}
}
}
@ -263,11 +343,28 @@ void CWaveDisPlay::on_Btn_Timewave_clicked()
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
if(m_ChannelType == "TACHOMETER"){
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "92");//获取键相
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}
}
void CWaveDisPlay::on_Btn_Fswave_clicked()
{
if(ui->pushButton_4S->isChecked()){
QMessageBox::information(this, QStringLiteral("提示"), "请切换到1S波形");
ui->Btn_Fswave->setChecked(false);
return;
}
ui->Btn_Timewave->setChecked(false);
if(!ui->Btn_Fswave->isChecked()){
InitGraph();
@ -297,10 +394,10 @@ void CWaveDisPlay::mouseMoveEvent(QMouseEvent *event)
//获得鼠标位置处对应的横坐标数据x
double x = ui->widget_wave->xAxis->pixelToCoord(event->pos().x());
//遍历曲线
for (int i = 0; i < graphCount && tracer->visible(); ++i)
//for (int i = 0; i < graphCount && tracer->visible(); ++i)
{
//显示锚点
QCPGraph *mGraph = ui->widget_wave->graph(i);
QCPGraph *mGraph = ui->widget_wave->graph(0);
tracer->setGraph(mGraph);//将锚点设置到被选中的曲线上
tracer->setGraphKey(x); //将游标横坐标设置成刚获得的横坐标数据x
tracer->updatePosition(); //使得刚设置游标的横纵坐标位置生效
@ -309,7 +406,7 @@ void CWaveDisPlay::mouseMoveEvent(QMouseEvent *event)
tracerLabel->setVisible(true);
tracerLabel->setText(QString("X: %1 Y: %2").arg( QString::number(xValue)).arg(QString::number(yValue)));
//显示tip框
QCPDataContainer<QCPGraphData>::const_iterator coorPoint = ui->widget_wave->graph(i)->data().data()->findBegin(xValue, true);//true代表向左搜索
QCPDataContainer<QCPGraphData>::const_iterator coorPoint = ui->widget_wave->graph(0)->data().data()->findBegin(xValue, true);//true代表向左搜索
}
//重绘
@ -352,19 +449,44 @@ void CWaveDisPlay::on_comboBox_channel_2_currentTextChanged(const QString &arg1)
}
}
m_ChannelID = g_ChannelBaseInfo[i].channelID;
m_ChannelType = g_ChannelBaseInfo[i].channelType;
if(ui->Btn_Timewave->isChecked())
{
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
m_Times = 0;
if(ui->pushButton_4S->isChecked()){
OneSecond = false;
id1 = startTimer(1000); //参数1 间隔 单位 毫秒
//定时器第二种方式
QTimer * timer = new QTimer(this);
//启动定时器
timer->start(500);
}else if(ui->pushButton_1S->isChecked()){
OneSecond = true;
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
if(m_ChannelType == "TACHOMETER"){
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "92");//获取键相
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}
}
}
else if(ui->Btn_Fswave->isChecked())
{
@ -395,6 +517,7 @@ void CWaveDisPlay::timerEvent(QTimerEvent *ev)
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
m_Times = m_Times + 1;
qDebug() << "m_Times" << m_Times << endl;
if(m_Times == 4){
killTimer(id1);
m_Times = 0;
@ -405,9 +528,11 @@ void CWaveDisPlay::timerEvent(QTimerEvent *ev)
void CWaveDisPlay::on_pushButton_1S_clicked()
{
OneSecond = true;
ui->pushButton_4S->setChecked(false);
if(!ui->pushButton_1S->isChecked()){
if(ui->pushButton_1S->isChecked()){
on_comboBox_channel_2_currentTextChanged("");
return;
}
}
@ -415,14 +540,17 @@ void CWaveDisPlay::on_pushButton_1S_clicked()
void CWaveDisPlay::on_pushButton_4S_clicked()
{
if(ui->Btn_Fswave->isChecked()){
QMessageBox::information(this, QStringLiteral("提示"), "请切换到时域图!");
ui->pushButton_4S->setChecked(false);
return;
}
OneSecond = false;
m_Times = 0;
ui->pushButton_1S->setChecked(false);
if(ui->pushButton_4S->isChecked()){
id1 = startTimer(1000); //参数1 间隔 单位 毫秒
//定时器第二种方式
QTimer * timer = new QTimer(this);
//启动定时器
timer->start(500);
on_comboBox_channel_2_currentTextChanged("");
return;
}

View File

@ -47,8 +47,10 @@ private:
Ui::CWaveDisPlay *ui;
NetMgr *m_pNetMgr; //HTTP消息类对象
QString m_ChannelID;
QString m_ChannelType;
QString m_WaveData;
QStringList m_ListWaveData;
QStringList m_ListKeyPhaseData;
QString m_FsWaveData;
int m_PackgNum;
bool bFlag;
@ -57,9 +59,12 @@ private:
int id1; //定时器1的唯一标示
int m_Times;
int m_Count;
bool OneSecond;
void InitWindows();
void ParseDataTimeWave(QJsonObject&);
void ParseDataFsWave(QJsonObject&);
void ParseDataKeyPhase(QJsonObject&);
void InitGraph();
void Cursor();

View File

@ -11,7 +11,7 @@ CWorkingcondition::CWorkingcondition(QWidget *parent) :
ui->setupUi(this);
ui->widget_2->setProperty("flag","wcChannel");
ui->widget_3->setProperty("flag","normal");
headerStr = QObject::tr("序号,工况名称,使能,起始工况,描述");
headerStr = QObject::tr("ID,工况名称,使能,起始工况,描述");
model = new QStandardItemModel(ui->tableView);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行
QStringList headerList = headerStr.split(",");
@ -654,6 +654,7 @@ void CWorkingcondition::on_pushButton_del_clicked()
void CWorkingcondition::on_pushButton_save_clicked()
{
int flag = -1;
for (int i = 0; i < model->rowCount(); i++) {
QComboBox *gg = (QComboBox*)(ui->tableView->indexWidget(model->index(i,2)));
QRadioButton *radio = (QRadioButton*)(ui->tableView->indexWidget(model->index(i,3)));
@ -672,6 +673,7 @@ void CWorkingcondition::on_pushButton_save_clicked()
if(radiocheck){
strStartWorkCondition = "1";
flag = 1;
}else if(!radiocheck){
strStartWorkCondition = "0";
@ -682,7 +684,10 @@ void CWorkingcondition::on_pushButton_save_clicked()
g_SqliteDB->UpdateDataSql(strTablename,strSql);
}
if(flag == -1){
QMessageBox::information(this, QStringLiteral("提示"), "请选择起始工况!");
return;
}
QVector<WorkCondition_t> WorkCondition = g_SqliteDB->GetWorkCondition("t_WorkCondition","");
QJsonArray arrayWorkCondition;
@ -690,7 +695,7 @@ void CWorkingcondition::on_pushButton_save_clicked()
QJsonObject tempObj;
qDebug() << "WorkCondition[i].CheckWorkConditionInterval.toInt()" << WorkCondition[i].CheckWorkConditionInterval.toInt() << endl;
tempObj["CheckWorkConditionInterval"] = WorkCondition[i].CheckWorkConditionInterval.toInt();
tempObj["SN"] = WorkCondition[i].SN;
tempObj["SN"] = i + 1;
tempObj["Enable"] = WorkCondition[i].Enable;
if(WorkCondition[i].StartWorkCondition == "1")
tempObj["StartWorkCondition"] = true;

View File

@ -2601,7 +2601,7 @@ color: rgb(27, 30, 35);
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<widget class="QTextEdit" name="textEdit_comment">
<property name="minimumSize">
<size>
<width>0</width>

View File

@ -14,6 +14,7 @@ FtpClient::FtpClient(QWidget *parent)
m_inputFile = NULL;
m_fileName = "";
m_Type = -1;
connect(m_ftpManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
@ -36,6 +37,7 @@ void FtpClient::SetServerInfo(const QString fileAddr, int Port/* =21 */)
m_ftpManager->disconnect(SIGNAL(finished(QNetworkReply*)));
connect(m_ftpManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
//connect(m_ftpManager, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(CheckReplyStatus(QNetworkReply::NetworkError)));
m_ftpUrl = new QUrl(fileAddr);
m_ftpUrl->setPort(Port);
@ -53,9 +55,11 @@ void FtpClient::slotNetMgr(QString sAddr, const QVariant &msg)
bool Status = objec.take("success").toBool();
QString strMessage = objec.take("message").toString();
if(Status){
sigReplyStatus(1);
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("保存成功!"));
}else{
QMessageBox::information(this, QStringLiteral("提示"), strMessage);
sigReplyStatus(0);
}
}
}
@ -64,20 +68,24 @@ void FtpClient::slotNetMgr(QString sAddr, const QVariant &msg)
void FtpClient::finished(QNetworkReply* reply)
{
QNetworkReply::NetworkError error = reply->error();
qDebug() << "finished" << error <<endl;
if(m_fileName != ""){
//QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("保存成功!"));
QJsonObject allObj,cmdBody,temp;
QJsonArray tempArray;
if(m_fileName.contains("tar.gz")){
allObj.insert("cmd", "46");
temp["fileName"] = m_fileName;
allObj.insert("cmdBody",temp);
qDebug() << allObj << endl;
}else{
if(m_fileName.contains(".json")){
allObj.insert("cmd", "90");
temp["fileName"] = m_fileName;
if(m_Type >= 0)
temp["content"] = m_Type;
tempArray.append(temp);
allObj.insert("cmdBody",tempArray);
}else{
allObj.insert("cmd", "46");
allObj.insert("type", m_Type);
temp["fileName"] = m_fileName;
allObj.insert("cmdBody",temp);
}
qDebug() << allObj << endl;
@ -87,6 +95,7 @@ void FtpClient::finished(QNetworkReply* reply)
req.setUrl(sUrl);
g_NetMgr->PostJson(req,allObj);
m_fileName = "";
m_Type = -1;
//QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("保存成功!"));
}
@ -128,13 +137,14 @@ void FtpClient::CheckReplyStatus(QNetworkReply::NetworkError inputError)
}
}
void FtpClient::UpLoadFile(const QString fileSource, const QString fileName)
void FtpClient::UpLoadFile(const QString fileSource, const QString fileName,int type)
{
if(fileSource.isEmpty())
{
return;
}
m_fileName = fileName;
m_Type = type;
QFile file(fileSource);
if(!file.exists())
{
@ -146,9 +156,9 @@ void FtpClient::UpLoadFile(const QString fileSource, const QString fileName)
//QString result = QString::fromLatin1(fileDest.toStdString().c_str());
//m_ftpUrl->setPath(result);
QNetworkReply* reply = m_ftpManager->put(QNetworkRequest(*m_ftpUrl), data);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(CheckReplyStatus(QNetworkReply::NetworkError)));
//connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(CheckReplyStatus(QNetworkReply::NetworkError)));
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
//connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
reply->deleteLater();
file.close();

View File

@ -23,11 +23,13 @@ public:
//设置服务器地址和端口号
void SetServerInfo(const QString fileAddr, int Port=21);
//上传文件
void UpLoadFile(const QString fileSource, const QString fileDest);
void UpLoadFile(const QString fileSource, const QString fileDest,int type = -1);
//下载文件
void DownLoad(const QString fileSource, const QString fileDest);
private:
signals:
void sigReplyStatus(int result);
public slots:
void CheckReplyStatus(QNetworkReply::NetworkError inputError);
@ -39,6 +41,7 @@ private:
QFile* m_inputFile;
QNetworkAccessManager *m_ftpManager;
QUrl* m_ftpUrl;
int m_Type;
QString m_fileName;
};

View File

@ -213,6 +213,20 @@ typedef struct _TriggerConfig{
QString TriggerType;
} TriggerConfig_t;
typedef struct _TriggerEvent{
QString triggeredChannelName;
QString triggeredType;
QString triggeredValue;
QString triggeredNotification;
QString triggeredDataWatchNo;
QString triggeredDataWatchName;
QString triggeredChannelID;
int triggeredTime;
int triggeredEquipmentID;
QString triggeredEventName;
QString triggeredFeatureName;
}TriggerEvent_t ;
typedef struct _Charateristic{
double Amp1x;
double Phase1x;

BIN
image/unit/1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
image/unit/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

BIN
image/unit/dengpaoshi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

BIN
image/unit/gif.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 MiB

BIN
image/unit/hunliushi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 KiB

BIN
image/unit/kenishi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

BIN
image/unit/zhouliushi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

38
include/mqtt/qmqtt.h Normal file
View File

@ -0,0 +1,38 @@
/*
* qmqtt.h - qmqtt library heaer
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_H
#define QMQTT_H
#include <qmqtt_message.h>
#include <qmqtt_client.h>
#endif // QMQTT_H

286
include/mqtt/qmqtt_client.h Normal file
View File

@ -0,0 +1,286 @@
/*
* qmqtt_client.h - qmqtt client header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_CLIENT_H
#define QMQTT_CLIENT_H
#include <qmqtt_global.h>
#include <QObject>
#include <QString>
#include <QHostAddress>
#include <QByteArray>
#include <QAbstractSocket>
#include <QScopedPointer>
#include <QList>
#ifdef QT_WEBSOCKETS_LIB
#include <QWebSocket>
#endif // QT_WEBSOCKETS_LIB
#ifndef QT_NO_SSL
#include <QSslConfiguration>
QT_FORWARD_DECLARE_CLASS(QSslError)
#endif // QT_NO_SSL
#ifndef Q_ENUM_NS
#define Q_ENUM_NS(x)
#endif // Q_ENUM_NS
namespace QMQTT {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
Q_MQTT_EXPORT Q_NAMESPACE
#endif
static const quint8 LIBRARY_VERSION_MAJOR = 0;
static const quint8 LIBRARY_VERSION_MINOR = 3;
static const quint8 LIBRARY_VERSION_REVISION = 1;
//static const char* LIBRARY_VERSION = "0.3.1";
enum MQTTVersion
{
V3_1_0 = 3,
V3_1_1 = 4
};
Q_ENUM_NS(MQTTVersion)
enum ConnectionState
{
STATE_INIT = 0,
STATE_CONNECTING,
STATE_CONNECTED,
STATE_DISCONNECTED
};
Q_ENUM_NS(ConnectionState)
enum ClientError
{
UnknownError = 0,
SocketConnectionRefusedError,
SocketRemoteHostClosedError,
SocketHostNotFoundError,
SocketAccessError,
SocketResourceError,
SocketTimeoutError,
SocketDatagramTooLargeError,
SocketNetworkError,
SocketAddressInUseError,
SocketAddressNotAvailableError,
SocketUnsupportedSocketOperationError,
SocketUnfinishedSocketOperationError,
SocketProxyAuthenticationRequiredError,
SocketSslHandshakeFailedError,
SocketProxyConnectionRefusedError,
SocketProxyConnectionClosedError,
SocketProxyConnectionTimeoutError,
SocketProxyNotFoundError,
SocketProxyProtocolError,
SocketOperationError,
SocketSslInternalError,
SocketSslInvalidUserDataError,
SocketTemporaryError,
MqttUnacceptableProtocolVersionError=1<<16,
MqttIdentifierRejectedError,
MqttServerUnavailableError,
MqttBadUserNameOrPasswordError,
MqttNotAuthorizedError,
MqttNoPingResponse
};
Q_ENUM_NS(ClientError)
class ClientPrivate;
class Message;
class Frame;
class NetworkInterface;
class Q_MQTT_EXPORT Client : public QObject
{
Q_OBJECT
Q_PROPERTY(quint16 _port READ port WRITE setPort)
Q_PROPERTY(QHostAddress _host READ host WRITE setHost)
Q_PROPERTY(QString _hostName READ hostName WRITE setHostName)
Q_PROPERTY(QString _clientId READ clientId WRITE setClientId)
Q_PROPERTY(QString _username READ username WRITE setUsername)
Q_PROPERTY(QByteArray _password READ password WRITE setPassword)
Q_PROPERTY(quint16 _keepAlive READ keepAlive WRITE setKeepAlive)
Q_PROPERTY(MQTTVersion _version READ version WRITE setVersion)
Q_PROPERTY(bool _autoReconnect READ autoReconnect WRITE setAutoReconnect)
Q_PROPERTY(int _autoReconnectInterval READ autoReconnectInterval WRITE setAutoReconnectInterval)
Q_PROPERTY(bool _cleanSession READ cleanSession WRITE setCleanSession)
Q_PROPERTY(QString _willTopic READ willTopic WRITE setWillTopic)
Q_PROPERTY(quint8 _willQos READ willQos WRITE setWillQos)
Q_PROPERTY(bool _willRetain READ willRetain WRITE setWillRetain)
Q_PROPERTY(QByteArray _willMessage READ willMessage WRITE setWillMessage)
Q_PROPERTY(ConnectionState _connectionState READ connectionState)
#ifndef QT_NO_SSL
Q_PROPERTY(QSslConfiguration _sslConfiguration READ sslConfiguration WRITE setSslConfiguration)
#endif // QT_NO_SSL
public:
Client(const QHostAddress& host = QHostAddress::LocalHost,
const quint16 port = 1883,
QObject* parent = nullptr);
#ifndef QT_NO_SSL
Client(const QString& hostName,
const quint16 port,
const QSslConfiguration& config,
const bool ignoreSelfSigned=false,
QObject* parent = nullptr);
#endif // QT_NO_SSL
// This function is provided for backward compatibility with older versions of QMQTT.
// If the ssl parameter is true, this function will load a private key ('cert.key') and a local
// certificate ('cert.crt') from the current working directory. It will also set PeerVerifyMode
// to None. This may not be the safest way to set up an SSL connection.
Client(const QString& hostName,
const quint16 port,
const bool ssl,
const bool ignoreSelfSigned,
QObject* parent = nullptr);
#ifdef QT_WEBSOCKETS_LIB
// Create a connection over websockets
Client(const QString& url,
const QString& origin,
QWebSocketProtocol::Version version,
bool ignoreSelfSigned = false,
QObject* parent = nullptr);
#ifndef QT_NO_SSL
Client(const QString& url,
const QString& origin,
QWebSocketProtocol::Version version,
const QSslConfiguration& config,
const bool ignoreSelfSigned = false,
QObject* parent = nullptr);
#endif // QT_NO_SSL
#endif // QT_WEBSOCKETS_LIB
// for testing purposes only
Client(NetworkInterface* network,
const QHostAddress& host = QHostAddress::LocalHost,
const quint16 port = 1883,
QObject* parent = nullptr);
virtual ~Client();
QHostAddress host() const;
QString hostName() const;
quint16 port() const;
QString clientId() const;
QString username() const;
QByteArray password() const;
QMQTT::MQTTVersion version() const;
quint16 keepAlive() const;
bool cleanSession() const;
bool autoReconnect() const;
int autoReconnectInterval() const;
ConnectionState connectionState() const;
QString willTopic() const;
quint8 willQos() const;
bool willRetain() const;
QByteArray willMessage() const;
bool isConnectedToHost() const;
#ifndef QT_NO_SSL
QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration& config);
#endif // QT_NO_SSL
public Q_SLOTS:
void setHost(const QHostAddress& host);
void setHostName(const QString& hostName);
void setPort(const quint16 port);
void setClientId(const QString& clientId);
void setUsername(const QString& username);
void setPassword(const QByteArray& password);
void setVersion(const MQTTVersion version);
void setKeepAlive(const quint16 keepAlive);
void setCleanSession(const bool cleanSession);
void setAutoReconnect(const bool value);
void setAutoReconnectInterval(const int autoReconnectInterval);
void setWillTopic(const QString& willTopic);
void setWillQos(const quint8 willQos);
void setWillRetain(const bool willRetain);
void setWillMessage(const QByteArray& willMessage);
void connectToHost();
void disconnectFromHost();
void subscribe(const QString& topic, const quint8 qos = 0);
void unsubscribe(const QString& topic);
quint16 publish(const QMQTT::Message& message);
#ifndef QT_NO_SSL
void ignoreSslErrors();
void ignoreSslErrors(const QList<QSslError>& errors);
#endif // QT_NO_SSL
Q_SIGNALS:
void connected();
void disconnected();
void error(const QMQTT::ClientError error);
void subscribed(const QString& topic, const quint8 qos = 0);
void unsubscribed(const QString& topic);
void published(const QMQTT::Message& message, quint16 msgid = 0);
void received(const QMQTT::Message& message);
void pingresp();
#ifndef QT_NO_SSL
void sslErrors(const QList<QSslError>& errors);
#endif // QT_NO_SSL
protected Q_SLOTS:
void onNetworkConnected();
void onNetworkDisconnected();
void onNetworkReceived(const QMQTT::Frame& frame);
void onTimerPingReq();
void onPingTimeout();
void onNetworkError(QAbstractSocket::SocketError error);
#ifndef QT_NO_SSL
void onSslErrors(const QList<QSslError>& errors);
#endif // QT_NO_SSL
protected:
QScopedPointer<ClientPrivate> d_ptr;
private:
Q_DISABLE_COPY(Client)
Q_DECLARE_PRIVATE(Client)
};
} // namespace QMQTT
Q_DECLARE_METATYPE(QMQTT::ClientError)
#endif // QMQTT_CLIENT_H

View File

@ -0,0 +1,183 @@
/*
* qmqtt_client_p.h - qmqtt client private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_CLIENT_P_H
#define QMQTT_CLIENT_P_H
#include <qmqtt_client.h>
#include <QHostAddress>
#include <QString>
#include <QByteArray>
#include <QHash>
#include <QTimer>
#include <QAbstractSocket>
#ifdef QT_WEBSOCKETS_LIB
#include <QWebSocket>
#endif // QT_WEBSOCKETS_LIB
#ifndef QT_NO_SSL
#include <QSslConfiguration>
QT_FORWARD_DECLARE_CLASS(QSslError)
#endif // QT_NO_SSL
namespace QMQTT {
class NetworkInterface;
class ClientPrivate
{
public:
ClientPrivate(Client* qq_ptr);
~ClientPrivate();
void init(const QHostAddress& host, const quint16 port, NetworkInterface* network = nullptr);
#ifndef QT_NO_SSL
void init(const QString& hostName, const quint16 port, const QSslConfiguration& config,
const bool ignoreSelfSigned=false);
#endif // QT_NO_SSL
void init(const QString& hostName, const quint16 port, const bool ssl, const bool ignoreSelfSigned);
#ifdef QT_WEBSOCKETS_LIB
#ifndef QT_NO_SSL
void init(const QString& url,
const QString& origin,
QWebSocketProtocol::Version version,
const QSslConfiguration* sslConfig,
bool ignoreSelfSigned);
#endif // QT_NO_SSL
void init(const QString& url,
const QString& origin,
QWebSocketProtocol::Version version);
#endif // QT_WEBSOCKETS_LIB
void init(NetworkInterface* network);
QHostAddress _host;
QString _hostName;
quint16 _port;
#ifdef QT_WEBSOCKETS_LIB
QWebSocketProtocol::Version _webSocketVersion;
#endif // QT_WEBSOCKETS_LIB
#ifndef QT_NO_SSL
bool _ignoreSelfSigned;
#endif // QT_NO_SSL
quint16 _gmid;
MQTTVersion _version;
QString _clientId;
QString _username;
QByteArray _password;
bool _cleanSession;
ConnectionState _connectionState;
QScopedPointer<NetworkInterface> _network;
QTimer _timer;
QTimer _pingResponseTimer;
QString _willTopic;
quint8 _willQos;
bool _willRetain;
QByteArray _willMessage;
QHash<quint16, QString> _midToTopic;
QHash<quint16, Message> _midToMessage;
Client* const q_ptr;
quint16 nextmid();
void connectToHost();
void sendConnect();
void onTimerPingReq();
void onPingTimeout();
quint16 sendUnsubscribe(const QString &topic);
quint16 sendSubscribe(const QString &topic, const quint8 qos);
quint16 sendPublish(const Message &message);
void sendPuback(const quint8 type, const quint16 mid);
void sendDisconnect();
void sendFrame(const Frame &frame);
void disconnectFromHost();
void stopKeepAlive();
void onNetworkConnected();
void onNetworkDisconnected();
quint16 publish(const Message& message);
void puback(const quint8 type, const quint16 msgid);
void subscribe(const QString& topic, const quint8 qos);
void unsubscribe(const QString& topic);
void onNetworkReceived(const QMQTT::Frame& frame);
void handleConnack(const quint8 ack);
void handlePublish(const Message& message);
void handlePuback(const quint8 type, const quint16 msgid);
void handleSuback(const QString& topic, const quint8 qos);
void handleUnsuback(const QString& topic);
void handlePingresp();
bool autoReconnect() const;
void setAutoReconnect(const bool autoReconnect);
int autoReconnectInterval() const;
void setAutoReconnectInterval(const int autoReconnectInterval);
bool isConnectedToHost() const;
QMQTT::ConnectionState connectionState() const;
void setCleanSession(const bool cleanSession);
bool cleanSession() const;
void setKeepAlive(const quint16 keepAlive);
quint16 keepAlive() const;
void setPassword(const QByteArray& password);
QByteArray password() const;
void setUsername(const QString& username);
QString username() const;
void setVersion(const MQTTVersion);
MQTTVersion version() const;
void setClientId(const QString& clientId);
QString clientId() const;
void setPort(const quint16 port);
quint16 port() const;
void setHost(const QHostAddress& host);
QHostAddress host() const;
void setHostName(const QString& hostName);
QString hostName() const;
void setWillTopic(const QString& willTopic);
void setWillQos(const quint8 willQos);
void setWillRetain(const bool willRetain);
void setWillMessage(const QByteArray& willMessage);
QString willTopic() const;
quint8 willQos() const;
bool willRetain() const;
QByteArray willMessage() const;
void onNetworkError(QAbstractSocket::SocketError error);
#ifndef QT_NO_SSL
void ignoreSslErrors();
void ignoreSslErrors(const QList<QSslError>& errors);
QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration& config);
void onSslErrors(const QList<QSslError>& errors);
#endif // QT_NO_SSL
Q_DECLARE_PUBLIC(Client)
};
} // namespace QMQTT
#endif // QMQTT_CLIENT_P_H

137
include/mqtt/qmqtt_frame.h Normal file
View File

@ -0,0 +1,137 @@
/*
* qmqtt_frame.h - qmqtt frame heaer
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_FRAME_H
#define QMQTT_FRAME_H
#include <qmqtt_global.h>
#include <QMetaType>
#include <QByteArray>
#include <QString>
QT_FORWARD_DECLARE_CLASS(QDataStream)
#define PROTOCOL_MAGIC_3_1_0 "MQIsdp"
#define PROTOCOL_MAGIC_3_1_1 "MQTT"
#define RANDOM_CLIENT_PREFIX "QMQTT-"
#define CONNECT 0x10
#define CONNACK 0x20
#define PUBLISH 0x30
#define PUBACK 0x40
#define PUBREC 0x50
#define PUBREL 0x60
#define PUBCOMP 0x70
#define SUBSCRIBE 0x80
#define SUBACK 0x90
#define UNSUBSCRIBE 0xA0
#define UNSUBACK 0xB0
#define PINGREQ 0xC0
#define PINGRESP 0xD0
#define DISCONNECT 0xE0
#define LSB(A) quint8(A & 0x00FF)
#define MSB(A) quint8((A & 0xFF00) >> 8)
/*
|--------------------------------------
| 7 6 5 4 | 3 | 2 1 | 0 |
| Type | DUP flag | QoS | RETAIN |
|--------------------------------------
*/
#define GETTYPE(HDR) (HDR & 0xF0)
#define SETQOS(HDR, Q) (HDR | ((Q) << 1))
#define GETQOS(HDR) ((HDR & 0x06) >> 1)
#define SETDUP(HDR, D) (HDR | ((D) << 3))
#define GETDUP(HDR) ((HDR & 0x08) >> 3)
#define SETRETAIN(HDR, R) (HDR | (R))
#define GETRETAIN(HDR) (HDR & 0x01)
/*
|----------------------------------------------------------------------------------
| 7 | 6 | 5 | 4 3 | 2 | 1 | 0 |
| username | password | willretain | willqos | willflag | cleansession | reserved |
|----------------------------------------------------------------------------------
*/
#define FLAG_CLEANSESS(F, C) (F | ((C) << 1))
#define FLAG_WILL(F, W) (F | ((W) << 2))
#define FLAG_WILLQOS(F, Q) (F | ((Q) << 3))
#define FLAG_WILLRETAIN(F, R) (F | ((R) << 5))
#define FLAG_PASSWD(F, P) (F | ((P) << 6))
#define FLAG_USERNAME(F, U) (F | ((U) << 7))
namespace QMQTT {
class Q_MQTT_EXPORT Frame
{
public:
explicit Frame();
explicit Frame(const quint8 header);
explicit Frame(const quint8 header, const QByteArray &data);
virtual ~Frame();
Frame(const Frame& other);
Frame& operator=(const Frame& other);
bool operator==(const Frame& other) const;
inline bool operator!=(const Frame& other) const
{ return !operator==(other); }
quint8 header() const;
QByteArray data() const;
quint16 readInt();
quint8 readChar();
QByteArray readByteArray();
QString readString();
void writeInt(const quint16 i);
void writeChar(const quint8 c);
void writeByteArray(const QByteArray &data);
void writeString(const QString &string);
void writeRawData(const QByteArray &data);
//TODO: FIXME LATER
void write(QDataStream &stream) const;
bool encodeLength(QByteArray &lenbuf, int length) const;
private:
quint8 _header;
QByteArray _data;
};
} // namespace QMQTT
Q_DECLARE_METATYPE(QMQTT::Frame)
#endif // QMQTT_FRAME_H

View File

@ -0,0 +1,48 @@
/*
* qmqtt_global.h - qmqtt libray global
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_GLOBAL_H
#define QMQTT_GLOBAL_H
#include <QtGlobal>
#if !defined(QT_STATIC) && !defined(MQTT_PROJECT_INCLUDE_SRC)
# if defined(QT_BUILD_QMQTT_LIB)
# define Q_MQTT_EXPORT Q_DECL_EXPORT
# else
# define Q_MQTT_EXPORT Q_DECL_IMPORT
# endif
#else
# define Q_MQTT_EXPORT
#endif
#endif // QMQTT_GLOBAL_H

View File

@ -0,0 +1,96 @@
/*
* qmqtt_message.h - qmqtt message header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_MESSAGE_H
#define QMQTT_MESSAGE_H
#include <qmqtt_global.h>
#include <QMetaType>
#include <QString>
#include <QByteArray>
#include <QSharedDataPointer>
namespace QMQTT {
class MessagePrivate;
class Q_MQTT_EXPORT Message
{
public:
Message();
explicit Message(const quint16 id, const QString &topic, const QByteArray &payload,
const quint8 qos = 0, const bool retain = false, const bool dup = false);
Message(const Message &other);
~Message();
Message &operator=(const Message &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline Message &operator=(Message &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
bool operator==(const Message &other) const;
inline bool operator!=(const Message &other) const
{ return !operator==(other); }
inline void swap(Message &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
quint16 id() const;
void setId(const quint16 id);
quint8 qos() const;
void setQos(const quint8 qos);
bool retain() const;
void setRetain(const bool retain);
bool dup() const;
void setDup(const bool dup);
QString topic() const;
void setTopic(const QString &topic);
QByteArray payload() const;
void setPayload(const QByteArray &payload);
private:
QSharedDataPointer<MessagePrivate> d;
};
} // namespace QMQTT
Q_DECLARE_SHARED(QMQTT::Message)
Q_DECLARE_METATYPE(QMQTT::Message)
#endif // QMQTT_MESSAGE_H

View File

@ -0,0 +1,83 @@
/*
* qmqtt_message.h - qmqtt message private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_MESSAGE_P_H
#define QMQTT_MESSAGE_P_H
#include <QSharedData>
#include <QString>
#include <QByteArray>
namespace QMQTT {
class MessagePrivate : public QSharedData
{
public:
inline MessagePrivate()
: QSharedData(),
id(0),
qos(0),
retain(false),
dup(false)
{}
inline MessagePrivate(const MessagePrivate &other)
: QSharedData(other),
id(other.id),
qos(other.qos),
retain(other.retain),
dup(other.dup),
topic(other.topic),
payload(other.payload)
{}
inline MessagePrivate(quint16 id, const QString &topic, const QByteArray &payload,
quint8 qos, bool retain, bool dup)
: QSharedData(),
id(id),
qos(qos),
retain(retain),
dup(dup),
topic(topic),
payload(payload)
{}
quint16 id;
quint8 qos : 2;
quint8 retain: 1;
quint8 dup: 1;
QString topic;
QByteArray payload;
};
} // namespace QMQTT
#endif // QMQTT_MESSAGE_P_H

View File

@ -0,0 +1,139 @@
/*
* qmqtt_network_p.h - qmqtt network private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_NETWORK_P_H
#define QMQTT_NETWORK_P_H
#include <qmqtt_networkinterface.h>
#include <QObject>
#include <QHostAddress>
#include <QString>
#include <QByteArray>
#ifdef QT_WEBSOCKETS_LIB
#include <QWebSocket>
#endif // QT_WEBSOCKETS_LIB
#ifndef QT_NO_SSL
#include <QSslConfiguration>
QT_FORWARD_DECLARE_CLASS(QSslError)
#endif // QT_NO_SSL
namespace QMQTT {
class SocketInterface;
class TimerInterface;
class Frame;
class Network : public NetworkInterface
{
Q_OBJECT
public:
Network(QObject* parent = nullptr);
#ifndef QT_NO_SSL
Network(const QSslConfiguration& config, QObject* parent = nullptr);
#endif // QT_NO_SSL
#ifdef QT_WEBSOCKETS_LIB
#ifndef QT_NO_SSL
Network(const QString& origin,
QWebSocketProtocol::Version version,
const QSslConfiguration* sslConfig,
QObject* parent = nullptr);
#endif // QT_NO_SSL
Network(const QString& origin,
QWebSocketProtocol::Version version,
QObject* parent = nullptr);
#endif // QT_WEBSOCKETS_LIB
Network(SocketInterface* socketInterface, TimerInterface* timerInterface,
QObject* parent = nullptr);
~Network();
void sendFrame(const Frame &frame);
bool isConnectedToHost() const;
bool autoReconnect() const;
void setAutoReconnect(const bool autoReconnect);
QAbstractSocket::SocketState state() const;
int autoReconnectInterval() const;
void setAutoReconnectInterval(const int autoReconnectInterval);
#ifndef QT_NO_SSL
void ignoreSslErrors(const QList<QSslError>& errors);
QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration& config);
#endif // QT_NO_SSL
public Q_SLOTS:
void connectToHost(const QHostAddress& host, const quint16 port);
void connectToHost(const QString& hostName, const quint16 port);
void disconnectFromHost();
#ifndef QT_NO_SSL
void ignoreSslErrors();
#endif // QT_NO_SSL
protected Q_SLOTS:
void onSocketError(QAbstractSocket::SocketError socketError);
protected:
void initialize();
quint16 _port;
QHostAddress _host;
QString _hostName;
bool _autoReconnect;
int _autoReconnectInterval;
SocketInterface* _socket;
TimerInterface* _autoReconnectTimer;
enum ReadState {
Header,
Length,
PayLoad
};
ReadState _readState;
quint8 _header;
int _length;
int _shift;
QByteArray _data;
protected Q_SLOTS:
void onSocketReadReady();
void onDisconnected();
void connectToHost();
private:
Q_DISABLE_COPY(Network)
};
} // namespace QMQTT
#endif // QMQTT_NETWORK_P_H

View File

@ -0,0 +1,92 @@
/*
* qmqtt_networkinterface.h - qmqtt network interface header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_NETWORK_INTERFACE_H
#define QMQTT_NETWORK_INTERFACE_H
#include <qmqtt_global.h>
#include <QObject>
#include <QAbstractSocket>
#include <QHostAddress>
#include <QString>
#include <QList>
#ifndef QT_NO_SSL
#include <QSslConfiguration>
QT_FORWARD_DECLARE_CLASS(QSslError)
#endif // QT_NO_SSL
namespace QMQTT {
class Frame;
class Q_MQTT_EXPORT NetworkInterface : public QObject
{
Q_OBJECT
public:
explicit NetworkInterface(QObject* parent = nullptr) : QObject(parent) {}
virtual ~NetworkInterface() {}
virtual void sendFrame(const Frame& frame) = 0;
virtual bool isConnectedToHost() const = 0;
virtual bool autoReconnect() const = 0;
virtual void setAutoReconnect(const bool autoReconnect) = 0;
virtual int autoReconnectInterval() const = 0;
virtual void setAutoReconnectInterval(const int autoReconnectInterval) = 0;
virtual QAbstractSocket::SocketState state() const = 0;
#ifndef QT_NO_SSL
virtual void ignoreSslErrors(const QList<QSslError>& errors) = 0;
virtual QSslConfiguration sslConfiguration() const = 0;
virtual void setSslConfiguration(const QSslConfiguration& config) = 0;
#endif // QT_NO_SSL
public Q_SLOTS:
virtual void connectToHost(const QHostAddress& host, const quint16 port) = 0;
virtual void connectToHost(const QString& hostName, const quint16 port) = 0;
virtual void disconnectFromHost() = 0;
#ifndef QT_NO_SSL
virtual void ignoreSslErrors() = 0;
#endif // QT_NO_SSL
Q_SIGNALS:
void connected();
void disconnected();
void received(const QMQTT::Frame& frame);
void error(QAbstractSocket::SocketError error);
#ifndef QT_NO_SSL
void sslErrors(const QList<QSslError>& errors);
#endif // QT_NO_SSL
};
} // namespace QMQTT
#endif // QMQTT_NETWORK_INTERFACE_H

View File

@ -0,0 +1,71 @@
/*
* qmqtt_router.h - qmqtt router
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* Router added by Niklas Wulf <nwulf at geenen-it-systeme dot de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_ROUTEDMESSAGE_H
#define QMQTT_ROUTEDMESSAGE_H
#include <qmqtt_message.h>
#include <QMetaType>
#include <QHash>
#include <QString>
namespace QMQTT {
class RouteSubscription;
class Q_MQTT_EXPORT RoutedMessage
{
public:
inline RoutedMessage()
{}
inline RoutedMessage(const Message &message)
: _message(message)
{}
inline const Message &message() const
{ return _message; }
inline QHash<QString, QString> parameters() const
{ return _parameters; }
private:
friend class RouteSubscription;
Message _message;
QHash<QString, QString> _parameters;
};
} // namespace QMQTT
Q_DECLARE_METATYPE(QMQTT::RoutedMessage)
#endif // QMQTT_ROUTEDMESSAGE_H

View File

@ -0,0 +1,60 @@
/*
* qmqtt_router.h - qmqtt router
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* Router added by Niklas Wulf <nwulf at geenen-it-systeme dot de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_ROUTER_H
#define QMQTT_ROUTER_H
#include <qmqtt_global.h>
#include <QObject>
namespace QMQTT {
class Client;
class RouteSubscription;
class Q_MQTT_EXPORT Router : public QObject
{
Q_OBJECT
public:
explicit Router(Client *parent = nullptr);
RouteSubscription *subscribe(const QString &route);
Client *client() const;
private:
Client *_client;
};
} // namespace QMQTT
#endif // QMQTT_ROUTER_H

View File

@ -0,0 +1,79 @@
/*
* qmqtt_router.h - qmqtt router
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* Router added by Niklas Wulf <nwulf at geenen-it-systeme dot de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_ROUTESUBSCRIPTION_H
#define QMQTT_ROUTESUBSCRIPTION_H
#include <qmqtt_global.h>
#include <QObject>
#include <QPointer>
#include <QString>
#include <QRegularExpression>
#include <QStringList>
namespace QMQTT {
class Client;
class Message;
class RoutedMessage;
class Router;
class Q_MQTT_EXPORT RouteSubscription : public QObject
{
Q_OBJECT
public:
~RouteSubscription();
QString route() const;
Q_SIGNALS:
void received(const RoutedMessage &message);
private Q_SLOTS:
void routeMessage(const Message &message);
private:
friend class Router;
explicit RouteSubscription(Router *parent = nullptr);
void setRoute(const QString &route);
QPointer<Client> _client;
QString _topic;
QRegularExpression _regularExpression;
QStringList _parameterNames;
};
} // namespace QMQTT
#endif // QMQTT_ROUTESUBSCRIPTION_H

View File

@ -0,0 +1,69 @@
/*
* qmqtt_socket_p.h - qmqtt socket private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_SOCKET_P_H
#define QMQTT_SOCKET_P_H
#include <qmqtt_socketinterface.h>
#include <QObject>
#include <QHostAddress>
#include <QString>
#include <QAbstractSocket>
#include <QScopedPointer>
QT_FORWARD_DECLARE_CLASS(QIODevice)
QT_FORWARD_DECLARE_CLASS(QTcpSocket)
namespace QMQTT
{
class Socket : public SocketInterface
{
Q_OBJECT
public:
explicit Socket(QObject* parent = nullptr);
virtual ~Socket();
virtual QIODevice *ioDevice();
void connectToHost(const QHostAddress& address, quint16 port);
void connectToHost(const QString& hostName, quint16 port);
void disconnectFromHost();
QAbstractSocket::SocketState state() const;
QAbstractSocket::SocketError error() const;
protected:
QScopedPointer<QTcpSocket> _socket;
};
}
#endif // QMQTT_SOCKET_P_H

View File

@ -0,0 +1,84 @@
/*
* qmqtt_socketinterface.h - qmqtt socket interface header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_SOCKET_INTERFACE_H
#define QMQTT_SOCKET_INTERFACE_H
#include <qmqtt_global.h>
#include <QObject>
#include <QHostAddress>
#include <QString>
#include <QAbstractSocket>
#include <QList>
#ifndef QT_NO_SSL
#include <QSslConfiguration>
QT_FORWARD_DECLARE_CLASS(QSslError)
#endif // QT_NO_SSL
QT_FORWARD_DECLARE_CLASS(QIODevice)
namespace QMQTT
{
class Q_MQTT_EXPORT SocketInterface : public QObject
{
Q_OBJECT
public:
explicit SocketInterface(QObject* parent = nullptr) : QObject(parent) {}
virtual ~SocketInterface() {}
virtual QIODevice* ioDevice() = 0;
virtual void connectToHost(const QHostAddress& address, quint16 port) = 0;
virtual void connectToHost(const QString& hostName, quint16 port) = 0;
virtual void disconnectFromHost() = 0;
virtual QAbstractSocket::SocketState state() const = 0;
virtual QAbstractSocket::SocketError error() const = 0;
#ifndef QT_NO_SSL
virtual void ignoreSslErrors(const QList<QSslError>& errors) { Q_UNUSED(errors); }
virtual void ignoreSslErrors() {}
virtual QSslConfiguration sslConfiguration() const { return QSslConfiguration(); }
virtual void setSslConfiguration(const QSslConfiguration& config) { Q_UNUSED(config); }
#endif // QT_NO_SSL
Q_SIGNALS:
void connected();
void disconnected();
void error(QAbstractSocket::SocketError socketError);
#ifndef QT_NO_SSL
void sslErrors(const QList<QSslError>& errors);
#endif // QT_NO_SSL
};
}
#endif // QMQTT_SOCKET_INTERFACE_H

View File

@ -0,0 +1,79 @@
/*
* qmqtt_ssl_socket_p.h - qmqtt SSL socket private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* Copyright (c) 2016 Matthias Dieter Wallnöfer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_SSL_SOCKET_P_H
#define QMQTT_SSL_SOCKET_P_H
#ifndef QT_NO_SSL
#include <qmqtt_socketinterface.h>
#include <QObject>
#include <QHostAddress>
#include <QString>
#include <QList>
#include <QScopedPointer>
QT_FORWARD_DECLARE_CLASS(QSslSocket)
QT_FORWARD_DECLARE_CLASS(QSslError)
#include <QSslConfiguration>
namespace QMQTT
{
class SslSocket : public SocketInterface
{
Q_OBJECT
public:
explicit SslSocket(const QSslConfiguration& config, QObject* parent = nullptr);
virtual ~SslSocket();
virtual QIODevice *ioDevice();
void connectToHost(const QHostAddress& address, quint16 port);
void connectToHost(const QString& hostName, quint16 port);
void disconnectFromHost();
QAbstractSocket::SocketState state() const;
QAbstractSocket::SocketError error() const;
void ignoreSslErrors(const QList<QSslError>& errors);
void ignoreSslErrors();
QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration& config);
protected:
QScopedPointer<QSslSocket> _socket;
};
}
#endif // QT_NO_SSL
#endif // QMQTT_SSL_SOCKET_P_H

View File

@ -0,0 +1,62 @@
/*
* qmqtt_timer_p.h - qmqtt timer private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_TIMER_P_H
#define QMQTT_TIMER_P_H
#include <qmqtt_timerinterface.h>
#include <QObject>
#include <QTimer>
namespace QMQTT {
class Timer : public TimerInterface
{
Q_OBJECT
public:
explicit Timer(QObject *parent = nullptr);
virtual ~Timer();
bool isSingleShot() const;
void setSingleShot(bool singleShot);
int interval() const;
void setInterval(int msec);
void start();
void stop();
protected:
QTimer _timer;
};
}
#endif // QMQTT_TIMER_P_H

View File

@ -0,0 +1,62 @@
/*
* qmqtt_timerinterface.h - qmqtt timer interface header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_TIMER_INTERFACE_H
#define QMQTT_TIMER_INTERFACE_H
#include <qmqtt_global.h>
#include <QObject>
namespace QMQTT {
class Q_MQTT_EXPORT TimerInterface : public QObject
{
Q_OBJECT
public:
explicit TimerInterface(QObject* parent = nullptr) : QObject(parent) {}
virtual ~TimerInterface() {}
virtual bool isSingleShot() const = 0;
virtual void setSingleShot(bool singleShot) = 0;
virtual int interval() const = 0;
virtual void setInterval(int msec) = 0;
virtual void start() = 0;
virtual void stop() = 0;
Q_SIGNALS:
void timeout();
};
}
#endif // QMQTT_TIMER_INTERFACE_H

View File

@ -0,0 +1,102 @@
/*
* qmqtt_websocket_p.h - qmqtt socket private header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_WEBSOCKET_H
#define QMQTT_WEBSOCKET_H
#ifdef QT_WEBSOCKETS_LIB
#include <qmqtt_socketinterface.h>
#include <qmqtt_websocketiodevice_p.h>
#include <QObject>
#include <QWebSocket>
#include <QHostAddress>
#include <QString>
#include <QList>
#include <QAbstractSocket>
QT_FORWARD_DECLARE_CLASS(QIODevice)
#ifndef QT_NO_SSL
#include <QSslConfiguration>
QT_FORWARD_DECLARE_CLASS(QSslError)
#endif // QT_NO_SSL
namespace QMQTT
{
class WebSocket : public SocketInterface
{
Q_OBJECT
public:
#ifndef QT_NO_SSL
WebSocket(const QString& origin,
QWebSocketProtocol::Version version,
const QSslConfiguration* sslConfig,
QObject* parent = nullptr);
#endif // QT_NO_SSL
WebSocket(const QString& origin,
QWebSocketProtocol::Version version,
QObject* parent = nullptr);
virtual ~WebSocket();
QIODevice *ioDevice()
{
return _ioDevice;
}
void connectToHost(const QHostAddress& address, quint16 port);
void connectToHost(const QString& hostName, quint16 port);
void disconnectFromHost();
QAbstractSocket::SocketState state() const;
QAbstractSocket::SocketError error() const;
#ifndef QT_NO_SSL
void ignoreSslErrors(const QList<QSslError>& errors);
void ignoreSslErrors();
QSslConfiguration sslConfiguration() const;
void setSslConfiguration(const QSslConfiguration& config);
#endif // QT_NO_SSL
private:
void initialize();
QWebSocket *_socket;
WebSocketIODevice *_ioDevice;
};
}
#endif // QT_WEBSOCKETS_LIB
#endif // QMQTT_WEBSOCKET_H

View File

@ -0,0 +1,74 @@
/*
* qmqtt_socketinterface.h - qmqtt socket interface header
*
* Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of mqttc nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QMQTT_WEBSOCKETIODEVICE_H
#define QMQTT_WEBSOCKETIODEVICE_H
#ifdef QT_WEBSOCKETS_LIB
#include <QByteArray>
#include <QIODevice>
QT_FORWARD_DECLARE_CLASS(QWebSocket)
QT_FORWARD_DECLARE_CLASS(QNetworkRequest)
namespace QMQTT
{
class WebSocketIODevice : public QIODevice
{
Q_OBJECT
public:
explicit WebSocketIODevice(QWebSocket *socket, QObject *parent = nullptr);
bool connectToHost(const QNetworkRequest &request);
virtual qint64 bytesAvailable() const;
protected:
virtual qint64 readData(char *data, qint64 maxSize);
virtual qint64 writeData(const char *data, qint64 maxSize);
private Q_SLOTS:
void binaryMessageReceived(const QByteArray &frame);
private:
QByteArray _buffer;
QWebSocket *_webSocket;
};
}
#endif // QT_WEBSOCKETS_LIB
#endif // QMQTT_WEBSOCKETIODEVICE_H

5
lib/mqtt/Qt5Qmqtt.prl Normal file
View File

@ -0,0 +1,5 @@
QMAKE_PRL_BUILD_DIR = E:/ThunderDownload/build-qmqtt-Desktop_Qt_5_12_11_MinGW_32_bit-Release/src/mqtt
QMAKE_PRO_INPUT = qmqtt.pro
QMAKE_PRL_TARGET = libQt5Qmqtt.a
QMAKE_PRL_CONFIG = lex yacc depend_includepath testcase_targets import_plugins import_qpa_plugin windows qt_build_extra file_copies qmake_use qt warn_on release link_prl debug_and_release precompile_header shared release no_plugin_manifest win32 mingw gcc copy_dir_files sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples f16c largefile optimize_debug precompile_header rdrnd shani x86SimdAlways prefix_build force_independent utf8_source create_prl link_prl prepare_docs qt_docs_targets no_private_qt_headers_warning QTDIR_build qt_example_installs exceptions_off testcase_exceptions warning_clean release ReleaseBuild Release build_pass qtquickcompiler release ReleaseBuild Release build_pass relative_qt_rpath qmake_cache target_qt c++11 strict_c++ c++14 c++1z c99 c11 split_incpath qt_install_headers need_fwd_pri qt_install_module debug_and_release build_all create_cmake skip_target_version_ext compiler_supports_fpmath create_pc release ReleaseBuild Release build_pass have_target dll exclusive_builds no_autoqmake thread moc resources
QMAKE_PRL_VERSION = 1.0.2

5
lib/mqtt/Qt5Qmqttd.prl Normal file
View File

@ -0,0 +1,5 @@
QMAKE_PRL_BUILD_DIR = E:/ThunderDownload/build-qmqtt-Desktop_Qt_5_12_11_MinGW_32_bit-Release/src/mqtt
QMAKE_PRO_INPUT = qmqtt.pro
QMAKE_PRL_TARGET = libQt5Qmqttd.a
QMAKE_PRL_CONFIG = lex yacc debug depend_includepath testcase_targets import_plugins import_qpa_plugin windows qt_build_extra file_copies qmake_use qt warn_on link_prl debug_and_release precompile_header shared no_plugin_manifest win32 mingw gcc copy_dir_files sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples f16c largefile optimize_debug precompile_header rdrnd shani x86SimdAlways prefix_build force_independent utf8_source create_prl link_prl prepare_docs qt_docs_targets no_private_qt_headers_warning QTDIR_build qt_example_installs exceptions_off testcase_exceptions warning_clean debug DebugBuild Debug build_pass qtquickcompiler debug DebugBuild Debug build_pass relative_qt_rpath qmake_cache target_qt c++11 strict_c++ c++14 c++1z c99 c11 split_incpath qt_install_headers need_fwd_pri qt_install_module debug_and_release build_all create_cmake skip_target_version_ext compiler_supports_fpmath create_pc debug DebugBuild Debug build_pass have_target dll no_plist exclusive_builds debug_info no_autoqmake thread moc resources
QMAKE_PRL_VERSION = 1.0.2

View File

@ -0,0 +1,7 @@
list(APPEND _Qt5Qmqtt_OWN_INCLUDE_DIRS
"E:/ThunderDownload/qmqtt-master/include" "E:/ThunderDownload/qmqtt-master/include/QtQmqtt"
)
set(Qt5Qmqtt_PRIVATE_INCLUDE_DIRS
"E:/ThunderDownload/qmqtt-master/include/QtQmqtt/1.0.2" "E:/ThunderDownload/qmqtt-master/include/QtQmqtt/1.0.2/QtQmqtt"
)

View File

@ -0,0 +1,185 @@
if (CMAKE_VERSION VERSION_LESS 3.1.0)
message(FATAL_ERROR "Qt 5 Qmqtt module requires at least CMake version 3.1.0")
endif()
get_filename_component(_qt5Qmqtt_install_prefix "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
# For backwards compatibility only. Use Qt5Qmqtt_VERSION instead.
set(Qt5Qmqtt_VERSION_STRING 1.0.2)
set(Qt5Qmqtt_LIBRARIES Qt5::Qmqtt)
macro(_qt5_Qmqtt_check_file_exists file)
if(NOT EXISTS "${file}" )
message(FATAL_ERROR "The imported target \"Qt5::Qmqtt\" references the file
\"${file}\"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
\"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
endif()
endmacro()
macro(_populate_Qmqtt_target_properties Configuration LIB_LOCATION IMPLIB_LOCATION)
set_property(TARGET Qt5::Qmqtt APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
set(imported_location "${_qt5Qmqtt_install_prefix}/bin/${LIB_LOCATION}")
_qt5_Qmqtt_check_file_exists(${imported_location})
set_target_properties(Qt5::Qmqtt PROPERTIES
"INTERFACE_LINK_LIBRARIES" "${_Qt5Qmqtt_LIB_DEPENDENCIES}"
"IMPORTED_LOCATION_${Configuration}" ${imported_location}
# For backward compatibility with CMake < 2.8.12
"IMPORTED_LINK_INTERFACE_LIBRARIES_${Configuration}" "${_Qt5Qmqtt_LIB_DEPENDENCIES}"
)
set(imported_implib "${_qt5Qmqtt_install_prefix}/lib/${IMPLIB_LOCATION}")
_qt5_Qmqtt_check_file_exists(${imported_implib})
if(NOT "${IMPLIB_LOCATION}" STREQUAL "")
set_target_properties(Qt5::Qmqtt PROPERTIES
"IMPORTED_IMPLIB_${Configuration}" ${imported_implib}
)
endif()
endmacro()
if (NOT TARGET Qt5::Qmqtt)
set(_Qt5Qmqtt_OWN_INCLUDE_DIRS "${_qt5Qmqtt_install_prefix}/include/" "${_qt5Qmqtt_install_prefix}/include/QtQmqtt")
set(Qt5Qmqtt_PRIVATE_INCLUDE_DIRS "")
include("${CMAKE_CURRENT_LIST_DIR}/ExtraSourceIncludes.cmake" OPTIONAL)
foreach(_dir ${_Qt5Qmqtt_OWN_INCLUDE_DIRS})
_qt5_Qmqtt_check_file_exists(${_dir})
endforeach()
# Only check existence of private includes if the Private component is
# specified.
list(FIND Qt5Qmqtt_FIND_COMPONENTS Private _check_private)
if (NOT _check_private STREQUAL -1)
foreach(_dir ${Qt5Qmqtt_PRIVATE_INCLUDE_DIRS})
_qt5_Qmqtt_check_file_exists(${_dir})
endforeach()
endif()
set(Qt5Qmqtt_INCLUDE_DIRS ${_Qt5Qmqtt_OWN_INCLUDE_DIRS})
set(Qt5Qmqtt_DEFINITIONS -DQT_QMQTT_LIB)
set(Qt5Qmqtt_COMPILE_DEFINITIONS QT_QMQTT_LIB)
set(_Qt5Qmqtt_MODULE_DEPENDENCIES "Network;Core")
set(Qt5Qmqtt_OWN_PRIVATE_INCLUDE_DIRS ${Qt5Qmqtt_PRIVATE_INCLUDE_DIRS})
set(_Qt5Qmqtt_FIND_DEPENDENCIES_REQUIRED)
if (Qt5Qmqtt_FIND_REQUIRED)
set(_Qt5Qmqtt_FIND_DEPENDENCIES_REQUIRED REQUIRED)
endif()
set(_Qt5Qmqtt_FIND_DEPENDENCIES_QUIET)
if (Qt5Qmqtt_FIND_QUIETLY)
set(_Qt5Qmqtt_DEPENDENCIES_FIND_QUIET QUIET)
endif()
set(_Qt5Qmqtt_FIND_VERSION_EXACT)
if (Qt5Qmqtt_FIND_VERSION_EXACT)
set(_Qt5Qmqtt_FIND_VERSION_EXACT EXACT)
endif()
set(Qt5Qmqtt_EXECUTABLE_COMPILE_FLAGS "")
foreach(_module_dep ${_Qt5Qmqtt_MODULE_DEPENDENCIES})
if (NOT Qt5${_module_dep}_FOUND)
find_package(Qt5${_module_dep}
1.0.2 ${_Qt5Qmqtt_FIND_VERSION_EXACT}
${_Qt5Qmqtt_DEPENDENCIES_FIND_QUIET}
${_Qt5Qmqtt_FIND_DEPENDENCIES_REQUIRED}
PATHS "${CMAKE_CURRENT_LIST_DIR}/.." NO_DEFAULT_PATH
)
endif()
if (NOT Qt5${_module_dep}_FOUND)
set(Qt5Qmqtt_FOUND False)
return()
endif()
list(APPEND Qt5Qmqtt_INCLUDE_DIRS "${Qt5${_module_dep}_INCLUDE_DIRS}")
list(APPEND Qt5Qmqtt_PRIVATE_INCLUDE_DIRS "${Qt5${_module_dep}_PRIVATE_INCLUDE_DIRS}")
list(APPEND Qt5Qmqtt_DEFINITIONS ${Qt5${_module_dep}_DEFINITIONS})
list(APPEND Qt5Qmqtt_COMPILE_DEFINITIONS ${Qt5${_module_dep}_COMPILE_DEFINITIONS})
list(APPEND Qt5Qmqtt_EXECUTABLE_COMPILE_FLAGS ${Qt5${_module_dep}_EXECUTABLE_COMPILE_FLAGS})
endforeach()
list(REMOVE_DUPLICATES Qt5Qmqtt_INCLUDE_DIRS)
list(REMOVE_DUPLICATES Qt5Qmqtt_PRIVATE_INCLUDE_DIRS)
list(REMOVE_DUPLICATES Qt5Qmqtt_DEFINITIONS)
list(REMOVE_DUPLICATES Qt5Qmqtt_COMPILE_DEFINITIONS)
list(REMOVE_DUPLICATES Qt5Qmqtt_EXECUTABLE_COMPILE_FLAGS)
set(_Qt5Qmqtt_LIB_DEPENDENCIES "Qt5::Network;Qt5::Core")
add_library(Qt5::Qmqtt SHARED IMPORTED)
set_property(TARGET Qt5::Qmqtt PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${_Qt5Qmqtt_OWN_INCLUDE_DIRS})
set_property(TARGET Qt5::Qmqtt PROPERTY
INTERFACE_COMPILE_DEFINITIONS QT_QMQTT_LIB)
set_property(TARGET Qt5::Qmqtt PROPERTY INTERFACE_QT_ENABLED_FEATURES )
set_property(TARGET Qt5::Qmqtt PROPERTY INTERFACE_QT_DISABLED_FEATURES )
set(_Qt5Qmqtt_PRIVATE_DIRS_EXIST TRUE)
foreach (_Qt5Qmqtt_PRIVATE_DIR ${Qt5Qmqtt_OWN_PRIVATE_INCLUDE_DIRS})
if (NOT EXISTS ${_Qt5Qmqtt_PRIVATE_DIR})
set(_Qt5Qmqtt_PRIVATE_DIRS_EXIST FALSE)
endif()
endforeach()
if (_Qt5Qmqtt_PRIVATE_DIRS_EXIST)
add_library(Qt5::QmqttPrivate INTERFACE IMPORTED)
set_property(TARGET Qt5::QmqttPrivate PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${Qt5Qmqtt_OWN_PRIVATE_INCLUDE_DIRS}
)
set(_Qt5Qmqtt_PRIVATEDEPS)
foreach(dep ${_Qt5Qmqtt_LIB_DEPENDENCIES})
if (TARGET ${dep}Private)
list(APPEND _Qt5Qmqtt_PRIVATEDEPS ${dep}Private)
endif()
endforeach()
set_property(TARGET Qt5::QmqttPrivate PROPERTY
INTERFACE_LINK_LIBRARIES Qt5::Qmqtt ${_Qt5Qmqtt_PRIVATEDEPS}
)
endif()
_populate_Qmqtt_target_properties(RELEASE "Qt5Qmqtt.dll" "libQt5Qmqtt.a" )
_populate_Qmqtt_target_properties(DEBUG "Qt5Qmqttd.dll" "libQt5Qmqttd.a" )
file(GLOB pluginTargets "${CMAKE_CURRENT_LIST_DIR}/Qt5Qmqtt_*Plugin.cmake")
macro(_populate_Qmqtt_plugin_properties Plugin Configuration PLUGIN_LOCATION)
set_property(TARGET Qt5::${Plugin} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
set(imported_location "${_qt5Qmqtt_install_prefix}/plugins/${PLUGIN_LOCATION}")
_qt5_Qmqtt_check_file_exists(${imported_location})
set_target_properties(Qt5::${Plugin} PROPERTIES
"IMPORTED_LOCATION_${Configuration}" ${imported_location}
)
endmacro()
if (pluginTargets)
foreach(pluginTarget ${pluginTargets})
include(${pluginTarget})
endforeach()
endif()
_qt5_Qmqtt_check_file_exists("${CMAKE_CURRENT_LIST_DIR}/Qt5QmqttConfigVersion.cmake")
endif()

View File

@ -0,0 +1,11 @@
set(PACKAGE_VERSION 1.0.2)
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

View File

@ -0,0 +1,13 @@
prefix=D:/Qt/Qt5.12.11/5.12.11/mingw73_32
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: Qt5 Qmqtt
Description: Qt Qmqtt module
Version: 1.0.2
Libs: -L${libdir} -lQt5Qmqttd
Cflags: -DQT_QMQTT_LIB -I${includedir}/QtQmqtt -I${includedir}
Requires: Qt5Core Qt5Network

75
log.cpp Normal file
View File

@ -0,0 +1,75 @@
#include "log.h"
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QTextStream>
#include <QDateTime>
#include <QtDebug>
void setLogPath(const QString & path)
{
s_logPath = path;
}
void setLogLevel(int level)
{
s_logLevel = level;
}
bool static ensureDirExist(const QString &dirPath)
{
QDir dir(dirPath);
if (dir.exists())
{
return true;
}
return dir.mkpath(dirPath);
}
void customLogMessageHandler(QtMsgType type, const QString& msg)
{
if (type < s_logLevel)
{
return;
}
QString logInfo;
QString logTime = QDateTime::currentDateTime().toString("hh-mm-ss-MM-dd-yyyy");
switch (type)
{
case QtDebugMsg:
logInfo = QString("%1 [Debug] %2").arg(logTime, msg);
break;
case QtWarningMsg:
logInfo = QString("%1 [Warning] %2").arg(logTime, msg);
break;
case QtCriticalMsg:
logInfo = QString("%1 [Critical] %2").arg(logTime, msg);
break;
case QtFatalMsg:
logInfo = QString("%1 [Fatal] %2").arg(logTime, msg);
//abort();
break;
case QtInfoMsg:
logInfo = QString("%1 [Info] %2").arg(logTime, msg);
break;
}
s_logMutex.lock();
QFile outFile(LOG_FILE_NAME);
QFileInfo fileInfo(outFile);
if (!ensureDirExist(fileInfo.absoluteDir().absolutePath()))
return;
if (!outFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
return;
QTextStream ts(&outFile);
ts << logInfo << endl;
outFile.close();
s_logMutex.unlock();
}

20
log.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef LOG_H
#define LOG_H
#include <QCoreApplication>
#include <QMutex>
#include <QString>
#define LOG_FILE_NAME QCoreApplication::applicationDirPath() + QString("\\Log\\") + QDateTime::currentDateTime().toString("yyyy-MM-dd") + QString(".log")
static int s_logLevel = 0;
static QMutex s_logMutex;
static QString s_logPath;
void setLogPath(const QString &path);
void setLogLevel(int level);
//void customLogMessageHandler(QtMsgType type, const QMessageLogContext& ctx, const QString& msg);
void customLogMessageHandler(QtMsgType type, const QString& msg);
#endif // LOG_H

View File

@ -61,6 +61,14 @@ MainWindow::MainWindow(QWidget *parent) :
connect(pRealTimeForm,SIGNAL(sigWCStatus(QString&)), this, SLOT(slotWCStatus(QString&)));
connect(pRealTimeForm,SIGNAL(sigRPM(QString&)), this, SLOT(slotRPM(QString&)));
mqttclient = new MqttClient(this);
mqttclient->ConnectMQTT(IP);
m_strTriggerEnevtTopic = QString("up/%1/trigger").arg(MAC);//订阅
mqttclient->subscribed(m_strTriggerEnevtTopic);
connect(mqttclient, SIGNAL(Recevive_sig(QString,QByteArray)), this, SLOT(mqttReceive_slot(QString,QByteArray)));
}
MainWindow::~MainWindow()
@ -435,6 +443,9 @@ void MainWindow::leftConfigClick4()
delete pTerminalInfo;
pTerminalInfo = NULL;
}
}else if(name == "通道标定"){
QProcess process(this);
process.startDetached(".\\Calibration\\NARI3500Calibration.exe");
}
//ui->label->setText(name);
}
@ -510,11 +521,16 @@ void MainWindow::slotWCStatus(QString& strWCStatus)
QStringList strList = strWCStatus.split(",");
ui->label_WC->setText(strList[1]);
ui->label_Trg->setText(strList[0]);
}
void MainWindow::slotRPM(QString& str)
{
ui->label_RPM->setText(str);
}
void MainWindow::mqttReceive_slot(QString strTopic,QByteArray payload)
{
if(strTopic == m_strTriggerEnevtTopic){
QString strReceive = QString(payload);
}
}

View File

@ -26,6 +26,8 @@
#include "sqlitedb.h"
#include "global.h"
#include "Mqttclient.h"
class QAbstractButton;
@ -57,6 +59,7 @@ private slots:
void leftConfigClick4();
void slotWCStatus(QString&);
void slotRPM(QString&);
void mqttReceive_slot(QString,QByteArray);
private:
Ui::MainWindow *ui;
@ -84,6 +87,8 @@ private:
CSystemSelfcheck *pSystemSelfcheck;
CDIO_Board *pDIOBoard;
MqttClient *mqttclient;
QString m_strTriggerEnevtTopic;
};

View File

@ -24,7 +24,6 @@
<file>qss/blacksoft/radiobutton_unchecked.png</file>
<file>qss/blacksoft/radiobutton_unchecked_disable.png</file>
<file>qss/blacksoft.css</file>
<file>image/1.png</file>
<file>image/logo.png</file>
<file>image/Btn/hand.png</file>
<file>image/Btn/hand-p.png</file>

View File

@ -81,7 +81,7 @@ background-color:#636363;
font: 14pt ;
}
QWidget[nav="left"] QAbstractButton:hover{
color:#FFFFFF;
color:#ffffff;
background-color:#AAAAAA;
font: 16pt ;
}*/
@ -106,7 +106,7 @@ border-radius:3px;
padding:2px;
background:none;
selection-background-color:#AAAAAA;
selection-color:#FFFFFF;
selection-color:#ffffff;
}
QLineEdit:focus,QTextEdit:focus,QPlainTextEdit:focus,QSpinBox:focus,QDoubleSpinBox:focus,QComboBox:focus,QDateEdit:focus,QTimeEdit:focus,QDateTimeEdit:focus,QLineEdit:hover,QTextEdit:hover,QPlainTextEdit:hover,QSpinBox:hover,QDoubleSpinBox:hover,QComboBox:hover,QDateEdit:hover,QTimeEdit:hover,QDateTimeEdit:hover{
@ -156,6 +156,9 @@ background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1
image:None;
}*/
QToolButton#btnMenu,QPushButton#btnMenu_Min,QPushButton#btnMenu_Max,QPushButton#btnMenu_Close{
border-radius:3px;
color:#DCDCDC;
@ -166,13 +169,13 @@ border-style:none;
}
QToolButton#btnMenu:hover,QPushButton#btnMenu_Min:hover,QPushButton#btnMenu_Max:hover{
color:#FFFFFF;
color:#ffffff;
margin:1px 1px 2px 1px;
background-color:rgba(51,127,209,230);
}
QPushButton#btnMenu_Close:hover{
color:#FFFFFF;
color:#ffffff;
margin:1px 1px 2px 1px;
background-color:rgba(238,0,0,128);
}
@ -681,8 +684,18 @@ border-radius:3px;
margin:3px 3px 3px 3px;
padding:3px;
background:none;
}
QToolButton#qt_calendar_monthbutton,#qt_calendar_yearbutton{
color: #9ea5a9;
font: 9pt simHei;
}
QToolButton#qt_calendar_prevmonth:hover,QToolButton#qt_calendar_nextmonth:hover,QToolButton#qt_calendar_monthbutton:hover,QToolButton#qt_calendar_yearbutton:hover,QToolButton#qt_calendar_prevmonth:pressed,QToolButton#qt_calendar_nextmonth:pressed,QToolButton#qt_calendar_monthbutton:pressed,QToolButton#qt_calendar_yearbutton:pressed{
border:1px solid #242424;
}
@ -702,7 +715,8 @@ border-width:0px;
QCalendarWidget QWidget#qt_calendar_navigationbar{
border:1px solid #242424;
border-width:1px 1px 0px 1px;
background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);
background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #245d9b,stop:1 #245d9b);
}
QTableView[model="true"]::item{
@ -716,6 +730,9 @@ border:2px groove gray;
border-radius: 15px;*/
}
QTableView QLineEdit:focus,QTableView QComboBox:focus,QTableView QSpinBox:focus,QTableView QDoubleSpinBox:focus,QTableView QDateEdit:focus,QTableView QTimeEdit:focus,QTableView QDateTimeEdit:focus{
border-width:0px;
border-radius:0px;
@ -747,7 +764,7 @@ QMessageBox {
QMessageBox QLabel#qt_msgbox_label { /* textLabel */
color: #298DFF;
background-color: transparent;
min-width: 240px; /* textLabel设置最小宽度可以相应的改变QMessageBox的最小宽度 */
min-width: 340px; /* textLabel设置最小宽度可以相应的改变QMessageBox的最小宽度 */
min-height: 40px; /* textLabel和iconLabel高度保持一致 */
font-size: 24pt;
}
@ -782,6 +799,17 @@ QMessageBox QDialogButtonBox#qt_msgbox_buttonbox { /* buttonBox */
button-layout: 0; /* 设置QPushButton布局好像没啥作用 */
}
QPushButton{
width:120px;
height: 35px;
color: black;
background: inherit;
background-color: rgba(255, 255, 255, 0);
border-width: 1px;
border-style: solid;
border-color: #245d9b;
}
QListView[noborder="true"],QTreeView[noborder="true"],QTabWidget[noborder="true"]::pane{
border-width:0px;
@ -803,7 +831,7 @@ background-color:#245d9b;
}
QWidget[flag="Title2"] {
color:#000000;
color:#ffffff;
background-color:#ffffff;
}

View File

@ -10,6 +10,9 @@
#include "MyCustomGraphicsItem.h"
#include "NetMgr.h"
#include <QNetworkRequest>
#include "QGraphicsMovieItem.h"
#include <QLabel>
#include "log.h"
CRealTimeForm::CRealTimeForm(QWidget *parent) :
QWidget(parent),
@ -46,12 +49,12 @@ CRealTimeForm::CRealTimeForm(QWidget *parent) :
//QObject::connect(m_pSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(slotStateChanged(QAbstractSocket::SocketState)));
LoadGraphicsConfig();
m_EditMode = 0;
LoadGraphicsConfig(0);
InitChannelInfo();
m_strServerIp = IP;
//m_strServerIp = IP;
m_nServerPort = 7305;
m_pSocket = new QTcpSocket(this);
@ -97,7 +100,7 @@ void CRealTimeForm::timerEvent(QTimerEvent *ev)
QJsonObject allObj;
allObj.insert("cmd", "09");
// 设置IP和端口号连接
m_pSocket->connectToHost(m_strServerIp, m_nServerPort);
m_pSocket->connectToHost(IP, m_nServerPort);
// 设置超时连接时间
m_bConnected = m_pSocket->waitForConnected(1 * 1000);
@ -114,7 +117,10 @@ void CRealTimeForm::timerEvent(QTimerEvent *ev)
int nRet = m_pSocket->write(strData.toStdString().c_str(), strlen(strData.toStdString().c_str()));
// qDebug() << "nRet" << nRet << endl;
if(nRet !=0){
qDebug() << "09 通信失败" << endl;
customLogMessageHandler(QtWarningMsg,"09通信失败");
}
}
}
@ -152,6 +158,7 @@ void CRealTimeForm::on_graphView_customContextMenuRequested(const QPoint &pos)
pActionRect = menu.addAction("添加通道");
pActionPixmap = menu.addAction("添加图片");
pActionText = menu.addAction("添加文字");
pActionEdit = menu.addAction("编辑");
pActionSave = menu.addAction("保存");
pActionVerticalLine->setData(1);
@ -160,6 +167,7 @@ void CRealTimeForm::on_graphView_customContextMenuRequested(const QPoint &pos)
pActionPixmap->setData(4);
pActionText->setData(5);
pActionSave->setData(6);
pActionEdit->setData(7);
connect(pActionVerticalLine, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionHorizontalLine, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
@ -167,6 +175,7 @@ void CRealTimeForm::on_graphView_customContextMenuRequested(const QPoint &pos)
connect(pActionPixmap, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionText, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionSave, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionEdit, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
menu.exec(QCursor::pos());
//menu.exec(ui->graphicsView->mapToGlobal(pos));
@ -203,9 +212,17 @@ void CRealTimeForm::onTaskBoxContextMenuEvent()
case 6:
SetCurDrawType("Save");
break;
case 7:
SetEdit();
break;
}
}
void CRealTimeForm::SetEdit()
{
m_EditMode = 1;
LoadGraphicsConfig(1);
}
void CRealTimeForm::on_addchannel(channelBaseInfo channelbaseInfo,QString str)
{
@ -304,6 +321,10 @@ void CRealTimeForm::on_addchannel(channelBaseInfo channelbaseInfo,QString str)
void CRealTimeForm::SetCurDrawType(QString strType)
{
if(!m_EditMode){
QMessageBox::information(this, QStringLiteral("提示"), "请先进入编辑模式!");
return;
}
if(strType == "vertical"){
QGraphicsLineItem* pLine = new QGraphicsLineItem(0, 0, 100, 100);
pLine->setPos(-300, 0);
@ -334,15 +355,46 @@ void CRealTimeForm::SetCurDrawType(QString strType)
connect(pAddChannel,SIGNAL(addChannel_sg(channelBaseInfo,QString)),this,SLOT(on_addchannel(channelBaseInfo,QString)));
}else if (strType == "Pixmap"){
QGraphicsPixmapItem* pPixmap = new QGraphicsPixmapItem(QPixmap(":/image/1.png"));
// 设置可移动、可选择
pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(ui->tabWidget->currentIndex() == 0){
m_pGraphicsScene->addItem(pPixmap);
}else if(ui->tabWidget->currentIndex() == 1){
m_pGraphicsScene_2->addItem(pPixmap);
QString name = QCoreApplication::applicationDirPath() + "\\config\\UnitParameters.json";
QFile loadFile(name);
if(!loadFile.open(QIODevice::ReadOnly))
{
qDebug() << "could't open projects json";
return;
}
QString value = loadFile.readAll();
loadFile.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
QMessageBox::about(NULL, "提示", "读取文件错误!");
return;
}
QJsonObject jsonObject = document.object();
if (jsonObject.contains(QStringLiteral("UnitStyle"))) {
QJsonValue jsonValue = jsonObject.value(QStringLiteral("UnitStyle"));
QString strContent = jsonValue["content"].toString();
QGraphicsPixmapItem* pPixmap = NULL;
if(strContent == "混流式机组"){
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/hunliushi.png"));
}else if(strContent == "轴流定桨式机组" || strContent == "轴流转浆式机组"){
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.png"));
}else if(strContent == "可逆式机组"){
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.png"));
}else if(strContent == "灯泡式机组"){
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/dengpaoshi.png"));
}
// 设置可移动、可选择
pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(ui->tabWidget->currentIndex() == 0){
m_pGraphicsScene->addItem(pPixmap);
}else if(ui->tabWidget->currentIndex() == 1){
m_pGraphicsScene_2->addItem(pPixmap);
}
pPixmap->setPos(0,0);
}
pPixmap->setPos(0,0);
}else if (strType == "Text") {
QGraphicsTextItem* pText = new QGraphicsTextItem("请输入...");
@ -357,13 +409,16 @@ void CRealTimeForm::SetCurDrawType(QString strType)
pText->setPos(0,0);
}else if (strType == "Save") {
SaveGraphicsConfig();
LoadGraphicsConfig(0);
}
ui->graphicsView->update();
}
void CRealTimeForm::SaveGraphicsConfig()
{
m_EditMode = 0;
QJsonObject jsonObject;
QJsonArray RectjsonArray;
QJsonArray LinejsonArray;
@ -380,7 +435,7 @@ void CRealTimeForm::SaveGraphicsConfig()
foreach (QGraphicsItem *item, items) {
QGraphicsItem* graphicsItem = static_cast<QGraphicsItem *>(item);
int itemType = graphicsItem->type();
qDebug() << "itemType" << itemType << endl;
//qDebug() << "itemType" << itemType << endl;
switch (itemType) {
// case 3: {//Rect
// QPointF pos = graphicsItem->pos();
@ -400,7 +455,7 @@ void CRealTimeForm::SaveGraphicsConfig()
{
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
qDebug() << "Line" << pos << rect;
//qDebug() << "Line" << pos << rect;
QJsonObject LinejsonObject;
LinejsonObject.insert("x", pos.x());
LinejsonObject.insert("y", pos.y());
@ -412,9 +467,10 @@ void CRealTimeForm::SaveGraphicsConfig()
break;
case 7://Pixmap
{
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
qDebug() << "Pixmap" << pos << rect;
//qDebug() << "Pixmap" << pos << rect;
QJsonObject PixmapjsonObject;
PixmapjsonObject.insert("x", pos.x());
PixmapjsonObject.insert("y", pos.y());
@ -446,7 +502,7 @@ void CRealTimeForm::SaveGraphicsConfig()
channelBaseInfo temp;
//qDebug() << "Group" << pos << rect;
QString strChannelID = pGraphicGroupItem->data(0).toString();
qDebug() << "pGraphicGroupItem data" << strChannelID << endl;
//qDebug() << "pGraphicGroupItem data" << strChannelID << endl;
QJsonArray GroupRectjsonArray,GroupTextjsonArray;
QJsonObject itemjsonObject;
QList<QGraphicsItem *> items = pGraphicGroupItem->childItems();
@ -457,26 +513,26 @@ void CRealTimeForm::SaveGraphicsConfig()
itemData = item->data(i).toString();
if(itemData == "value"){
itemData2 = item->data(i+1).toString();
qDebug() << "item va data" << itemData << itemData2 << i << endl;
//qDebug() << "item va data" << itemData << itemData2 << i << endl;
break;
}else if (itemData == "channel") {
qDebug() << "item ch data" << itemData << i << endl;
//qDebug() << "item ch data" << itemData << i << endl;
break;
}else if(itemData == "units"){
qDebug() << "item un data" << itemData << i << endl;
//qDebug() << "item un data" << itemData << i << endl;
break;
}
}
QGraphicsItem* graphicsItem = static_cast<QGraphicsItem *>(item);
int itemType = graphicsItem->type();
qDebug() << "itemData2" << itemData << endl;
//qDebug() << "itemData2" << itemData << endl;
switch (itemType) {
case 3: {//Rect
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
qDebug() << "group Rect" << pos << rect;
//qDebug() << "group Rect" << pos << rect;
QJsonObject RectjsonObject;
RectjsonObject.insert("x", pos.x());
RectjsonObject.insert("y", pos.y());
@ -567,7 +623,7 @@ void CRealTimeForm::slotDoubleClick(QGraphicsSceneMouseEvent *event)
qDebug() << "QGraphicsItem" << pGraphicGroupItem->childItems() << endl;
}
void CRealTimeForm::LoadGraphicsConfig()
void CRealTimeForm::LoadGraphicsConfig(int type)
{
//读取图元的数据
@ -582,10 +638,9 @@ void CRealTimeForm::LoadGraphicsConfig()
for (int ii = 0; ii < ui->tabWidget->count(); ii++) {
QString strFileName = QString("Graph%1.json").arg(ii+1);
QString fileName = QCoreApplication::applicationDirPath() + "\\config\\" + strFileName;
qDebug() << "打开" << fileName ;
if(!fileName.isEmpty())
{
qDebug() << "打开" << fileName ;
QFile file(fileName);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString value = file.readAll();
@ -613,7 +668,8 @@ void CRealTimeForm::LoadGraphicsConfig()
key["w"].toDouble(), key["h"].toDouble());
pLine->setPos(key["x"].toDouble(), key["y"].toDouble());
pLine->setRotation(key["rotation"].toInt());
pLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(type)
pLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(ii == 0){
m_pGraphicsScene->addItem(pLine);
}else if(ii == 1){
@ -635,11 +691,12 @@ void CRealTimeForm::LoadGraphicsConfig()
0,
key["w"].toDouble(), key["h"].toDouble());
pRect->setPos(key["x"].toDouble(), key["y"].toDouble());
pRect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(type)
pRect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(ii == 0){
m_pGraphicsScene->addItem(pRect);
}else if(ii == 1){
m_pGraphicsScene_2->addItem(pRect);
m_pGraphicsScene_2->addItem(pRect);
}
}
}
@ -652,26 +709,124 @@ void CRealTimeForm::LoadGraphicsConfig()
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsPixmapItem *pPixmap = new QGraphicsPixmapItem(QPixmap(":/image/1.png"));
pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(ii == 0){
m_pGraphicsScene->addItem(pPixmap);
}else if(ii == 1){
m_pGraphicsScene_2->addItem(pPixmap);
QString name = QCoreApplication::applicationDirPath() + "\\config\\UnitParameters.json";
QFile loadFile(name);
if(!loadFile.open(QIODevice::ReadOnly))
{
qDebug() << "could't open projects json";
return;
}
QString value = loadFile.readAll();
loadFile.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
QMessageBox::about(NULL, "提示", "读取文件错误!");
return;
}
QJsonObject jsonObject = document.object();
if (jsonObject.contains(QStringLiteral("UnitStyle"))) {
QJsonValue jsonValue = jsonObject.value(QStringLiteral("UnitStyle"));
QString strContent = jsonValue["content"].toString();
QGraphicsPixmapItem* pPixmap = NULL;
QLabel *gif_anim = new QLabel();
QMovie *movie = NULL;
qDebug() << "strContent" << strContent << endl;
if(strContent == "混流式机组"){
if(type)
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/hunliushi.png"));
else
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/hunliushi.gif");
}else if(strContent == "轴流定桨式机组" || strContent == "轴流转浆式机组"){
if(type)
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.png"));
else
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.gif");
//pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.png"));
}else if(strContent == "可逆式机组"){
if(type)
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.png"));
else
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.gif");
//pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.png"));
}else if(strContent == "灯泡式机组"){
if(type)
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/dengpaoshi.png"));
else
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/dengpaoshi.gif");
}
qDebug() << "type" << type << ii << endl;
if(type){
pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
// 设置可移动、可选择
pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(ii == 0){
m_pGraphicsScene->addItem(pPixmap);
}else if(ii == 1){
m_pGraphicsScene_2->addItem(pPixmap);
}
}else{
gif_anim->setMovie(movie);
movie->start();
QGraphicsProxyWidget *proxy = NULL;
if(ii == 0){
qDebug() << "strContent111" << strContent << endl;
proxy = m_pGraphicsScene->addWidget(gif_anim);
}else if(ii == 1){
proxy = m_pGraphicsScene_2->addWidget(gif_anim);
}
proxy->setGeometry(QRectF(key["x"].toInt(),key["y"].toInt(),460,478));
}
}
// QGraphicsPixmapItem *pPixmap = new QGraphicsPixmapItem(QPixmap(":/image/1.png"));
// pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
// pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
// if(ii == 0){
// m_pGraphicsScene->addItem(pPixmap);
// }else if(ii == 1){
// m_pGraphicsScene_2->addItem(pPixmap);
// }
// QLabel *gif_anim = new QLabel();
// QMovie *movie = new QMovie(":/image/1.gif");
// gif_anim->setMovie(movie);
// movie->start();
// QGraphicsProxyWidget *proxy = m_pGraphicsScene->addWidget(gif_anim);
// QGraphicsMovieItem *pPixmap = new QGraphicsMovieItem();
// pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
// QMovie movie(":/image/1.png");
// pPixmap->setMovie(&movie);
// movie.start();
// m_pGraphicsScene->addItem(pPixmap);
}
}
}
// Text字段
if (jsonObject.contains(QStringLiteral("Text"))) {
if(type){
QGraphicsTextItem *pText = new QGraphicsTextItem("正在编辑中...");
pText->setPos(-400, 750);
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
QFont font ( "黑体", 20, 50);
font.setPixelSize(30);
pText->setDefaultTextColor(QColor(255, 0, 0));
pText->setFont(font);
if(ii == 0){
m_pGraphicsScene->addItem(pText);
}else if(ii == 1){
m_pGraphicsScene_2->addItem(pText);
}
}
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Text"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsTextItem *pText = new QGraphicsTextItem(key["word"].toString());
pText->setPos(key["x"].toInt(), key["y"].toInt());
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
@ -682,7 +837,7 @@ void CRealTimeForm::LoadGraphicsConfig()
if(ii == 0){
m_pGraphicsScene->addItem(pText);
}else if(ii == 1){
m_pGraphicsScene_2->addItem(pText);
m_pGraphicsScene_2->addItem(pText);
}
}
}
@ -695,9 +850,10 @@ void CRealTimeForm::LoadGraphicsConfig()
for (int i = 0; i < array.size(); i++) {
channelBaseInfo temp;
CMyCustomGraphicsItem* pItemGroup = new CMyCustomGraphicsItem();
pItemGroup->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(type)
pItemGroup->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
connect(pItemGroup, SIGNAL(doubleclick(QGraphicsSceneMouseEvent*)), this, SLOT(slotDoubleClick(QGraphicsSceneMouseEvent*)));
qDebug() << array.at(i)["x"].toDouble() << array.at(i)["y"].toDouble() << endl;
//qDebug() << array.at(i)["x"].toDouble() << array.at(i)["y"].toDouble() << endl;
QJsonObject jsonObject = array.at(i).toObject();
@ -713,7 +869,8 @@ void CRealTimeForm::LoadGraphicsConfig()
0,
470, 50);
pRect->setPos(key["x"].toDouble(), key["y"].toDouble());
pRect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
if(type)
pRect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pRect->setBrush(QBrush(QColor(255, 255, 255)));
pRect->setPen(pen);
pItemGroup->addToGroup(pRect);
@ -730,8 +887,10 @@ void CRealTimeForm::LoadGraphicsConfig()
QGraphicsTextItem *pText = new QGraphicsTextItem(key["word"].toString());
pText->setPos(key["x"].toDouble(), key["y"].toDouble());
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pText->setTextInteractionFlags(Qt::TextEditorInteraction);
if(type){
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pText->setTextInteractionFlags(Qt::TextEditorInteraction);
}
QFont font;
QFont font2 ( "黑体", 20, 50);
font.setPixelSize(25);
@ -805,7 +964,7 @@ void CRealTimeForm::keyPressEvent(QKeyEvent *event)
void CRealTimeForm::UpdateCharacteristic(QVector<_Charateristic>& m_vecCharateristic)
{
QString RPM = "";
QString RPM = "0";
if(m_vecCharateristic.size() > 0){
for (int i = 0; i < m_vecCharateristic.size(); i++) {
QList<QGraphicsItem *> items;
@ -948,25 +1107,26 @@ void CRealTimeForm::slotRecieve()
{
QByteArray arrayReady = m_pSocket->readAll();
m_arrayReady += arrayReady;
//qDebug() << "arrayReady" << arrayReady << endl;
QJsonDocument doc = QJsonDocument::fromJson(arrayReady);
QJsonObject objec = doc.object();
if(objec.contains("cmd"))
{
QJsonValue arrays_value = objec.take("cmd");
qDebug()<<"cmd ="<<arrays_value.toString();
if(arrays_value.toString() == "09"){
QJsonArray arrayValue = objec["content"].toArray();
QJsonArray arrayValueDIs = objec["DIO_Board_DIs"].toArray();
QJsonArray arrayValueDOs = objec["DIO_Board_DOs"].toArray();
ParseCharacteristic(arrayValue);
QString strTrgStatus = objec["currentTriggerStatus"].toString();
QString strWCStatus = objec["currentWorkCondition"].toString();
QString str = strTrgStatus + "," + strWCStatus;
sigWCStatus(str);
sigDOStatus(arrayValueDIs,arrayValueDOs);
}
}
// customLogMessageHandler(QtDebugMsg,m_arrayReady);
// qDebug() << "arrayReady" << arrayReady << endl;
// QJsonDocument doc = QJsonDocument::fromJson(arrayReady);
// QJsonObject objec = doc.object();
// if(objec.contains("cmd"))
// {
// QJsonValue arrays_value = objec.take("cmd");
// qDebug()<<"cmd ="<<arrays_value.toString();
// if(arrays_value.toString() == "09"){
// QJsonArray arrayValue = objec["content"].toArray();
// QJsonArray arrayValueDIs = objec["DIO_Board_DIs"].toArray();
// QJsonArray arrayValueDOs = objec["DIO_Board_DOs"].toArray();
// ParseCharacteristic(arrayValue);
// QString strTrgStatus = objec["currentTriggerStatus"].toString();
// QString strWCStatus = objec["currentWorkCondition"].toString();
// QString str = strTrgStatus + "," + strWCStatus;
// sigWCStatus(str);
// sigDOStatus(arrayValueDIs,arrayValueDOs);
// }
// }
}
void CRealTimeForm::disConnect()
@ -978,6 +1138,7 @@ void CRealTimeForm::disConnect()
QJsonValue arrays_value = objec.take("cmd");
qDebug()<<"cmd ="<<arrays_value.toString();
if(arrays_value.toString() == "09"){
qDebug()<<"cmd ="<<arrays_value.toString();
QJsonArray arrayValue = objec["content"].toArray();
QJsonArray arrayValueDIs = objec["DIO_Board_DIs"].toArray();
QJsonArray arrayValueDOs = objec["DIO_Board_DOs"].toArray();

View File

@ -8,6 +8,7 @@
#include <QGraphicsRectItem>
#include <QGraphicsLineItem>
#include <QGraphicsTextItem>
#include <QGraphicsProxyWidget>
#include <QKeyEvent>
#include <AddChannel.h>
#include "sqlitedb.h"
@ -98,6 +99,7 @@ private:
QAction *pActionRect ;
QAction *pActionPixmap ;
QAction *pActionText ;
QAction *pActionEdit ;
QAction *pActionSave ;
int id1; //定时器1的唯一标示
@ -107,7 +109,8 @@ private:
void InitChannelInfo();
void SetCurDrawType(QString strType);
void LoadGraphicsConfig();
void SetEdit();
void LoadGraphicsConfig(int type);
void SaveGraphicsConfig();
void UpdateCharacteristic(QVector<_Charateristic>& m_vecCharateristic);
void ParseCharacteristic(QJsonArray& arrayValue);
@ -118,7 +121,7 @@ private:
bool m_bConnected; // 连接的标志
int m_nConnectWaitTimes; // 连接的等待时间
int m_nServerPort; // 服务端端口号
int m_EditMode;
NetMgr *m_pNetMgr; //HTTP消息类对象
QVector<_Charateristic> m_vecCharateristic;

View File

@ -204,9 +204,9 @@ QVector<ChannelSetting> SqliteDB::GetDataMultiLine(QString tablename, QString co
tempchannel.stopBrands = sql_query.value(81).toString();
tempchannel.tachAutoTach = sql_query.value(82).toBool();
tempchannel.tachTriggerEdge = sql_query.value(83).toString();
tempchannel.tachTriggerHysteresis = sql_query.value(84).toInt();
tempchannel.tachTriggerHysteresis = sql_query.value(84).toDouble();
tempchannel.tachTriggerPerRev = sql_query.value(85).toString();
tempchannel.tachTriggerVoltageLevel = sql_query.value(86).toBool();
tempchannel.tachTriggerVoltageLevel = sql_query.value(86).toDouble();
tempchannel.thermalCoupleType = sql_query.value(87).toString();
tempchannel.xFullScalePosition = sql_query.value(88).toString();
tempchannel.xProcessVariableName = sql_query.value(89).toString();
@ -381,6 +381,46 @@ SqliteDB::GetTriggerConfig(QString tablename,QString whereCon)
return vecResult;
}
QVector<TriggerEvent_t>
SqliteDB::GetTriggerEvent(QString tablename,QString whereCon)
{
QSqlQuery sql_query;
QVector<TriggerEvent_t> vecResult;
TriggerEvent_t tempTriggerEvent;
QString strSql;
if(whereCon == "")
strSql = QString("SELECT * FROM %1 ;").arg(tablename);
else
strSql = QString("SELECT * FROM %1 where %2;").arg(tablename).arg(whereCon);
sql_query.exec(strSql);
qDebug() << "strSql" <<strSql << endl;
if(!sql_query.exec())
{
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
}
else
{
while(sql_query.next())
{
tempTriggerEvent.triggeredChannelName = sql_query.value(0).toString();
tempTriggerEvent.triggeredType = sql_query.value(1).toString();
tempTriggerEvent.triggeredValue = sql_query.value(2).toString();
tempTriggerEvent.triggeredNotification = sql_query.value(3).toString();
tempTriggerEvent.triggeredDataWatchNo = sql_query.value(4).toString();
tempTriggerEvent.triggeredDataWatchName = sql_query.value(5).toString();
tempTriggerEvent.triggeredChannelID = sql_query.value(6).toString();
tempTriggerEvent.triggeredTime = sql_query.value(7).toInt();
tempTriggerEvent.triggeredEquipmentID = sql_query.value(8).toInt();
tempTriggerEvent.triggeredEventName = sql_query.value(9).toString();
tempTriggerEvent.triggeredFeatureName = sql_query.value(10).toString();
vecResult.append(tempTriggerEvent);
}
}
return vecResult;
}
int SqliteDB::InsertData(QString& tablename,QString& sql)
{
QSqlQuery sql_query;

View File

@ -30,6 +30,7 @@ public:
QVector<WorkCondition_t> GetWorkCondition(QString tablename,QString whereCon = "");
QVector<WorkConditionInfo_t> GetWorkConditionInfo(QString tablename,QString whereCon = "");
QVector<TriggerConfig_t> GetTriggerConfig(QString tablename,QString whereCon = "");
QVector<TriggerEvent_t> GetTriggerEvent(QString tablename,QString whereCon = "");
QString GetSingelLine(QString& tablename, QString& column, QString whereCon = "");
int DeleteData(QString& tablename, QString condColumnName = "", QString condColumnValue = "");
int DeleteDataW(QString& tablename, QString& whereCon);