This commit is contained in:
maliakal_d 2019-06-17 15:51:17 +02:00
parent 4213a161fe
commit 326b14737f
5 changed files with 59 additions and 205 deletions

View File

@ -40,11 +40,6 @@ xxxxxxxxxxxxxxx
void SetXRange(); void SetXRange();
void SetYRange(); void SetYRange();
void CheckAspectRatio(); void CheckAspectRatio();
void SetXYRange();
/**
* Maintain aspect ratio
*/
void MaintainAspectRatio(int dimension);
void SetZRange(); void SetZRange();
@ -66,9 +61,8 @@ private:
void SetupWidgetWindow(); void SetupWidgetWindow();
void Initialization(); void Initialization();
void GetGapPixels(); void GetGapPixels();
void EnableRange(); void SetXYRange();
void SetAxesRange(); void MaintainAspectRatio(int dimension);
bool CheckZRange(QString value);
multiSlsDetector *myDet; multiSlsDetector *myDet;
qDrawPlot *myPlot; qDrawPlot *myPlot;

View File

@ -1,23 +1,8 @@
/** #pragma once
* @author Ian Johnson
* @version 1.0
* @comments
* 19.06.2012 All modifications with the Ian flag has been made since
* z_range_ne and the buttons are defined in another class.
* Logz button and z_range_ne have wrappers to connect them
* 05.05.2013 Added ResetZMinZMax
*/
#ifndef SLSQT2DPLOTLAYOUT_H
#define SLSQT2DPLOTLAYOUT_H
#include <qwidget.h> #include <qwidget.h>
#include <qgroupbox.h> #include <qgroupbox.h>
#include "SlsQtNumberEntry.h"
#include "SlsQt2DPlot.h" #include "SlsQt2DPlot.h"
class QGridLayout; class QGridLayout;
@ -37,7 +22,7 @@ public:
void SetXTitle(QString st); void SetXTitle(QString st);
void SetYTitle(QString st); void SetYTitle(QString st);
void SetZTitle(QString st); void SetZTitle(QString st);
void UpdateNKeepSetRangeIfSet(); void KeepZRangeIfSet();
private: private:
@ -46,32 +31,23 @@ private:
QToolButton* btnContour; QToolButton* btnContour;
QToolButton* btnLogz; QToolButton* btnLogz;
SlsQt2DPlot* the_plot; SlsQt2DPlot* the_plot;
SlsQtNumberEntry* z_range_ne;
#ifndef IAN
bool zRangeChecked;
#endif
void CreateTheButtons();
void ConnectSignalsAndSlots(); void ConnectSignalsAndSlots();
void Layout(); void Layout();
bool isLog;
double zmin;
double zmax;
bool isZmin;
bool isZmax;
public slots: public slots:
void SetZScaleToLog(bool yes); void SetZScaleToLog(bool enable);
void ResetRange(); void ResetRange();
void SetZRange(bool isMin, bool isMax, double min, double max);
#ifndef IAN
void SetZRange(double,double);
void EnableZRange(bool enable);
void ResetZMinZMax(bool zmin, bool zmax, double min, double max);
#endif
signals: signals:
void InterpolateSignal(bool); void InterpolateSignal(bool);
void ContourSignal(bool); void ContourSignal(bool);
void LogzSignal(bool);
}; };
#endif

View File

