All the ranges of the axes work properly without zooming in and out each time

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@11 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d
2012-06-19 15:01:40 +00:00
parent 8246154032
commit 69e6500522
22 changed files with 521 additions and 412 deletions

View File

@ -2,7 +2,13 @@
/**
* @author Ian Johnson
* @version 1.0
*/
* Modifications:
* 19.06.2012: {Some functions have been added by Dhanya to enable zooming in and out
* without using mouse control:
* DisableZoom,
* SetXMinMax,SetYMinMax,
* GetXMinimum,GetXMaximum,GetYMinimum,GetYMaximum}
* */
#ifndef SLSQT1DPLOT_H
#define SLSQT1DPLOT_H
@ -12,6 +18,8 @@
#include <qwt_plot_marker.h>
#include <qwt_scale_div.h>
#include "SlsQt1DZoomer.h"
#include <iostream>
using namespace std;
class QPen;
class SlsQt1DPlot;
@ -104,14 +112,18 @@ class SlsQt1DPlot:public QwtPlot{
void InsertVLine(double v);
void RemoveVLine();
void DisableZoom(bool disableZoom);
void SetXAxisScale(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYAxisScale(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
double GetXAxisLowerBound(){return axisScaleDiv(QwtPlot::xBottom)->lowerBound();};
double GetXAxisUpperBound(){return axisScaleDiv(QwtPlot::xBottom)->upperBound();};
double GetYAxisLowerBound(){return axisScaleDiv(QwtPlot::yLeft)->lowerBound();};
double GetYAxisUpperBound(){return axisScaleDiv(QwtPlot::yLeft)->upperBound(); };
/** This group of functions have been added by Dhanya on 19.06.2012 to be able to
use zooming functionality without mouse control*/
void DisableZoom(bool disableZoom);
void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
double GetXMinimum(){return hist_list->Hist()->GetXMin();};
double GetXMaximum(){return hist_list->Hist()->GetXMax();};
double GetYMinimum(){return hist_list->Hist()->GetYMin();};
double GetYMaximum(){return hist_list->Hist()->GetYMax();};
/**---*/
void SetZoom(double xmin,double ymin,double x_width,double y_width);
void SetZoomBase(double xmin,double ymin,double x_width, double y_width){ zoomer->SetZoomBase(xmin,ymin,x_width,y_width);}

View File

@ -2,6 +2,12 @@
/**
* @author Ian Johnson
* @version 1.0
* Modifications:
* 19.06.2012: {Some functions have been added by Dhanya to enable zooming in and out
* without using mouse control:
* DisableZoom,
* SetXMinMax,SetYMinMax,
* GetXMinimum,GetXMaximum,GetYMinimum,GetYMaximum}
*/
@ -43,10 +49,22 @@ public:
SlsQt2DPlot(QWidget * = NULL);
// SlsQt2DHist *GetHistogram(){ return hist; }
void UnZoom();
void SetZoom(double xmin,double ymin,double x_width,double y_width);
/** This group of functions have been added by Dhanya on 19.06.2012 to be able to
use zooming functionality without mouse control*/
void DisableZoom(bool disableZoom);
void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
double GetXMinimum(){return hist->GetXMin();};
double GetXMaximum(){return hist->GetXMax();};
double GetYMinimum(){return hist->GetYMin();};
double GetYMaximum(){return hist->GetYMax();};
/**---*/
double GetZMinimum(){ return hist->GetMinimum();}
double GetZMaximum(){ return hist->GetMaximum();}
void SetZMinMax(double zmin=0,double zmax=-1);

View File

@ -1,6 +1,10 @@
/**
* @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
*/
@ -15,7 +19,7 @@
class QGridLayout;
class QString;
class QToolButton;
class SlsQt2DPlotLayout: public QGroupBox{
@ -26,33 +30,42 @@ public:
SlsQt2DPlotLayout(QWidget * = NULL);
~SlsQt2DPlotLayout();
SlsQt2DPlot* GetPlot() {return the_plot;}
SlsQt2DPlot* GetPlot(){return the_plot;}
void SetXTitle(QString st);
void SetYTitle(QString st);
void SetZTitle(QString st);
void UpdateNKeepSetRangeIfSet();
void UpdateNKeepSetRangeIfSet();
private:
QGridLayout* the_layout;
SlsQt2DPlot* the_plot;
QGridLayout* the_layout;
QToolButton* btnInterpolate;
QToolButton* btnContour;
QToolButton* btnLogz;
SlsQt2DPlot* the_plot;
SlsQtNumberEntry* z_range_ne;
SlsQtNumberEntry* z_range_ne;
bool logsChecked;
#ifndef IAN
bool zRangeChecked;
#endif
void CreateTheButtons();
void ConnectSignalsAndSlots();
void Layout();
public slots:
void SetZScaleToLog(bool yes);
void ResetRange();
void SetTitle(QString st);
#ifndef IAN
void SetZRange(double,double);
void EnableZRange(bool enable);
#endif
signals:
void InterpolateSignal(bool);
void ContourSignal(bool);
};
#endif

View File

@ -457,6 +457,8 @@ void SlsQt1DPlot::UnknownStuff(){
}
//Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range has been set
void SlsQt1DPlot::DisableZoom(bool disableZoom){
#ifdef VERBOSE
if(disableZoom) cout<<"Disabling zoom"<<endl;

View File

@ -72,7 +72,6 @@ void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,doubl
ny=nbinsy;
nb=nx*ny;
data[nb]=0;//set over flow to zero
if(d){
memcpy(data,d,nb*sizeof(double));
SetMinMax(zmin,zmax);

View File

@ -129,8 +129,14 @@ void SlsQt2DPlot::SetupZoom(){
zoomer->setTrackerPen(c);
}
/*void SlsQt2DPlot::CompletelyUnZoom(){
setAxisScale(QwtPlot::xBottom,hist->GetXMin(),hist->GetXMin()+(hist->GetXMax()-hist->GetXMin()));
setAxisScale(QwtPlot::yLeft,hist->GetYMin(),hist->GetYMin()+(hist->GetYMax()-hist->GetYMin()));
zoomer->setZoomBase();
//replot();
}*/
void SlsQt2DPlot::UnZoom(){
zoomer->setZoomBase(QwtDoubleRect(hist->GetXMin(),hist->GetYMin(),hist->GetXMax()-hist->GetXMin(),hist->GetYMax()-hist->GetYMin()));
zoomer->setZoomBase();//Call replot for the attached plot before initializing the zoomer with its scales.
@ -147,7 +153,7 @@ void SlsQt2DPlot::SetZMinMax(double zmin,double zmax){
void SlsQt2DPlot::Update(){
rightAxis->setColorMap(d_spectrogram->data().range(),d_spectrogram->colorMap());
rightAxis->setColorMap(d_spectrogram->data().range(),d_spectrogram->colorMap());
if(!zoomer->zoomRectIndex()) UnZoom();
setAxisScale(QwtPlot::yRight,d_spectrogram->data().range().minValue(),
d_spectrogram->data().range().maxValue());
@ -190,6 +196,36 @@ void SlsQt2DPlot::LogZ(bool on){
}
//Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range has been set
void SlsQt2DPlot::DisableZoom(bool disableZoom){
#ifdef VERBOSE
if(disableZoom) cout<<"Disabling zoom"<<endl;
else cout<<"Enabling zoom"<<endl;
#endif
if(disableZoom){
if(zoomer){
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,Qt::NoButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::NoButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::NoButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,Qt::NoButton);
}
if(panner) panner->setMouseButton(Qt::NoButton);
}else {
if(zoomer){
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,Qt::LeftButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::RightButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::RightButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,Qt::RightButton);
}
if(panner) panner->setMouseButton(Qt::MidButton);
}
}
/*

View File

@ -6,7 +6,7 @@
#include <iostream>
#include <qtoolbutton.h>
#include <qgroupbox.h>
#include <qgridlayout.h>
#include <qlabel.h>
@ -17,96 +17,180 @@
using namespace std;
SlsQt2DPlotLayout::SlsQt2DPlotLayout(QWidget *parent):QGroupBox(parent){
the_layout=0;
the_plot = new SlsQt2DPlot(this);
the_layout=0;
the_plot = new SlsQt2DPlot(this);
z_range_ne = new SlsQtNumberEntry(this,1,"Set the z axis range from",2,"to",2);
// z_range_ne->SetNDecimalsOfDoubleValidators(2);
z_range_ne->setFixedWidth(402);
z_range_ne->hide();
z_range_ne = new SlsQtNumberEntry(this,1,"Set the z axis range from",2,"to",2);
z_range_ne->setFixedWidth(402);
#ifndef IAN
zRangeChecked = false;
z_range_ne->hide();
#endif
logsChecked = false;
Layout();
ConnectSignalsAndSlots();
CreateTheButtons();
Layout();
ConnectSignalsAndSlots();
}
SlsQt2DPlotLayout::~SlsQt2DPlotLayout(){
if(the_layout) delete the_layout;
if(the_layout) delete the_layout;
delete the_plot;
delete z_range_ne;
delete the_plot;
delete z_range_ne;
}
void SlsQt2DPlotLayout::CreateTheButtons(){
/** Dhanya: All these buttons are already in another class, logz is used and a wrapper around it*/
#ifdef IAN
btnInterpolate = new QToolButton(this);
btnInterpolate->setText("Interpolate");
btnInterpolate->setCheckable(true);
btnInterpolate->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btnContour = new QToolButton(this);
btnContour->setText("Contour");
btnContour->setCheckable(true);
btnContour->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif
btnLogz = new QToolButton(this);
btnLogz->setText("Log Scale (Z)");
btnLogz->setCheckable(true);
btnLogz->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#ifndef IAN
btnLogz->hide();
#endif
}
void SlsQt2DPlotLayout::Layout(){
if(the_layout) delete the_layout;
the_layout = new QGridLayout(this);
the_layout->addWidget(the_plot,2,1,3,3);
the_layout->addWidget(z_range_ne,5,1,1,3);
if(the_layout) delete the_layout;
the_layout = new QGridLayout(this);
#ifdef IAN
the_layout->addWidget(btnInterpolate,1,1);
the_layout->addWidget(btnContour,1,2);
the_layout->addWidget(btnLogz,1,3);
#endif
the_layout->addWidget(the_plot,2,1,3,3);
the_layout->addWidget(z_range_ne,5,1,1,3);
#ifdef IAN
the_layout->setMargin(12);
#endif
}
void SlsQt2DPlotLayout::ConnectSignalsAndSlots(){
#ifndef IAN
connect(this, SIGNAL(InterpolateSignal(bool)), the_plot, SLOT(InterpolatedPlot(bool)));
connect(this, SIGNAL(ContourSignal(bool)), the_plot, SLOT(showContour(bool)));
connect(z_range_ne, SIGNAL(CheckBoxChanged(bool)), this, SLOT(ResetRange()));
connect(z_range_ne, SIGNAL(AValueChanged(SlsQtNumberEntry*)), this, SLOT(ResetRange()));
#else
connect(btnInterpolate, SIGNAL(toggled(bool)),the_plot, SLOT(InterpolatedPlot(bool)));
connect(btnContour, SIGNAL(toggled(bool)),the_plot, SLOT(showContour(bool)));
connect(btnLogz, SIGNAL(toggled(bool)),this,SLOT(SetZScaleToLog(bool)));
btnInterpolate->setChecked(false);
btnContour->setChecked(false);
#endif
connect(z_range_ne, SIGNAL(CheckBoxChanged(bool)), this, SLOT(ResetRange()));
connect(z_range_ne, SIGNAL(AValueChanged(SlsQtNumberEntry*)), this, SLOT(ResetRange()));
btnLogz->setChecked(false);
}
void SlsQt2DPlotLayout::UpdateNKeepSetRangeIfSet(){
if(z_range_ne->CheckBoxState()){
//just reset histogram range before update
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
}
the_plot->Update();
#ifdef IAN
if(z_range_ne->CheckBoxState()){
#else
if(zRangeChecked){
#endif
//just reset histogram range before update
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
}
the_plot->Update();
}
void SlsQt2DPlotLayout::ResetRange(){
//refind z limits
the_plot->SetZMinMax();
if(logsChecked) the_plot->SetZMinimumToFirstGreaterThanZero();
//refind z limits
the_plot->SetZMinMax();
if(btnLogz->isChecked()) the_plot->SetZMinimumToFirstGreaterThanZero();
#ifdef IAN
if(z_range_ne->CheckBoxState()){
#else
if(zRangeChecked){cout<<"entering:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
#endif
//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);cout<<"isok 0:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
if(!z_range_ne->IsValueOk(1)||same) z_range_ne->SetValue(the_plot->GetZMaximum(),1);cout<<"isok1:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
z_range_ne->SetRange(the_plot->GetZMinimum(),z_range_ne->GetValue(1),0); cout<<"setrange:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
z_range_ne->SetRange(z_range_ne->GetValue(0),the_plot->GetZMaximum(),1); cout<<"setrange:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
if(z_range_ne->CheckBoxState()){
//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
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
}
the_plot->Update();
//set histogram range
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1)); cout<<"setminmax:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
}
the_plot->Update();
}
void SlsQt2DPlotLayout::SetZScaleToLog(bool yes){
logsChecked=yes;
the_plot->LogZ(yes);
ResetRange();
#ifndef IAN
#ifdef VERBOSE
cout<<"Setting ZScale to log:"<<yes<<endl;
#endif
btnLogz->setChecked(yes);
#endif
the_plot->LogZ(yes);
ResetRange();
}
void SlsQt2DPlotLayout::SetXTitle(QString st){
GetPlot()->axisWidget(QwtPlot::xBottom)->setTitle(st);
#ifndef IAN
QwtText title(st);
title.setFont(QFont("Sans Serif",11,QFont::Normal));
GetPlot()->axisWidget(QwtPlot::xBottom)->setTitle(title);
#else
GetPlot()->axisWidget(QwtPlot::xBottom)->setTitle(st);
#endif
}
void SlsQt2DPlotLayout::SetYTitle(QString st){
GetPlot()->axisWidget(QwtPlot::yLeft)->setTitle(st);
#ifndef IAN
QwtText title(st);
title.setFont(QFont("Sans Serif",11,QFont::Normal));
GetPlot()->axisWidget(QwtPlot::yLeft)->setTitle(title);
#else
GetPlot()->axisWidget(QwtPlot::yLeft)->setTitle(st);
#endif
}
void SlsQt2DPlotLayout::SetZTitle(QString st){
GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(st);
#ifndef IAN
QwtText title(st);
title.setFont(QFont("Sans Serif",11,QFont::Normal));
GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(title);
#else
GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(st);
#endif
}
void SlsQt2DPlotLayout::SetTitle(QString st){
setTitle(st);
#ifndef IAN
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);
cout<<"\n\nthe valuessssssssssssssss:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
ResetRange();
cout<<"finaaaal valueeeeeeees:"<<z_range_ne->GetValue(0)<<"\t"<<z_range_ne->GetValue(1)<<endl;
}
void SlsQt2DPlotLayout::EnableZRange(bool enable){
#ifdef VERBOSE
cout<<"Setting Z Range Enable to "<<enable<<endl;
#endif
zRangeChecked = enable;
ResetRange();
}
#endif

View File

@ -253,7 +253,7 @@ double SlsQtNumberEntry::SetNumber(double v,int which_number_field){
}
if(validator_double[i]){
QString s = QString::number(v);
validator_double[i]->fixup(s);
validator_double[i]->fixup(s);
num_field[i]->setText(s);
}
}else if(spin_box[i]){
@ -267,7 +267,7 @@ double SlsQtNumberEntry::SetNumber(double v,int which_number_field){
void SlsQtNumberEntry::SetRange(int min, int max,int which_number_field){
int i = (which_number_field<0||which_number_field>1) ? 0:which_number_field;
if(min>max){
cout<<"Waring: SetRange(int,int) no effect min > max"<<endl;
cout<<"Warning: SetRange(int,int) no effect min > max"<<endl;
}else{
if(validator_int[i]) validator_int[i]->setRange(min,max);
if(validator_double[i]) validator_double[i]->setRange(min,max,validator_double[i]->decimals());
@ -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<<"Waring: SetRange(double,double) no effect min >= max"<<endl;
cout<<"Warning: SetRange(double,double) no effect min >= max"<<endl;
}else{
if(validator_int[i]) cout<<"Waring can not call SetRange(double,double) with \"int\" type Validator"<<endl;
if(validator_double[i]) validator_double[i]->setRange(min,max,validator_double[i]->decimals());