520 lines
24 KiB
C++
520 lines
24 KiB
C++
#include "subform.h"
|
|
#include <ui_sub.h>
|
|
|
|
#include <QSerialPortInfo>
|
|
#include <QDebug>
|
|
#include <QMutex>
|
|
#include "Qss.h"
|
|
#include "libmodbus/modbus.h"
|
|
#include <math.h>
|
|
#include <QTimer>
|
|
#include <QFileDialog>
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
|
# pragma execution_character_set("utf-8")
|
|
#endif
|
|
|
|
float gOffset[20];
|
|
|
|
SubForm::SubForm(QString addr,int baurate,int device_addr,int rate)
|
|
:ui(new Ui::Form) {
|
|
ui->setupUi(this);
|
|
|
|
init_charts();
|
|
QTimer *pTimer = new QTimer(this);
|
|
QString *com = new QString(addr);
|
|
qDebug()<<*com;
|
|
mModel = new QStandardItemModel(this);
|
|
// mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间"<<"操作");
|
|
ui->tableView->setModel(mModel);
|
|
ui->tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
|
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
mConfig = new Config;
|
|
mConfig->addr = device_addr;
|
|
mConfig->com = *com;
|
|
mConfig->baurate = baurate;
|
|
mConfig->rate = rate;
|
|
|
|
connect(pTimer,&QTimer::timeout,[=]() {
|
|
static float sd = 0;
|
|
if(gAsyncData == nullptr)
|
|
return;
|
|
CapData *z = new CapData;
|
|
|
|
int ret = gAsyncData->TakeLast(device_addr,&z);
|
|
if(ret == 0){
|
|
bool succ = z->succ;
|
|
if(this->mLines.find(z->addr) != mLines.end()){
|
|
static int i = 0;
|
|
qDebug()<< mLines[z->addr]->count()<<"fsdf";
|
|
if(fabs(float(z->val1[0])) < 10000) {
|
|
|
|
if((z->val1[0] > 0)&&(float(z->val1[0]<= 200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[0]*1000));
|
|
}else if((z->val1[0] > 200)&&((z->val1[0]<= 400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[1]*1000));
|
|
}else if((z->val1[0] > 400)&&((z->val1[0]<= 600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[2]*1000));
|
|
}else if((z->val1[0] > 600)&&((z->val1[0]<= 800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[3]*1000));
|
|
}else if((z->val1[0] > 800)&&((z->val1[0]<= 1000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[4]*1000));
|
|
}else if((z->val1[0] > 1000)&&((z->val1[0]<= 1200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[5]*1000));
|
|
}else if((z->val1[0] > 1200)&&((z->val1[0]<= 1400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[6]*1000));
|
|
}else if((z->val1[0] > 1400)&&((z->val1[0]<= 1600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[7]*1000));
|
|
}else if((z->val1[0] > 1600)&&((z->val1[0]<= 1800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[8]*1000));
|
|
}else if((z->val1[0] > 1800)&&((z->val1[0]<= 2000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[9]*1000));
|
|
}else if((z->val1[0] > 2000)&&((z->val1[0]<= 2200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[10]*1000));
|
|
}else if((z->val1[0] > 2200)&&((z->val1[0]<= 2400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[11]*1000));
|
|
}else if((z->val1[0] > 2400)&&((z->val1[0]<= 2600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[12]*1000));
|
|
}else if((z->val1[0] > 2600)&&((z->val1[0]<= 2800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[13]*1000));
|
|
}else if((z->val1[0] > 2800)&&((z->val1[0]<= 3000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[14]*1000));
|
|
}else if((z->val1[0] > 3000)&&((z->val1[0]<= 3400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[15]*1000));
|
|
}else if((z->val1[0] > 3400)&&((z->val1[0]<= 3800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[16]*1000));
|
|
}else if((z->val1[0] > 3800)&&((z->val1[0]<= 4200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[17]*1000));
|
|
}else if((z->val1[0] > 4200)&&((z->val1[0]<= 4600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[18]*1000));
|
|
}else if((z->val1[0] > 4600)&&((z->val1[0]<= 5000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[19]*1000));
|
|
}else{
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0]));
|
|
}
|
|
|
|
mCapMax++;
|
|
}
|
|
|
|
}else{
|
|
mLines[z->addr] = new QLineSeries;
|
|
mChart->addSeries(mLines[z->addr]); //
|
|
mLines[z->addr]->attachAxis(mAxisX); //
|
|
mLines[z->addr]->attachAxis(mAxisY);
|
|
if(fabs(float(z->val1[0])) < 10000){
|
|
if((z->val1[0] > 0)&&(float(z->val1[0]<= 200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[0]*1000));
|
|
}else if((z->val1[0] > 200)&&((z->val1[0]<= 400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[1]*1000));
|
|
}else if((z->val1[0] > 400)&&((z->val1[0]<= 600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[2]*1000));
|
|
}else if((z->val1[0] > 600)&&((z->val1[0]<= 800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[3]*1000));
|
|
}else if((z->val1[0] > 800)&&((z->val1[0]<= 1000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[4]*1000));
|
|
}else if((z->val1[0] > 1000)&&((z->val1[0]<= 1200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[5]*1000));
|
|
}else if((z->val1[0] > 1200)&&((z->val1[0]<= 1400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[6]*1000));
|
|
}else if((z->val1[0] > 1400)&&((z->val1[0]<= 1600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[7]*1000));
|
|
}else if((z->val1[0] > 1600)&&((z->val1[0]<= 1800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[8]*1000));
|
|
}else if((z->val1[0] > 1800)&&((z->val1[0]<= 2000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[9]*1000));
|
|
}else if((z->val1[0] > 2000)&&((z->val1[0]<= 2200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[10]*1000));
|
|
}else if((z->val1[0] > 2200)&&((z->val1[0]<= 2400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[11]*1000));
|
|
}else if((z->val1[0] > 2400)&&((z->val1[0]<= 2600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[12]*1000));
|
|
}else if((z->val1[0] > 2600)&&((z->val1[0]<= 2800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[13]*1000));
|
|
}else if((z->val1[0] > 2800)&&((z->val1[0]<= 3000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[14]*1000));
|
|
}else if((z->val1[0] > 3000)&&((z->val1[0]<= 3400))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[15]*1000));
|
|
}else if((z->val1[0] > 3400)&&((z->val1[0]<= 3800))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[16]*1000));
|
|
}else if((z->val1[0] > 3800)&&((z->val1[0]<= 4200))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[17]*1000));
|
|
}else if((z->val1[0] > 4200)&&((z->val1[0]<= 4600))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[18]*1000));
|
|
}else if((z->val1[0] > 4600)&&((z->val1[0]<= 5000))){
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0] + gOffset[19]*1000));
|
|
}else{
|
|
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0]));
|
|
}
|
|
|
|
|
|
mCapMax++;
|
|
|
|
}
|
|
mLines[z->addr]->setName(QString::asprintf("%d",z->addr));
|
|
}
|
|
// mSeries1->append(sd,z->val1);
|
|
pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
|
|
|
|
QStandardItem *found = nullptr;
|
|
qDebug()<<"mModel->columnCount()"<<mModel->columnCount()
|
|
<<mModel->rowCount();
|
|
int i = 0;
|
|
int j = 0;
|
|
for(;i < mModel->rowCount();i++){
|
|
for(;j < mModel->columnCount();j++){
|
|
if(mModel->item((i,j)) != nullptr){
|
|
qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole);
|
|
if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){
|
|
found = mModel->item((i,j));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(found == 0){
|
|
QStandardItem *item;
|
|
if(succ)
|
|
item = new QStandardItem(QString("%1").arg(z->val1[0]));
|
|
else
|
|
item = new QStandardItem(QString("超时"));
|
|
|
|
mModel->setItem(i, 1, item);
|
|
QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr));
|
|
mModel->setItem(i, 0, item1);
|
|
mModel->setItem(i, 2, new QStandardItem(QString("%1").arg(z->time)));
|
|
QPushButton *button = new QPushButton(this);
|
|
ui->tableView->setIndexWidget(mModel->index(i,3),button);
|
|
button->setText("绘图");
|
|
connect(button,&QPushButton::clicked,[=](){
|
|
qDebug()<<i<<mModel->item(i,0)->data(Qt::DisplayRole).toInt();
|
|
if(this->mLines[mModel->item(i,0)->data(Qt::DisplayRole).toInt()]->isVisible()){
|
|
this->mLines[mModel->item(i,0)->data(Qt::DisplayRole).toInt()]->hide();
|
|
}else{
|
|
this->mLines[mModel->item(i,0)->data(Qt::DisplayRole).toInt()]->show();
|
|
}
|
|
});
|
|
|
|
|
|
}else{
|
|
mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole);
|
|
if(succ){
|
|
if((z->val1[0] > 0)&&(float(z->val1[0]<= 200))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[0]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 200)&&((z->val1[0]<= 400))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[1]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 400)&&((z->val1[0]<= 600))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[2]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 600)&&((z->val1[0]<= 800))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[3]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 800)&&((z->val1[0]<= 1000))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[4]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 1000)&&((z->val1[0]<= 1200))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[5]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 1200)&&((z->val1[0]<= 1400))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[6]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 1400)&&((z->val1[0]<= 1600))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[7]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 1600)&&((z->val1[0]<= 1800))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[8]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 1800)&&((z->val1[0]<= 2000))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[9]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 2000)&&((z->val1[0]<= 2200))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[10]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 2200)&&((z->val1[0]<= 2400))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[11]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 2400)&&((z->val1[0]<= 2600))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[12]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 2600)&&((z->val1[0]<= 2800))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[13]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 2800)&&((z->val1[0]<= 3000))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[14]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 3000)&&((z->val1[0]<= 3400))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[15]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 3400)&&((z->val1[0]<= 3800))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[16]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 3800)&&((z->val1[0]<= 4200))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[17]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 4200)&&((z->val1[0]<= 4600))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[18]*1000),Qt::DisplayRole);
|
|
}else if((z->val1[0] > 4600)&&((z->val1[0]<= 5000))){
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0] + gOffset[19]*1000),Qt::DisplayRole);
|
|
}else{
|
|
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0]),Qt::DisplayRole);
|
|
}
|
|
|
|
}
|
|
else
|
|
mModel->item(found->row(),1)->setData(QString("超时"),Qt::DisplayRole);
|
|
mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole);
|
|
|
|
}
|
|
|
|
sd ++;
|
|
if(sd > mMaxX){
|
|
mMaxX += 1024;
|
|
mAxisX->setMax(mMaxX);
|
|
}
|
|
delete z;
|
|
}
|
|
|
|
});
|
|
pTimer->start(10);
|
|
qDebug()<<QDateTime::currentDateTime().toString();
|
|
ui->lineEdit_2->setText(addr);
|
|
gAsyncData->AddConfig(this->mConfig);
|
|
ui->tableView->setColumnWidth(2,230);
|
|
connect(gAsyncData,SIGNAL(Info(QString)),this,SLOT(on_log(QString)));
|
|
|
|
ui->graphicsView->setRubberBand(QChartView::RectangleRubberBand);
|
|
|
|
|
|
|
|
// connect(this, &MainWindow::rubberBandChanged,this, &MainWindow::rubberZoomAdapt);
|
|
// mRubberBand = this->mChart->findChild<QRubberBand *>();
|
|
// mRubberBand->installEventFilter(this);
|
|
// mRubberBand->installEventFilter(this);
|
|
// connect(this, &SubForm::rubberBandChanged,this, &SubForm::rubberZoomAdapt);
|
|
|
|
// QObject::connect(qobject_cast<QGraphicsView*>(ui->graphicsView),
|
|
// &QGraphicsView::rubberBandChanged,
|
|
// this,
|
|
// &SubForm::rubberZoomAdapt);
|
|
|
|
QFile file("offset.csv");
|
|
bool isopen = file.open(QFile::ReadOnly);
|
|
if(isopen){
|
|
qDebug() << "open txt file is success";
|
|
}
|
|
QString tmp = QString(file.readAll());
|
|
QStringList iat = tmp.split("\r\n");
|
|
qDebug()<<iat.size();
|
|
if(iat.size() > 20){
|
|
for(int i = 0;i < iat.size();i++){
|
|
gOffset[i] = iat.at(i).toFloat();
|
|
}
|
|
}
|
|
}
|
|
|
|
void SubForm::on_pushButton_clicked() {
|
|
auto mGifFile = QFileDialog::getSaveFileName(this, "",
|
|
QString("%1-%2.csv").arg(ui->lineEdit_2->text())
|
|
.arg(QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss")));
|
|
|
|
if(mGifFile != ""){
|
|
//.csv
|
|
QFile file(mGifFile);
|
|
if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
{
|
|
qDebug()<<"Cannot open file for writing";
|
|
return;
|
|
}
|
|
QTextStream out(&file);
|
|
for(auto itr = mLines.begin();itr != mLines.end();itr++){
|
|
out << tr((QString::asprintf("%d",itr.key()) + ",").toStdString().c_str());
|
|
}
|
|
out <<tr("x value ")<<"\n";
|
|
//
|
|
|
|
|
|
for(int i = 0;i < mCapMax;i++){
|
|
for(auto itr = mLines.begin();itr != mLines.end();itr++){
|
|
itr.value()->count();
|
|
if((i + itr.value()->count()) > mCapMax){
|
|
out <<tr(QString::asprintf("%.1f,",
|
|
itr.value()->at(i + itr.value()->count() - mCapMax).y()).toStdString().c_str());
|
|
}else{
|
|
out <<tr("x value,");
|
|
}
|
|
}
|
|
out <<tr(QString::asprintf("%d,",i).toStdString().c_str())<<"\n";
|
|
}
|
|
//
|
|
file.close();
|
|
}
|
|
}
|
|
|
|
|
|
void SubForm::init_charts()
|
|
{
|
|
mChart = new QChart();
|
|
mSeries1 = new QLineSeries;
|
|
|
|
|
|
mAxisX = new QValueAxis();
|
|
mAxisY = new QValueAxis();
|
|
mAxisY2 = new QValueAxis();
|
|
|
|
mChart->legend()->hide(); //
|
|
mChart->addSeries(mSeries1); //
|
|
|
|
mAxisX->setMin(0); //Y围
|
|
mAxisX->setMax(256);
|
|
mMaxX = 256;
|
|
mAxisX->setTickCount(8);
|
|
mAxisX->setLabelFormat("%d");
|
|
mAxisX->setTitleText("point"); //X
|
|
mAxisX->setLineVisible(true);
|
|
mAxisX->setGridLinePen(QPen(Qt::white,0.1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
mAxisX->setLinePen(QPen(Qt::yellow,1,Qt::SolidLine,Qt::FlatCap,Qt::RoundJoin));
|
|
mAxisX->setLabelsFont(QFont("",8,18,false));
|
|
mAxisX->setLabelsBrush(QBrush(QColor(Qt::white),
|
|
Qt::SolidPattern));
|
|
mAxisX->setLabelsColor(QColor(Qt::white));
|
|
|
|
mAxisY->setMin(-10); //Y围
|
|
mAxisY->setMax(100);
|
|
mAxisY->setTickCount(6);
|
|
mAxisY->setLabelFormat("%d");
|
|
mAxisY->setLinePenColor(QColor(Qt::yellow)); //
|
|
mAxisY->setGridLineColor(QColor(Qt::yellow));
|
|
mAxisY->setGridLinePen(QPen(Qt::white,0.1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
mAxisY->setGridLineVisible(true);
|
|
mAxisY->setLinePen(QPen(Qt::yellow,1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
|
|
mAxisY->setLabelsFont(QFont("",8,18,false));
|
|
mAxisY->setLabelsBrush(QBrush(QColor(Qt::white),
|
|
Qt::SolidPattern));
|
|
mAxisY->setLabelsColor(QColor(Qt::white));
|
|
mAxisY->setTitleFont(QFont("",13,20,false));
|
|
mAxisY->setTitleBrush(QBrush(QColor(Qt::white),
|
|
Qt::SolidPattern));
|
|
mAxisY->setTitleText("temperature (掳C)");
|
|
|
|
mChart->addAxis(mAxisX,Qt::AlignBottom); //位mChart械位
|
|
mChart->addAxis(mAxisY,Qt::AlignLeft);
|
|
mChart->addAxis(mAxisY2,Qt::AlignRight);
|
|
|
|
mChart->setBackgroundVisible(false);
|
|
mSeries1->attachAxis(mAxisX); //
|
|
mSeries1->attachAxis(mAxisY);
|
|
|
|
//mChart
|
|
mChart->setMargins(QMargins(0,0,0,0));
|
|
|
|
ui->graphicsView->setChart(mChart);
|
|
|
|
|
|
// ui->graphicsView->setRubberBand(QChartView::HorizontalRubberBand);
|
|
// this->mRubberBand = ui->graphicsView->findChild<QRubberBand *>();
|
|
// this->mRubberBand->installEventFilter(this);
|
|
|
|
// connect(this, &SubForm::rubberBandChanged,this, &SubForm::rubberZoomAdapt);
|
|
|
|
ui->graphicsView->setRenderHint(QPainter::TextAntialiasing); //
|
|
ui->graphicsView->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern));
|
|
ui->graphicsView->scene()->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern));
|
|
ui->graphicsView->setRubberBand(QChartView::RectangleRubberBand);
|
|
|
|
mChart->legend()->setAlignment(Qt::AlignBottom);//
|
|
mChart->legend()->setContentsMargins(0,0,0,0);//left,top,right,bottom
|
|
mChart->legend()->setVisible(true);//
|
|
QFont font = mChart->legend()->font();
|
|
font.setItalic(!font.italic());
|
|
mChart->legend()->setFont(font);//斜
|
|
font.setPointSizeF(12);
|
|
mChart->legend()->setFont(font);//小
|
|
mChart->legend()->setLabelColor(Qt::white); //
|
|
|
|
|
|
|
|
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
|
|
ui->graphicsView->setRubberBand(QChartView::NoRubberBand);
|
|
ui->graphicsView->setDragMode(QChartView::RubberBandDrag);
|
|
|
|
connect(ui->graphicsView,&QChartView::rubberBandChanged,this,[=](QRect viewportRect, QPointF fromScenePoint, QPointF toScenePoint){
|
|
qDebug()<<"rubberBandChanged"<<viewportRect<<fromScenePoint<<toScenePoint;
|
|
if (viewportRect.isNull()) {//结束选择
|
|
// QScatterSeries *series = (QScatterSeries *)chartWidget->chart()->series().first();
|
|
// QVector<QPointF> ver = series->pointsVector();
|
|
// // qDebug() << "ver="<<ver;
|
|
|
|
// for (const QPointF &p:ver) {
|
|
// if (m_viewportRect.contains(chart_to_view_point(p))) {
|
|
// qDebug() << "ver0 x="<<p.x()<<" y="<<p.y();
|
|
// // emit signal_selected("scatter1",p);
|
|
// }
|
|
// }
|
|
|
|
// Debug() << "ver0 x="<<p.x()<<" y="<<p.y();
|
|
// for (int i = 0 ; i < series->points().size();i++){
|
|
// qDebug() << "-------------------------- " << i;
|
|
// }
|
|
}
|
|
else {
|
|
// m_viewportRect = viewportRect;
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
void SubForm::on_pushButton_2_clicked(bool checked) {
|
|
|
|
}
|
|
|
|
|
|
void SubForm::on_pushButton_2_clicked() {
|
|
for(int i = 0;i < mConfig->req.length();i++){
|
|
if(ui->lineEdit->text().toInt() == mConfig->req[i].addr){
|
|
return;
|
|
}
|
|
}
|
|
mConfig->req.append(Req{
|
|
ui->lineEdit->text().toUShort(),
|
|
ui->lineEdit_3->text().toUShort(),
|
|
});
|
|
}
|
|
|
|
void SubForm::on_log(QString info)
|
|
{
|
|
qDebug()<<info;
|
|
ui->textEdit->append(info + "\r\n");
|
|
}
|
|
|
|
|
|
void SubForm::on_pushButton_3_clicked()
|
|
{
|
|
gAsyncData->Pause();
|
|
}
|
|
|
|
|
|
void SubForm::on_pushButton_4_clicked()
|
|
{
|
|
gAsyncData->Continue();
|
|
}
|
|
|
|
void SubForm::rubberZoomAdapt(QPointF fp, QPointF tp)
|
|
{
|
|
qDebug()<<"rubberZoomAdapt"<<fp<<tp;
|
|
}
|
|
|
|
|
|
|
|
void SubForm::on_pushButton_5_clicked()
|
|
{
|
|
int count = 0;
|
|
float sum = 0;
|
|
qDebug()<<"on_pushButton_5_clicked"<<this->mAxisX->max()<<this->mAxisX->min();
|
|
auto itr = this->mLines.begin();
|
|
for(int i = 0;i < itr.value()->count();i++){
|
|
qDebug()<<"on_pushButton_5_clicked"<<i<<":"<<itr.value()->at(i);
|
|
if((i >= mAxisX->min()) && (i <= mAxisX->max())){
|
|
sum += itr.value()->at(i).y();
|
|
count++;
|
|
}
|
|
}
|
|
qDebug()<<"on_pushButton_5_clicked count"<<sum<<count;
|
|
|
|
ui->label_7->setText(QString::asprintf("测试值:%f",sum/float(count)));
|
|
}
|
|
|
|
void SubForm::on_pushButton_6_clicked()
|
|
{
|
|
for(auto itr = this->mLines.begin();itr != this->mLines.end();itr++){
|
|
itr.value()->removePoints(0,itr.value()->points().size());
|
|
itr.value()->clear();
|
|
}
|
|
this->mCapMax = 0;
|
|
|
|
}
|
|
|