Changeset - b0405ffbfd80
[Not reviewed]
snapshots
0 7 3
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-09-19 15:24:02
hy@ozderya.net
take snapshot button creates a new snapshot and opens its window
10 files changed with 218 insertions and 10 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -52,7 +52,12 @@ endif (QWT_USE_STATIC)
 
include_directories(${QWT_INCLUDE_DIR})
 

	
 
# wrap UI and resource files
 
qt5_wrap_ui(UI_FILES mainwindow.ui portcontrol.ui about_dialog.ui)
 
qt5_wrap_ui(UI_FILES
 
  mainwindow.ui
 
  portcontrol.ui
 
  about_dialog.ui
 
  snapshotview.ui
 
  )
 
qt5_add_resources(RES_FILES misc/icons.qrc)
 

	
 
add_executable(${PROGRAM_NAME} WIN32
 
@@ -66,6 +71,7 @@ add_executable(${PROGRAM_NAME} WIN32
 
  scalepicker.cpp
 
  scalezoomer.cpp
 
  portlist.cpp
 
  snapshotview.cpp
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  misc/windows_icon.rc
framebuffer.cpp
Show inline comments
 
@@ -45,7 +45,7 @@ void FrameBuffer::resize(size_t size)
 

	
 
    for (int i = fill_start; i < int(size); i++)
 
    {
 
        newData[i] = _sample(i - offset);
 
        newData[i] = sampleY(i - offset);
 
    }
 

	
 
    // fill the beginning of the new data
 
@@ -143,7 +143,7 @@ size_t FrameBuffer::size() const
 

	
 
QPointF FrameBuffer::sample(size_t i) const
 
{
 
    return QPointF(i, _sample(i));
 
    return QPointF(i, sampleY(i));
 
}
 

	
 
QRectF FrameBuffer::boundingRect() const
 
@@ -151,7 +151,7 @@ QRectF FrameBuffer::boundingRect() const
 
    return _boundingRect;
 
}
 

	
 
double FrameBuffer::_sample(size_t i) const
 
double FrameBuffer::sampleY(size_t i) const
 
{
 
    size_t index = headIndex + i;
 
    if (index >= _size) index -= _size;
framebuffer.h
Show inline comments
 
@@ -37,6 +37,7 @@ public:
 
    // QwtSeriesData implementations
 
    size_t size() const;
 
    QPointF sample(size_t i) const;
 
    double sampleY(size_t i) const;
 
    QRectF boundingRect() const;
 

	
 
private:
 
@@ -46,7 +47,6 @@ private:
 

	
 
    QRectF _boundingRect;
 

	
 
    double _sample(size_t i) const;
 
};
 

	
 
#endif // FRAMEBUFFER_H
mainwindow.cpp
Show inline comments
 
@@ -31,6 +31,8 @@
 
#include <cmath>
 
#include <iostream>
 

	
 
#include <snapshotview.h>
 

	
 
#include "utils.h"
 
#include "version.h"
 
#include "floatswap.h"
 
@@ -112,6 +114,9 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->actionClear, SIGNAL(triggered(bool)),
 
                     this, SLOT(clearPlot()));
 

	
 
    QObject::connect(ui->actionSnapShot, SIGNAL(triggered(bool)),
 
                     this, SLOT(takeSnapShot()));
 

	
 
    // setup number of channels spinbox
 
    QObject::connect(ui->spNumOfChannels,
 
                     SELECT<int>::OVERLOAD_OF(&QSpinBox::valueChanged),
 
@@ -241,6 +246,12 @@ MainWindow::~MainWindow()
 
    {
 
        serialPort.close();
 
    }
 

	
 
    for (auto snapshot : snapshots)
 
    {
 
        delete snapshot;
 
    }
 

	
 
    delete ui;
 
    ui = NULL; // we check if ui is deleted in messageHandler
 
}
 
@@ -745,3 +756,23 @@ void MainWindow::messageHandler(QtMsgTyp
 
        ui->statusBar->showMessage(msg, 5000);
 
    }
 
}
 

	
 
