Merge pull request #2181 from wh201906/data_slider

Add a slider in the plot window for navigation
This commit is contained in:
Iceman 2023-11-17 04:23:09 +01:00 committed by GitHub
commit bfb42ec8b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 4 deletions

View file

@ -44,7 +44,7 @@ void ExitGraphics(void);
extern double g_CursorScaleFactor; extern double g_CursorScaleFactor;
extern char g_CursorScaleFactorUnit[11]; extern char g_CursorScaleFactorUnit[11];
extern double g_PlotGridX, g_PlotGridY, g_PlotGridXdefault, g_PlotGridYdefault, g_GridOffset; extern double g_PlotGridX, g_PlotGridY, g_PlotGridXdefault, g_PlotGridYdefault, g_GridOffset;
extern uint32_t g_CursorCPos, g_CursorDPos, g_GraphStart, g_GraphStop; extern uint32_t g_CursorCPos, g_CursorDPos, g_GraphStart, g_GraphStart_old, g_GraphStop;
extern int CommandFinished; extern int CommandFinished;
extern int offline; extern int offline;
extern bool g_GridLocked; extern bool g_GridLocked;

View file

@ -49,6 +49,7 @@ static int s_Buff[MAX_GRAPH_TRACE_LEN];
static bool gs_useOverlays = false; static bool gs_useOverlays = false;
static int gs_absVMax = 0; static int gs_absVMax = 0;
static uint32_t startMax; // Maximum offset in the graph (right side of graph) static uint32_t startMax; // Maximum offset in the graph (right side of graph)
static uint32_t startMaxOld;
static uint32_t PageWidth; // How many samples are currently visible on this 'page' / graph static uint32_t PageWidth; // How many samples are currently visible on this 'page' / graph
static int unlockStart = 0; static int unlockStart = 0;
@ -372,6 +373,18 @@ void ProxWidget::vchange_dthr_down(int v) {
RepaintGraphWindow(); RepaintGraphWindow();
} }
void ProxWidget::updateNavSlider() {
navSlider->blockSignals(true);
navSlider->setValue(g_GraphStart);
navSlider->setMaximum(startMax);
// for startMaxOld < g_GraphStart or startMax < g_GraphStart_old
navSlider->setValue(g_GraphStart);
navSlider->setMaximum(startMax);
// for click
navSlider->setPageStep(startMax / 10);
navSlider->blockSignals(false);
}
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) { ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
this->master = master; this->master = master;
@ -406,10 +419,20 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
// Set up the plot widget, which does the actual plotting // Set up the plot widget, which does the actual plotting
plot = new Plot(this); plot = new Plot(this);
navSlider = new QSlider(this);
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(plot); layout->addWidget(plot, 1);
layout->addWidget(navSlider);
setLayout(layout); setLayout(layout);
navSlider->setOrientation(Qt::Horizontal);
plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
navSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QObject::connect(navSlider, SIGNAL(valueChanged(int)), plot, SLOT(MoveTo(int)));
QObject::connect(plot, SIGNAL(startMaxChanged(uint32_t)), this, SLOT(updateNavSlider(void)));
QObject::connect(plot, SIGNAL(graphStartChanged(uint32_t)), this, SLOT(updateNavSlider(void)));
// plot window title // plot window title
QString pt = QString("[*]Plot [ %1 ]").arg(g_conn.serial_port_name); QString pt = QString("[*]Plot [ %1 ]").arg(g_conn.serial_port_name);
setWindowTitle(pt); setWindowTitle(pt);
@ -809,6 +832,16 @@ void Plot::paintEvent(QPaintEvent *event) {
); );
painter.setPen(WHITE); painter.setPen(WHITE);
painter.drawText(20, infoRect.bottom() - 3, str); painter.drawText(20, infoRect.bottom() - 3, str);
if (startMaxOld != startMax) {
emit startMaxChanged(startMax);
}
startMaxOld = startMax;
if (g_GraphStart != g_GraphStart_old) {
emit graphStartChanged(g_GraphStart);
}
g_GraphStart_old = g_GraphStart;
} }
Plot::Plot(QWidget *parent) : QWidget(parent), g_GraphPixelsPerPoint(1) { Plot::Plot(QWidget *parent) : QWidget(parent), g_GraphPixelsPerPoint(1) {
@ -868,6 +901,22 @@ void Plot::Zoom(double factor, uint32_t refX) {
} }
} }
void Plot::MoveTo(uint32_t pos) {
if (g_GraphTraceLen == 0) return;
g_GraphStart = pos;
QObject* signalSender = sender();
if (signalSender != nullptr && signalSender != this) {
// Update if it's triggered by a signal from other object
this->update();
}
}
void Plot::MoveTo(int pos) {
MoveTo((uint32_t)((pos >= 0) ? pos : 0));
// sender() is still valid in the inner call
}
void Plot::Move(int offset) { void Plot::Move(int offset) {
if (g_GraphTraceLen == 0) return; if (g_GraphTraceLen == 0) return;
if (offset > 0) { // Move right if (offset > 0) { // Move right

View file

@ -38,6 +38,8 @@ class ProxWidget;
* @brief The actual plot, black area were we paint the graph * @brief The actual plot, black area were we paint the graph
*/ */
class Plot: public QWidget { class Plot: public QWidget {
Q_OBJECT; //needed for slot/signal classes
private: private:
QWidget *master; QWidget *master;
double g_GraphPixelsPerPoint; // How many visual pixels are between each sample point (x axis) double g_GraphPixelsPerPoint; // How many visual pixels are between each sample point (x axis)
@ -55,16 +57,24 @@ class Plot: public QWidget {
public: public:
Plot(QWidget *parent = 0); Plot(QWidget *parent = 0);
public slots:
void Zoom(double factor, uint32_t refX);
void MoveTo(uint32_t pos);
void MoveTo(int pos);
void Move(int offset);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
void Zoom(double factor, uint32_t refX);
void Move(int offset);
void Trim(void); void Trim(void);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
signals:
void startMaxChanged(uint32_t startMax);
void graphStartChanged(uint32_t graphStart);
}; };
class ProxGuiQT; class ProxGuiQT;
@ -97,6 +107,7 @@ class ProxWidget : public QWidget {
Plot *plot; Plot *plot;
Ui::Form *opsController; Ui::Form *opsController;
SliderWidget *controlWidget; SliderWidget *controlWidget;
QSlider *navSlider;
public: public:
ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL); ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL);
@ -120,6 +131,7 @@ class ProxWidget : public QWidget {
void vchange_askedge(int v); void vchange_askedge(int v);
void vchange_dthr_up(int v); void vchange_dthr_up(int v);
void vchange_dthr_down(int v); void vchange_dthr_down(int v);
void updateNavSlider(void);
}; };
class WorkerThread : public QThread { class WorkerThread : public QThread {

View file

@ -52,6 +52,7 @@ char g_CursorScaleFactorUnit[11] = {0};
double g_PlotGridX = 0, g_PlotGridY = 0, g_PlotGridXdefault = 64, g_PlotGridYdefault = 64; double g_PlotGridX = 0, g_PlotGridY = 0, g_PlotGridXdefault = 64, g_PlotGridYdefault = 64;
uint32_t g_CursorCPos = 0, g_CursorDPos = 0, g_GraphStop = 0; uint32_t g_CursorCPos = 0, g_CursorDPos = 0, g_GraphStop = 0;
uint32_t g_GraphStart = 0; // Starting point/offset for the left side of the graph uint32_t g_GraphStart = 0; // Starting point/offset for the left side of the graph
uint32_t g_GraphStart_old = 0;
double g_GraphPixelsPerPoint = 1.f; // How many visual pixels are between each sample point (x axis) double g_GraphPixelsPerPoint = 1.f; // How many visual pixels are between each sample point (x axis)
static bool flushAfterWrite = false; static bool flushAfterWrite = false;
double g_GridOffset = 0; double g_GridOffset = 0;