将每种材料的参数设置保存为json,并将整个json语句放到数据库中,同时显示到列表中。
选中某行时,将参数反馈到控件上
源码
Material.h
#pragma once
#include "QtWindow.h"
#include "ui_Widget.h"
#include <QWidget>
#include <QObject>
#include <QDialog>
//防止中文乱码
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")// 该指令仅支持VS环境
#endif
class Material :
public QtWindow
{
public:
Material(QtWindow* parent,
QtWindowId id,
const QtPoint& pos = qtDefaultPos,
const QtSize& size = qtDefaultSize);
public:
void InitNewList();
void InitNewControl();
void SetControlStyle();
QtBox* __mainbox;
QtBox* __Topbox;
QtBox* __Belowbox;
void InitParaTable();
void InitTableWidget();
void InitCheck();
void ShowData();
void ShowDataNew();
void ClearLineEdit();
int selectRow;//tablewidget点击所在行
QWidget* w;
Ui::Widget ui;
void InitMap();
QMap<int, QString>mp;
QStringList GetName();
void SetFalseCheckBox();
QByteArray ReturnPara(QString strName);
QString ReturnParaNew(QString strName);
private slots:
void on_pushButton_add_clicked();
void on_pushButton_dele_clicked();
void on_pushButton_modify_clicked();
void on_pushButton_send_clicked();
void feedback(int row, int column);
};
std::list<QtString> GetMaterialName();
void OpenMaterial();
Material.cpp
#include "Material.h"
#include "QtBox.h"
#include "QtTool.h"
#include "Res.h"
#include "QtEdit.h"
#include "QtBlock.h"
#include "QtGroup.h"
#include "QtBound.h"
#include "QtCombo.h"
#include "QtMsgBox.h"
#include <SvWindow.h>
#include "qdebug.h"
#include "..\include\QtSql\QSqlDatabase"
#include"..\include\QtSql\QSqlError"
#include"..\include\QtSql\QSqlQuery"
#include"..\include\QtSql\QSqlRecord"
#include <SysParam_Basic.h>
#define SQL_QUERY_DATA "Select * from machpara"//查询sql语句
#define CLEAR_BIT(x, bit) (x &= ~(1 << bit)) /* 清零第bit位 */
#define SET_BIT(x, bit) (x |= (1 << bit)) /* 置位第bit位 */
#include <iostream>
#include <fstream>
#include<QFile>
#include<QJsonArray>
#include<QJsonObject>
#include<QJsonDocument>
#include<QMap>
Material::Material(QtWindow* parent, QtWindowId id, const QtPoint& pos, const QtSize& size)
: QtWindow(parent, id, pos, size)
{
/* setFillColor(0x9e9e9e);
setLineInvalid();*/
/* InitNewList();
InitNewControl();
__mainbox= qtMakeVBox(QtMargin{ 2,12,12,12 }, __Topbox, 12, __Belowbox, 2);
setLayout(__mainbox);*/
w = new QWidget();
ui.setupUi(w);
w->show();
SetControlStyle();
InitMap();
InitTableWidget();
InitCheck();
ShowDataNew();
selectRow = -1;
connect(ui.pushButton_add, &QPushButton::clicked, this, &Material::on_pushButton_add_clicked);
connect(ui.pushButton_dele, &QPushButton::clicked, this, &Material::on_pushButton_dele_clicked);
connect(ui.pushButto_modify, &QPushButton::clicked, this, &Material::on_pushButton_modify_clicked);
connect(ui.pushButton_send, &QPushButton::clicked, this, &Material::on_pushButton_send_clicked);
// 返回鼠标单击所在的row和col
connect(ui.tableWidget_MaterialLibrary, &QTableWidget::cellClicked, this, &Material::feedback);
//2023.7.31 关联Groupbox和控件状态
connect(ui.groupBox, &QGroupBox::clicked, [&](bool _flag) {
ui.checkBox1->setChecked(_flag);
ui.checkBox2->setChecked(_flag);
ui.checkBox3->setChecked(_flag);
});
connect(ui.groupBox_2, &QGroupBox::clicked, [&](bool _flag) {
ui.checkBox4->setChecked(_flag);
ui.checkBox5->setChecked(_flag);
ui.checkBox6->setChecked(_flag);
ui.checkBox7->setChecked(_flag);
ui.checkBox8->setChecked(_flag);
ui.checkBox9->setChecked(_flag);
ui.checkBox10->setChecked(_flag);
ui.checkBox11->setChecked(_flag);
ui.checkBox12->setChecked(_flag);
ui.checkBox13->setChecked(_flag);
ui.checkBox_2->setChecked(_flag);
});
connect(ui.groupBox_3, &QGroupBox::clicked, [&](bool _flag) {
ui.checkBox14->setChecked(_flag);
ui.checkBox15->setChecked(_flag);
ui.checkBox16->setChecked(_flag);
ui.checkBox17->setChecked(_flag);
});
ReturnParaNew("材料1");
}
void Material::InitNewList()
{
QtLabel* __no = new QtButton(this, qtAnyId, L"序号", qtDefaultPos, QtSize(41, 64));
QtLabel* __name = new QtButton(this, qtAnyId, L"材料名称", qtDefaultPos, QtSize(qtDefaultCoord, 64));
QtLabel* __width = new QtButton(this, qtAnyId, L"向心加速度", qtDefaultPos, QtSize(75, 64));
QtLabel* __length = new QtButton(this, qtAnyId, L"旋转加速度", qtDefaultPos, QtSize(75, 64));
QtLabel* __userate = new QtButton(this, qtAnyId, L"最大旋转速度", qtDefaultPos, QtSize(78, 64));
QtLabel* __sampnum = new QtButton(this, qtAnyId, L"抬刀振动频率", qtDefaultPos, QtSize(78, 64));
QtLabel* __perimeter = new QtButton(this, qtAnyId, L"裁刀最小振动频率", qtDefaultPos, QtSize(90, 64));
QtLabel* __notchnum = new QtButton(this, qtAnyId, L"裁刀最大振动频率", qtDefaultPos, QtSize(90, 64));
QtLabel* __punchnum = new QtButton(this, qtAnyId, L"运动速度", qtDefaultPos, QtSize(55, 64));
QtLabel* __state = new QtButton(this, qtAnyId, L"运动加速度", qtDefaultPos, QtSize(75, 64));
QtLabel* __endtime = new QtButton(this, qtAnyId, L"压盘压力", qtDefaultPos, QtSize(55, 64));
QtLabel* __usetime = new QtButton(this, qtAnyId, L"压盘抬落压力", qtDefaultPos, QtSize(78, 64));
QtLabel* __stoptimes = new QtButton(this, qtAnyId, L"真空压", qtDefaultPos, QtSize(50, 64));
QtLabel* __stoptime = new QtButton(this, qtAnyId, L"保持真空压", qtDefaultPos, QtSize(75, 64));
QtLabel* __tdjd = new QtButton(this, qtAnyId, L"抬刀角度", qtDefaultPos, QtSize(55, 64));
QtLabel* __lfxt = new QtButton(this, qtAnyId, L"冷风系统", qtDefaultPos, QtSize(55, 64));
QtLabel* __firstpress = new QtButton(this, qtAnyId, L"第一面磨刀压力", qtDefaultPos, QtSize(90, 64));
QtLabel* __firsttime = new QtButton(this, qtAnyId, L"第一面磨刀时间", qtDefaultPos, QtSize(90, 64));
QtLabel* __secondpree = new QtButton(this, qtAnyId, L"第二面磨刀压力", qtDefaultPos, QtSize(90, 64));
QtLabel* __secondtime = new QtButton(this, qtAnyId, L"第二面磨刀时间", qtDefaultPos, QtSize(90, 64));
QtLabel* __sdchange = new QtButton(this, qtAnyId, L"砂带选择", qtDefaultPos, QtSize(90, 64));
QtBox* __boxNo = qtMakeDefaultVBox(__no);
QtBox* __boxName = qtMakeDefaultVBox(__name);
QtBox* __boxWidth = qtMakeDefaultVBox(__width);
QtBox* __boxLength = qtMakeDefaultVBox(__length);
QtBox* __boxUseRate = qtMakeDefaultVBox(__userate);
QtBox* __boxSampNum = qtMakeDefaultVBox(__sampnum);
QtBox* __boxPerimeter = qtMakeDefaultVBox(__perimeter);
QtBox* __boxNotchNum = qtMakeDefaultVBox(__notchnum);
QtBox* __boxPunchNum = qtMakeDefaultVBox(__punchnum);
QtBox* __boxState = qtMakeDefaultVBox(__state);
QtBox* __boxEndTime = qtMakeDefaultVBox(__endtime);
QtBox* __boxUseTime = qtMakeDefaultVBox(__usetime);
QtBox* __boxStopTimes = qtMakeDefaultVBox(__stoptimes);
QtBox* __boxStopTime = qtMakeDefaultVBox(__stoptime);
QtBox* __box1 = qtMakeDefaultVBox(__tdjd);
QtBox* __box2 = qtMakeDefaultVBox(__lfxt);
QtBox* __box3 = qtMakeDefaultVBox(__firstpress);
QtBox* __box4 = qtMakeDefaultVBox(__firsttime);
QtBox* __box5 = qtMakeDefaultVBox(__secondpree);
QtBox* __box6 = qtMakeDefaultVBox(__secondtime);
QtBox* __box7 = qtMakeDefaultVBox(__sdchange);
std::vector< QtLabel*> __labellist;
__labellist.push_back(__no);
__labellist.push_back(__name);
__labellist.push_back(__width);
__labellist.push_back(__length);
__labellist.push_back(__userate);
__labellist.push_back(__sampnum);
__labellist.push_back(__perimeter);
__labellist.push_back(__notchnum);
__labellist.push_back(__punchnum);
__labellist.push_back(__state);
__labellist.push_back(__endtime);
__labellist.push_back(__usetime);
__labellist.push_back(__stoptimes);
__labellist.push_back(__stoptime);
__labellist.push_back(__tdjd);
__labellist.push_back(__lfxt);
__labellist.push_back(__firstpress);
__labellist.push_back(__firsttime);
__labellist.push_back(__secondpree);
__labellist.push_back(__secondtime);
__labellist.push_back(__sdchange);
for (auto __x : __labellist)
{
__x->setFillColor(0xbfbfbf);
__x->setLineColor(0xd9d9d9);
}
__boxNo->addStretch(1);
__boxName->addStretch(1);
__boxWidth->addStretch(1);
__boxLength->addStretch(1);
__boxUseRate->addStretch(1);
__boxSampNum->addStretch(1);
__boxPerimeter->addStretch(1);
__boxNotchNum->addStretch(1);
__boxPunchNum->addStretch(1);
__boxState->addStretch(1);
__boxEndTime->