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
 
@@ -184,32 +184,45 @@ Plot* PlotManager::addPlotWidget()
 

	
 
    return plot;
 
}
 

	
 
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
 
        plot = addPlotWidget();
 
    }
 
    else
 
    {
 
        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();
 
}
 

	
 
void PlotManager::removeCurves(unsigned number)
 
{
src/plotmanager.h
Show inline comments
 
@@ -34,26 +34,23 @@ class PlotManager : public QObject
 
{
 
    Q_OBJECT
 

	
 
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();
 

	
 
public slots:
 
    /// Enable/Disable multiple plot display
 
    void setMulti(bool enabled);
 
@@ -83,15 +80,18 @@ private:
 
    QAction showMinorGridAction;
 
    QAction unzoomAction;
 
    QAction darkBackgroundAction;
 
    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);
 
    void showMinorGrid(bool show = true);
 
    void showLegend(bool show = true);
 
    void unzoom();
src/snapshotview.cpp
Show inline comments
 
@@ -25,39 +25,37 @@ SnapshotView::SnapshotView(QWidget *pare
 
    ui(new Ui::SnapshotView),
 
    renameDialog(this)
 
{
 
    _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");
 
    renameDialog.setLabelText("Enter new name:");
 
    connect(ui->actionRename, &QAction::triggered,
 
            this, &SnapshotView::showRenameDialog);
 

	
 
    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()
 
{
 
    for (auto curve : curves)
 
    {
src/snapshotview.h
Show inline comments
 
@@ -26,13 +26,13 @@
 
#include <QVector>
 
#include <QPointF>
 
#include <QPen>
 
#include <QCloseEvent>
 
#include <qwt_plot_curve.h>
 

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

	
 
namespace Ui {
 
class SnapshotView;
 
}
 

	
 
@@ -49,12 +49,13 @@ signals:
 

	
 
private:
 
    Ui::SnapshotView *ui;
 
    QList<QwtPlotCurve*> curves;
 
    Snapshot* _snapshot;
 
    QInputDialog renameDialog;
 
    PlotManager* plotMan;
 

	
 
    void closeEvent(QCloseEvent *event);
 

	
 
private slots:
 
    void showRenameDialog();
 
    void renameSnapshot(QString name);
src/snapshotview.ui
Show inline comments
 
@@ -13,23 +13,23 @@
 
  <property name="windowTitle">
 
   <string>MainWindow</string>
 
  </property>
 
  <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>
 
  <widget class="QMenuBar" name="menubar">
 
   <property name="geometry">
 
    <rect>
 
     <x>0</x>
 
     <y>0</y>
 
     <width>544</width>
 
     <height>27</height>
 
     <height>20</height>
 
    </rect>
 
   </property>
 
   <widget class="QMenu" name="menuSnapshot">
 
    <property name="title">
 
     <string>Snapshot</string>
 
    </property>
 
@@ -70,20 +70,12 @@
 
   </property>
 
   <property name="shortcut">
 
    <string>Ctrl+W</string>
 
   </property>
 
  </action>
 
 </widget>
 
 <customwidgets>
 
  <customwidget>
 
   <class>Plot</class>
 
   <extends>QWidget</extends>
 
   <header>plot.h</header>
 
   <container>1</container>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections>
 
  <connection>
 
   <sender>actionClose</sender>
 
   <signal>triggered()</signal>
 
   <receiver>SnapshotView</receiver>
0 comments (0 inline, 0 general)