void MainWindow::takeSnapShot()
 
{
 
    qDebug() << "taking a snopshot yay!";
 
    auto snapShot = new SnapShot();
 
    snapShot->name = QString("SnapShot");
 

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        snapShot->data.append(QVector<QPointF>(numOfSamples));
 
        for (unsigned i = 0; i < numOfSamples; i++)
 
        {
 
            snapShot->data[ci][i] = channelBuffers[ci]->sample(i);
 
        }
 
    }
 
    snapshots.append(snapShot);
 

	
 
    auto sv = new SnapShotView(this, snapShot);
 
    sv->show();
 
}
mainwindow.h
Show inline comments
 
@@ -35,6 +35,7 @@
 
#include <qwt_plot_textlabel.h>
 

	
 
#include "portcontrol.h"
 
#include "snapshotview.h"
 
#include "ui_about_dialog.h"
 
#include "framebuffer.h"
 

	
 
@@ -99,6 +100,9 @@ private:
 
    unsigned int sampleCount;
 
    QTimer spsTimer;
 

	
 
    // snapshots
 
    QList<SnapShot*> snapshots;
 

	
 
    // demo
 
    QTimer demoTimer;
 
    int demoCount;
 
@@ -128,6 +132,8 @@ private slots:
 

	
 
    void spsTimerTimeout();
 

	
 
    void takeSnapShot();
 

	
 
    void demoTimerTimeout();
 
    void enableDemo(bool enabled);
 

	
mainwindow.ui
Show inline comments
 
@@ -16,7 +16,7 @@
 
  <widget class="QWidget" name="centralWidget">
 
   <layout class="QVBoxLayout" name="verticalLayout_2">
 
    <item>
 
     <widget class="Plot" name="plot">
 
     <widget class="Plot" name="plot" native="true">
 
      <property name="sizePolicy">
 
       <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
 
        <horstretch>0</horstretch>
 
@@ -501,6 +501,7 @@
 
   </attribute>
 
   <addaction name="actionPause"/>
 
   <addaction name="actionClear"/>
 
   <addaction name="actionSnapShot"/>
 
  </widget>
 
  <widget class="QStatusBar" name="statusBar"/>
 
  <action name="actionPause">
 
@@ -604,12 +605,23 @@
 
    <string>Toggle Dark Background</string>
 
   </property>
 
  </action>
 
  <action name="actionSnapShot">
 
   <property name="text">
 
    <string>SnapShot</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Take a snapshot of the current plot (F5)</string>
 
   </property>
 
   <property name="shortcut">
 
    <string>F5</string>
 
   </property>
 
  </action>
 
 </widget>
 
 <layoutdefault spacing="6" margin="11"/>
 
 <customwidgets>
 
  <customwidget>
 
   <class>Plot</class>
 
   <extends>QFrame</extends>
 
   <extends>QWidget</extends>
 
   <header>plot.h</header>
 
   <container>1</container>
 
  </customwidget>
serialplot.pro
Show inline comments
 
@@ -42,7 +42,8 @@ SOURCES += main.cpp\
 
    framebuffer.cpp \
 
    scalepicker.cpp \
 
    scalezoomer.cpp \
 
    portlist.cpp
 
    portlist.cpp \
 
    snapshotview.cpp
 

	
 
HEADERS  += mainwindow.h \
 
    utils.h \
 
@@ -54,11 +55,13 @@ HEADERS  += mainwindow.h \
 
    framebuffer.h \
 
    scalepicker.h \
 
    scalezoomer.h \
 
    portlist.h
 
    portlist.h \
 
    snapshotview.h
 

	
 
FORMS    += mainwindow.ui \
 
    about_dialog.ui \
 
    portcontrol.ui
 
    portcontrol.ui \
 
    snapshotview.ui
 

	
 
INCLUDEPATH += qmake/
 

	
snapshotview.cpp
Show inline comments
 
new file 100644
 
