diff --git a/inc/graph/plugins/plugin.h b/inc/graph/plugins/plugin.h index 8d5499d..95760f9 100644 --- a/inc/graph/plugins/plugin.h +++ b/inc/graph/plugins/plugin.h @@ -1,14 +1,22 @@ #pragma once +#ifdef __cplusplus #include +#else +#include +#endif -typedef bool (*init_t)(); +typedef struct { + double x, y; +} point_t; + +typedef bool (*start_t)(); typedef void (*destroy_t)(); -typedef void (*update_callback_t)(); +typedef void (*update_callback_t)(unsigned int chartIndex, const char* seriesName, const point_t* points); typedef struct { uint32_t version; - init_t init_method; + start_t init_method; destroy_t destroy_method; update_callback_t update_callback; } plugin_t; \ No newline at end of file diff --git a/inc/graph/server/gui/chart/chart.h b/inc/graph/server/gui/chart/chart.h index ddb819d..1c873ca 100644 --- a/inc/graph/server/gui/chart/chart.h +++ b/inc/graph/server/gui/chart/chart.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include diff --git a/inc/graph/server/gui/mainwindow.h b/inc/graph/server/gui/mainwindow.h index fc09188..8dae1c3 100644 --- a/inc/graph/server/gui/mainwindow.h +++ b/inc/graph/server/gui/mainwindow.h @@ -1,14 +1,14 @@ #pragma once +#include +#include +#include #include #include #include #include #include #include "graph/server/gui/chart/chart.h" -#include -#include -#include namespace Ui { class MainWindow; @@ -17,16 +17,16 @@ class MainWindow; namespace Graph::GUI { class MainWindow : public QMainWindow { Q_OBJECT -public: - explicit MainWindow(QWidget *parent = nullptr); + public: + explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); -private slots: + private slots: void on_action_Add_triggered(); void on_action_Load_triggered(); -private: - Ui::MainWindow *ui; + private: + Ui::MainWindow* ui; PluginModel* pluginModel; std::vector charts; diff --git a/inc/graph/server/gui/specdialog/specdialog.h b/inc/graph/server/gui/specdialog/specdialog.h new file mode 100644 index 0000000..a1d2bbd --- /dev/null +++ b/inc/graph/server/gui/specdialog/specdialog.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +namespace Ui { +class SpecDialog; +} + +namespace Graph::GUI { +class SpecDialog : public QDialog { + Q_OBJECT + public: + explicit SpecDialog(QWidget* parent = nullptr); + ~SpecDialog(); + + QStringList getList() const { return series->stringList(); } + chart_spec_t getSpec() const; + + private: + Ui::SpecDialog* ui; + + QStringListModel* series; +}; +} // namespace Graph::GUI diff --git a/src/graph/server/gui/mainwindow.cpp b/src/graph/server/gui/mainwindow.cpp index 0af40b2..0e320ae 100644 --- a/src/graph/server/gui/mainwindow.cpp +++ b/src/graph/server/gui/mainwindow.cpp @@ -1,15 +1,13 @@ +#include #include +#include #include +#include #include -#include -#include -#include #include #include #include #include -#include "graph/server/gui/chart/chart.h" -#include "graph/server/spec.h" namespace Graph::GUI { MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -40,17 +38,22 @@ MainWindow::~MainWindow() { } void MainWindow::on_action_Add_triggered() { - ChartWidget* chart = - new ChartWidget(ui->graphsListWidget, {.title = "My Title", .grid = true, .legend = true, .axis = {.x = {.label = "x axis"}, .y = {.label = "y axis"}}}); + SpecDialog dialog; + if (dialog.exec() == SpecDialog::Rejected) + return; + + ChartWidget* chart = new ChartWidget(ui->graphsListWidget, dialog.getSpec()); ui->graphsListWidget->addItem(chart); ui->graphsListWidget->setItemWidget(chart, chart->getView()); - QLineSeries* series = new QLineSeries(); - series->setName("some series"); - *series << QPointF(0, 1) << QPointF(1, 2) << QPoint(2, 3); + for (QString title : dialog.getList()) { + QLineSeries* series = new QLineSeries(); + series->setName(title); + chart->getChart()->addSeries(series); - chart->getChart()->addSeries(series); + *series << QPointF(0, 1) << QPointF(1, 2) << QPoint(2, 3); + } } void MainWindow::on_action_Load_triggered() { diff --git a/src/graph/server/gui/specdialog/specdialog.cpp b/src/graph/server/gui/specdialog/specdialog.cpp new file mode 100644 index 0000000..f065d3e --- /dev/null +++ b/src/graph/server/gui/specdialog/specdialog.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +namespace Graph::GUI { +SpecDialog::SpecDialog(QWidget* parent) : QDialog(parent), ui(new Ui::SpecDialog) { + ui->setupUi(this); + + series = new QStringListModel(this); + ui->seriesListView->setModel(series); + + ui->seriesListView->setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::DoubleClicked); + + connect(ui->addSeriesButton, &QPushButton::clicked, [&]() { + int row = series->rowCount(); + series->insertRow(row); + QModelIndex index = series->index(row); + ui->seriesListView->setCurrentIndex(index); + ui->seriesListView->edit(index); + }); + + connect(ui->removeSeriesButton, &QPushButton::clicked, [&]() { series->removeRow(ui->seriesListView->currentIndex().row()); }); +} + +SpecDialog::~SpecDialog() { + delete series; +} + +chart_spec_t SpecDialog::getSpec() const { + return { + .title = ui->chartTitle->text(), + .grid = (ui->grid->checkState() == Qt::Checked), + .legend = (ui->legend->checkState() == Qt::Checked), + .axis = { + .x = {.label = ui->xTitle->text(), .auto_limit = (ui->xAutoRange->checkState() == Qt::Checked), .min = ui->xMin->value(), .max = ui->xMax->value()}, + .y = {.label = ui->yTitle->text(), .auto_limit = (ui->yAutoRange->checkState() == Qt::Checked), .min = ui->yMin->value(), .max = ui->yMax->value()}}}; +} +} // namespace Graph::GUI \ No newline at end of file diff --git a/src/graph/server/gui/specdialog/specdialog.ui b/src/graph/server/gui/specdialog/specdialog.ui new file mode 100644 index 0000000..1a1dff4 --- /dev/null +++ b/src/graph/server/gui/specdialog/specdialog.ui @@ -0,0 +1,293 @@ + + + SpecDialog + + + + 0 + 0 + 302 + 372 + + + + + 0 + 0 + + + + Chart Specification + + + + + + Chart Title + + + + + + + 0 + + + + Series + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + Axis + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 0 + + + + + 16777215 + 16 + + + + X + + + + + + + Axis Title + + + + + + + Auto-Range + + + true + + + + + + + minimum + + + + + + + + <html><head/><body><p>maximum</p></body></html> + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 0 + + + + + 16777215 + 16 + + + + Y + + + + + + + Axis Title + + + + + + + Auto-Range + + + true + + + + + + + + <html><head/><body><p>minimum</p></body></html> + + + + + + + + <html><head/><body><p>maximum</p></body></html> + + + + + + + + + + + + 0 + 0 + + + + Display + + + + + + Legend + + + true + + + + + + + Grid + + + true + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SpecDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SpecDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +