Changeset - bd649e494eb1
[Not reviewed]
plot-manager
0 6 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-08-26 16:16:49
hy@ozderya.net
show demo indicator on all plots
6 files changed with 35 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -187,16 +187,8 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     this, &MainWindow::enableDemo);
 

	
 
    {   // init demo indicator
 
        QwtText demoText(" DEMO RUNNING ");  // looks better with spaces
 
        demoText.setColor(QColor("white"));
 
        demoText.setBackgroundBrush(Qt::darkRed);
 
        demoText.setBorderRadius(4);
 
        demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop);
 
        demoIndicator.setText(demoText);
 
        demoIndicator.hide();
 
        demoIndicator.attach(ui->plot);
 
    }
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     plotMan, &PlotManager::showDemoIndicator);
 
}
 

	
 
MainWindow::~MainWindow()
 
@@ -356,9 +348,6 @@ void MainWindow::enableDemo(bool enabled
 
        if (!serialPort.isOpen())
 
        {
 
            dataFormatPanel.enableDemo(true);
 
            ui->actionDemoMode->setChecked(true);
 
            demoIndicator.show();
 
            plotMan->replot();
 
        }
 
        else
 
        {
 
@@ -369,8 +358,6 @@ void MainWindow::enableDemo(bool enabled
 
    {
 
        dataFormatPanel.enableDemo(false);
 
        ui->actionDemoMode->setChecked(false);
 
        demoIndicator.hide();
 
        plotMan->replot();
 
    }
 
}
 

	
src/mainwindow.h
Show inline comments
 
@@ -32,7 +32,6 @@
 
#include <QColor>
 
#include <QtGlobal>
 
#include <qwt_plot_curve.h>
 
#include <qwt_plot_textlabel.h>
 

	
 
#include "portcontrol.h"
 
#include "commandpanel.h"
 
@@ -83,7 +82,6 @@ private:
 

	
 
    SnapshotManager snapshotMan;
 

	
 
    QwtPlotTextLabel demoIndicator;
 
    bool isDemoRunning();
 

	
 
    // test widget
src/plot.cpp
Show inline comments
 
@@ -43,6 +43,16 @@ Plot::Plot(QWidget* parent) :
 
    darkBackground(false);
 

	
 
    snapshotOverlay = NULL;
 

	
 
    // init demo indicator
 
    QwtText demoText(" DEMO RUNNING ");  // looks better with spaces
 
    demoText.setColor(QColor("white"));
 
    demoText.setBackgroundBrush(Qt::darkRed);
 
    demoText.setBorderRadius(4);
 
    demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop);
 
    demoIndicator.setText(demoText);
 
    demoIndicator.hide();
 
    demoIndicator.attach(this);
 
}
 

	
 
Plot::~Plot()
 
@@ -104,6 +114,12 @@ void Plot::showLegend(bool show)
 
    replot();
 
}
 

	
 
void Plot::showDemoIndicator(bool show)
 
{
 
    demoIndicator.setVisible(show);
 
    replot();
 
}
 

	
 
void Plot::unzoom()
 
{
 
    zoomer.zoom(0);
src/plot.h
Show inline comments
 
@@ -27,6 +27,7 @@
 
#include <qwt_plot_grid.h>
 
#include <qwt_plot_shapeitem.h>
 
#include <qwt_plot_legenditem.h>
 
#include <qwt_plot_textlabel.h>
 

	
 
#include "zoomer.h"
 
#include "scalezoomer.h"
 
@@ -50,6 +51,7 @@ private:
 
    QwtPlotGrid grid;
 
    PlotSnapshotOverlay* snapshotOverlay;
 
    QwtPlotLegendItem legend;
 
    QwtPlotTextLabel demoIndicator;
 

	
 
    void resetAxes();
 

	
 
@@ -57,6 +59,7 @@ public slots:
 
    void showGrid(bool show = true);
 
    void showMinorGrid(bool show = true);
 
    void showLegend(bool show = true);
 
    void showDemoIndicator(bool show = true);
 
    void unzoom();
 
    void darkBackground(bool enabled = true);
 
    void setAxis(bool autoScaled, double yMin = 0, double yMax = 1);
src/plotmanager.cpp
Show inline comments
 
@@ -35,6 +35,7 @@ PlotManager::PlotManager(QWidget* plotAr
 
{
 
    // initalize layout and single widget
 
    isMulti = false;
 
    isDemoShown = false;
 
    scrollArea = NULL;
 
    setupLayout(isMulti);
 
    addPlotWidget();
 
@@ -174,6 +175,7 @@ Plot* PlotManager::addPlotWidget()
 
    plot->showGrid(showGridAction.isChecked());
 
    plot->showMinorGrid(showMinorGridAction.isChecked());
 
    plot->showLegend(showLegendAction.isChecked());
 
    plot->showDemoIndicator(isDemoShown);
 

	
 
    return plot;
 
}
 
@@ -286,6 +288,15 @@ void PlotManager::showLegend(bool show)
 
    }
 
}
 

	
 
void PlotManager::showDemoIndicator(bool show)
 
{
 
    isDemoShown = show;
 
    for (auto plot : plotWidgets)
 
    {
 
        plot->showDemoIndicator(show);
 
    }
 
}
 

	
 
void PlotManager::unzoom()
 
{
 
    for (auto plot : plotWidgets)
src/plotmanager.h
Show inline comments
 
@@ -59,6 +59,8 @@ public slots:
 
    void setMulti(bool enabled);
 
    /// Update all plot widgets
 
    void replot();
 
    /// Enable display of a "DEMO" label on each plot
 
    void showDemoIndicator(bool show = true);
 

	
 
private:
 
    bool isMulti;
 
@@ -67,6 +69,7 @@ private:
 
    QScrollArea* scrollArea;
 
    QList<QwtPlotCurve*> curves;
 
    QList<Plot*> plotWidgets;
 
    bool isDemoShown;
 

	
 
    // menu actions
 
    QAction showGridAction;
0 comments (0 inline, 0 general)