#include "snapshotview.h"
 
#include "ui_snapshotview.h"
 

	
 
SnapShotView::SnapShotView(QWidget *parent, SnapShot* snapShot) :
 
    QMainWindow(parent),
 
    ui(new Ui::SnapShotView)
 
{
 
    ui->setupUi(this);
 

	
 
    unsigned numOfChannels = snapShot->data.size();
 

	
 
    for (unsigned ci = 0; ci < numOfChannels; ci++)
 
    {
 
        QwtPlotCurve* curve = new QwtPlotCurve();
 
        curves.append(curve);
 
        curve->setSamples(snapShot->data[ci]);
 
        curve->attach(ui->plot);
 
    }
 

	
 
    _snapShot = snapShot;
 
}
 

	
 
SnapShotView::~SnapShotView()
 
{
 
    for (auto curve : curves)
 
    {
 
        delete curve;
 
    }
 
    delete ui;
 
}
snapshotview.h
Show inline comments
 
new file 100644
 
#ifndef SNAPSHOTVIEW_H
 
#define SNAPSHOTVIEW_H
 

	
 
#include <QMainWindow>
 
#include <QVector>
 
#include <QPointF>
 
#include <qwt_plot_curve.h>
 
#include "plot.h"
 

	
 
class SnapShotView;
 
struct SnapShot
 
{
 
    QString name;
 
    QVector<QVector<QPointF>> data;
 
    SnapShotView* view;
 
};
 

	
 
namespace Ui {
 
class SnapShotView;
 
}
 

	
 
class SnapShotView : public QMainWindow
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit SnapShotView(QWidget *parent, SnapShot* snapShot);
 
    ~SnapShotView();
 

	
 
private:
 
    Ui::SnapShotView *ui;
 
    QList<QwtPlotCurve*> curves;
 

	
 
    SnapShot* _snapShot;
 
};
 

	
 
#endif // SNAPSHOTVIEW_H
snapshotview.ui
Show inline comments
 
new file 100644
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>SnapShotView</class>
 
 <widget class="QMainWindow" name="SnapShotView">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>544</width>
 
    <height>449</height>
 
   </rect>
 
  </property>
 
  <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"/>
 
    </item>
 
   </layout>
 
  </widget>
 
  <widget class="QMenuBar" name="menubar">
 
   <property name="geometry">
 
    <rect>
 
     <x>0</x>
 
     <y>0</y>
 
     <width>544</width>
 
     <height>27</height>
 
    </rect>
 
   </property>
 
   <widget class="QMenu" name="menuFile">
 
    <property name="title">
 
     <string>File</string>
 
    </property>
 
    <addaction name="actionExportCSV"/>
 
   </widget>
 
   <widget class="QMenu" name="menuView">
 
    <property name="title">
 
     <string>View</string>
 
    </property>
 
   </widget>
 
   <addaction name="menuFile"/>
 
   <addaction name="menuView"/>
 
  </widget>
 
  <widget class="QToolBar" name="toolBar">
 
   <property name="windowTitle">
 
    <string>toolBar</string>
 
   </property>
 
   <attribute name="toolBarArea">
 
    <enum>TopToolBarArea</enum>
 
   </attribute>
 
   <attribute name="toolBarBreak">
 
    <bool>false</bool>
 
   </attribute>
 
   <addaction name="actionExportCSV"/>
 
   <addaction name="actionDelete"/>
 
  </widget>
 
  <action name="actionExportCSV">
 
   <property name="text">
 
    <string>Export CSV</string>
 
   </property>
 
  </action>
 
  <action name="actionDelete">
 
   <property name="text">
 
    <string>Delete</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Delete this snapshot!</string>
 
   </property>
 
  </action>
 
 </widget>
 
 <customwidgets>
 
  <customwidget>
 
   <class>Plot</class>
 
   <extends>QWidget</extends>
 
   <header>plot.h</header>
 
   <container>1</container>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
 
</ui>
0 comments (0 inline, 0 general)