2018-12-29 00:46:47 +08:00
|
|
|
#include "TestWidgetPeaksPlots.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestWidgetPeaksPlots::TestWidgetPeaksPlots(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2019-06-21 21:46:53 +08:00
|
|
|
QVBoxLayout* layoutpeaks=new QVBoxLayout();
|
2018-12-29 00:46:47 +08:00
|
|
|
setLayout(layoutpeaks);
|
|
|
|
resize(1000, 800);
|
2019-01-20 23:15:10 +08:00
|
|
|
plotPeaks=new JKQTPlotter(true, this);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotPeaks->setPlotUpdateEnabled(false);
|
|
|
|
plotPeaks->getPlotter()->setPlotLabel(tr("\\textbf{peaks stream plot}"));
|
2018-12-29 00:46:47 +08:00
|
|
|
plotPeaks->setObjectName("plotPeaks");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotPeaks->getPlotter()->setUserSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "plot_peaks/");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
QCheckBox* chkDrawBaseline=new QCheckBox(tr("draw baseline"), this);
|
|
|
|
chkDrawBaseline->setChecked(true);
|
|
|
|
connect(chkDrawBaseline, SIGNAL(toggled(bool)), this, SLOT(setDrawBaseline(bool)));
|
|
|
|
layoutpeaks->addWidget(chkDrawBaseline);
|
|
|
|
QCheckBox* chkYPeaks=new QCheckBox(tr("y peaks"), this);
|
|
|
|
chkYPeaks->setChecked(true);
|
|
|
|
connect(chkYPeaks, SIGNAL(toggled(bool)), this, SLOT(setYPeaks(bool)));
|
|
|
|
layoutpeaks->addWidget(chkYPeaks);
|
|
|
|
layoutpeaks->addWidget(plotPeaks);
|
|
|
|
|
|
|
|
QVector<double> photons1, photons2;
|
|
|
|
for (int i=0; i<1000; i++) {
|
|
|
|
double x=double(i)/1000.0;
|
2019-11-24 17:42:44 +08:00
|
|
|
const double p=0.33*fabs(sin(x*4.0*JKQTPSTATISTICS_PI))*fabs(sin(x*4.0*JKQTPSTATISTICS_PI));
|
2018-12-29 00:46:47 +08:00
|
|
|
if (static_cast<double>(rand())/static_cast<double>(RAND_MAX)<=p) photons1<<x;
|
|
|
|
if (static_cast<double>(rand())/static_cast<double>(RAND_MAX)<=p) photons2<<x;
|
|
|
|
}
|
|
|
|
int phot1=plotPeaks->getDatastore()->addCopiedColumn(photons1, "photons 1");
|
|
|
|
int phot2=plotPeaks->getDatastore()->addCopiedColumn(photons2, "photons 2");
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
graphPeakStream1=new JKQTPPeakStreamGraph(plotPeaks->getPlotter());
|
|
|
|
graphPeakStream1->setDataColumn(phot1);
|
|
|
|
graphPeakStream1->setColor(QColor("darkgreen"));
|
|
|
|
graphPeakStream1->setPeakHeight(1);
|
|
|
|
graphPeakStream1->setBaseline(0.05);
|
2019-01-26 20:00:40 +08:00
|
|
|
graphPeakStream1->setTitle("channel 1");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotPeaks->getPlotter()->addGraph(graphPeakStream1);
|
2019-04-22 19:27:50 +08:00
|
|
|
graphPeakStream2=new JKQTPPeakStreamGraph(plotPeaks->getPlotter());
|
|
|
|
graphPeakStream2->setDataColumn(phot2);
|
|
|
|
graphPeakStream2->setColor(QColor("darkred"));
|
|
|
|
graphPeakStream2->setPeakHeight(-1);
|
|
|
|
graphPeakStream2->setBaseline(-0.05);
|
2019-01-26 20:00:40 +08:00
|
|
|
graphPeakStream2->setTitle("channel 2");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotPeaks->getPlotter()->addGraph(graphPeakStream2);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
plotPeaks->setPlotUpdateEnabled(true);
|
2018-12-29 00:46:47 +08:00
|
|
|
plotPeaks->zoomToFit();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetPeaksPlots::setDrawBaseline(bool checked)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
graphPeakStream1->setDrawBaseline(checked);
|
|
|
|
graphPeakStream2->setDrawBaseline(checked);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotPeaks->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWidgetPeaksPlots::setYPeaks(bool checked)
|
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
graphPeakStream1->setYPeaks(checked);
|
|
|
|
graphPeakStream2->setYPeaks(checked);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotPeaks->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|