add Canvas, try to make a hostorgam class

This commit is contained in:
splitPoleDAQ 2023-05-17 17:40:32 -04:00
parent 2db8f90ae6
commit a3deb59e0c
7 changed files with 179 additions and 7 deletions

View File

@ -150,6 +150,7 @@
"cinttypes": "cpp", "cinttypes": "cpp",
"typeinfo": "cpp", "typeinfo": "cpp",
"variant": "cpp", "variant": "cpp",
"qmainwindow": "cpp" "qmainwindow": "cpp",
"qchartview": "cpp"
} }
} }

81
CanvasClass.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "CanvasClass.h"
#include <QValueAxis>
#include <QRandomGenerator>
#include <QGroupBox>
#include <QStandardItemModel>
#include <QLabel>
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<int> 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<int>((xMax - xMin) / binSize) + 1;
// Create a bar series
barSeries = new QBarSeries();
// Create a histogram data array with the number of bins
QVector<int> histogramData(numBins, 0);
// Calculate the histogram bin counts
for (double value : data) {
int binIndex = static_cast<int>((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(){
}

58
CanvasClass.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef CANVAS_H
#define CANVAS_H
#include <QMainWindow>
#include <QChart>
#include <QChartView>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QLineSeries>
#include <QRubberBand>
#include <QMouseEvent>
#include <QGestureEvent>
#include "macro.h"
#include "ClassDigitizer.h"
#include "CustomThreads.h"
#include "CustomWidgets.h"
#include <QWidget>
#include <QChart>
#include <QChartView>
#include <QBarSeries>
#include <QBarSet>
#include <QBarCategoryAxis>
//^====================================================
//^====================================================
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

View File

@ -14,7 +14,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QGestureEvent> #include <QGestureEvent>
//^======================================= //^====================================================
class RSpinBox : public QDoubleSpinBox{ class RSpinBox : public QDoubleSpinBox{
Q_OBJECT Q_OBJECT
public : public :
@ -46,7 +46,7 @@ class RSpinBox : public QDoubleSpinBox{
} }
}; };
//^======================================= //^====================================================
class RComboBox : public QComboBox{ class RComboBox : public QComboBox{
public : public :
RComboBox(QWidget * parent = nullptr): QComboBox(parent){ RComboBox(QWidget * parent = nullptr): QComboBox(parent){
@ -163,6 +163,8 @@ private:
QLabel * m_coordinateLabel; QLabel * m_coordinateLabel;
}; };
//^====================================================
#endif #endif

View File

@ -12,8 +12,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QScrollArea> #include <QScrollArea>
#include <TH1.h>
#include "CustomWidgets.h" #include "CustomWidgets.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
@ -27,6 +25,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
scalar = nullptr; scalar = nullptr;
scope = nullptr; scope = nullptr;
digiSettings = nullptr; digiSettings = nullptr;
canvas = nullptr;
QWidget * mainLayoutWidget = new QWidget(this); QWidget * mainLayoutWidget = new QWidget(this);
setCentralWidget(mainLayoutWidget); setCentralWidget(mainLayoutWidget);
@ -54,6 +53,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
layout->addWidget(bnDigiSettings, 1, 1); layout->addWidget(bnDigiSettings, 1, 1);
connect(bnDigiSettings, &QPushButton::clicked, this, &MainWindow::OpenDigiSettings); 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 {//^====================== ACQ control
@ -176,6 +179,8 @@ MainWindow::~MainWindow(){
if( digiSettings ) delete digiSettings; if( digiSettings ) delete digiSettings;
if( canvas ) delete canvas;
if( scalar ) { if( scalar ) {
CleanUpScalar(); CleanUpScalar();
scalarThread->Stop(); 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){ void MainWindow::LogMsg(QString msg){

View File

@ -15,6 +15,7 @@
#include "CustomThreads.h" #include "CustomThreads.h"
#include "Scope.h" #include "Scope.h"
#include "DigiSettingsPanel.h" #include "DigiSettingsPanel.h"
#include "CanvasClass.h"
//^#===================================================== MainWindow //^#===================================================== MainWindow
class MainWindow : public QMainWindow{ class MainWindow : public QMainWindow{
@ -26,6 +27,7 @@ public:
void closeEvent(QCloseEvent * event){ void closeEvent(QCloseEvent * event){
if( scope ) scope->close(); if( scope ) scope->close();
if( digiSettings ) digiSettings->close(); if( digiSettings ) digiSettings->close();
if( canvas ) canvas->close();
event->accept(); event->accept();
} }
@ -56,6 +58,8 @@ private slots:
void OpenDigiSettings(); void OpenDigiSettings();
void OpenCanvas();
private: private:
Digitizer ** digi; Digitizer ** digi;
@ -76,6 +80,8 @@ private:
QPushButton * bnStartACQ; QPushButton * bnStartACQ;
QPushButton * bnStopACQ; QPushButton * bnStopACQ;
QPushButton * bnCanvas;
//@----- log msg //@----- log msg
QPlainTextEdit * logInfo; QPlainTextEdit * logInfo;
void LogMsg(QString msg); void LogMsg(QString msg);
@ -111,6 +117,9 @@ private:
//@----- DigiSettings //@----- DigiSettings
DigiSettingsPanel * digiSettings; DigiSettingsPanel * digiSettings;
//@----- Canvas
Canvas * canvas;
}; };

View File

@ -27,9 +27,11 @@ HEADERS += ClassData.h \
FSUDAQ.h \ FSUDAQ.h \
macro.h \ macro.h \
RegisterAddress.h \ RegisterAddress.h \
Scope.h Scope.h \
CanvasClass.h
SOURCES += ClassDigitizer.cpp \ SOURCES += ClassDigitizer.cpp \
DigiSettingsPanel.cpp \ DigiSettingsPanel.cpp \
FSUDAQ.cpp \ FSUDAQ.cpp \
main.cpp \ main.cpp \
Scope.cpp Scope.cpp \
CanvasClass.cpp