#include "ChannelList.h" #include "ui_channellist.h" #include #include "sqlitedb.h" #include #include #include #include #include #include #include "NetMgr.h" CChannelList::CChannelList(QWidget *parent) : QWidget(parent), ui(new Ui::CChannelList) { ui->setupUi(this); ui->comboBox_operate->setView(new QListView()); // this->setWindowTitle("QTableView简单使用"); // //建立模型对象空间并指定父对象 // m_pModel = new QStandardItemModel(ui->tableView); // //添加列标题 // //m_pModel->setHorizontalHeaderLabels(QStringList() << "one" << "two"\ // << "three" << "four"); // m_pModel->setColumnCount(5); // //将数据模型设置到表对象上 // ui->tableView->setModel(m_pModel); // //建立表头对象空间并指定父对象 // m_pHeaderView = new CHeaderView(Qt::Horizontal, ui->tableView); // //将表对象的表头设为自定义表头 // ui->tableView->setHorizontalHeader(m_pHeaderView); // //连接表头点击信号槽 // connect(m_pHeaderView, &CHeaderView::columnSectionClicked // , this, &CChannelList::on_columnSectionClicked); // //循环添加三行数据 // for(int index = 0; index != 3; ++index) // { // m_pModel->appendRow(QList() // << new QStandardItem(QString("第%1行,第0列").arg(index)) // << new QStandardItem(QString("第%1行,第1列").arg(index)) // << new QStandardItem(QString("第%1行,第2列").arg(index)) // << new QStandardItem(QString("第%1行,第3列").arg(index))); // } // //m_pModel->appendRow(new QStandardItem(QString("第%1行,第0列"))); // //设置第0列和第2列为可选 // this->setColumnCheckable(0, true); // //this->setColumnCheckable(2, true); //--1 初始化 headerStr = QObject::tr(" ,通道名称,模块编号,通道滤波状态,通道状态,通道类型,采样频率(Hz),灵敏度,工程单位,范围检查,最小值,\ 最大值,1x幅值补偿,1x相位补偿,初始间距,安装角度,安装位置,转向,速度参考,转速比,关联通道,\ 轴承间隙,启动位置,IEPE,耦合性,0值电压,满程电压,自动转速,触发沿,触发次数,Hysteresis(V),\ 触发阈值,热电偶类型,配置时间,滤波器,起始频率,截止频率,备注"); iniVar(); iniUi(); iniConnect(); connect(ui->tableView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotRowDoubleClicked(const QModelIndex &))); ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->tableView->setColumnWidth(33, 256); m_nCurRow = -1; ui->comboBox_operate->addItem("通道"); ui->comboBox_operate->addItem("带通滤波"); //--2 创建表格项 // QStringList workingConditionName; // workingConditionName<clear(); for (int i = 0; i < g_channelSetting.size(); i++) { QString strChannelType; QMap::Iterator iter = g_MapChannelType.begin(); for (; iter != g_MapChannelType.end(); iter++) { if(iter.key() == g_channelSetting[i].sensorType){ strChannelType = iter.value(); break; } } QVariantList strRowItem ; QString strChannelStatus,strChannelFilterStatus,strChannelNo; if(g_channelSetting[i].isEnable) strChannelStatus = "启用"; else strChannelStatus = "关闭"; if(g_channelSetting[i].filterStatus) strChannelFilterStatus = "启用"; else strChannelFilterStatus = "关闭"; QString strcouplingACDC; if(g_channelSetting[i].couplingACDC) strcouplingACDC = "AC"; else strcouplingACDC = "DC"; strChannelNo = QString("%1-%2").arg(g_channelSetting[i].sensorModuleNo).arg(g_channelSetting[i].sensorNo); QString TStr = QDateTime::fromSecsSinceEpoch(g_channelSetting[i].sensorConfigureDate.toInt()).toString("yyyy-MM-dd hh:mm:ss"); strRowItem << g_channelSetting[i].channelName << strChannelNo << strChannelFilterStatus\ << strChannelStatus << strChannelType << g_channelSetting[i].samplingRate\ << g_channelSetting[i].sensorSensitivity <tableView->sortByColumn(2,Qt::AscendingOrder);//第3列是按照升序来排列 // ui->tableView->setSortingEnabled(true); } void CChannelList::iniVar() { myHeader = new TableHeaderView(Qt::Horizontal, ui->tableView); model = new QStandardItemModel(ui->tableView); } void CChannelList::iniUi() { ui->tableView->setHorizontalHeader(myHeader); ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行 QStringList headerList = headerStr.split(","); model->setHorizontalHeaderLabels(headerList); model->setColumnCount(headerList.size()); CheckBoxDelegate *pCheckDelegate = new CheckBoxDelegate(this); ui->tableView->setItemDelegateForColumn(0, pCheckDelegate); ui->tableView->setModel(model); ui->tableView->setAlternatingRowColors(true); for (int i = 0; i < model->columnCount() ; i++) { if(i == 1){ ui->tableView->setColumnWidth(i, 200); }else{ ui->tableView->setColumnWidth(i, 130); } } } void CChannelList::iniConnect() { connect(myHeader, &TableHeaderView::stateChanged, this, &CChannelList::headerStateChangedSlot); connect(model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(itemChangedSlot(QStandardItem*))); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); #ifndef NO_FILTER QJsonObject sendData; sendData["cmd"] = "97"; QJsonArray chan_list; for (int i = 0; i < g_channelSetting.size(); i++) { if(g_channelSetting[i].boardType != "5" && g_channelSetting[i].boardType != "6" ) chan_list.append(g_channelSetting[i].channelId); } sendData["chan_list"] = chan_list; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); #endif } void CChannelList::createItem(QStringList filename) { qDebug()<< "createItem" << endl; int rowCount = filename.size(); model->setRowCount(rowCount); for(int i = 0; i < rowCount; ++i) { model->setItem(i,1,new QStandardItem(filename.at(i))); QModelIndex index = model->index(i, 1, QModelIndex()); QStandardItem *item = model->itemFromIndex(index); item->setData(QColor(Qt::green), Qt::BackgroundRole); } } void CChannelList::createRowItem(int Row,QVariantList RowItem) { model->setRowCount(Row+1); { for (int j = 1; j < RowItem.size()+1; ++j) { //model->setItem(i,j,new QStandardItem(filename.at(j-1))); model->setData(model->index(Row,j,QModelIndex()),RowItem.at(j-1)); //model->set } } } void CChannelList::headerStateChangedSlot(int state) { int rowCount = model->rowCount(); if (state == 2)//全选 { for (int j = 0; jindex(j, 0, QModelIndex()); model->setData(index, true, Qt::UserRole); } } else if (state == 0) //全不选 { for (int j = 0; jindex(j, 0, QModelIndex()); model->setData(index, false, Qt::UserRole); } } } void CChannelList::itemChangedSlot(QStandardItem *item) { int rowCount = model->rowCount(); int column = item->index().column(); if (column == 0) //第0列 checkbox { Qt::CheckState state = Qt::Unchecked; int nSelectedCount = 0; for (int i = 0; i< rowCount; i++) { if (model->index(i, 0).data(Qt::UserRole).toBool()) { nSelectedCount++; } } if (nSelectedCount >= rowCount) { state = Qt::Checked; } else if (nSelectedCount > 0) { state = Qt::PartiallyChecked; } myHeader->onStateChanged(state); } } void CChannelList::slotChannelSettingClose() { on_pushButton_refresh_clicked(); } void CChannelList::slotSetChannelData(ChannelSetting channelSetting) { qDebug() << "slotSetChannelData" << endl; int i; for (i = 0;i ::Iterator iter = g_MapChannelType.begin(); for (; iter != g_MapChannelType.end(); iter++) { if(iter.key() == channelSetting.sensorType){ strChannelType = iter.value(); break; } } QVariantList strRowItem ; QString strChannelStatus; if(channelSetting.isEnable) strChannelStatus = "启用"; else strChannelStatus = "关闭"; QString TStr = QDateTime::fromSecsSinceEpoch(channelSetting.sensorConfigureDate.toInt()).toString("yyyy-MM-dd hh:mm:ss"); strRowItem << channelSetting.channelName << channelSetting.sensorModuleNo << channelSetting.sensorNo\ << strChannelStatus << strChannelType << channelSetting.samplingRate\ << channelSetting.sensorSensitivity <setData(model->index(m_nCurRow,j,QModelIndex()),strRowItem.at(j-1)); // } // model->setData(model->index(m_nCurRow,1,QModelIndex()),g_channelSetting[i].channelName); // QJsonDocument document; // document.setArray(m_JsonArray); // QByteArray byteArray = document.toJson(QJsonDocument::Compact); // QString name = QCoreApplication::applicationDirPath() + "\\config\\channelSettings.json"; // QFile file(name); // file.open(QIODevice::WriteOnly); // file.write(byteArray); // file.close(); QString strUpdateSql = QString(" set ChUnitCoeff = '%1' , ChUnitDot = %2,SensorICP = '%3', \ SensorType = '%4',bearingClearance='%5',bearingStartPosition='%6',\ channelIntDiff = '%7',channelName='%8',channelRMSPkPk2Pk='%9',channelSensorType='%10',\ comments = '%11',couplingACDC='%12',envelopeHighpassband=%13,envelopeLowpassband=%14,\ equipmentId = %15,filter='%16',frequencyRangeMax='%17',frequencyRangeMin='%18',\ fullScalePosition=%19,highPassFrequency='%20',installMethod='%21',isEnable=%22,\ isWork=%23,lowPassFrequency='%24',measuringRange='%25',offset=%26,pairChannelId='%27',\ pairChannelName='%28',rpmMultiplier='%29',samplingRate=%30,sensor1xAmplitudeRunout='%31',\ sensor1xPhaseRunout='%32',sensorConfigureDate='%33',sensorEngineeringUnit='%34',\ sensorGapVoltage='%35',sensorLeftOrRight='%36',sensorLocationInDegree=%37,sensorModuleNo=%38,\ sensorNo=%39,sensorRange='%40',sensorRangeCheck='%41',sensorRangeMax='%42',sensorRangeMin='%43',\ sensorSensitivity='%44',shaftRotationDirection='%45',speedRefChannelId='%46',\ startBrands='%47',stopBrands='%48',tachAutoTach='%49',tachTriggerEdge='%50',tachTriggerHysteresis=%51,\ tachTriggerPerRev='%52',tachTriggerVoltageLevel='%53',thermalCoupleType = '%54',xFullScalePosition='%55',\ xProcessVariableName='%56',xZeroScalePosition='%57',zeroScalePosition='%58',speedRefChannelName = '%59',defaultDisplay = '%60',sensorTypes = '%61',\ confidenceDegree = %62,sectionNum = %63,EngineeringUnit2 = '%64',firstPoleNum = '%65' where channelId = '%66'").\ arg(channelSetting.ChUnitCoeff).arg(channelSetting.ChUnitDot).arg(channelSetting.sensorICP).\ arg(channelSetting.sensorType).arg(channelSetting.bearingClearance).arg(channelSetting.bearingStartPosition).\ arg(channelSetting.channelIntDiff).arg(channelSetting.channelName).arg(channelSetting.channelRMSPkPk2Pk).arg(channelSetting.channelSensorType).\ arg(channelSetting.comments).arg(channelSetting.couplingACDC).arg(channelSetting.envelopeHighpassband).arg(channelSetting.envelopeLowpassband).\ arg(channelSetting.equipmentId).arg(channelSetting.filter).arg(channelSetting.frequencyRangeMax).\ arg(channelSetting.frequencyRangeMin).arg(channelSetting.fullScalePosition).arg(channelSetting.highPassFrequency).\ arg(channelSetting.installMethod).arg(channelSetting.isEnable).arg(channelSetting.isWork).\ arg(channelSetting.lowPassFrequency).arg(channelSetting.measuringRange).arg(channelSetting.offset).\ arg(channelSetting.pairChannelId).arg(channelSetting.pairChannelName).arg(channelSetting.rpmMultiplier).\ arg(channelSetting.samplingRate).arg(channelSetting.sensor1xAmplitudeRunout).arg(channelSetting.sensor1xPhaseRunout).\ arg(channelSetting.sensorConfigureDate).arg(channelSetting.sensorEngineeringUnit).arg(channelSetting.sensorGapVoltage).\ arg(channelSetting.sensorLeftOrRight).arg(channelSetting.sensorLocationInDegree).arg(channelSetting.sensorModuleNo).\ arg(channelSetting.sensorNo).arg(channelSetting.sensorRange).arg(channelSetting.sensorRangeCheck).\ arg(channelSetting.sensorRangeMax).arg(channelSetting.sensorRangeMin).arg(channelSetting.sensorSensitivity).\ arg(channelSetting.shaftRotationDirection).arg(channelSetting.speedRefChannelId).\ arg(channelSetting.startBrands).arg(channelSetting.stopBrands).arg(channelSetting.tachAutoTach).arg(channelSetting.tachTriggerEdge).\ arg(channelSetting.tachTriggerHysteresis).arg(channelSetting.tachTriggerPerRev).arg(channelSetting.tachTriggerVoltageLevel).\ arg(channelSetting.thermalCoupleType).arg(channelSetting.xFullScalePosition).arg(channelSetting.xProcessVariableName).arg(channelSetting.xZeroScalePosition).\ arg(channelSetting.zeroScalePosition).arg(channelSetting.speedRefChannelName).arg(channelSetting.defaultDisplay).arg(channelSetting.sensorTypes).\ arg(channelSetting.confidenceDegree).arg(channelSetting.sectionNum).arg(channelSetting.EngineeringUnit).arg(channelSetting.firstPoleNum).arg(channelSetting.channelId); QString tableName = "t_ChannelSetting "; g_SqliteDB->UpdateDataSql(tableName,strUpdateSql); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); putJson(); //disconnect(ChannelSettingdialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting))); //disconnect(SlowSpeeddialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting))); } void CChannelList::putJson() { QJsonArray channelArray; for(int i = 0; i < g_channelSetting.size();i++){ QJsonObject channelObj; channelObj["ChUnitCoeff"] = g_channelSetting[i].ChUnitCoeff; channelObj["ChUnitDot"] = g_channelSetting[i].ChUnitDot; channelObj["sensorICP"] = g_channelSetting[i].sensorICP; channelObj["bearingClearance"] = g_channelSetting[i].bearingClearance.toDouble(); channelObj["bearingStartPosition"] = g_channelSetting[i].bearingStartPosition; channelObj["channel1P5XAMP"] = g_channelSetting[i].channel1P5XAMP; channelObj["channel1P5XAMPDefaultValue"] = g_channelSetting[i].channel1P5XAMPDefaultValue; channelObj["channel1xAmpl"] = g_channelSetting[i].channel1xAmpl; channelObj["channel1xAmpleDefaultValue"] = g_channelSetting[i].channel1xAmpleDefaultValue; channelObj["channel2P5XAMP"] = g_channelSetting[i].channel2P5XAMP; channelObj["channel2P5XAMPDefaultValue"] = g_channelSetting[i].channel2P5XAMPDefaultValue; channelObj["channel2p5xAmpl"] = g_channelSetting[i].channel2p5xAmpl; channelObj["channel2p5xAmplDefaultValue"] = g_channelSetting[i].channel2p5xAmplDefaultValue; channelObj["channel2xAmpl"] = g_channelSetting[i].channel2xAmpl; channelObj["channel2xAmplDefaultValue"] = g_channelSetting[i].channel2xAmplDefaultValue; channelObj["channel3XAmpl"] = g_channelSetting[i].channel3XAmpl; channelObj["channel3XAmplDefaultValue"] = g_channelSetting[i].channel3XAmplDefaultValue; channelObj["channelACHighpassband"] = g_channelSetting[i].channelACHighpassband; channelObj["channelDefaultValueEU"] = g_channelSetting[i].channelDefaultValueEU; channelObj["channelDirect"] = g_channelSetting[i].channelDirect; channelObj["channelDirectDefaultValue"] = g_channelSetting[i].channelDirectDefaultValue; channelObj["channelElement"] = g_channelSetting[i].channelElement; channelObj["channelElementDefaultValue"] = g_channelSetting[i].channelElementDefaultValue; channelObj["channelGapVoltage"] = g_channelSetting[i].channelGapVoltage; channelObj["channelGapVoltageDefaultValue"] = g_channelSetting[i].channelGapVoltageDefaultValue; channelObj["channelId"] = g_channelSetting[i].channelId; channelObj["channelIntDiff"] = g_channelSetting[i].channelIntDiff; channelObj["channelName"] = g_channelSetting[i].channelName; channelObj["channelNot1xAmp"] = g_channelSetting[i].channelNot1xAmp; channelObj["channelNot1xAmpDefaultValue"] = g_channelSetting[i].channelNot1xAmpDefaultValue; channelObj["channelOP5XAMP"] = g_channelSetting[i].channelOP5XAMP; channelObj["channelOP5XAMPDefaultValue"] = g_channelSetting[i].channelOP5XAMPDefaultValue; channelObj["channelRMSPkPk2Pk"] = g_channelSetting[i].channelRMSPkPk2Pk; channelObj["channelRecorderOutput"] = g_channelSetting[i].channelRecorderOutput; channelObj["channelRecorderOutputDefaultVal"] = g_channelSetting[i].channelRecorderOutputDefaultVal; channelObj["channelRotor"] = g_channelSetting[i].channelRotor; channelObj["channelRotorDefaultValue"] = g_channelSetting[i].channelRotorDefaultValue; channelObj["channelSensorType"] = g_channelSetting[i].channelSensorType; channelObj["channelSmax"] = g_channelSetting[i].channelSmax; channelObj["channelSmaxDefaultValue"] = g_channelSetting[i].channelSmaxDefaultValue; channelObj["channelSpike"] = g_channelSetting[i].channelSpike; channelObj["channelSpikeDefaultValue"] = g_channelSetting[i].channelSpikeDefaultValue; channelObj["comments"] = g_channelSetting[i].comments; channelObj["couplingACDC"] = g_channelSetting[i].couplingACDC; channelObj["dataWatchNo"] = g_channelSetting[i].dataWatchNo; channelObj["envelopeHighpassband"] = g_channelSetting[i].envelopeHighpassband; channelObj["envelopeLowpassband"] = g_channelSetting[i].envelopeLowpassband; channelObj["equipmentId"] = g_channelSetting[i].equipmentId; channelObj["filter"] = g_channelSetting[i].filter; channelObj["frequencyRangeMax"] = g_channelSetting[i].frequencyRangeMax.toDouble(); channelObj["frequencyRangeMin"] = g_channelSetting[i].frequencyRangeMin.toDouble(); channelObj["fullScalePosition"] = g_channelSetting[i].fullScalePosition; channelObj["highPassFrequency"] = g_channelSetting[i].highPassFrequency.toDouble(); channelObj["installMethod"] = g_channelSetting[i].installMethod; channelObj["isEnable"] = g_channelSetting[i].isEnable; channelObj["isWork"] = g_channelSetting[i].isWork; channelObj["lowPassFrequency"] = g_channelSetting[i].lowPassFrequency.toDouble(); channelObj["measuringRange"] = g_channelSetting[i].measuringRange.toDouble(); channelObj["offset"] = g_channelSetting[i].offset; channelObj["pairChannelId"] = g_channelSetting[i].pairChannelId; channelObj["pairChannelName"] = g_channelSetting[i].pairChannelName; channelObj["rpmMultiplier"] = g_channelSetting[i].rpmMultiplier.toDouble(); channelObj["samplingRate"] = g_channelSetting[i].samplingRate; channelObj["sensor1xAmplitudeRunout"] = g_channelSetting[i].sensor1xAmplitudeRunout.toDouble(); channelObj["sensor1xPhaseRunout"] = g_channelSetting[i].sensor1xPhaseRunout.toDouble(); channelObj["sensorConfigureDate"] = g_channelSetting[i].sensorConfigureDate.toInt(); channelObj["sensorEngineeringUnit"] = g_channelSetting[i].sensorEngineeringUnit; channelObj["sensorGapVoltage"] = g_channelSetting[i].sensorGapVoltage.toDouble(); channelObj["sensorLeftOrRight"] = g_channelSetting[i].sensorLeftOrRight; channelObj["sensorLocationInDegree"] = g_channelSetting[i].sensorLocationInDegree; channelObj["sensorModuleNo"] = g_channelSetting[i].sensorModuleNo; channelObj["sensorNo"] = g_channelSetting[i].sensorNo; channelObj["sensorRange"] = g_channelSetting[i].sensorRange; channelObj["sensorRangeCheck"] = g_channelSetting[i].sensorRangeCheck; channelObj["sensorRangeMax"] = g_channelSetting[i].sensorRangeMax.toDouble(); channelObj["sensorRangeMin"] = g_channelSetting[i].sensorRangeMin.toDouble(); channelObj["sensorSensitivity"] = g_channelSetting[i].sensorSensitivity.toDouble(); channelObj["sensorType"] = g_channelSetting[i].sensorType; channelObj["shaftRotationDirection"] = g_channelSetting[i].shaftRotationDirection; channelObj["speedRefChannelId"] = g_channelSetting[i].speedRefChannelId; channelObj["startBrands"] = g_channelSetting[i].startBrands; channelObj["stopBrands"] = g_channelSetting[i].stopBrands; channelObj["tachAutoTach"] = g_channelSetting[i].tachAutoTach; channelObj["tachTriggerEdge"] = g_channelSetting[i].tachTriggerEdge; channelObj["tachTriggerHysteresis"] = g_channelSetting[i].tachTriggerHysteresis; channelObj["tachTriggerPerRev"] = g_channelSetting[i].tachTriggerPerRev.toInt(); channelObj["tachTriggerVoltageLevel"] = g_channelSetting[i].tachTriggerVoltageLevel; channelObj["thermalCoupleType"] = g_channelSetting[i].thermalCoupleType; channelObj["xFullScalePosition"] = g_channelSetting[i].xFullScalePosition.toDouble(); channelObj["xProcessVariableName"] = g_channelSetting[i].xProcessVariableName; channelObj["xZeroScalePosition"] = g_channelSetting[i].xZeroScalePosition.toDouble(); channelObj["zeroScalePosition"] = g_channelSetting[i].zeroScalePosition.toDouble(); channelObj["boardType"] = g_channelSetting[i].boardType; channelObj["defaultDisplay"] = g_channelSetting[i].defaultDisplay; channelObj["sectionNum"] = g_channelSetting[i].sectionNum; channelObj["confidenceDegree"] = g_channelSetting[i].confidenceDegree; channelObj["EngineeringUnit"] = g_channelSetting[i].EngineeringUnit; channelObj["firstPoleNum"] = g_channelSetting[i].firstPoleNum; channelArray.append(channelObj); } QJsonDocument jsonDoc; jsonDoc.setArray(channelArray); #ifdef Q_OS_WIN32 QString name = QCoreApplication::applicationDirPath() + "\\config\\ChannelSettings.json"; #endif #ifdef Q_OS_LINUX QString name = QCoreApplication::applicationDirPath() + "/config/ChannelSettings.json"; #endif QFile file(name); file.open(QIODevice::WriteOnly); file.write(jsonDoc.toJson()); file.close(); QVector().swap(g_channelSetting); QVector().swap(g_ChannelBaseInfo); QMap>().swap(g_MapChannel); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); for (int i = 0; i < g_channelSetting.size(); i++) { QMap mapChannelType; mapChannelType.insert(g_channelSetting[i].sensorType,g_channelSetting[i].channelName); g_MapChannel.insert(g_channelSetting[i].channelId,mapChannelType); channelBaseInfo tempchannelbaseinfo; tempchannelbaseinfo.bordNo = g_channelSetting[i].sensorModuleNo; tempchannelbaseinfo.channelID = g_channelSetting[i].channelId; tempchannelbaseinfo.channelNoInBoard = g_channelSetting[i].sensorNo; tempchannelbaseinfo.channelName = g_channelSetting[i].channelName; tempchannelbaseinfo.channelType = g_channelSetting[i].sensorType; tempchannelbaseinfo.sensorEngineeringUnit = g_channelSetting[i].sensorEngineeringUnit; tempchannelbaseinfo.defaultDisplay = g_channelSetting[i].defaultDisplay; tempchannelbaseinfo.speedRefChannelId = g_channelSetting[i].speedRefChannelId; tempchannelbaseinfo.boardType = g_channelSetting[i].boardType; tempchannelbaseinfo.isEnable = g_channelSetting[i].isEnable; tempchannelbaseinfo.ChUnitDot = g_channelSetting[i].ChUnitDot; g_ChannelBaseInfo.append(tempchannelbaseinfo); } initReadConfig(); #if QT_NO_DEBUG QString str = QString("ftp://%1/CIDW/qtconfig/%2").arg(IP).arg("ChannelSettings.json"); g_FtpClient->SetServerInfo(str); g_FtpClient->SetUserInfo("root","@#cidw!@123456"); g_FtpClient->UpLoadFile(name,"ChannelSettings.json"); #endif } void CChannelList::slotRowDoubleClicked(const QModelIndex &index) { if (index.isValid()) { m_nCurRow = ui->tableView->currentIndex().row();//选中行 QAbstractItemModel *modessl = ui->tableView->model(); QModelIndex indextemp = modessl->index(m_nCurRow,1);//遍历第一行的所有列 QModelIndex indexCheck = modessl->index(m_nCurRow,0); QVariant datatemp = modessl->data(indextemp); qDebug() << datatemp << m_nCurRow << endl; qDebug() << g_channelSetting[m_nCurRow].channelId << endl; qDebug() << g_channelSetting[m_nCurRow].boardType << endl; bool check = model->data(indexCheck, Qt::UserRole).toBool(); qDebug() << check << endl; for (int i = 0; i < g_channelSetting.size(); i++) { if(g_channelSetting[m_nCurRow].boardType.toInt() == 1 && g_channelSetting[i].channelId == g_channelSetting[m_nCurRow].channelId){//开入开出板卡 SlowSpeeddialog = new CSlowSpeedChannelSetting(); connect(SlowSpeeddialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting))); SlowSpeeddialog->channelSetting = g_channelSetting[i]; SlowSpeeddialog->setWindowModality(Qt::ApplicationModal); SlowSpeeddialog->displayChannelSetting(); SlowSpeeddialog->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){//高速板卡 qDebug() << g_channelSetting[m_nCurRow].boardType << g_channelSetting[i].channelId << g_channelSetting[m_nCurRow].channelId<< endl; ChannelSettingdialog = new CChannelSetting(); connect(ChannelSettingdialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting))); connect(ChannelSettingdialog, SIGNAL(ChannelSettingClose_sg()), this, SLOT(slotChannelSettingClose())); ChannelSettingdialog->channelSetting = g_channelSetting[i]; ChannelSettingdialog->setWindowModality(Qt::ApplicationModal); ChannelSettingdialog->displayChannelSetting(); ChannelSettingdialog->show(); }else if((g_channelSetting[m_nCurRow].boardType.toInt() == 5) && g_channelSetting[i].channelId == g_channelSetting[m_nCurRow].channelId){//低速板卡 SlowSpeeddialog = new CSlowSpeedChannelSetting(); connect(SlowSpeeddialog, SIGNAL(sgSetChannelData(ChannelSetting)), this, SLOT(slotSetChannelData(ChannelSetting))); SlowSpeeddialog->channelSetting = g_channelSetting[i]; SlowSpeeddialog->setWindowModality(Qt::ApplicationModal); SlowSpeeddialog->displayChannelSetting(); SlowSpeeddialog->show(); }else if(g_channelSetting[m_nCurRow].boardType.toInt() == 6 && g_channelSetting[i].channelId == g_channelSetting[m_nCurRow].channelId){//开入开出板卡 QString strTips = "输入开入开出板卡通道名称"; bool ok; QString channleName = QInputDialog::getText(this, tr("输入名称对话框"), strTips, QLineEdit::Normal,"",&ok); if(!ok) return; qDebug() << channleName << endl; QString strUpdateSql = QString(" set channelName = '%1' where sensorModuleNo = %2 and sensorNo = %3 ")\ .arg(channleName).arg(g_channelSetting[m_nCurRow].sensorModuleNo).arg(g_channelSetting[m_nCurRow].sensorNo); QString tableName = "t_ChannelSetting "; g_SqliteDB->UpdateDataSql(tableName,strUpdateSql); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); putJson(); } } } } void CChannelList::setColumnCheckable(int column, bool checkable) { m_pHeaderView->setColumnCheckable(column, checkable); for(int row = 0; row != m_pModel->rowCount(); ++row) { m_pModel->item(row, column)->setCheckable(checkable); } } void CChannelList::on_columnSectionClicked(int column, bool checked) { //遍历行 for(int row = 0; row != m_pModel->rowCount(); ++row) { //获取指定列当前行的item,根据checked设置选中状态 if(checked) { m_pModel->item(row, column)->setCheckState(Qt::Checked); } else { m_pModel->item(row, column)->setCheckState(Qt::Unchecked); } } } void CChannelList::on_pushButton_open_clicked() { if(ui->comboBox_operate->currentText() == "通道"){ for (int i = 0; i < model->rowCount(); i++) { QModelIndex indexCheck = model->index(i,0); bool check = model->data(indexCheck, Qt::UserRole).toBool(); if(check){ // QLabel *pLabel = new QLabel(this); // pLabel->setText("启用"); // QPalette palette; // palette.setColor(QPalette::Background, QColor(Qt::green)); // //palette.setColor(QPalette::WindowText,Qt::white); // //pLabel->setAutoFillBackground(true); // pLabel->setPalette(palette); // ui->tableView->setIndexWidget(model->index(i,4),pLabel); //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 , 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"); } } putJson(); }else if(ui->comboBox_operate->currentText() == "带通滤波") { QJsonArray channleList; for (int i = 0; i < model->rowCount(); i++) { QModelIndex indexCheck = model->index(i,0); bool check = model->data(indexCheck, Qt::UserRole).toBool(); if(check){ model->setItem(i,3,new QStandardItem("启用")); QString strChannelID = model->data(model->index(i,38)).toString(); QString strUpdateSql = QString(" set filterStatus = %1 where channelId = '%2' ").arg(1).arg(g_channelSetting[i].channelId); QString tableName = "t_ChannelSetting "; g_SqliteDB->UpdateDataSql(tableName,strUpdateSql); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); channleList.append(g_channelSetting[i].channelId); } } operateChannelFilter(true,channleList); } } void CChannelList::on_pushButton_close_clicked() { if(ui->comboBox_operate->currentText() == "通道"){ for (int i = 0; i < model->rowCount(); i++) { QModelIndex indexCheck = model->index(i,0); bool check = model->data(indexCheck, Qt::UserRole).toBool(); if(check){ model->setItem(i,4,new QStandardItem("关闭")); QString strChannelID = model->data(model->index(i,39)).toString(); QString strUpdateSql = QString(" set isEnable = %1, isWork = %2 where channelId = '%3' ").arg(0).arg(0).arg(g_channelSetting[i].channelId); QString tableName = "t_ChannelSetting "; g_SqliteDB->UpdateDataSql(tableName,strUpdateSql); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); } } putJson(); }else if(ui->comboBox_operate->currentText() == "带通滤波"){ QJsonArray channleList; for (int i = 0; i < model->rowCount(); i++) { QModelIndex indexCheck = model->index(i,0); bool check = model->data(indexCheck, Qt::UserRole).toBool(); if(check){ model->setItem(i,3,new QStandardItem("关闭")); QString strChannelID = model->data(model->index(i,38)).toString(); QString strUpdateSql = QString(" set filterStatus = %1 where channelId = '%2' ").arg(0).arg(g_channelSetting[i].channelId); QString tableName = "t_ChannelSetting "; g_SqliteDB->UpdateDataSql(tableName,strUpdateSql); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); channleList.append(g_channelSetting[i].channelId); } } operateChannelFilter(false,channleList); } } void CChannelList::on_pushButton_refresh_clicked() { model->removeRows(0, model->rowCount()); g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting"); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); #ifndef NO_FILTER QJsonObject sendData; sendData["cmd"] = "97"; QJsonArray chan_list; for (int i = 0; i < g_channelSetting.size(); i++) { chan_list.append(g_channelSetting[i].channelId); } sendData["chan_list"] = chan_list; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); #else initReadConfig(); #endif #ifdef QT_DEBUG initReadConfig(); #endif } void CChannelList::slotNetMgr(QString sAddr, const QVariant &msg) { QJsonObject objec = msg.value(); if(objec.contains("cmd")) { QJsonValue arrays_value = objec.take("cmd"); //qDebug()<<"cmd ="<PostJson(req,allObj); } } void CChannelList::operateChannelFilter(bool type,QJsonArray& channleList) { connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); QJsonObject sendData; sendData["cmd"] = "96"; sendData["open"] = type; sendData["chan_list"] = channleList; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); }