Changeset - 4f8a97f79619
[Not reviewed]
plot-manager
0 6 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-08-25 02:02:15
hy@ozderya.net
plot menu is moved to the plotmanager, not completely functional
6 files changed with 107 insertions and 74 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -88,7 +88,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
    setupAboutDialog();
 

	
 
    // init view menu
 
    for (auto a : ui->plot->menuActions())
 
    for (auto a : plotMan->menuActions())
 
    {
 
        ui->menuView->addAction(a);
 
    }
src/plot.cpp
Show inline comments
 
@@ -29,12 +29,7 @@
 
Plot::Plot(QWidget* parent) :
 
    QwtPlot(parent),
 
    zoomer(this->canvas(), false),
 
    sZoomer(this, &zoomer),
 
    showGridAction("Grid", this),
 
    showMinorGridAction("Minor Grid", this),
 
    unzoomAction("Unzoom", this),
 
    darkBackgroundAction("Dark Background", this),
 
    showLegendAction("Legend", this)
 
    sZoomer(this, &zoomer)
 
{
 
    isAutoScaled = true;
 

	
 
@@ -47,39 +42,6 @@ Plot::Plot(QWidget* parent) :
 
    showGrid(false);
 
    darkBackground(false);
 

	
 
    showGridAction.setToolTip("Show Grid");
 
    showMinorGridAction.setToolTip("Show Minor Grid");
 
    unzoomAction.setToolTip("Unzoom the Plot");
 
    darkBackgroundAction.setToolTip("Enable Dark Plot Background");
 
    showLegendAction.setToolTip("Display the Legend on Plot");
 

	
 
    showGridAction.setShortcut(QKeySequence("G"));
 
    showMinorGridAction.setShortcut(QKeySequence("M"));
 

	
 
    showGridAction.setCheckable(true);
 
    showMinorGridAction.setCheckable(true);
 
    darkBackgroundAction.setCheckable(true);
 
    showLegendAction.setCheckable(true);
 

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

	
 
    showMinorGridAction.setEnabled(false);
 

	
 
    connect(&showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::showGrid);
 
    connect(&showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            &showMinorGridAction, &QAction::setEnabled);
 
    connect(&showMinorGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::showMinorGrid);
 
    connect(&unzoomAction, &QAction::triggered, this, &Plot::unzoom);
 
    connect(&darkBackgroundAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::darkBackground);
 
    connect(&showLegendAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            [this](bool enabled){legend.setVisible(enabled); replot();});
 

	
 
    snapshotOverlay = NULL;
 
}
 

	
 
@@ -102,17 +64,6 @@ void Plot::setAxis(bool autoScaled, doub
 
    resetAxes();
 
}
 

	
 
QList<QAction*> Plot::menuActions()
 
{
 
    QList<QAction*> actions;
 
    actions << &showGridAction;
 
    actions << &showMinorGridAction;
 
    actions << &unzoomAction;
 
    actions << &darkBackgroundAction;
 
    actions << &showLegendAction;
 
    return actions;
 
}
 

	
 
void Plot::resetAxes()
 
