Changeset - 45bff47b2ed9
[Not reviewed]
barplot
0 7 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-10-07 08:30:07
hy@ozderya.net
move barplot under plotmanager and enable dark background
7 files changed with 68 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/barplot.cpp
Show inline comments
 
@@ -40,3 +40,16 @@ void BarPlot::update()
 
    barChart.resample();
 
    replot();
 
}
 

	
 
void BarPlot::darkBackground(bool enabled)
 
{
 
    if (enabled)
 
    {
 
        setCanvasBackground(QBrush(Qt::black));
 
    }
 
    else
 
    {
 
        setCanvasBackground(QBrush(Qt::white));
 
    }
 
    replot();
 
}
src/barplot.h
Show inline comments
 
@@ -38,8 +38,12 @@ private:
 

	
 
    QVector<double> chartData() const;
 

	
 
public slots:
 
    void darkBackground(bool enabled);
 

	
 
private slots:
 
    void update();
 

	
 
};
 

	
 
#endif // BARPLOT_H
src/mainwindow.cpp
Show inline comments
 
@@ -60,7 +60,6 @@ MainWindow::MainWindow(QWidget *parent) 
 
    aboutDialog(this),
 
    portControl(&serialPort),
 
    channelMan(1, 1, this),
 
    barPlot(&channelMan),
 
    snapshotMan(this, &channelMan),
 
    commandPanel(&serialPort),
 
    dataFormatPanel(&serialPort, &channelMan, &recorder),
 
@@ -69,7 +68,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
{
 
    ui->setupUi(this);
 

	
 
    plotMan = new PlotManager(ui->plotArea, channelMan.infoModel());
 
    plotMan = new PlotManager(ui->plotArea, ui->splitter, &channelMan, channelMan.infoModel());
 

	
 
    ui->tabWidget->insertTab(0, &portControl, "Port");
 
    ui->tabWidget->insertTab(1, &dataFormatPanel, "Data Format");
 
@@ -265,8 +264,6 @@ MainWindow::MainWindow(QWidget *parent) 
 
                this->ui->tabWidget->setCurrentWidget(&commandPanel);
 
                this->ui->tabWidget->showTabs();
 
            });
 

	
 
    ui->splitter->addWidget(&barPlot);
 
}
 

	
 
MainWindow::~MainWindow()
src/mainwindow.h
Show inline comments
 
@@ -44,7 +44,6 @@
 
#include "channelmanager.h"
 
#include "snapshotmanager.h"
 
#include "plotmanager.h"
 
#include "barplot.h"
 
#include "datarecorder.h"
 
#include "updatecheckdialog.h"
 

	
 
@@ -79,7 +78,6 @@ private:
 
    QList<QwtPlotCurve*> curves;
 
    ChannelManager channelMan;
 
    PlotManager* plotMan;
 
    BarPlot barPlot;
 
    SnapshotManager snapshotMan;
 
    DataRecorder recorder;       // operated by `recordPanel`
 

	
src/plotmanager.cpp
Show inline comments
 
@@ -28,15 +28,19 @@
 
#include "utils.h"
 
#include "setting_defines.h"
 

	
 
PlotManager::PlotManager(QWidget* plotArea, ChannelInfoModel* infoModel, QObject *parent) :
 
PlotManager::PlotManager(
 
    QWidget* plotArea, QSplitter* splitter, ChannelManager* channelMan,
 
    ChannelInfoModel* infoModel, QObject *parent) :
 
    QObject(parent),
 
    _plotArea(plotArea),
 
    _splitter(splitter),
 
    showGridAction("&Grid", this),
 
    showMinorGridAction("&Minor Grid", this),
 
    unzoomAction("&Unzoom", this),
 
    darkBackgroundAction("&Dark Background", this),
 
    showLegendAction("&Legend", this),
 
    showMultiAction("Multi &Plot", this),
 
    showBarPlotAction("&Bar Plot", this),
 
    setSymbolsAction("Symbols", this)
 
