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

View File

@ -1,23 +1,8 @@
/**
* @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
#pragma once
#include <qwidget.h>
#include <qgroupbox.h>
#include "SlsQtNumberEntry.h"
#include "SlsQt2DPlot.h"
class QGridLayout;
@ -37,7 +22,7 @@ public:
void SetXTitle(QString st);
void SetYTitle(QString st);
void SetZTitle(QString st);
void UpdateNKeepSetRangeIfSet();
void KeepZRangeIfSet();
private:
@ -46,32 +31,23 @@ private:
QToolButton* btnContour;
QToolButton* btnLogz;
SlsQt2DPlot* the_plot;
SlsQtNumberEntry* z_range_ne;
#ifndef IAN
bool zRangeChecked;
#endif
void CreateTheButtons();
void ConnectSignalsAndSlots();
void Layout();
bool isLog;
double zmin;
double zmax;
bool isZmin;
bool isZmax;
public slots:
void SetZScaleToLog(bool yes);
void SetZScaleToLog(bool enable);
void ResetRange();
#ifndef IAN
void SetZRange(double,double);
void EnableZRange(bool enable);
void ResetZMinZMax(bool zmin, bool zmax, double min, double max);
#endif
void SetZRange(bool isMin, bool isMax, double min, double max);
signals:
void InterpolateSignal(bool);
void ContourSignal(bool);
void LogzSignal(bool);
};
#endif

View File

@ -1,9 +1,3 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#include <iostream>
#include <qtoolbutton.h>
@ -19,125 +13,67 @@
SlsQt2DPlotLayout::SlsQt2DPlotLayout(QWidget *parent):QGroupBox(parent){
the_layout=0;
the_plot = new SlsQt2DPlot(this);
z_range_ne = new SlsQtNumberEntry(this,1,(char*)"Set the z axis range from",2,(char*)"to",2);
z_range_ne->setFixedWidth(402);
zRangeChecked = false;
z_range_ne->hide();
CreateTheButtons();
isLog = false;
zmin = 0;
zmax = 0;
isZmin = false;
isZmax = false;
Layout();
ConnectSignalsAndSlots();
}
SlsQt2DPlotLayout::~SlsQt2DPlotLayout(){
if(the_layout) delete the_layout;
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(){
if(the_layout) delete the_layout;
the_layout = new QGridLayout(this);
the_layout->addWidget(the_plot,2,0,3,3);
the_layout->addWidget(z_range_ne,5,0,1,3);
}
void SlsQt2DPlotLayout::ConnectSignalsAndSlots(){
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()));
btnLogz->setChecked(false);
connect(this, SIGNAL(InterpolateSignal(bool)), the_plot, SLOT(InterpolatedPlot(bool)));
connect(this, SIGNAL(ContourSignal(bool)), the_plot, SLOT(showContour(bool)));
connect(this, SIGNAL(LogzSignal(bool)), this, SLOT(SetZScaleToLog(bool)));
}
void SlsQt2DPlotLayout::UpdateNKeepSetRangeIfSet(){
//just reset histogram range before update
the_plot->SetZMinMax(z_range_ne->GetValue(0),z_range_ne->GetValue(1));
the_plot->Update();
void SlsQt2DPlotLayout::KeepZRangeIfSet(){
SetZRange(isZMin, isZmax, zmin, zmax);
}
void SlsQt2DPlotLayout::ResetRange(){
//refind z limits
void SlsQt2DPlotLayout::SetZRange(bool isMin, bool isMax, double min, double max){
isZMin = isMin;
isZmax = isMax;
// reset zmin and zmax first
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
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())
if(isLog) {
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();
}
void SlsQt2DPlotLayout::SetZScaleToLog(bool yes){
#ifdef VERBOSE
cout<<"Setting ZScale to log:"<<yes<<endl;
#endif
btnLogz->setChecked(yes);
the_plot->LogZ(yes);
ResetRange();
void SlsQt2DPlotLayout::SetZScaleToLog(bool enable) {
FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Z Scale to log";
isLog = enable;
the_plot->LogZ(enable);
SetZRange(isZMin, isZmax, zmin, zmax);
}
@ -158,23 +94,3 @@ void SlsQt2DPlotLayout::SetZTitle(QString st){
title.setFont(QFont("Sans Serif",11,QFont::Normal));
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();
}