diff --git a/src/icons.qrc b/src/icons.qrc
new file mode 100644
index 0000000..3184676
--- /dev/null
+++ b/src/icons.qrc
@@ -0,0 +1,7 @@
+
+
+ icons/media-playback-pause.png
+ icons/media-playback-start.png
+ icons/media-playback-stop.png
+
+
diff --git a/src/icons/media-playback-pause.png b/src/icons/media-playback-pause.png
new file mode 100644
index 0000000..5c7d128
Binary files /dev/null and b/src/icons/media-playback-pause.png differ
diff --git a/src/icons/media-playback-start.png b/src/icons/media-playback-start.png
new file mode 100644
index 0000000..7190685
Binary files /dev/null and b/src/icons/media-playback-start.png differ
diff --git a/src/icons/media-playback-stop.png b/src/icons/media-playback-stop.png
new file mode 100644
index 0000000..650874f
Binary files /dev/null and b/src/icons/media-playback-stop.png differ
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 49d64fc..a94f894 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,14 +1,57 @@
#include "mainwindow.h"
-#include "ui_mainwindow.h"
+#include "qt5/ui_mainwindow.h"
+#include "pointgenerator.h"
-MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
-{
- ui->setupUi(this);
+
+MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
+ ui->setupUi(this);
+ ui->buttonPause->setEnabled(false);
+ ui->buttonStart->setEnabled(true);
+ ui->buttonStop->setEnabled(false);
+ generator = new PointGenerator();
+ connect(generator, &PointGenerator::newPoints, this, [this](QVector points){
+ if (generator->isRunning() && !generator->isPause()) ui->graphic->setGraphicData(points);
+ }, Qt::QueuedConnection);
+ connect(generator, &PointGenerator::finished, this, [this](){
+ ui->graphic->clear();
+ ui->graphic->update(true);
+ });
}
-MainWindow::~MainWindow()
-{
- delete ui;
+
+MainWindow::~MainWindow() {
+ stopGenerator();
+ delete generator;
+ delete ui;
+}
+
+
+void MainWindow::on_buttonStart_clicked() {
+ if (!generator->isRunning()) generator->start();
+ ui->buttonPause->setEnabled(true);
+ ui->buttonStart->setEnabled(false);
+ ui->buttonStop->setEnabled(true);
+}
+
+
+void MainWindow::on_buttonStop_clicked() {
+ stopGenerator();
+ ui->buttonPause->setEnabled(false);
+ ui->buttonStart->setEnabled(true);
+ ui->buttonStop->setEnabled(false);
+}
+
+
+void MainWindow::on_buttonPause_clicked() {
+ if (generator->isPause()) generator->resume();
+ else generator->pause();
+ ui->graphic->update(true);
+}
+
+
+void MainWindow::stopGenerator() {
+ generator->requestInterruption();
+ if (generator->isPause()) generator->resume();
+ generator->wait();
+ ui->buttonPause->setChecked(false);
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9353441..6469f7f 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -3,20 +3,30 @@
#include
+
namespace Ui {
class MainWindow;
}
+class PointGenerator;
+
class MainWindow : public QMainWindow
{
- Q_OBJECT
-
+ Q_OBJECT
public:
- explicit MainWindow(QWidget *parent = nullptr);
- ~MainWindow();
+ explicit MainWindow(QWidget *parent = nullptr);
+ ~MainWindow();
+
+private slots:
+ void on_buttonStart_clicked();
+ void on_buttonStop_clicked();
+ void on_buttonPause_clicked();
private:
- Ui::MainWindow *ui;
+ void stopGenerator();
+
+ Ui::MainWindow *ui;
+ PointGenerator * generator;
};
#endif // MAINWINDOW_H
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 0a06936..8d60ce5 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -1,9 +1,7 @@
+
-
-
-
MainWindow
-
+
0
@@ -13,12 +11,110 @@
- MainWindow
+ Strata Solutions Test
-
-
-
+
+
+ -
+
+
+ 4.000000000000000
+
+
+ true
+
+
+ Graphic::Autofit|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Save
+
+
+ true
+
+
+ false
+
+
+ -1.000000000000000
+
+
+
+ -
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Start
+
+
+
+ :/icons/media-playback-start.png:/icons/media-playback-start.png
+
+
+
+ -
+
+
+ Pause
+
+
+
+ :/icons/media-playback-pause.png:/icons/media-playback-pause.png
+
+
+ true
+
+
+
+ -
+
+
+ Stop
+
+
+
+ :/icons/media-playback-stop.png:/icons/media-playback-stop.png
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+
+
-
+
+
+ Graphic
+ QFrame
+
+
+
+
+
+
diff --git a/src/pointgenerator.h b/src/pointgenerator.h
new file mode 100644
index 0000000..591da9e
--- /dev/null
+++ b/src/pointgenerator.h
@@ -0,0 +1,50 @@
+#ifndef POINTGENERATOR_H
+#define POINTGENERATOR_H
+#include
+#include
+#include
+#include
+
+
+class PointGenerator : public QThread {
+ Q_OBJECT
+public:
+ void pause() {
+ mutex_pause.lock();
+ is_pause = true;
+ }
+
+ void resume() {
+ is_pause = false;
+ mutex_pause.unlock();
+ }
+
+ bool isPause() const {return is_pause;}
+
+private:
+ void run() override {
+ is_pause = false;
+ while(!isInterruptionRequested()) {
+ QThread::msleep(1);
+ QVector v;
+ v.resize(100);
+ for (QPointF & p : v) {
+ p = QPointF(QRandomGenerator::global()->generateDouble(),
+ QRandomGenerator::global()->generateDouble());
+ }
+ emit newPoints(v);
+ if (is_pause) {
+ mutex_pause.lock();
+ mutex_pause.unlock();
+ }
+ }
+ }
+
+ QMutex mutex_pause;
+ std::atomic_bool is_pause;
+
+signals:
+ void newPoints(QVector points);
+};
+
+#endif // POINTGENERATOR_H