completed
This commit is contained in:
7
src/icons.qrc
Normal file
7
src/icons.qrc
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>icons/media-playback-pause.png</file>
|
||||||
|
<file>icons/media-playback-start.png</file>
|
||||||
|
<file>icons/media-playback-stop.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
BIN
src/icons/media-playback-pause.png
Normal file
BIN
src/icons/media-playback-pause.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/icons/media-playback-start.png
Normal file
BIN
src/icons/media-playback-start.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/icons/media-playback-stop.png
Normal file
BIN
src/icons/media-playback-stop.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -1,14 +1,57 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "qt5/ui_mainwindow.h"
|
||||||
|
#include "pointgenerator.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
|
||||||
QMainWindow(parent),
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||||
ui(new Ui::MainWindow)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
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<QPointF> 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()
|
|
||||||
{
|
MainWindow::~MainWindow() {
|
||||||
|
stopGenerator();
|
||||||
|
delete generator;
|
||||||
delete ui;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,20 +3,30 @@
|
|||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
class PointGenerator;
|
||||||
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_buttonStart_clicked();
|
||||||
|
void on_buttonStop_clicked();
|
||||||
|
void on_buttonPause_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void stopGenerator();
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
PointGenerator * generator;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<author/>
|
|
||||||
<comment/>
|
|
||||||
<exportmacro/>
|
|
||||||
<class>MainWindow</class>
|
<class>MainWindow</class>
|
||||||
<widget name="MainWindow" class="QMainWindow">
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@@ -13,12 +11,110 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>Strata Solutions Test</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="Graphic" name="graphic">
|
||||||
|
<property name="graphicPointWidth">
|
||||||
|
<double>4.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="graphicPointsEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="buttons">
|
||||||
|
<set>Graphic::Autofit|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Save</set>
|
||||||
|
</property>
|
||||||
|
<property name="antialiasing">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="statusVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="historySize">
|
||||||
|
<double>-1.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<widget name="menubar" class="QMenuBar"/>
|
|
||||||
<widget name="centralwidget" class="QWidget"/>
|
|
||||||
<widget name="statusbar" class="QStatusBar"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<pixmapfunction/>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonStart">
|
||||||
|
<property name="text">
|
||||||
|
<string>Start</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="icons.qrc">
|
||||||
|
<normaloff>:/icons/media-playback-start.png</normaloff>:/icons/media-playback-start.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonPause">
|
||||||
|
<property name="text">
|
||||||
|
<string>Pause</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="icons.qrc">
|
||||||
|
<normaloff>:/icons/media-playback-pause.png</normaloff>:/icons/media-playback-pause.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonStop">
|
||||||
|
<property name="text">
|
||||||
|
<string>Stop</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="icons.qrc">
|
||||||
|
<normaloff>:/icons/media-playback-stop.png</normaloff>:/icons/media-playback-stop.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>Graphic</class>
|
||||||
|
<extends>QFrame</extends>
|
||||||
|
<header>graphic.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources>
|
||||||
|
<include location="icons.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
50
src/pointgenerator.h
Normal file
50
src/pointgenerator.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#ifndef POINTGENERATOR_H
|
||||||
|
#define POINTGENERATOR_H
|
||||||
|
#include <QThread>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
|
||||||
|
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<QPointF> 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<QPointF> points);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // POINTGENERATOR_H
|
||||||
Reference in New Issue
Block a user