From a3deb59e0c884f3e602dd9a33f1c5c3e3a6c654a Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Wed, 17 May 2023 17:40:32 -0400 Subject: [PATCH] add Canvas, try to make a hostorgam class --- .vscode/settings.json | 3 +- CanvasClass.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ CanvasClass.h | 58 +++++++++++++++++++++++++++++++ CustomWidgets.h | 6 ++-- FSUDAQ.cpp | 23 ++++++++++-- FSUDAQ.h | 9 +++++ FSUDAQ_Qt6.pro | 6 ++-- 7 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 CanvasClass.cpp create mode 100644 CanvasClass.h diff --git a/.vscode/settings.json b/.vscode/settings.json index e4d19a5..0378a2e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -150,6 +150,7 @@ "cinttypes": "cpp", "typeinfo": "cpp", "variant": "cpp", - "qmainwindow": "cpp" + "qmainwindow": "cpp", + "qchartview": "cpp" } } \ No newline at end of file diff --git a/CanvasClass.cpp b/CanvasClass.cpp new file mode 100644 index 0000000..c8b98ad --- /dev/null +++ b/CanvasClass.cpp @@ -0,0 +1,81 @@ +#include "CanvasClass.h" + +#include +#include +#include +#include +#include + +Canvas::Canvas(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent) : QMainWindow(parent){ + + this->digi = digi; + this->nDigi = nDigi; + this->readDataThread = readDataThread; + + setWindowTitle("Canvas"); + setGeometry(0, 0, 1000, 800); + //setWindowFlags( this->windowFlags() & ~Qt::WindowCloseButtonHint ); + + + QVector data = {1, 1, 2, 2, 3, 1, 2, 4, 5, 6, 5, 3, 4, 1, 3}; + double xMax = 5; + double xMin = -1; + double binSize = 0.5; + + // Calculate the number of bins based on the X-axis range and bin size + int numBins = static_cast((xMax - xMin) / binSize) + 1; + + // Create a bar series + barSeries = new QBarSeries(); + + // Create a histogram data array with the number of bins + QVector histogramData(numBins, 0); + + // Calculate the histogram bin counts + for (double value : data) { + int binIndex = static_cast((value - xMin) / binSize); + if (binIndex >= 0 && binIndex < numBins) { + histogramData[binIndex]++; + } + } + + // Create bar sets and add them to the series + for (int i = 0; i < numBins; ++i) { + double binStart = xMin + i * binSize; + double binEnd = binStart + binSize; + QString binLabel = QString("%1-%2").arg(binStart).arg(binEnd); + + QBarSet *barSet = new QBarSet(binLabel); + *barSet << histogramData[i]; + barSeries->append(barSet); + } + + // Create the chart and set the series + chart = new QChart(); + chart->addSeries(barSeries); + + // Create the X-axis category axis + axisX = new QBarCategoryAxis(); + chart->setAxisX(axisX, barSeries); + + // Create category labels for the bins + QStringList categories; + for (int i = 0; i < numBins; ++i) { + double binStart = xMin + i * binSize; + double binEnd = binStart + binSize; + QString binLabel = QString("%1-%2").arg(binStart).arg(binEnd); + categories.append(binLabel); + axisX->append(binLabel); + } + + // Create a chart view and set the chart + chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + + // Set the chart view as the main widget + setCentralWidget(chartView); +} + +Canvas::~Canvas(){ + +} \ No newline at end of file diff --git a/CanvasClass.h b/CanvasClass.h new file mode 100644 index 0000000..0ec64f8 --- /dev/null +++ b/CanvasClass.h @@ -0,0 +1,58 @@ +#ifndef CANVAS_H +#define CANVAS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "macro.h" +#include "ClassDigitizer.h" +#include "CustomThreads.h" +#include "CustomWidgets.h" + + +#include +#include +#include +#include +#include +#include + + +//^==================================================== +//^==================================================== +class Canvas : public QMainWindow{ + Q_OBJECT + +public: + Canvas(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent = nullptr); + ~Canvas(); + + +private: + + Digitizer ** digi; + unsigned short nDigi; + ReadDataThread ** readDataThread; + + QChartView *chartView; + QChart *chart; + QBarSeries *barSeries; + QBarCategoryAxis *axisX; + +}; + + +#endif \ No newline at end of file diff --git a/CustomWidgets.h b/CustomWidgets.h index 3162368..801d407 100644 --- a/CustomWidgets.h +++ b/CustomWidgets.h @@ -14,7 +14,7 @@ #include #include -//^======================================= +//^==================================================== class RSpinBox : public QDoubleSpinBox{ Q_OBJECT public : @@ -46,7 +46,7 @@ class RSpinBox : public QDoubleSpinBox{ } }; -//^======================================= +//^==================================================== class RComboBox : public QComboBox{ public : RComboBox(QWidget * parent = nullptr): QComboBox(parent){ @@ -163,6 +163,8 @@ private: QLabel * m_coordinateLabel; }; +//^==================================================== + #endif \ No newline at end of file diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index ad08023..049d6e0 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -12,8 +12,6 @@ #include #include -#include - #include "CustomWidgets.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ @@ -27,6 +25,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ scalar = nullptr; scope = nullptr; digiSettings = nullptr; + canvas = nullptr; QWidget * mainLayoutWidget = new QWidget(this); setCentralWidget(mainLayoutWidget); @@ -54,6 +53,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ layout->addWidget(bnDigiSettings, 1, 1); connect(bnDigiSettings, &QPushButton::clicked, this, &MainWindow::OpenDigiSettings); + bnCanvas = new QPushButton("Canvas", this); + layout->addWidget(bnCanvas, 2, 0); + connect(bnCanvas, &QPushButton::clicked, this, &MainWindow::OpenCanvas); + } {//^====================== ACQ control @@ -176,6 +179,8 @@ MainWindow::~MainWindow(){ if( digiSettings ) delete digiSettings; + if( canvas ) delete canvas; + if( scalar ) { CleanUpScalar(); scalarThread->Stop(); @@ -818,6 +823,20 @@ void MainWindow::OpenDigiSettings(){ } +//*************************************************************** +//*************************************************************** +void MainWindow::OpenCanvas(){ + + if( canvas == nullptr ) { + canvas = new Canvas(digi, nDigi, readDataThread); + canvas->show(); + }else{ + canvas->show(); + canvas->activateWindow(); + } + +} + //*************************************************************** //*************************************************************** void MainWindow::LogMsg(QString msg){ diff --git a/FSUDAQ.h b/FSUDAQ.h index 625a43c..fec7587 100644 --- a/FSUDAQ.h +++ b/FSUDAQ.h @@ -15,6 +15,7 @@ #include "CustomThreads.h" #include "Scope.h" #include "DigiSettingsPanel.h" +#include "CanvasClass.h" //^#===================================================== MainWindow class MainWindow : public QMainWindow{ @@ -26,6 +27,7 @@ public: void closeEvent(QCloseEvent * event){ if( scope ) scope->close(); if( digiSettings ) digiSettings->close(); + if( canvas ) canvas->close(); event->accept(); } @@ -56,6 +58,8 @@ private slots: void OpenDigiSettings(); + void OpenCanvas(); + private: Digitizer ** digi; @@ -76,6 +80,8 @@ private: QPushButton * bnStartACQ; QPushButton * bnStopACQ; + QPushButton * bnCanvas; + //@----- log msg QPlainTextEdit * logInfo; void LogMsg(QString msg); @@ -111,6 +117,9 @@ private: //@----- DigiSettings DigiSettingsPanel * digiSettings; + //@----- Canvas + Canvas * canvas; + }; diff --git a/FSUDAQ_Qt6.pro b/FSUDAQ_Qt6.pro index a8eded2..9f4062a 100644 --- a/FSUDAQ_Qt6.pro +++ b/FSUDAQ_Qt6.pro @@ -27,9 +27,11 @@ HEADERS += ClassData.h \ FSUDAQ.h \ macro.h \ RegisterAddress.h \ - Scope.h + Scope.h \ + CanvasClass.h SOURCES += ClassDigitizer.cpp \ DigiSettingsPanel.cpp \ FSUDAQ.cpp \ main.cpp \ - Scope.cpp + Scope.cpp \ + CanvasClass.cpp