refactor: 去掉多余的显示点数控件,来一个点画一个点,自动滚动
- 移除SpinBox和onDisplayPointsChanged - 内部滚动窗口固定3000个点,数据无限追加 - 收到UDP包立即刷新绘图
This commit is contained in:
@@ -79,29 +79,12 @@ void MainWindow::setupUi()
|
|||||||
);
|
);
|
||||||
connect(m_clearBtn, &QPushButton::clicked, this, &MainWindow::onClear);
|
connect(m_clearBtn, &QPushButton::clicked, this, &MainWindow::onClear);
|
||||||
|
|
||||||
QLabel *displayLabel = new QLabel("显示点数:");
|
|
||||||
displayLabel->setStyleSheet("color: #ccc; font-size: 13px;");
|
|
||||||
|
|
||||||
m_displaySpinBox = new QSpinBox();
|
|
||||||
m_displaySpinBox->setRange(50, 10000);
|
|
||||||
m_displaySpinBox->setValue(500);
|
|
||||||
m_displaySpinBox->setSingleStep(100);
|
|
||||||
m_displaySpinBox->setStyleSheet(
|
|
||||||
"QSpinBox { background: #2a2a3e; color: #fff; border: 1px solid #555; "
|
|
||||||
"border-radius: 4px; padding: 4px; font-size: 13px; }"
|
|
||||||
);
|
|
||||||
connect(m_displaySpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
||||||
this, &MainWindow::onDisplayPointsChanged);
|
|
||||||
|
|
||||||
controlLayout->addWidget(portLabel);
|
controlLayout->addWidget(portLabel);
|
||||||
controlLayout->addWidget(m_portEdit);
|
controlLayout->addWidget(m_portEdit);
|
||||||
controlLayout->addWidget(m_startStopBtn);
|
controlLayout->addWidget(m_startStopBtn);
|
||||||
controlLayout->addSpacing(20);
|
controlLayout->addSpacing(20);
|
||||||
controlLayout->addWidget(m_openFileBtn);
|
controlLayout->addWidget(m_openFileBtn);
|
||||||
controlLayout->addWidget(m_clearBtn);
|
controlLayout->addWidget(m_clearBtn);
|
||||||
controlLayout->addSpacing(20);
|
|
||||||
controlLayout->addWidget(displayLabel);
|
|
||||||
controlLayout->addWidget(m_displaySpinBox);
|
|
||||||
controlLayout->addStretch();
|
controlLayout->addStretch();
|
||||||
|
|
||||||
mainLayout->addLayout(controlLayout);
|
mainLayout->addLayout(controlLayout);
|
||||||
@@ -321,11 +304,6 @@ void MainWindow::processDataLine(const QString &line)
|
|||||||
m_packetLabel->setText(QString("收到: %1 包").arg(m_packetCount));
|
m_packetLabel->setText(QString("收到: %1 包").arg(m_packetCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onDisplayPointsChanged(int count)
|
|
||||||
{
|
|
||||||
m_plotWidget->setDisplayPointCount(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onToggleChannel(int channel, bool visible)
|
void MainWindow::onToggleChannel(int channel, bool visible)
|
||||||
{
|
{
|
||||||
m_plotWidget->setChannelVisible(channel, visible);
|
m_plotWidget->setChannelVisible(channel, visible);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QSpinBox>
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
@@ -31,7 +30,6 @@ private slots:
|
|||||||
void onOpenFile();
|
void onOpenFile();
|
||||||
void onClear();
|
void onClear();
|
||||||
void onDataReceived(const QByteArray &data);
|
void onDataReceived(const QByteArray &data);
|
||||||
void onDisplayPointsChanged(int count);
|
|
||||||
void onToggleChannel(int channel, bool visible);
|
void onToggleChannel(int channel, bool visible);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -48,7 +46,6 @@ private:
|
|||||||
QPushButton *m_clearBtn;
|
QPushButton *m_clearBtn;
|
||||||
QLabel *m_statusLabel;
|
QLabel *m_statusLabel;
|
||||||
QLabel *m_packetLabel;
|
QLabel *m_packetLabel;
|
||||||
QSpinBox *m_displaySpinBox;
|
|
||||||
PlotWidget *m_plotWidget;
|
PlotWidget *m_plotWidget;
|
||||||
|
|
||||||
// 功能组件
|
// 功能组件
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
PlotWidget::PlotWidget(QWidget *parent)
|
PlotWidget::PlotWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_totalPoints(0)
|
, m_totalPoints(0)
|
||||||
, m_displayPoints(500)
|
, m_displayPoints(3000)
|
||||||
, m_yMin(0)
|
, m_yMin(0)
|
||||||
, m_yMax(65535)
|
, m_yMax(65535)
|
||||||
, m_autoYRange(true)
|
, m_autoYRange(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user