{
 
    if (isAutoScaled)
 
@@ -213,7 +164,9 @@ void Plot::flashSnapshotOverlay()
 
    if (snapshotOverlay != NULL) delete snapshotOverlay;
 

	
 
    QColor color;
 
    if (darkBackgroundAction.isChecked())
 
    // TODO: fix snapshot overlay
 
    // if (darkBackgroundAction.isChecked())
 
    if(1)
 
    {
 
        color = QColor(Qt::white);
 
    }
src/plot.h
Show inline comments
 
@@ -40,8 +40,6 @@ public:
 
    Plot(QWidget* parent = 0);
 
    ~Plot();
 

	
 
    QList<QAction*> menuActions();
 

	
 
    static QColor makeColor(unsigned int channelIndex);
 

	
 
private:
 
@@ -53,12 +51,6 @@ private:
 
    PlotSnapshotOverlay* snapshotOverlay;
 
    QwtPlotLegendItem legend;
 

	
 
    QAction showGridAction;
 
    QAction showMinorGridAction;
 
    QAction unzoomAction;
 
    QAction darkBackgroundAction;
 
    QAction showLegendAction;
 

	
 
    void resetAxes();
 

	
 
public slots:
src/plotmanager.cpp
Show inline comments
 
@@ -17,15 +17,21 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <QtDebug>
 

	
 
#include "plot.h"
 

	
 
#include "plotmanager.h"
 
#include "utils.h"
 

	
 
#include <QtDebug>
 

	
 
PlotManager::PlotManager(QWidget* plotArea, QObject *parent) :
 
    QObject(parent),
 
    _plotArea(plotArea)
 
    _plotArea(plotArea),
 
    showGridAction("Grid", this),
 
    showMinorGridAction("Minor Grid", this),
 
    unzoomAction("Unzoom", this),
 
    darkBackgroundAction("Dark Background", this),
 
    showLegendAction("Legend", this)
 
{
 
    // initalize layout and single widget
 
    isMulti = false;
 
@@ -33,13 +39,40 @@ PlotManager::PlotManager(QWidget* plotAr
 
    setupLayout(isMulti);
 
    addPlotWidget();
 

	
 
    // test code
 
    // addCurve("test", new FrameBuffer(100));
 
    // addCurve("test", new FrameBuffer(100));
 
    // addCurve("test", new FrameBuffer(100));
 
    // initialize menu actions
 
    showGridAction.setToolTip("Show Grid");
 
    showMinorGridAction.setToolTip("Show Minor Grid");
 
    unzoomAction.setToolTip("Unzoom the Plot");
 
    darkBackgroundAction.setToolTip("Enable Dark Plot Background");
 
    showLegendAction.setToolTip("Display the Legend on Plot");
 

	
 
    showGridAction.setShortcut(QKeySequence("G"));
 
    showMinorGridAction.setShortcut(QKeySequence("M"));
 

	
 
    showGridAction.setCheckable(true);
 
    showMinorGridAction.setCheckable(true);
 
    darkBackgroundAction.setCheckable(true);
 
    showLegendAction.setCheckable(true);
 

	
 
    // setMulti(true);
 
    // setMulti(false);
 
    showGridAction.setChecked(false);
 
    showMinorGridAction.setChecked(false);
 
    darkBackgroundAction.setChecked(false);
 
    showLegendAction.setChecked(true);
 

	
 
    showMinorGridAction.setEnabled(false);
 

	
 
    connect(&showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &PlotManager::showGrid);
 
    connect(&showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            &showMinorGridAction, &QAction::setEnabled);
 
    connect(&showMinorGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &PlotManager::showMinorGrid);
 
    connect(&unzoomAction, &QAction::triggered, this, &PlotManager::unzoom);
 
    connect(&darkBackgroundAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &PlotManager::darkBackground);
 
    // TODO: enable legend
 
    // connect(&showLegendAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
    //         [this](bool enabled){legend.setVisible(enabled); replot();});
 
}
 

	
 
PlotManager::~PlotManager()
 
@@ -212,3 +245,43 @@ void PlotManager::replot()
 
        plot->replot();
 
    }
 
}
 

	
 
QList<QAction*> PlotManager::menuActions()
 
{
 
    QList<QAction*> actions;
 
    actions << &showGridAction;
 
    actions << &showMinorGridAction;
 
    actions << &unzoomAction;
 
    actions << &darkBackgroundAction;
 
    actions << &showLegendAction;
 
    return actions;
 
}
 

	
 
void PlotManager::showGrid(bool show)
 
{
 
    for (auto plot : plotWidgets)
 
    {
 
        plot->showGrid(show);
 
    }
 
}
 
void PlotManager::showMinorGrid(bool show)
 
{
 
    for (auto plot : plotWidgets)
 
    {
 
        plot->showMinorGrid(show);
 
    }
 
}
 
void PlotManager::unzoom()
 
{
 
    for (auto plot : plotWidgets)
 
    {
 
        plot->unzoom();
 
    }
 
}
 
void PlotManager::darkBackground(bool enabled)
 
{
 
    for (auto plot : plotWidgets)
 
    {
 
        plot->darkBackground(enabled);
 
    }
 
}
src/plotmanager.h
Show inline comments
 
@@ -51,7 +51,8 @@ public:
 
    /// Returns current number of curves known by plot manager
 
    unsigned numOfCurves();
 

	
 
signals:
 
    /// Returns the list of actions to be inserted into the `View` menu
 
    QList<QAction*> menuActions();
 

	
 
public slots:
 
    /// Enable/Disable multiple plot display
 
@@ -67,10 +68,23 @@ private:
 
    QList<QwtPlotCurve*> curves;
 
    QList<Plot*> plotWidgets;
 

	
 
    // menu actions
 
    QAction showGridAction;
 
    QAction showMinorGridAction;
 
    QAction unzoomAction;
 
    QAction darkBackgroundAction;
 
    QAction showLegendAction;
 

	
 
    void setupLayout(bool multiPlot);
 
    Plot* addPlotWidget(); ///< inserts a new plot widget to the current layout
 
    /// Returns the plot widget that given curve is attached to
 
    Plot* plotWidget(unsigned curveIndex);
 

	
 
private slots:
 
    void showGrid(bool show = true);
 
    void showMinorGrid(bool show = true);
 
    void unzoom();
 
    void darkBackground(bool enabled = true);
 
};
 

	
 
#endif // PLOTMANAGER_H
src/snapshotview.cpp
Show inline comments
 
@@ -50,10 +50,11 @@ SnapshotView::SnapshotView(QWidget *pare
 
    connect(ui->actionExport, &QAction::triggered,
 
            this, &SnapshotView::save);
 

	
 
    for (auto a : ui->plot->menuActions())
 
    {
 
        ui->menuView->addAction(a);
 
    }
 
    // TODO: fix snapshot menu
 
    // for (auto a : ui->plot->menuActions())
 
    // {
 
    //     ui->menuView->addAction(a);
 
    // }
 
}
 

	
 
SnapshotView::~SnapshotView()
0 comments (0 inline, 0 general)