# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-09-19 15:24:02 # Node ID b0405ffbfd8024e01119267f87a87128f177d4fe # Parent ffc9598dcddf54906c2fe4634d745c5a9f3ac7fa take snapshot button creates a new snapshot and opens its window diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/framebuffer.cpp b/framebuffer.cpp --- a/framebuffer.cpp +++ b/framebuffer.cpp @@ -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; diff --git a/framebuffer.h b/framebuffer.h --- a/framebuffer.h +++ b/framebuffer.h @@ -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 diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -31,6 +31,8 @@ #include #include +#include + #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::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(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(); +} diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,7 @@ #include #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 snapshots; + // demo QTimer demoTimer; int demoCount; @@ -128,6 +132,8 @@ private slots: void spsTimerTimeout(); + void takeSnapShot(); + void demoTimerTimeout(); void enableDemo(bool enabled); diff --git a/mainwindow.ui b/mainwindow.ui --- a/mainwindow.ui +++ b/mainwindow.ui @@ -16,7 +16,7 @@ - + 0 @@ -501,6 +501,7 @@ + @@ -604,12 +605,23 @@ Toggle Dark Background + + + SnapShot + + + Take a snapshot of the current plot (F5) + + + F5 + + Plot - QFrame + QWidget
plot.h
1
diff --git a/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -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/ diff --git a/snapshotview.cpp b/snapshotview.cpp new file mode 100644 --- /dev/null +++ b/snapshotview.cpp @@ -0,0 +1,30 @@ +#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; +} diff --git a/snapshotview.h b/snapshotview.h new file mode 100644 --- /dev/null +++ b/snapshotview.h @@ -0,0 +1,37 @@ +#ifndef SNAPSHOTVIEW_H +#define SNAPSHOTVIEW_H + +#include +#include +#include +#include +#include "plot.h" + +class SnapShotView; +struct SnapShot +{ + QString name; + QVector> 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 curves; + + SnapShot* _snapShot; +}; + +#endif // SNAPSHOTVIEW_H diff --git a/snapshotview.ui b/snapshotview.ui new file mode 100644 --- /dev/null +++ b/snapshotview.ui @@ -0,0 +1,83 @@ + + + SnapShotView + + + + 0 + 0 + 544 + 449 + + + + MainWindow + + + + + + + + + + + + 0 + 0 + 544 + 27 + + + + + File + + + + + + View + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + Export CSV + + + + + Delete + + + Delete this snapshot! + + + + + + Plot + QWidget +
plot.h
+ 1 +
+
+ + +