{
 
    _autoScaled = true;
 
@@ -44,11 +48,13 @@ PlotManager::PlotManager(QWidget* plotAr
 
    _yMax = 1;
 
    _xAxisAsIndex = true;
 
    isDemoShown = false;
 
    _channelMan = channelMan;
 
    _infoModel = infoModel;
 
    _numOfSamples = 1;
 
    _plotWidth = 1;
 
    showSymbols = Plot::ShowSymbolsAuto;
 
    emptyPlot = NULL;
 
    barPlot = NULL;
 

	
 
    // initalize layout and single widget
 
    isMulti = false;
 
@@ -63,6 +69,7 @@ PlotManager::PlotManager(QWidget* plotAr
 
    darkBackgroundAction.setToolTip("Enable Dark Plot Background");
 
    showLegendAction.setToolTip("Display the Legend on Plot");
 
    showMultiAction.setToolTip("Display All Channels Separately");
 
    showBarPlotAction.setToolTip("Show bar plot");
 
    setSymbolsAction.setToolTip("Show/Hide symbols");
 

	
 
    showGridAction.setShortcut(QKeySequence("G"));
 
@@ -73,12 +80,14 @@ PlotManager::PlotManager(QWidget* plotAr
 
    darkBackgroundAction.setCheckable(true);
 
    showLegendAction.setCheckable(true);
 
    showMultiAction.setCheckable(true);
 
    showBarPlotAction.setCheckable(true);
 

	
 
    showGridAction.setChecked(false);
 
    showMinorGridAction.setChecked(false);
 
    darkBackgroundAction.setChecked(false);
 
    showLegendAction.setChecked(true);
 
    showMultiAction.setChecked(false);
 
    showBarPlotAction.setChecked(false);
 

	
 
    showMinorGridAction.setEnabled(false);
 

	
 
@@ -128,6 +137,8 @@ PlotManager::PlotManager(QWidget* plotAr
 
            this, &PlotManager::showLegend);
 
    connect(&showMultiAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &PlotManager::setMulti);
 
    connect(&showBarPlotAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &PlotManager::showBarPlot);
 

	
 
    // connect to channel info model
 
    if (_infoModel != NULL)     // TODO: remove when snapshots have infomodel
 
@@ -264,6 +275,26 @@ void PlotManager::setMulti(bool enabled)
 
    checkNoVisChannels();
 
}
 

	
 
void PlotManager::showBarPlot(bool show)
 
{
 
    // A secondary plot can only be shown if splitter is provided.
 
    Q_ASSERT(_splitter != NULL);
 

	
 
    if (show)
 
    {
 
        Q_ASSERT(barPlot == NULL);
 

	
 
        barPlot = new BarPlot(_channelMan, _splitter);
 
    }
 
    else
 
    {
 
        Q_ASSERT(barPlot != NULL);
 

	
 
        delete barPlot;
 
        barPlot = NULL;
 
    }
 
}
 

	
 
void PlotManager::setupLayout(bool multiPlot)
 
{
 
    // delete previous layout if it exists
 
@@ -428,6 +459,7 @@ QList<QAction*> PlotManager::menuActions
 
    actions << &darkBackgroundAction;
 
    actions << &showLegendAction;
 
    actions << &showMultiAction;
 
    actions << &showBarPlotAction;
 
    actions << &setSymbolsAction;
 
    return actions;
 
}
 
@@ -479,6 +511,7 @@ void PlotManager::darkBackground(bool en
 
    {
 
        plot->darkBackground(enabled);
 
    }
 
    if (barPlot != NULL) barPlot->darkBackground(enabled);
 
}
 

	
 
void PlotManager::setSymbols(Plot::ShowSymbols shown)
src/plotmanager.h
Show inline comments
 
@@ -28,10 +28,13 @@
 
#include <QSettings>
 
#include <QAction>
 
#include <QMenu>
 
#include <QSplitter>
 

	
 
#include <qwt_plot_curve.h>
 
#include "plot.h"
 
#include "barplot.h"
 
#include "framebufferseries.h"
 
#include "channelmanager.h"
 
#include "channelinfomodel.h"
 

	
 
struct PlotViewSettings
 
@@ -49,7 +52,10 @@ class PlotManager : public QObject
 
    Q_OBJECT
 

	
 
public:
 
    explicit PlotManager(QWidget* plotArea, ChannelInfoModel* infoModel = NULL, QObject *parent = 0);
 
    explicit PlotManager(
 
        QWidget* plotArea, QSplitter* splitter = NULL,
 
        ChannelManager* channelMan = NULL, ChannelInfoModel* infoModel = NULL,
 
        QObject *parent = 0);
 
    ~PlotManager();
 
    /// Add a new curve with title and buffer. A color is
 
    /// automatically chosen for curve.
 
@@ -74,8 +80,6 @@ public:
 
    void loadSettings(QSettings* settings);
 

	
 
public slots:
 
    /// Enable/Disable multiple plot display
 
    void setMulti(bool enabled);
 
    /// Update all plot widgets
 
    void replot();
 
    /// Enable display of a "DEMO" label on each plot
 
@@ -94,11 +98,14 @@ public slots:
 
private:
 
    bool isMulti;
 
    QWidget* _plotArea;
 
    BarPlot* barPlot;
 
    QSplitter* _splitter;
 
    QVBoxLayout* layout; ///< layout of the `plotArea`
 
    QScrollArea* scrollArea;
 
    QList<QwtPlotCurve*> curves;
 
    QList<Plot*> plotWidgets;
 
    Plot* emptyPlot;  ///< for displaying when all channels are hidden
 
    ChannelManager* _channelMan;
 
    ChannelInfoModel* _infoModel;
 
    bool isDemoShown;
 
    bool _autoScaled;
 
@@ -118,6 +125,7 @@ private:
 
    QAction darkBackgroundAction;
 
    QAction showLegendAction;
 
    QAction showMultiAction;
 
    QAction showBarPlotAction;
 
    QAction setSymbolsAction;
 
    QMenu setSymbolsMenu;
 
    QAction* setSymbolsAutoAct;
 
@@ -141,6 +149,10 @@ private slots:
 
    void showLegend(bool show = true);
 
    void unzoom();
 
    void darkBackground(bool enabled = true);
 
    /// Enable/Disable multiple plot display
 
    void setMulti(bool enabled);
 
    /// Display/Hide bar plot
 
    void showBarPlot(bool show = true);
 

	
 
    void onChannelInfoChanged(const QModelIndex & topLeft,
 
                              const QModelIndex & bottomRight,
src/snapshotview.cpp
Show inline comments
 
@@ -29,7 +29,7 @@ SnapshotView::SnapshotView(MainWindow* p
 

	
 
    ui->setupUi(this);
 

	
 
    plotMan = new PlotManager(ui->plotArea, snapshot->infoModel(), this);
 
    plotMan = new PlotManager(ui->plotArea, NULL, NULL, snapshot->infoModel(), this);
 
    plotMan->setViewSettings(parent->viewSettings());
 

	
 
    ui->menuSnapshot->insertAction(ui->actionClose, snapshot->deleteAction());
0 comments (0 inline, 0 general)