@ -1,9 +1,3 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#include <iostream> #include <iostream>
#include <qtoolbutton.h> #include <qtoolbutton.h>
@ -19,125 +13,67 @@
SlsQt2DPlotLayout::SlsQt2DPlotLayout(QWidget *parent):QGroupBox(parent){ SlsQt2DPlotLayout::SlsQt2DPlotLayout(QWidget *parent):QGroupBox(parent){
the_layout=0; the_layout=0;
the_plot = new SlsQt2DPlot(this); the_plot = new SlsQt2DPlot(this);
isLog = false;
z_range_ne = new SlsQtNumberEntry(this,1,(char*)"Set the z axis range from",2,(char*)"to",2); zmin = 0;
z_range_ne->setFixedWidth(402); zmax = 0;
zRangeChecked = false; isZmin = false;
z_range_ne->hide(); isZmax = false;
CreateTheButtons();
Layout(); Layout();
ConnectSignalsAndSlots(); ConnectSignalsAndSlots();
} }
SlsQt2DPlotLayout::~SlsQt2DPlotLayout(){ SlsQt2DPlotLayout::~SlsQt2DPlotLayout(){
if(the_layout) delete the_layout; if(the_layout) delete the_layout;
delete the_plot; delete the_plot;
delete z_range_ne;
} }
void SlsQt2DPlotLayout::CreateTheButtons(){
btnLogz = new QToolButton(this);
btnLogz->setText("Log Scale (Z)");
btnLogz->setCheckable(true);
btnLogz->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btnLogz->hide();
}
void SlsQt2DPlotLayout::Layout(){ void SlsQt2DPlotLayout::Layout(){
if(the_layout) delete the_layout; if(the_layout) delete the_layout;
the_layout = new QGridLayout(this); the_layout = new QGridLayout(this);
the_layout->addWidget(the_plot,2,0,3,3); the_layout->addWidget(the_plot,2,0,3,3);
the_layout->addWidget(z_range_ne,5,0,1,3);
} }
void SlsQt2DPlotLayout::ConnectSignalsAndSlots(){ void SlsQt2DPlotLayout::ConnectSignalsAndSlots(){
connect(this, SIGNAL(InterpolateSignal(bool)), the_plot, SLOT(InterpolatedPlot(bool))); connect(this, SIGNAL(InterpolateSignal(bool)), the_plot, SLOT(InterpolatedPlot(bool)));
connect(this, SIGNAL(ContourSignal(bool)), the_plot, SLOT(showContour(bool))); connect(this, SIGNAL(ContourSignal(bool)), the_plot, SLOT(showContour(bool)));
connect(z_range_ne, SIGNAL(CheckBoxChanged(bool)), this, SLOT(ResetRange())); connect(this, SIGNAL(LogzSignal(bool)), this, SLOT(SetZScaleToLog(bool)));
connect(z_range_ne, SIGNAL(AValueChanged(SlsQtNumberEntry*)), this, SLOT(ResetRange()));
btnLogz->setChecked(false);
} }
void SlsQt2DPlotLayout::UpdateNKeepSetRangeIfSet(){ void SlsQt2DPlotLayout::KeepZRangeIfSet(){
//just reset histogram range before update SetZRange(isZMin, isZmax, zmin, zmax);
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
the_plot->Update();
} }
void SlsQt2DPlotLayout::ResetRange(){ void SlsQt2DPlotLayout::SetZRange(bool isMin, bool isMax, double min, double max){
//refind z limits isZMin = isMin;
isZmax = isMax;
// reset zmin and zmax first
the_plot->SetZMinMax(); the_plot->SetZMinMax();
if(btnLogz->isChecked()) the_plot->SetZMinimumToFirstGreaterThanZero();
if(zRangeChecked){
//first time check validity
bool same = (z_range_ne->GetValue(0)==z_range_ne->GetValue(1)) ? 1:0;
if(!z_range_ne->IsValueOk(0)||same) z_range_ne->SetValue(the_plot->GetZMinimum(),0);
if(!z_range_ne->IsValueOk(1)||same) z_range_ne->SetValue(the_plot->GetZMaximum(),1);
z_range_ne->SetRange(the_plot->GetZMinimum(),z_range_ne->GetValue(1),0);
z_range_ne->SetRange(z_range_ne->GetValue(0),the_plot->GetZMaximum(),1);
//set histogram range if(isLog) {
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
}
the_plot->Update();
}
void SlsQt2DPlotLayout::ResetZMinZMax(bool zmin, bool zmax, double min, double max){
if(zmin || zmax) zRangeChecked = true;
else zRangeChecked = false;
if(zmin) z_range_ne->SetNumber(min,0);
if(zmax) z_range_ne->SetNumber(max,1);
//refind z limits
the_plot->SetZMinMax();
//finds zmin value from hist
if(btnLogz->isChecked())
the_plot->SetZMinimumToFirstGreaterThanZero(); the_plot->SetZMinimumToFirstGreaterThanZero();
if(zRangeChecked){
//if value not given, take max or min of plot
if(zmax) z_range_ne->SetValue(max,0);
else z_range_ne->SetValue(the_plot->GetZMaximum(),1);
if(zmin) z_range_ne->SetValue(min,0);
else z_range_ne->SetValue(the_plot->GetZMinimum(),0);
//check if zmin and zmax is same or not a proper double value
//if(zmin && zmax){
bool same = (z_range_ne->GetValue(0)==z_range_ne->GetValue(1)) ? 1:0;
if(!z_range_ne->IsValueOk(0)||same) z_range_ne->SetValue(the_plot->GetZMinimum(),0);
if(!z_range_ne->IsValueOk(1)||same) z_range_ne->SetValue(the_plot->GetZMaximum(),1);
//}
z_range_ne->SetRange(the_plot->GetZMinimum(),z_range_ne->GetValue(1),0);
z_range_ne->SetRange(z_range_ne->GetValue(0),the_plot->GetZMaximum(),1);
//set histogram range
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
} }
// set zmin and zmax
if (isZmin || isZmax) {
zmin = (isZmin ? min : the_plot->GetZMinimum());
zmax = (isZmax ? max : the_plot->GetZMaximum());
// if it is the same values, we should reset it to plots min and max (not doing this now: not foolproof now)
// setting the range of values possible in the dispZMin and dispZMax (not doin this now: not foolproof)
the_plot->SetZMinMax(zmin, zmax);
} else {
zmin = 0;
zmax = -1;
}
the_plot->Update(); the_plot->Update();
} }
void SlsQt2DPlotLayout::SetZScaleToLog(bool enable) {
void SlsQt2DPlotLayout::SetZScaleToLog(bool yes){ FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Z Scale to log";
#ifdef VERBOSE isLog = enable;
cout<<"Setting ZScale to log:"<<yes<<endl; the_plot->LogZ(enable);
#endif SetZRange(isZMin, isZmax, zmin, zmax);
btnLogz->setChecked(yes);
the_plot->LogZ(yes);
ResetRange();
} }
@ -158,23 +94,3 @@ void SlsQt2DPlotLayout::SetZTitle(QString st){
title.setFont(QFont("Sans Serif",11,QFont::Normal)); title.setFont(QFont("Sans Serif",11,QFont::Normal));
GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(title); GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(title);
} }
void SlsQt2DPlotLayout::SetZRange(double zmin, double zmax){
#ifdef VERBOSE
cout<<"zmin:"<<zmin<<"\tzmax:"<<zmax<<endl;
#endif
z_range_ne->SetNumber(zmin,0);
z_range_ne->SetNumber(zmax,1);
ResetRange();
}
void SlsQt2DPlotLayout::EnableZRange(bool enable){
#ifdef VERBOSE
cout<<"Setting Z Range Enable to "<<enable<<endl;
#endif
zRangeChecked = enable;
ResetRange();
}

