1st working demo
This commit is contained in:
parent
5e8455c8a2
commit
60cef3cb54
@ -13,7 +13,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef bool (*start_t)();
|
typedef bool (*start_t)();
|
||||||
typedef void (*destroy_t)();
|
typedef void (*destroy_t)();
|
||||||
typedef void (*update_callback_t)(unsigned int chartIndex, const char* seriesName, const point_t* points);
|
typedef void (*update_callback_t)(unsigned int chartIndex, const char* seriesName, const point_t* points, int count);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
|
@ -16,10 +16,14 @@ class ChartWidget : public QListWidgetItem {
|
|||||||
QChartView* getView() const { return view; }
|
QChartView* getView() const { return view; }
|
||||||
QChart* getChart() const { return chart; }
|
QChart* getChart() const { return chart; }
|
||||||
QList<QAbstractSeries*> getSeries() const { return chart->series(); }
|
QList<QAbstractSeries*> getSeries() const { return chart->series(); }
|
||||||
|
QValueAxis* getX() const { return x; }
|
||||||
|
QValueAxis* getY() const { return y; }
|
||||||
|
const chart_spec_t& getSpec() const { return spec; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QChartView* view;
|
QChartView* view;
|
||||||
QChart* chart;
|
QChart* chart;
|
||||||
QValueAxis *x, *y;
|
QValueAxis *x, *y;
|
||||||
|
chart_spec_t spec;
|
||||||
};
|
};
|
||||||
} // namespace Graph::GUI
|
} // namespace Graph::GUI
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <graph/server/gui/chart/chart.h>
|
||||||
#include <graph/server/plugin.h>
|
#include <graph/server/plugin.h>
|
||||||
#include <qlineseries.h>
|
|
||||||
#include <qlistwidget.h>
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "graph/server/gui/chart/chart.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -17,10 +15,19 @@ class MainWindow;
|
|||||||
namespace Graph::GUI {
|
namespace Graph::GUI {
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
private:
|
||||||
explicit MainWindow(QWidget* parent = nullptr);
|
explicit MainWindow(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWindow(MainWindow& other) = delete;
|
||||||
|
void operator=(const MainWindow&) = delete;
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
static MainWindow* getInstance();
|
||||||
|
static void close();
|
||||||
|
|
||||||
|
void addData(unsigned int chartIndex, const char* seriesName, const point_t* points, int count);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_action_Add_triggered();
|
void on_action_Add_triggered();
|
||||||
void on_action_Load_triggered();
|
void on_action_Load_triggered();
|
||||||
|
@ -32,6 +32,7 @@ class PluginModel : public QAbstractListModel {
|
|||||||
|
|
||||||
void add(Plugin* plugin);
|
void add(Plugin* plugin);
|
||||||
void remove(int index);
|
void remove(int index);
|
||||||
|
QList<Plugin*>& getPlugins() { return plugins; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Plugin*> plugins;
|
QList<Plugin*> plugins;
|
||||||
|
@ -14,12 +14,11 @@ bool init() {
|
|||||||
std::cout << "init" << std::endl;
|
std::cout << "init" << std::endl;
|
||||||
point_t points[100];
|
point_t points[100];
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
double deg = i*360/100.0;
|
points[i].x = i;
|
||||||
points[i].x = deg;
|
points[i].y = i;
|
||||||
points[i].y = sin(to_rad(deg));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.update_callback(0, "1st", points);
|
plugin.update_callback(0, "1st", points, 100);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace Graph::GUI {
|
namespace Graph::GUI {
|
||||||
ChartWidget::ChartWidget(QWidget* parent, const chart_spec_t& spec) : QListWidgetItem() {
|
ChartWidget::ChartWidget(QWidget* parent, const chart_spec_t& spec) : QListWidgetItem(), spec(spec) {
|
||||||
view = new QChartView(parent);
|
view = new QChartView(parent);
|
||||||
chart = new QChart();
|
chart = new QChart();
|
||||||
|
|
||||||
@ -30,9 +30,10 @@ ChartWidget::ChartWidget(QWidget* parent, const chart_spec_t& spec) : QListWidge
|
|||||||
chart->addAxis(x, Qt::AlignBottom);
|
chart->addAxis(x, Qt::AlignBottom);
|
||||||
chart->addAxis(y, Qt::AlignLeft);
|
chart->addAxis(y, Qt::AlignLeft);
|
||||||
|
|
||||||
|
view->setRenderHint(QPainter::Antialiasing);
|
||||||
view->setChart(chart);
|
view->setChart(chart);
|
||||||
view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
setSizeHint(view->sizeHint()*2);
|
setSizeHint(view->sizeHint() * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChartWidget::~ChartWidget() {
|
ChartWidget::~ChartWidget() {
|
||||||
|
@ -9,7 +9,62 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#define MIN(a, b) (a < b ? a : b)
|
||||||
|
#define MAX(a, b) (a > b ? a : b)
|
||||||
|
|
||||||
namespace Graph::GUI {
|
namespace Graph::GUI {
|
||||||
|
MainWindow* instance = nullptr;
|
||||||
|
|
||||||
|
MainWindow* MainWindow::getInstance() {
|
||||||
|
if (!instance)
|
||||||
|
instance = new MainWindow();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::close() {
|
||||||
|
if (instance)
|
||||||
|
delete instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addData(unsigned int chartIndex, const char* seriesName, const point_t* points, int count) {
|
||||||
|
MainWindow::getInstance()->addData(chartIndex, seriesName, points, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addData(unsigned int chartIndex, const char* seriesName, const point_t* points, int count) {
|
||||||
|
if (chartIndex < 0 || chartIndex >= charts.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString name(seriesName);
|
||||||
|
|
||||||
|
ChartWidget* chart = charts[chartIndex];
|
||||||
|
|
||||||
|
double minX = std::numeric_limits<double>::max(), maxX = std::numeric_limits<double>::min();
|
||||||
|
double minY = std::numeric_limits<double>::max(), maxY = std::numeric_limits<double>::min();
|
||||||
|
|
||||||
|
for (QAbstractSeries* series : chart->getSeries()) {
|
||||||
|
if (series->name() == name) {
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
*((QLineSeries*)series) << QPointF(points[i].x, points[i].y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (QPointF point : ((QLineSeries*)series)->points()) {
|
||||||
|
minX = MIN(minX, point.x());
|
||||||
|
maxX = MAX(maxX, point.x());
|
||||||
|
minY = MIN(minY, point.y());
|
||||||
|
maxY = MAX(maxY, point.y());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chart->getSpec().axis.x.auto_limit)
|
||||||
|
chart->getX()->setRange(minX, maxX);
|
||||||
|
if (chart->getSpec().axis.y.auto_limit)
|
||||||
|
chart->getY()->setRange(minY, maxY);
|
||||||
|
|
||||||
|
chart->getView()->update();
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -44,6 +99,8 @@ void MainWindow::on_action_Add_triggered() {
|
|||||||
|
|
||||||
ChartWidget* chart = new ChartWidget(ui->graphsListWidget, dialog.getSpec());
|
ChartWidget* chart = new ChartWidget(ui->graphsListWidget, dialog.getSpec());
|
||||||
|
|
||||||
|
charts.push_back(chart);
|
||||||
|
|
||||||
ui->graphsListWidget->addItem(chart);
|
ui->graphsListWidget->addItem(chart);
|
||||||
ui->graphsListWidget->setItemWidget(chart, chart->getView());
|
ui->graphsListWidget->setItemWidget(chart, chart->getView());
|
||||||
|
|
||||||
@ -51,8 +108,9 @@ void MainWindow::on_action_Add_triggered() {
|
|||||||
QLineSeries* series = new QLineSeries();
|
QLineSeries* series = new QLineSeries();
|
||||||
series->setName(title);
|
series->setName(title);
|
||||||
chart->getChart()->addSeries(series);
|
chart->getChart()->addSeries(series);
|
||||||
|
for (QAbstractAxis* axis : chart->getChart()->axes()) {
|
||||||
*series << QPointF(0, 1) << QPointF(1, 2) << QPoint(2, 3);
|
series->attachAxis(axis);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +122,7 @@ void MainWindow::on_action_Load_triggered() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Plugin* plugin = new Plugin(file.toStdString());
|
Plugin* plugin = new Plugin(file.toStdString());
|
||||||
// plugin->init(update_callback);
|
plugin->init(&Graph::GUI::addData);
|
||||||
pluginModel->add(plugin);
|
pluginModel->add(plugin);
|
||||||
} catch (std::runtime_error e) {
|
} catch (std::runtime_error e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
Graph::GUI::MainWindow window;
|
Graph::GUI::MainWindow::getInstance()->show();
|
||||||
window.show();
|
int result = app.exec();
|
||||||
|
Graph::GUI::MainWindow::close();
|
||||||
return app.exec();
|
return result;
|
||||||
}
|
}
|
@ -17,10 +17,10 @@ Plugin::Plugin(const std::string& path) : path(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Plugin::~Plugin() {
|
Plugin::~Plugin() {
|
||||||
if (this->plugin->update_callback)
|
if (this->plugin->destroy_method)
|
||||||
this->plugin->destroy_method();
|
this->plugin->destroy_method();
|
||||||
|
|
||||||
if (this->handle)
|
if (handle)
|
||||||
dlclose((void*)this->handle);
|
dlclose((void*)this->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user