add Canvas, try to make a hostorgam class
This commit is contained in:
parent
2db8f90ae6
commit
a3deb59e0c
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -150,6 +150,7 @@
|
|||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"qmainwindow": "cpp"
|
||||
"qmainwindow": "cpp",
|
||||
"qchartview": "cpp"
|
||||
}
|
||||
}
|
81
CanvasClass.cpp
Normal file
81
CanvasClass.cpp
Normal 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
58
CanvasClass.h
Normal 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
|
|
@ -14,7 +14,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QGestureEvent>
|
||||
|
||||
//^=======================================
|
||||
//^====================================================
|
||||
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
|
23
FSUDAQ.cpp
23
FSUDAQ.cpp
|
@ -12,8 +12,6 @@
|
|||
#include <QFileDialog>
|
||||
#include <QScrollArea>
|
||||
|
||||
#include <TH1.h>
|
||||
|
||||
#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){
|
||||
|
|
9
FSUDAQ.h
9
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user