View File

@ -373,9 +373,9 @@ void qDrawPlot::Initialization() {
connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot())); connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot()));
connect(this, SIGNAL(InterpolateSignal(bool)), plot2D, SIGNAL(InterpolateSignal(bool))); connect(this, SIGNAL(InterpolateSignal(bool)), plot2D, SIGNAL(InterpolateSignal(bool)));
connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool))); connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool)));
connect(this, SIGNAL(LogzSignal(bool)), plot2D, SLOT(SetZScaleToLog(bool))); connect(this, SIGNAL(LogzSignal(bool)), plot2D, SIGNAL(LogzSignal(bool))));
connect(this, SIGNAL(LogySignal(bool)), plot1D, SLOT(SetLogY(bool))); connect(this, SIGNAL(LogySignal(bool)), plot1D, SLOT(SetLogY(bool)));
connect(this, SIGNAL(ResetZMinZMaxSignal(bool, bool, double, double)), plot2D, SLOT(ResetZMinZMax(bool, bool, double, double))); connect(this, SIGNAL(ResetZMinZMaxSignal(bool, bool, double, double)), plot2D, SLOT(SetZRange(bool, bool, double, double)));
connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString))); connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString)));
@ -1425,7 +1425,7 @@ void qDrawPlot::UpdatePlot() {
plot2D->SetXTitle(imageXAxisTitle); plot2D->SetXTitle(imageXAxisTitle);
plot2D->SetYTitle(imageYAxisTitle); plot2D->SetYTitle(imageYAxisTitle);
plot2D->SetZTitle(imageZAxisTitle); plot2D->SetZTitle(imageZAxisTitle);
plot2D->UpdateNKeepSetRangeIfSet(); //keep a "set" z range, and call Update(); plot2D->KeepZRangeIfSet(); //keep a "set" z range, and call Update();
if (gainPlotEnable) { if (gainPlotEnable) {
gainplot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, gainImageArray); gainplot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, gainImageArray);
gainplot2D->setTitle(GetImageTitle()); gainplot2D->setTitle(GetImageTitle());
@ -1734,7 +1734,7 @@ void qDrawPlot::DisableZoom(bool disable) {
plot2D->SetXTitle("Pixel"); plot2D->SetXTitle("Pixel");
plot2D->SetYTitle("Pixel"); plot2D->SetYTitle("Pixel");
plot2D->SetZTitle("Trimbits"); plot2D->SetZTitle("Trimbits");
plot2D->UpdateNKeepSetRangeIfSet(); plot2D->KeepZRangeIfSet();
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Trimbits Plot updated" <<'\n'; std::cout << "Trimbits Plot updated" <<'\n';
#endif #endif

View File

@ -562,46 +562,16 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
void qTabPlot::SetZRange() { void qTabPlot::SetZRange() {
emit ResetZMinZMaxSignal( bool isZmin = chkZMin->isChecked();
(chkZMin->isChecked() && CheckZRange(dispZMin->text())), bool isZmax = chkZMax->isChecked();
(chkZMax->isChecked() && CheckZRange(dispZMax->text())), double zmin = 0, zmax = 1;
dispZMin->text().toDouble(), if (!dispZMin->text().empty()) {
dispZMax->text().toDouble()); zmin = dispZMin->text().toDouble();
}
void qTabPlot::EnableZRange() {
disconnect(dispZMin, SIGNAL(editingFinished()), this, SLOT(SetZRange()));
disconnect(dispZMax, SIGNAL(editingFinished()), this, SLOT(SetZRange()));
dispZMin->setEnabled(chkZMin->isChecked());
dispZMax->setEnabled(chkZMax->isChecked());
emit ResetZMinZMaxSignal(
(chkZMin->isChecked() && CheckZRange(dispZMin->text())),
(chkZMax->isChecked() && CheckZRange(dispZMax->text())),
dispZMin->text().toDouble(),
dispZMax->text().toDouble());
connect(dispZMin, SIGNAL(editingFinished()), this, SLOT(SetZRange()));
connect(dispZMax, SIGNAL(editingFinished()), this, SLOT(SetZRange()));
}
bool qTabPlot::CheckZRange(QString value) {
if (value.isEmpty())
return false;
bool ok;
value.toDouble(&ok);
if (!ok) {
qDefs::Message(qDefs::WARNING, "<nobr>Check Z Range</nobr><br><nobr>"
"Zmin and Zmax should be in double</nobr>",
"qTabPlot::CheckZRange");
return false;
} }
if (!dispZMax->text().empty()) {
return true; zmax = dispZMax->text().toDouble();
}
emit ResetZMinZMaxSignal(isZmin, isZmax, zmin, zmax);
} }
@ -679,8 +649,6 @@ bool qTabPlot::CheckZRange(QString value) {