Changeset - 37727123d513
[Not reviewed]
plot-manager
0 5 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-08-28 16:43:56
hy@ozderya.net
updated snapshot view to use plot manager
5 files changed with 41 insertions and 37 deletions:
0 comments (0 inline, 0 general)
src/plotmanager.cpp
Show inline comments
 
@@ -187,8 +187,28 @@ Plot* PlotManager::addPlotWidget()
 

	
 
void PlotManager::addCurve(QString title, FrameBuffer* buffer)
 
{
 
    auto curve = new QwtPlotCurve(title);
 
    curve->setSamples(new FrameBufferSeries(buffer));
 
    _addCurve(curve);
 
}
 

	
 
void PlotManager::addCurve(QString title, QVector<QPointF> data)
 
{
 
    auto curve = new QwtPlotCurve(title);
 
    curve->setSamples(data);
 
    _addCurve(curve);
 
}
 

	
 
void PlotManager::_addCurve(QwtPlotCurve* curve)
 
{
 
    // store and init the curve
 
    curves.append(curve);
 

	
 
    unsigned index = curves.size()-1;
 
    curve->setPen(Plot::makeColor(index));
 

	
 
    // create the plot for the curve if we are on multi display
 
    Plot* plot;
 

	
 
    if (isMulti)
 
    {
 
        // create a new plot widget
 
@@ -199,14 +219,7 @@ void PlotManager::addCurve(QString title
 
        plot = plotWidgets[0];
 
    }
 

	
 
    // create the curve
 
    QwtPlotCurve* curve = new QwtPlotCurve(title);
 
    curves.append(curve);
 

	
 
    curve->setSamples(new FrameBufferSeries(buffer));
 
    unsigned index = curves.size()-1;
 
    curve->setPen(Plot::makeColor(index));
 

	
 
    // show the curve
 
    curve->attach(plot);
 
    plot->replot();
 
}
src/plotmanager.h
Show inline comments
 
@@ -37,20 +37,17 @@ class PlotManager : public QObject
 
public:
 
    explicit PlotManager(QWidget* plotArea, QObject *parent = 0);
 
    ~PlotManager();
 

	
 
    /// Add a new curve with title and buffer. A color is
 
    /// automatically chosen for curve.
 
    void addCurve(QString title, FrameBuffer* buffer);
 

	
 
    /// Alternative of `addCurve` for static curve data (snapshots).
 
    void addCurve(QString title, QVector<QPointF> data);
 
    /// Set the displayed title for a curve
 
    void setTitle(unsigned index, QString title);
 

	
 
    /// Removes curves from the end
 
    void removeCurves(unsigned number);
 

	
 
    /// Returns current number of curves known by plot manager
 
    unsigned numOfCurves();
 

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

	
 
@@ -86,9 +83,12 @@ private:
 
    QAction showLegendAction;
 

	
 
    void setupLayout(bool multiPlot);
 
    Plot* addPlotWidget(); ///< inserts a new plot widget to the current layout
 
    /// Inserts a new plot widget to the current layout.
 
    Plot* addPlotWidget();
 
    /// Returns the plot widget that given curve is attached to
 
    Plot* plotWidget(unsigned curveIndex);
 
    /// Common part of overloaded `addCurve` functions
 
    void _addCurve(QwtPlotCurve* curve);
 

	
 
private slots:
 
    void showGrid(bool show = true);
src/snapshotview.cpp
Show inline comments
 
@@ -28,18 +28,17 @@ SnapshotView::SnapshotView(QWidget *pare
 
    _snapshot = snapshot;
 

	
 
    ui->setupUi(this);
 

	
 
    plotMan = new PlotManager(ui->plotArea);
 

	
 
    ui->menuSnapshot->insertAction(ui->actionClose, snapshot->deleteAction());
 
    this->setWindowTitle(snapshot->name());
 

	
 
    // initialize curves
 
    unsigned numOfChannels = snapshot->data.size();
 

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        QwtPlotCurve* curve = new QwtPlotCurve(snapshot->channelName(ci));
 
        curves.append(curve);
 
        curve->setSamples(snapshot->data[ci]);
 
        curve->setPen(Plot::makeColor(ci));
 
        curve->attach(ui->plot);
 
        plotMan->addCurve(snapshot->channelName(ci), snapshot->data[ci]);
 
    }
 

	
 
    renameDialog.setWindowTitle("Rename Snapshot");
 
@@ -50,11 +49,10 @@ SnapshotView::SnapshotView(QWidget *pare
 
    connect(ui->actionExport, &QAction::triggered,
 
            this, &SnapshotView::save);
 

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

	
 
SnapshotView::~SnapshotView()
src/snapshotview.h
Show inline comments
 
@@ -29,7 +29,7 @@
 
#include <QCloseEvent>
 
#include <qwt_plot_curve.h>
 

	
 
#include "plot.h"
 
#include "plotmanager.h"
 
#include "snapshot.h"
 

	
 
namespace Ui {
 
@@ -52,6 +52,7 @@ private:
 
    QList<QwtPlotCurve*> curves;
 
    Snapshot* _snapshot;
 
    QInputDialog renameDialog;
 
    PlotManager* plotMan;
 

	
 
    void closeEvent(QCloseEvent *event);
 

	
src/snapshotview.ui
Show inline comments
 
@@ -16,7 +16,7 @@
 
  <widget class="QWidget" name="centralwidget">
 
   <layout class="QVBoxLayout" name="verticalLayout">
 
    <item>
 
     <widget class="Plot" name="plot" native="true"/>
 
     <widget class="QWidget" name="plotArea" native="true"/>
 
    </item>
 
   </layout>
 
  </widget>
 
@@ -26,7 +26,7 @@
 
     <x>0</x>
 
     <y>0</y>
 
     <width>544</width>
 
     <height>27</height>
 
     <height>20</height>
 
    </rect>
 
   </property>
 
   <widget class="QMenu" name="menuSnapshot">
 
@@ -73,14 +73,6 @@
 
   </property>
 
  </action>
 
 </widget>
 
 <customwidgets>
 
  <customwidget>
 
   <class>Plot</class>
 
   <extends>QWidget</extends>
 
   <header>plot.h</header>
 
   <container>1</container>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections>
 
  <connection>
0 comments (0 inline, 0 general)