添加平均值计算功能

master
zcy 2024-01-15 18:04:07 +08:00
parent 4c0784d6ba
commit 85fe60b81f
6 changed files with 355 additions and 26 deletions

View File

@ -16,6 +16,8 @@ extern "C"{
# pragma execution_character_set("utf-8") # pragma execution_character_set("utf-8")
#endif #endif
extern float gOffset[20];
typedef struct { typedef struct {
@ -86,7 +88,10 @@ public:
float x = 0; float x = 0;
while(mRuning){ while(mRuning){
int count = 0; int count = 0;
if(mPause){
QThread::msleep(10);
continue;
}
for(int it = 0;it < mConf.size();it++) { for(int it = 0;it < mConf.size();it++) {
auto itr = mConf.at(it); auto itr = mConf.at(it);
@ -121,6 +126,56 @@ public:
for(int i =0;i < resp_length;i++){ for(int i =0;i < resp_length;i++){
log += QString::asprintf("0x%02x ",rsp[i]); log += QString::asprintf("0x%02x ",rsp[i]);
} }
log += "\r\n流速: ";
float tmp = 0;
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[0]*1000;
if((tmp > 0)&&(float(tmp<= 200))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[0]*1000;
}else if((tmp > 200)&&((tmp<= 400))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[1]*1000;
}else if((tmp > 400)&&((tmp<= 600))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[2]*1000;
}else if((tmp > 600)&&((tmp<= 800))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[3]*1000;
}else if((tmp > 800)&&((tmp<= 1000))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[4]*1000;
}else if((tmp > 1000)&&((tmp<= 1200))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[5]*1000;
}else if((tmp > 1200)&&((tmp<= 1400))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[6]*1000;
}else if((tmp > 1400)&&((tmp<= 1600))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[7]*1000;
}else if((tmp > 1600)&&((tmp<= 1800))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[8]*1000;
}else if((tmp > 1800)&&((tmp<= 2000))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[9]*1000;
}else if((tmp > 2000)&&((tmp<= 2200))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[10]*1000;
}else if((tmp > 2200)&&((tmp<= 2400))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[11]*1000;
}else if((tmp > 2400)&&((tmp<= 2600))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[12]*1000;
}else if((tmp > 2600)&&((tmp<= 2800))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[13]*1000;
}else if((tmp > 2800)&&((tmp<= 3000))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[14]*1000;
}else if((tmp > 3000)&&((tmp<= 3400))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[15]*1000;
}else if((tmp > 3400)&&((tmp<= 3800))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[16]*1000;
}else if((tmp > 3800)&&((tmp<= 4200))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[17]*1000;
}else if((tmp > 4200)&&((tmp<= 4600))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[18]*1000;
}else if((tmp > 4600)&&((tmp<= 5000))){
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[20]*1000;
}else{
tmp = float(rsp[3]*256 + rsp[4]) + gOffset[0]*1000;
}
log += QString::asprintf("%.2f\r\n",tmp);
if(ret < 0){ if(ret < 0){
log += "超时"; log += "超时";
} }
@ -156,7 +211,7 @@ public:
mMux.unlock(); mMux.unlock();
} }
} }
qDebug()<<"keep alive"; // qDebug()<<"keep alive";
QThread::msleep(100); QThread::msleep(100);
} }

View File

@ -35,7 +35,6 @@ MainWindow::MainWindow(QWidget *parent)
ui->comboBox->addItem("57600"); ui->comboBox->addItem("57600");
ui->comboBox->addItem("115200"); ui->comboBox->addItem("115200");
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

25
sub.ui
View File

@ -83,6 +83,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>计算</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_6">
<property name="text">
<string>清除</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
@ -99,7 +113,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1,0,5">
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
@ -126,10 +140,17 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>数值:</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="7,4">
<item> <item>
<widget class="QChartView" name="graphicsView"/> <widget class="QChartView" name="graphicsView"/>
</item> </item>

View File

@ -14,6 +14,7 @@
# pragma execution_character_set("utf-8") # pragma execution_character_set("utf-8")
#endif #endif
float gOffset[20];
SubForm::SubForm(QString addr,int baurate,int device_addr,int rate) SubForm::SubForm(QString addr,int baurate,int device_addr,int rate)
:ui(new Ui::Form) { :ui(new Ui::Form) {
@ -46,18 +47,110 @@ SubForm::SubForm(QString addr,int baurate,int device_addr,int rate)
if(this->mLines.find(z->addr) != mLines.end()){ if(this->mLines.find(z->addr) != mLines.end()){
static int i = 0; static int i = 0;
qDebug()<< mLines[z->addr]->count()<<"fsdf"; qDebug()<< mLines[z->addr]->count()<<"fsdf";
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0])); if(fabs(float(z->val1[0])) < 10000) {
mCapMax++; 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{ }else{
mLines[z->addr] = new QLineSeries; mLines[z->addr] = new QLineSeries;
mChart->addSeries(mLines[z->addr]); // mChart->addSeries(mLines[z->addr]); //
mLines[z->addr]->attachAxis(mAxisX); // mLines[z->addr]->attachAxis(mAxisX); //
mLines[z->addr]->attachAxis(mAxisY); mLines[z->addr]->attachAxis(mAxisY);
mLines[z->addr]->append( (mCapMax + 1),float(z->val1[0])); 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)); mLines[z->addr]->setName(QString::asprintf("%d",z->addr));
mCapMax++;
} }
// mSeries1->append(sd,z->val1); // mSeries1->append(sd,z->val1);
pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss")); pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
@ -105,15 +198,58 @@ SubForm::SubForm(QString addr,int baurate,int device_addr,int rate)
}else{ }else{
mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole); mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole);
if(succ) if(succ){
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0]),Qt::DisplayRole); 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 else
mModel->item(found->row(),1)->setData(QString("³¬Ê±"),Qt::DisplayRole); mModel->item(found->row(),1)->setData(QString("³¬Ê±"),Qt::DisplayRole);
mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole); mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole);
} }
sd ++; sd ++;
if(sd > mMaxX){ if(sd > mMaxX){
mMaxX += 1024; mMaxX += 1024;
@ -121,13 +257,43 @@ SubForm::SubForm(QString addr,int baurate,int device_addr,int rate)
} }
delete z; delete z;
} }
}); });
pTimer->start(10); pTimer->start(10);
qDebug()<<QDateTime::currentDateTime().toString(); qDebug()<<QDateTime::currentDateTime().toString();
ui->lineEdit_2->setText(addr); ui->lineEdit_2->setText(addr);
gAsyncData->AddConfig(this->mConfig); gAsyncData->AddConfig(this->mConfig);
ui->tableView->setColumnWidth(2,230); ui->tableView->setColumnWidth(2,230);
connect(gAsyncData,SIGNAL(Info(QString)),this,SLOT( on_log(QString))); 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() { void SubForm::on_pushButton_clicked() {
@ -183,9 +349,9 @@ void SubForm::init_charts()
mChart->addSeries(mSeries1); // mChart->addSeries(mSeries1); //
mAxisX->setMin(0); //YΧ mAxisX->setMin(0); //YΧ
mAxisX->setMax(1024); mAxisX->setMax(256);
mMaxX = 1024; mMaxX = 256;
mAxisX->setTickCount(17); mAxisX->setTickCount(8);
mAxisX->setLabelFormat("%d"); mAxisX->setLabelFormat("%d");
mAxisX->setTitleText("point"); //X mAxisX->setTitleText("point"); //X
mAxisX->setLineVisible(true); mAxisX->setLineVisible(true);
@ -198,7 +364,7 @@ void SubForm::init_charts()
mAxisY->setMin(-10); //YΧ mAxisY->setMin(-10); //YΧ
mAxisY->setMax(100); mAxisY->setMax(100);
mAxisY->setTickCount(11); mAxisY->setTickCount(6);
mAxisY->setLabelFormat("%d"); mAxisY->setLabelFormat("%d");
mAxisY->setLinePenColor(QColor(Qt::yellow)); // mAxisY->setLinePenColor(QColor(Qt::yellow)); //
mAxisY->setGridLineColor(QColor(Qt::yellow)); mAxisY->setGridLineColor(QColor(Qt::yellow));
@ -226,13 +392,21 @@ void SubForm::init_charts()
mChart->setMargins(QMargins(0,0,0,0)); mChart->setMargins(QMargins(0,0,0,0));
ui->graphicsView->setChart(mChart); 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->setRenderHint(QPainter::TextAntialiasing); //
ui->graphicsView->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern)); ui->graphicsView->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern));
ui->graphicsView->scene()->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern)); ui->graphicsView->scene()->setBackgroundBrush(QBrush(QColor(Qt::black),Qt::SolidPattern));
ui->graphicsView->setRubberBand(QChartView::VerticalRubberBand); ui->graphicsView->setRubberBand(QChartView::RectangleRubberBand);
mChart->legend()->setAlignment(Qt::AlignBottom);// mChart->legend()->setAlignment(Qt::AlignBottom);//
mChart->legend()->setContentsMargins(10,10,10,10);//left,top,right,bottom mChart->legend()->setContentsMargins(0,0,0,0);//left,top,right,bottom
mChart->legend()->setVisible(true);// mChart->legend()->setVisible(true);//
QFont font = mChart->legend()->font(); QFont font = mChart->legend()->font();
font.setItalic(!font.italic()); font.setItalic(!font.italic());
@ -240,6 +414,36 @@ void SubForm::init_charts()
font.setPointSizeF(12); font.setPointSizeF(12);
mChart->legend()->setFont(font);//С mChart->legend()->setFont(font);//С
mChart->legend()->setLabelColor(Qt::white); // 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;
}
});
} }
@ -255,9 +459,9 @@ void SubForm::on_pushButton_2_clicked() {
} }
} }
mConfig->req.append(Req{ mConfig->req.append(Req{
ui->lineEdit->text().toUShort(), ui->lineEdit->text().toUShort(),
ui->lineEdit_3->text().toUShort(), ui->lineEdit_3->text().toUShort(),
}); });
} }
void SubForm::on_log(QString info) void SubForm::on_log(QString info)
@ -275,6 +479,41 @@ void SubForm::on_pushButton_3_clicked()
void SubForm::on_pushButton_4_clicked() void SubForm::on_pushButton_4_clicked()
{ {
gAsyncData->Continue(); 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;
} }

