Compare commits
No commits in common. "31a19f41ece58f9282142e6099a3628f59b80b5f" and "37fdeaedbc6013c9edcdfa11aae06ca3b19988f8" have entirely different histories.
31a19f41ec
...
37fdeaedbc
|
@ -6,7 +6,6 @@
|
|||
//^==============================================
|
||||
//^==============================================
|
||||
class Histogram1D : public QCustomPlot{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Histogram1D(QString title, QString xLabel, int xbin, double xmin, double xmax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
||||
Rebin(xbin, xmin, xmax);
|
||||
|
@ -79,7 +78,8 @@ public:
|
|||
QAction * a1 = menu.addAction("UnZoom");
|
||||
QAction * a2 = menu.addAction("Clear hist.");
|
||||
QAction * a3 = menu.addAction("Toggle Stat.");
|
||||
QAction * a4 = menu.addAction("Rebin (clear histogram)");
|
||||
|
||||
//TODO rebin
|
||||
//TODO fitGuass
|
||||
|
||||
QAction *selectedAction = menu.exec(event->globalPosition().toPoint());
|
||||
|
@ -104,64 +104,6 @@ public:
|
|||
replot();
|
||||
usingMenu = false;
|
||||
}
|
||||
if( selectedAction == a4 ){
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle("Rebin histogram");
|
||||
|
||||
QFormLayout layout(&dialog);
|
||||
|
||||
QLabel * info = new QLabel(&dialog);
|
||||
info->setStyleSheet("color:red;");
|
||||
info->setText("This will also clear histogram!!");
|
||||
layout.addRow(info);
|
||||
|
||||
QStringList nameList = {"Num. Bin", "x-Min", "x-Max"};
|
||||
QLineEdit* lineEdit[3];
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
lineEdit[i] = new QLineEdit(&dialog);
|
||||
layout.addRow(nameList[i] + " : ", lineEdit[i]);
|
||||
}
|
||||
|
||||
QLabel * msg = new QLabel(&dialog);
|
||||
msg->setStyleSheet("color:red;");
|
||||
layout.addRow(msg);
|
||||
|
||||
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
||||
layout.addRow(&buttonBox);
|
||||
|
||||
double number[3];
|
||||
|
||||
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() {
|
||||
int OKcount = 0;
|
||||
bool conversionOk = true;
|
||||
for( int i = 0; i < 3; i++ ){
|
||||
number[i] = lineEdit[i]->text().toDouble(&conversionOk);
|
||||
if( conversionOk ){
|
||||
OKcount++;
|
||||
}else{
|
||||
msg->setText(nameList[i] + " is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( OKcount == 3 ) {
|
||||
if( number[2] > number[1] ) {
|
||||
dialog.accept();
|
||||
}else{
|
||||
msg->setText(nameList[2] + " is smaller than " + nameList[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();});
|
||||
|
||||
if( dialog.exec() == QDialog::Accepted ){
|
||||
Rebin((int)number[0], number[1], number[2]);
|
||||
emit ReBinned();
|
||||
UpdatePlot();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -245,9 +187,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
void ReBinned(); //ONLY for right click rebin
|
||||
|
||||
private:
|
||||
double xMin, xMax, dX;
|
||||
int xBin;
|
||||
|
|
219
Histogram2D.h
219
Histogram2D.h
|
@ -3,20 +3,18 @@
|
|||
|
||||
#include "qcustomplot.h"
|
||||
|
||||
const QList<QPair<QColor, QString>> colorCycle = { {QColor(Qt::red), "Red"},
|
||||
{QColor(Qt::blue), "Blue"},
|
||||
{QColor(Qt::darkGreen), "Dark Geen"},
|
||||
{QColor(Qt::darkCyan), "Dark Cyan"},
|
||||
{QColor(Qt::darkYellow), "Drak Yellow"},
|
||||
{QColor(Qt::magenta), "Magenta"},
|
||||
{QColor(Qt::darkMagenta), "Dark Magenta"},
|
||||
{QColor(Qt::gray), "Gray"}};
|
||||
|
||||
const QList<QColor> colorCycle = { QColor(Qt::red),
|
||||
QColor(Qt::blue),
|
||||
QColor(Qt::darkGreen),
|
||||
QColor(Qt::darkCyan),
|
||||
QColor(Qt::darkYellow),
|
||||
QColor(Qt::magenta),
|
||||
QColor(Qt::darkMagenta),
|
||||
QColor(Qt::gray)};
|
||||
|
||||
//^==============================================
|
||||
//^==============================================
|
||||
class Histogram2D : public QCustomPlot{
|
||||
|
||||
public:
|
||||
Histogram2D(QString title, QString xLabel, QString yLabel, int xbin, double xmin, double xmax, int ybin, double ymin, double ymax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
||||
xMin = xmin;
|
||||
|
@ -46,10 +44,9 @@ public:
|
|||
|
||||
QCPColorGradient color;
|
||||
color.clearColorStops();
|
||||
color.setColorStopAt( 0.0, QColor("white" ));
|
||||
color.setColorStopAt( 0.3, QColor("blue"));
|
||||
color.setColorStopAt( 0.4, QColor("green"));
|
||||
color.setColorStopAt( 1.0, QColor("yellow"));
|
||||
color.setColorStopAt( 0, QColor("white" ));
|
||||
color.setColorStopAt( 0.5, QColor("blue"));
|
||||
color.setColorStopAt( 1, QColor("yellow"));
|
||||
colorMap->setGradient(color);
|
||||
|
||||
cutList.clear();
|
||||
|
@ -79,18 +76,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
rescaleAxes();
|
||||
|
||||
usingMenu = false;
|
||||
isDrawCut = false;
|
||||
tempCutID = -1;
|
||||
numCut = 0;
|
||||
lastPlottableID = -1;
|
||||
|
||||
line = new QCPItemLine(this);
|
||||
line->setPen(QPen(Qt::gray, 1, Qt::DashLine));
|
||||
line->setVisible(false);
|
||||
|
||||
|
||||
connect(this, &QCustomPlot::mouseMove, this, [=](QMouseEvent *event){
|
||||
double x = xAxis->pixelToCoord(event->pos().x());
|
||||
|
@ -102,12 +92,8 @@ public:
|
|||
QString coordinates = QString("X: %1, Y: %2, Z: %3").arg(x).arg(y).arg(z);
|
||||
QToolTip::showText(event->globalPosition().toPoint(), coordinates, this);
|
||||
|
||||
//when drawing cut, show dashhed line
|
||||
if( isDrawCut && tempCut.size() > 0 ){
|
||||
line->end->setCoords(x,y);
|
||||
line->setVisible(true);
|
||||
replot();
|
||||
}
|
||||
//TODO, when drawing cut, show dashhed line
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
@ -117,19 +103,14 @@ public:
|
|||
}
|
||||
if (event->button() == Qt::LeftButton && isDrawCut){
|
||||
|
||||
oldMouseX = xAxis->pixelToCoord(event->pos().x());
|
||||
oldMouseY = yAxis->pixelToCoord(event->pos().y());
|
||||
double x = xAxis->pixelToCoord(event->pos().x());
|
||||
double y = yAxis->pixelToCoord(event->pos().y());
|
||||
|
||||
tempCut.push_back(QPointF(oldMouseX,oldMouseY));
|
||||
|
||||
line->start->setCoords(oldMouseX, oldMouseY);
|
||||
line->end->setCoords(oldMouseX, oldMouseY);
|
||||
line->setVisible(true);
|
||||
tempCut.push_back(QPointF(x,y));
|
||||
|
||||
DrawCut();
|
||||
}
|
||||
|
||||
//^================= right click
|
||||
if (event->button() == Qt::RightButton) {
|
||||
usingMenu = true;
|
||||
setSelectionRectMode(QCP::SelectionRectMode::srmNone);
|
||||
|
@ -141,15 +122,8 @@ public:
|
|||
QAction * a2 = menu->addAction("Clear hist.");
|
||||
QAction * a3 = menu->addAction("Toggle Stat.");
|
||||
QAction * a4 = menu->addAction("Create a Cut");
|
||||
if( numCut > 0 ) {
|
||||
menu->addSeparator();
|
||||
menu->addAction("Add/Edit names to Cuts");
|
||||
menu->addAction("Clear all Cuts");
|
||||
}
|
||||
for( int i = 0; i < cutList.size(); i++){
|
||||
if( cutList[i].isEmpty()) continue;
|
||||
QString haha = "";
|
||||
menu->addAction("Delete " + cutNameList[i] + " ["+ colorCycle[cutIDList[i]%colorCycle.count()].second+"]");
|
||||
menu->addAction("Delete Cut-" + QString::number(i));
|
||||
}
|
||||
|
||||
QAction *selectedAction = menu->exec(event->globalPosition().toPoint());
|
||||
|
@ -181,133 +155,23 @@ public:
|
|||
|
||||
if( selectedAction == a4 ){
|
||||
tempCut.clear();
|
||||
tempCutID ++;
|
||||
isDrawCut= true;
|
||||
usingMenu = false;
|
||||
numCut ++;
|
||||
qDebug() << "#### Create Cut Plottable count : " << plottableCount() << ", numCut :" << numCut << ", " << lastPlottableID;
|
||||
}
|
||||
|
||||
if( selectedAction && selectedAction->text().contains("Delete ") ){
|
||||
QString haha = selectedAction->text();
|
||||
int index1 = haha.indexOf("-");
|
||||
int index2 = haha.indexOf("[");
|
||||
int cutID = haha.mid(index1+1, index2-index1-1).remove(' ').toInt();
|
||||
// if( selectedAction->text().contains("Delete Cut") ){
|
||||
// qDebug() << "delete Cut";
|
||||
// }
|
||||
|
||||
removeItem(cutTextIDList[cutID]);
|
||||
removePlottable(plottableIDList[cutID]);
|
||||
replot();
|
||||
|
||||
numCut --;
|
||||
cutList[cutID].clear();
|
||||
cutIDList[cutID] = -1;
|
||||
cutTextIDList[cutID] = -1;
|
||||
plottableIDList[cutID] = -1;
|
||||
cutNameList[cutID] = "";
|
||||
|
||||
for( int i = cutID + 1; i < cutTextIDList.count() ; i++){
|
||||
cutTextIDList[i] --;
|
||||
plottableIDList[i] --;
|
||||
}
|
||||
|
||||
if( numCut == 0 ){
|
||||
cutList.clear();
|
||||
cutIDList.clear();
|
||||
cutTextIDList.clear();
|
||||
plottableIDList.clear();
|
||||
cutNameList.clear();
|
||||
}
|
||||
|
||||
qDebug() << "================= delete Cut-" << cutID;
|
||||
qDebug() << " cutIDList " << cutIDList ;
|
||||
qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount();
|
||||
qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount();
|
||||
|
||||
}
|
||||
|
||||
if( selectedAction && selectedAction->text().contains("Clear all Cuts") ){
|
||||
numCut = 0;
|
||||
tempCutID = -1;
|
||||
lastPlottableID = -1;
|
||||
cutList.clear();
|
||||
cutIDList.clear();
|
||||
for( int i = cutTextIDList.count() - 1; i >= 0 ; i--){
|
||||
if( cutTextIDList[i] < 0 ) continue;
|
||||
removeItem(cutTextIDList[i]);
|
||||
removePlottable(plottableIDList[i]);
|
||||
}
|
||||
replot();
|
||||
|
||||
cutTextIDList.clear();
|
||||
plottableIDList.clear();
|
||||
cutNameList.clear();
|
||||
|
||||
}
|
||||
|
||||
if( selectedAction && selectedAction->text().contains("Add/Edit names to Cuts") ){
|
||||
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle("Add/Edit name of cuts ");
|
||||
|
||||
QFormLayout layout(&dialog);
|
||||
|
||||
for(int i = 0; i < cutTextIDList.count(); i++){
|
||||
if( cutTextIDList[i] < 0 ) continue;
|
||||
QLineEdit * le = new QLineEdit(&dialog);
|
||||
layout.addRow(colorCycle[i%colorCycle.count()].second, le);
|
||||
le->setText( cutNameList[i] );
|
||||
connect(le, &QLineEdit::textChanged, this, [=](){
|
||||
le->setStyleSheet("color : blue;");
|
||||
});
|
||||
connect(le, &QLineEdit::returnPressed, this, [=](){
|
||||
le->setStyleSheet("");
|
||||
cutNameList[i] = le->text();
|
||||
((QCPItemText *) this->item(cutTextIDList[i]))->setText(le->text());
|
||||
replot();
|
||||
});
|
||||
}
|
||||
|
||||
// QDialogButtonBox buttonBox(QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
||||
// layout.addRow(&buttonBox);
|
||||
|
||||
// QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();});
|
||||
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
}///================= end of right click
|
||||
}
|
||||
});
|
||||
|
||||
//connect( this, &QCustomPlot::mouseDoubleClick, this, [=](QMouseEvent *event){
|
||||
connect( this, &QCustomPlot::mouseDoubleClick, this, [=](){
|
||||
if( isDrawCut) {
|
||||
tempCut.push_back(tempCut[0]);
|
||||
DrawCut();
|
||||
isDrawCut = false;
|
||||
line->setVisible(false);
|
||||
|
||||
plottableIDList.push_back(plottableCount() -1 );
|
||||
|
||||
cutNameList.push_back("Cut-" + QString::number(cutList.count()));
|
||||
//QCPItemText is not a plottable
|
||||
QCPItemText * text = new QCPItemText(this);
|
||||
text->setText(cutNameList.last());
|
||||
text->position->setCoords(tempCut[0].rx(), tempCut[0].ry());
|
||||
int colorID = tempCutID% colorCycle.count();
|
||||
text->setColor(colorCycle[colorID].first);
|
||||
cutTextIDList.push_back(itemCount() - 1);
|
||||
|
||||
replot();
|
||||
|
||||
cutList.push_back(tempCut);
|
||||
cutIDList.push_back(tempCutID);
|
||||
|
||||
qDebug() << "----------- end of create cut";
|
||||
qDebug() << " cutIDList " << cutIDList ;
|
||||
qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount();
|
||||
qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount();
|
||||
|
||||
}
|
||||
isDrawCut = false;
|
||||
tempCut.push_back(tempCut[0]);
|
||||
cutList.push_back(tempCut);
|
||||
DrawCut();
|
||||
});
|
||||
|
||||
connect(this, &QCustomPlot::mouseRelease, this, [=](){
|
||||
|
@ -355,18 +219,16 @@ public:
|
|||
|
||||
void DrawCut(){
|
||||
|
||||
//The histogram is the 1st plottable.
|
||||
// the lastPlottableID should be numCut+ 1
|
||||
if( lastPlottableID != numCut ){
|
||||
removePlottable(lastPlottableID);
|
||||
}
|
||||
//TODO how to delete cut from plot and from QList
|
||||
|
||||
if(tempCut.size() > 0) {
|
||||
plottableCount();
|
||||
|
||||
//TODO how to not double plot?
|
||||
|
||||
if(tempCut.size() > 1) {
|
||||
QCPCurve *polygon = new QCPCurve(xAxis, yAxis);
|
||||
lastPlottableID = plottableCount() - 1;
|
||||
|
||||
int colorID = tempCutID% colorCycle.count();
|
||||
QPen pen(colorCycle[colorID].first);
|
||||
QPen pen(Qt::blue);
|
||||
pen.setWidth(1);
|
||||
polygon->setPen(pen);
|
||||
|
||||
|
@ -376,12 +238,11 @@ public:
|
|||
}
|
||||
polygon->data()->set(dataPoints, false);
|
||||
}
|
||||
replot();
|
||||
|
||||
qDebug() << "Plottable count : " << plottableCount() << ", cutList.count :" << cutList.count() << ", cutID :" << lastPlottableID;
|
||||
replot();
|
||||
}
|
||||
|
||||
QList<QPolygonF> GetCutList() const{return cutList;} // this list may contain empty element
|
||||
QList<QPolygonF> GetCutList() const{return cutList;}
|
||||
|
||||
private:
|
||||
double xMin, xMax, yMin, yMax;
|
||||
|
@ -398,18 +259,8 @@ private:
|
|||
QCPItemText * txt[3][3];
|
||||
|
||||
QPolygonF tempCut;
|
||||
int tempCutID; // only incresing;
|
||||
QList<QPolygonF> cutList;
|
||||
QList<int> cutIDList;
|
||||
int numCut;
|
||||
bool isDrawCut;
|
||||
int lastPlottableID;
|
||||
QList<int> cutTextIDList;
|
||||
QList<int> plottableIDList;
|
||||
QList<QString> cutNameList;
|
||||
|
||||
QCPItemLine * line;
|
||||
double oldMouseX = 0.0, oldMouseY = 0.0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -121,13 +121,6 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
|
|||
for( int j = 0; j < digi[i]->GetNChannels(); j++){
|
||||
if( i < nDigi ) {
|
||||
hist[i][j] = new Histogram1D("Digi-" + QString::number(digi[i]->GetSerialNumber()) +", Ch-" + QString::number(j), "Raw Energy [ch]", nBin, xMin, xMax);
|
||||
connect(hist[i][j], &Histogram1D::ReBinned , this, [=](){
|
||||
enableSignalSlot = false;
|
||||
sbNBin->setValue(hist[i][j]->GetNBin());
|
||||
sbXMin->setValue(hist[i][j]->GetXMin());
|
||||
sbXMax->setValue(hist[i][j]->GetXMax());
|
||||
enableSignalSlot = true;
|
||||
});
|
||||
}else{
|
||||
hist[i][j] = nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user