diff --git a/ExampleProject/Backend/ExampleBackend.cpp b/ExampleProject/Backend/ExampleBackend.cpp new file mode 100644 index 0000000..b54b1a4 --- /dev/null +++ b/ExampleProject/Backend/ExampleBackend.cpp @@ -0,0 +1,60 @@ +#include "ExampleBackend.h" + +#include +#include + + +ExampleBackend::ExampleBackend(QObject* parent) + :QThread(parent) +{ + connect(this, &QThread::finished, [=]() { deleteLater(); }); +} + +ExampleBackend::~ExampleBackend() +{ +} + +void ExampleBackend::stopAndClear() +{ + quit(); + wait(); +} + +void ExampleBackend::quit() +{ + bIsQuit = true; + generateNewData.unlock(); + + QThread::quit(); +} + +void ExampleBackend::copyingCompleted() +{ + generateNewData.unlock(); +} + +void ExampleBackend::run() +{ + int size = 512; + double* data = new double[size]; + double d = 0; + bIsQuit = false; + + while(!bIsQuit) + { + generateNewData.lock(); + + if (bIsQuit) break; + + d = (rand() % 4 + 2); + for(int i = 0; i < size; i++) + { + data[i] = sin(i / (size/d)) * 100.0; + } + + emit generatedNewData(data, size); + } + + generateNewData.unlock(); + delete data; +} diff --git a/ExampleProject/Backend/ExampleBackend.h b/ExampleProject/Backend/ExampleBackend.h new file mode 100644 index 0000000..7f99dc0 --- /dev/null +++ b/ExampleProject/Backend/ExampleBackend.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include + +class ExampleBackend : public QThread +{ + Q_OBJECT + +public: + ExampleBackend(QObject* parent = nullptr); + ~ExampleBackend(); + + void stopAndClear(); + void quit(); + +signals: + void generatedNewData(double* data, int size); + +public slots: + void copyingCompleted(); + +protected: + void run() override; + +private: + QMutex generateNewData; + bool bIsQuit; + +}; + diff --git a/ExampleProject/ExampleProject.vcxproj b/ExampleProject/ExampleProject.vcxproj index d522224..6951839 100644 --- a/ExampleProject/ExampleProject.vcxproj +++ b/ExampleProject/ExampleProject.vcxproj @@ -111,6 +111,7 @@ + @@ -121,6 +122,9 @@ + + + diff --git a/ExampleProject/ExampleProject.vcxproj.filters b/ExampleProject/ExampleProject.vcxproj.filters index 96d0fc8..dca8272 100644 --- a/ExampleProject/ExampleProject.vcxproj.filters +++ b/ExampleProject/ExampleProject.vcxproj.filters @@ -27,6 +27,12 @@ {c35943ba-525b-4101-b762-ae4109c92804} + + {0f712421-3941-42c2-b5d3-7ca2aec510a1} + + + {1a055f30-a1ef-4d4e-83f6-9ee2afa1c182} + @@ -40,6 +46,9 @@ Source Files\Frontend + + Source Files\Backend + @@ -50,5 +59,8 @@ Header Files\Frontend + + Header Files\Backend + \ No newline at end of file diff --git a/ExampleProject/Frontend/MainWindow/MainWindow.cpp b/ExampleProject/Frontend/MainWindow/MainWindow.cpp index 108c0cc..3d37d0c 100644 --- a/ExampleProject/Frontend/MainWindow/MainWindow.cpp +++ b/ExampleProject/Frontend/MainWindow/MainWindow.cpp @@ -1,6 +1,8 @@ #include "MainWindow.h" #include "Plot/QtPlot.h" +#include "Waterfall/WaterfallContent.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -9,10 +11,16 @@ MainWindow::MainWindow(QWidget *parent) initializePlot(); initializeWaterfall(); + + backend.start(); + + connect(&backend, &ExampleBackend::generatedNewData, [=](double* data, int size) { ui.waterfallPlot->appendData(data, size); }); + connect(ui.waterfallPlot, &WaterfallPlot::copyingCompleted, &backend, &ExampleBackend::copyingCompleted); } MainWindow::~MainWindow() -{} +{ +} void MainWindow::initializePlot() { @@ -118,7 +126,10 @@ void MainWindow::initializeWaterfall() ui.waterfallPlot->setBackground(Qt::black); ui.waterfallPlot->setFillColor(Qt::black); - ui.waterfallPlot->setAppendHeight(5); + ui.waterfallPlot->setAppendHeight(3); + ui.waterfallPlot->setAppendSide(EAS_Top); + ui.waterfallPlot->setResolution(512, 512); + ui.waterfallPlot->setFPSLimit(30); QCPTextElement* chartSpectrRuntimeText = new QCPTextElement(ui.waterfallPlot); chartSpectrRuntimeText->setText("Waterfall"); diff --git a/ExampleProject/Frontend/MainWindow/MainWindow.h b/ExampleProject/Frontend/MainWindow/MainWindow.h index 3c8a2a7..1a4f5d4 100644 --- a/ExampleProject/Frontend/MainWindow/MainWindow.h +++ b/ExampleProject/Frontend/MainWindow/MainWindow.h @@ -2,6 +2,11 @@ #include #include "ui_MainWindow.h" +#include "Backend/ExampleBackend.h" + + +class ExampleBackend; + class MainWindow : public QMainWindow { @@ -15,6 +20,9 @@ class MainWindow : public QMainWindow void initializePlot(); void initializeWaterfall(); +signals: + private: Ui::MainWindowClass ui; + ExampleBackend backend; }; diff --git a/ExampleProject/main.cpp b/ExampleProject/main.cpp index e0cec93..8db6310 100644 --- a/ExampleProject/main.cpp +++ b/ExampleProject/main.cpp @@ -1,12 +1,16 @@ #include #include "Frontend/MainWindow/MainWindow.h" +#include "Backend/ExampleBackend.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - QApplication a(argc, argv); - MainWindow w; + QApplication app(argc, argv); + MainWindow w; + + w.setWindowTitle("QtPlot Example"); w.show(); - return a.exec(); + + return app.exec(); } diff --git a/QtPlot/QtPlot.vcxproj b/QtPlot/QtPlot.vcxproj index b4a710c..184acf7 100644 --- a/QtPlot/QtPlot.vcxproj +++ b/QtPlot/QtPlot.vcxproj @@ -100,7 +100,7 @@ - + diff --git a/QtPlot/QtPlot.vcxproj.filters b/QtPlot/QtPlot.vcxproj.filters index efd5403..4a5acee 100644 --- a/QtPlot/QtPlot.vcxproj.filters +++ b/QtPlot/QtPlot.vcxproj.filters @@ -59,9 +59,6 @@ Header Files\Library - - Header Files\Waterfall - Header Files @@ -135,5 +132,8 @@ Header Files\Waterfall + + Header Files\Waterfall + \ No newline at end of file diff --git a/QtPlot/Waterfall/Waterfall.cpp b/QtPlot/Waterfall/Waterfall.cpp index 9f148b1..abb2c9f 100644 --- a/QtPlot/Waterfall/Waterfall.cpp +++ b/QtPlot/Waterfall/Waterfall.cpp @@ -21,6 +21,8 @@ WaterfallPlot::WaterfallPlot(QWidget* parent) loadThread->stopAndClear(); loadThread->setWaterfallContent(content); loadThread->start(); + + connect(loadThread, &WaterfallThread::copyingCompleted, [=]() { emit copyingCompleted(); }); } WaterfallPlot::~WaterfallPlot() diff --git a/QtPlot/Waterfall/Waterfall.h b/QtPlot/Waterfall/Waterfall.h index 77f2257..2eee2f1 100644 --- a/QtPlot/Waterfall/Waterfall.h +++ b/QtPlot/Waterfall/Waterfall.h @@ -9,6 +9,8 @@ class WfColorMap; class QTPLOT_EXPORT WaterfallPlot : public QtPlot { + Q_OBJECT + public: explicit WaterfallPlot(QWidget* parent); ~WaterfallPlot() override; @@ -27,6 +29,9 @@ class QTPLOT_EXPORT WaterfallPlot : public QtPlot void setInterval(int minval, int maxval) const; void setFillColor(const QColor& fillColor) const; +signals: + void copyingCompleted(); + private: WaterfallThread* loadThread; WaterfallContent* content; diff --git a/QtPlot/Waterfall/WaterfallThread.cpp b/QtPlot/Waterfall/WaterfallThread.cpp index 5b327ad..361f248 100644 --- a/QtPlot/Waterfall/WaterfallThread.cpp +++ b/QtPlot/Waterfall/WaterfallThread.cpp @@ -48,7 +48,7 @@ void WaterfallThread::run() if (bIsQuit) return; - if (content) + if (content) { content->append(data, size); emit update(); @@ -99,7 +99,7 @@ void WaterfallThread::addData(double* inData, int inSize) if(data) { - memcpy(inData, data, size); + memcpy(data, inData, size * sizeof(double)); } emit copyingCompleted();