diff --git a/slsDetectorGui/include/qTabPlot.h b/slsDetectorGui/include/qTabPlot.h index 016f130d6..9ed83be7e 100644 --- a/slsDetectorGui/include/qTabPlot.h +++ b/slsDetectorGui/include/qTabPlot.h @@ -136,6 +136,9 @@ private slots: /** Enables the range of the z axis */ void EnableZRange(); + /** Return true if valid */ + bool CheckZRange(QString value); + /** Set Plot to none, data graph, histogram*/ void SetPlot(); diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx index 74769e76e..df80824a5 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx @@ -133,32 +133,43 @@ void SlsQt2DPlotLayout::ResetRange(){ void SlsQt2DPlotLayout::ResetZMinZMax(bool zmin, bool zmax, double min, double max){ - z_range_ne->SetNumber(min,0); - z_range_ne->SetNumber(max,1); + + 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(); - if(btnLogz->isChecked()) the_plot->SetZMinimumToFirstGreaterThanZero(); + //finds zmin value from hist + if(btnLogz->isChecked()) + the_plot->SetZMinimumToFirstGreaterThanZero(); - //first time check validity - if(zmax) z_range_ne->SetValue(max,0); - else z_range_ne->SetValue(the_plot->GetZMaximum(),1); + if(zRangeChecked){ - if(zmin) z_range_ne->SetValue(min,0); - else z_range_ne->SetValue(the_plot->GetZMinimum(),0); + //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)); - 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)); - the_plot->Update(); } @@ -216,6 +227,7 @@ void SlsQt2DPlotLayout::SetZRange(double zmin, double zmax){ ResetRange(); } + void SlsQt2DPlotLayout::EnableZRange(bool enable){ #ifdef VERBOSE cout<<"Setting Z Range Enable to "<fixup(s); + //validator_double[i]->fixup(s);//commented out as it ignores the zmax values num_field[i]->setText(s); } }else if(spin_box[i]){ @@ -280,7 +280,7 @@ void SlsQtNumberEntry::SetRange(int min, int max,int which_number_field){ void SlsQtNumberEntry::SetRange(double min, double max,int which_number_field){ int i = (which_number_field<0||which_number_field>1) ? 0:which_number_field; if(min>max){ - cout<<"Warning: SetRange(double,double) no effect min >= max"<= max("<setRange(min,max,validator_double[i]->decimals()); @@ -407,7 +407,13 @@ double SlsQtNumberEntry::GetNumber(int which_number_field,bool* ok){ if(num_field[i]){ if(validator_int[i]) return num_field[i]->text().toInt(ok); - else return num_field[i]->text().toDouble(ok); + else { + bool k; + cout<<"val:"<text().toDouble(&k)<text().toDouble(ok); + } } else if(spin_box[i]) return spin_box[i]->value(); else {if(ok) *ok=0;} diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index 336358f48..97f73a078 100644 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -510,8 +510,11 @@ void qTabPlot::SetAxesRange(){ void qTabPlot::SetZRange(){ -// emit SetZRangeSignal(dispZMin->text().toDouble(),dispZMax->text().toDouble()); - emit ResetZMinZMaxSignal(chkZMin->isChecked(),chkZMax->isChecked(),dispZMin->text().toDouble(),dispZMax->text().toDouble()); + emit ResetZMinZMaxSignal( + (chkZMin->isChecked() && CheckZRange(dispZMin->text())), + (chkZMax->isChecked() && CheckZRange(dispZMax->text())), + dispZMin->text().toDouble(), + dispZMax->text().toDouble()); } @@ -519,9 +522,30 @@ void qTabPlot::SetZRange(){ void qTabPlot::EnableZRange(){ + dispZMin->setEnabled(chkZMin->isChecked()); dispZMax->setEnabled(chkZMax->isChecked()); - emit ResetZMinZMaxSignal(chkZMin->isChecked(),chkZMax->isChecked(),dispZMin->text().toDouble(),dispZMax->text().toDouble()); + emit ResetZMinZMaxSignal( + (chkZMin->isChecked() && CheckZRange(dispZMin->text())), + (chkZMax->isChecked() && CheckZRange(dispZMax->text())), + dispZMin->text().toDouble(), + dispZMax->text().toDouble()); +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + +bool qTabPlot::CheckZRange(QString value){ + if(value.isEmpty()) + return false; + + bool ok; + value.toDouble(&ok); + if(!ok) + return false; + + return true; }