View File

@ -13,15 +13,19 @@
#include "global.h" #include "global.h"
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QStandardItem> #include <QStandardItem>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QAreaSeries>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class Form; } namespace Ui { class Form; }
QT_END_NAMESPACE QT_END_NAMESPACE
using namespace QtCharts;
class SubForm :QWidget
class SubForm :public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -41,6 +45,15 @@ private slots:
void on_pushButton_4_clicked(); void on_pushButton_4_clicked();
void on_pushButton_5_clicked();
void on_pushButton_6_clicked();
public slots:
void rubberZoomAdapt(QPointF fp, QPointF tp);
signals:
void rubberBandChanged(QPointF fp, QPointF tp);
private: private:
Ui::Form *ui; Ui::Form *ui;
QChart *mChart; QChart *mChart;
@ -59,6 +72,8 @@ private:
bool mStart; bool mStart;
QStandardItemModel *mModel; QStandardItemModel *mModel;
int mCapMax = 0; int mCapMax = 0;
QRubberBand *mRubberBand;
}; };

View File

@ -8,7 +8,7 @@ CONFIG += c++11
# In order to do so, uncomment the following line. # In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
include(G:\project\c++qt\qsswraper\qsswraper.pri) include(C:\\Users\\zheng\\Documents\\qsswraper\\qsswraper.pri)
SOURCES += \ SOURCES += \