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)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* layoutpeaks=new QVBoxLayout(this);
|
|
|
|
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;
|
|
|
|
const double p=0.33*fabs(sin(x*4.0*M_PI))*fabs(sin(x*4.0*M_PI));
|
|
|
|
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-01-26 03:16:04 +08:00
|
|
|
graphPeakStream1=new JKQTPPeakStreamGraph(phot1, 0.05, 1, QColor("darkgreen"), plotPeaks->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
graphPeakStream1->setTitle("channel 1");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotPeaks->getPlotter()->addGraph(graphPeakStream1);
|
|
|
|
graphPeakStream2=new JKQTPPeakStreamGraph(phot2, -0.05, -1, QColor("darkred"), plotPeaks->getPlotter());
|
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
|
|
|
}
|