mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
gui works, including clone plots
This commit is contained in:
@ -114,9 +114,12 @@ class SlsQt1DPlot:public QwtPlot{
|
||||
SlsQt1DPlot(QWidget* = NULL);
|
||||
~SlsQt1DPlot();
|
||||
|
||||
void SetTitle(const char *t);
|
||||
void SetXTitle(const char* title);
|
||||
void SetYTitle(const char* title);
|
||||
void SetTitle(QString title);
|
||||
void SetXTitle(QString title);
|
||||
void SetYTitle(QString title);
|
||||
void SetTitleFont(const QFont& f);
|
||||
void SetXFont(const QFont& f);
|
||||
void SetYFont(const QFont& f);
|
||||
|
||||
void InsertHLine(double y);
|
||||
void RemoveHLine();
|
||||
|
@ -1,19 +1,4 @@
|
||||
|
||||
/**
|
||||
* @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 SLSQT2DPLOT_H
|
||||
#define SLSQT2DPLOT_H
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
@ -33,43 +18,20 @@ class QwtLinearColorMap;
|
||||
class SlsQt2DPlot: public QwtPlot{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QwtPlotSpectrogram *d_spectrogram;
|
||||
SlsQt2DHist* hist;
|
||||
SlsQt2DZoomer* zoomer;
|
||||
QwtPlotPanner* panner;
|
||||
QwtScaleWidget *rightAxis;
|
||||
|
||||
QwtLinearColorMap* colorMapLinearScale;
|
||||
QwtLinearColorMap* colorMapLogScale;
|
||||
#if QWT_VERSION<0x060000
|
||||
QwtValueList* contourLevelsLinear;
|
||||
QwtValueList* contourLevelsLog;
|
||||
#else
|
||||
QList<double> contourLevelsLinear;
|
||||
QList<double> contourLevelsLog;
|
||||
#endif
|
||||
bool disableZoom{false};
|
||||
|
||||
void SetupZoom();
|
||||
void SetupColorMap();
|
||||
|
||||
QwtLinearColorMap* myColourMap(QVector<double> colourStops);
|
||||
QwtLinearColorMap* myColourMap(int log=0);
|
||||
|
||||
int isLog;
|
||||
|
||||
|
||||
public:
|
||||
SlsQt2DPlot(QWidget * = NULL);
|
||||
|
||||
// SlsQt2DHist *GetHistogram(){ return hist; }
|
||||
void UnZoom(bool replot=true);
|
||||
void SetZoom(double xmin,double ymin,double x_width,double y_width);
|
||||
void SetTitle(QString title);
|
||||
void SetXTitle(QString title);
|
||||
void SetYTitle(QString title);
|
||||
void SetZTitle(QString title);
|
||||
void SetTitleFont(const QFont& f);
|
||||
void SetXFont(const QFont& f);
|
||||
void SetYFont(const QFont& f);
|
||||
void SetZFont(const QFont& f);
|
||||
|
||||
|
||||
/** This group of functions have been added by Dhanya on 19.06.2012 to be able to
|
||||
use zooming functionality without mouse control*/
|
||||
void UnZoom(bool replot=true);
|
||||
void SetZoom(double xmin,double ymin,double x_width,double y_width);
|
||||
void DisableZoom(bool disable);
|
||||
void EnableXAutoScaling() {setAxisAutoScale(QwtPlot::xBottom, true);};
|
||||
void EnableYAutoScaling() {setAxisAutoScale(QwtPlot::yLeft, true);};
|
||||
@ -79,38 +41,58 @@ public:
|
||||
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);
|
||||
void SetZMinimumToFirstGreaterThanZero(){hist->SetMinimumToFirstGreaterThanZero();}
|
||||
void SetZMinMax(double zmin=0,double zmax=-1);
|
||||
void SetZMinimumToFirstGreaterThanZero(){hist->SetMinimumToFirstGreaterThanZero();}
|
||||
double GetZMean() { return hist->GetMean();}
|
||||
|
||||
void SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax,double *d,double zmin=0, double zmax=-1){
|
||||
hist->SetData(nbinsx,xmin,xmax,nbinsy,ymin,ymax,d,zmin,zmax);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double* GetDataPtr() {return hist->GetDataPtr();}
|
||||
int GetBinIndex(int bx,int by) {return hist->GetBinIndex(bx,by);}
|
||||
int FindBinIndex(double x,double y) {return hist->FindBinIndex(x,y);}
|
||||
void SetBinValue(int bx,int by,double v) { hist->SetBinValue(bx,by,v);}
|
||||
double GetBinValue(int bx,int by) {return hist->GetBinValue(bx,by);}
|
||||
|
||||
|
||||
void FillTestPlot(int i=0);
|
||||
void Update();
|
||||
int GetBinIndex(int bx,int by) {return hist->GetBinIndex(bx,by);}
|
||||
int FindBinIndex(double x,double y) {return hist->FindBinIndex(x,y);}
|
||||
void SetBinValue(int bx,int by,double v) { hist->SetBinValue(bx,by,v);}
|
||||
double GetBinValue(int bx,int by) {return hist->GetBinValue(bx,by);}
|
||||
void FillTestPlot(int i=0);
|
||||
void Update();
|
||||
|
||||
void SetInterpolate(bool enable);
|
||||
void SetContour(bool enable);
|
||||
void SetLogz(bool enable, bool isMin, bool isMax, double min, double max);
|
||||
void SetZRange(bool isMin, bool isMax, double min, double max);
|
||||
void LogZ(bool on=1);
|
||||
void InterpolatedPlot(bool on);
|
||||
void showContour(bool on);
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
void showSpectrogram(bool on);
|
||||
// void printPlot();
|
||||
|
||||
|
||||
private:
|
||||
void SetupZoom();
|
||||
void SetupColorMap();
|
||||
QwtLinearColorMap* myColourMap(QVector<double> colourStops);
|
||||
QwtLinearColorMap* myColourMap(int log=0);
|
||||
|
||||
QwtPlotSpectrogram *d_spectrogram;
|
||||
SlsQt2DHist* hist;
|
||||
SlsQt2DZoomer* zoomer;
|
||||
QwtPlotPanner* panner;
|
||||
QwtScaleWidget *rightAxis;
|
||||
|
||||
QwtLinearColorMap* colorMapLinearScale;
|
||||
QwtLinearColorMap* colorMapLogScale;
|
||||
#if QWT_VERSION<0x060000
|
||||
QwtValueList* contourLevelsLinear;
|
||||
QwtValueList* contourLevelsLog;
|
||||
#else
|
||||
QList<double> contourLevelsLinear;
|
||||
QList<double> contourLevelsLog;
|
||||
#endif
|
||||
bool disableZoom{false};
|
||||
int isLog;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <qgroupbox.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
#include "SlsQt2DPlot.h"
|
||||
|
||||
class QGridLayout;
|
||||
class QString;
|
||||
class QToolButton;
|
||||
|
||||
class SlsQt2DPlotLayout : public QGroupBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SlsQt2DPlotLayout(QWidget * = NULL);
|
||||
~SlsQt2DPlotLayout();
|
||||
|
||||
SlsQt2DPlot *GetPlot();
|
||||
void SetXTitle(QString st);
|
||||
void SetYTitle(QString st);
|
||||
void SetZTitle(QString st);
|
||||
void SetInterpolate(bool enable);
|
||||
void SetContour(bool enable);
|
||||
void SetLogz(bool enable, bool isMin, bool isMax, double min, double max);
|
||||
void SetZRange(bool isMin, bool isMax, double min, double max);
|
||||
|
||||
private:
|
||||
void Layout();
|
||||
|
||||
QGridLayout *the_layout;
|
||||
QToolButton *btnInterpolate;
|
||||
QToolButton *btnContour;
|
||||
QToolButton *btnLogz;
|
||||
SlsQt2DPlot *the_plot;
|
||||
|
||||
bool isLog;
|
||||
};
|
@ -395,18 +395,34 @@ void SlsQt1DPlot::Update() {
|
||||
replot();
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::SetTitle(const char *title) {
|
||||
void SlsQt1DPlot::SetTitle(QString title) {
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::SetXTitle(const char *title) {
|
||||
QwtText t(title);
|
||||
t.setFont(QFont("Sans Serif", 11, QFont::Normal));
|
||||
void SlsQt1DPlot::SetXTitle(QString title) {
|
||||
setAxisTitle(QwtPlot::xBottom, title);
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::SetYTitle(QString title) {
|
||||
setAxisTitle(QwtPlot::yLeft, title);
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::SetTitleFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
t.setRenderFlags( Qt::AlignLeft | Qt::AlignVCenter);
|
||||
setTitle(t);
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::SetXFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
setAxisTitle(QwtPlot::xBottom, t);
|
||||
}
|
||||
void SlsQt1DPlot::SetYTitle(const char *title) {
|
||||
QwtText t(title);
|
||||
t.setFont(QFont("Sans Serif", 11, QFont::Normal));
|
||||
|
||||
void SlsQt1DPlot::SetYFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
setAxisTitle(QwtPlot::yLeft, t);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include "SlsQt2DPlot.h"
|
||||
|
||||
/**
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
#include "ansi.h"
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
@ -22,7 +19,7 @@
|
||||
#include <qwt_scale_engine.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
|
||||
#include "SlsQt2DPlot.h"
|
||||
|
||||
|
||||
#if QWT_VERSION >= 0x060100
|
||||
#define QwtLog10ScaleEngine QwtLogScaleEngine
|
||||
@ -54,6 +51,48 @@ SlsQt2DPlot::SlsQt2DPlot(QWidget *parent) : QwtPlot(parent) {
|
||||
Update();
|
||||
}
|
||||
|
||||
|
||||
void SlsQt2DPlot::SetTitle(QString title) {
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetXTitle(QString title) {
|
||||
setAxisTitle(QwtPlot::xBottom, title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetYTitle(QString title) {
|
||||
setAxisTitle(QwtPlot::yLeft, title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetZTitle(QString title) {
|
||||
setAxisTitle(QwtPlot::yRight, title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetTitleFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
t.setRenderFlags( Qt::AlignLeft | Qt::AlignVCenter);
|
||||
setTitle(t);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetXFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
setAxisTitle(QwtPlot::xBottom, t);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetYFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
setAxisTitle(QwtPlot::yLeft, t);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetZFont(const QFont& f) {
|
||||
QwtText t("");
|
||||
t.setFont(f);
|
||||
setAxisTitle(QwtPlot::yRight, t);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetupColorMap() {
|
||||
|
||||
colorMapLinearScale = myColourMap(0);
|
||||
@ -179,6 +218,45 @@ void SlsQt2DPlot::SetZoom(double xmin, double ymin, double x_width, double y_wid
|
||||
#endif
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::DisableZoom(bool disable) {
|
||||
if (disableZoom != disable) {
|
||||
disableZoom = disable;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (disable)
|
||||
std::cout << "Disabling zoom\n";
|
||||
else
|
||||
std::cout << "Enabling zoom\n";
|
||||
#endif
|
||||
if (disable) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SlsQt2DPlot::SetZMinMax(double zmin, double zmax) {
|
||||
hist->SetMinMax(zmin, zmax);
|
||||
}
|
||||
@ -250,22 +328,34 @@ void SlsQt2DPlot::Update() {
|
||||
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::showContour(bool on) {
|
||||
d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ContourMode, on);
|
||||
void SlsQt2DPlot::SetInterpolate(bool enable) {
|
||||
hist->Interpolate(enable);
|
||||
Update();
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::showSpectrogram(bool on) {
|
||||
// static int io=0;
|
||||
// FillTestPlot(io++);
|
||||
d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, on);
|
||||
d_spectrogram->setDefaultContourPen(on ? QPen() : QPen(Qt::NoPen));
|
||||
void SlsQt2DPlot::SetContour(bool enable) {
|
||||
d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ContourMode, enable);
|
||||
Update();
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::InterpolatedPlot(bool on) {
|
||||
hist->Interpolate(on);
|
||||
Update();
|
||||
void SlsQt2DPlot::SetLogz(bool enable, bool isMin, bool isMax, double min, double max) {
|
||||
LogZ(enable);
|
||||
SetZRange(isMin, isMax, min, max);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetZRange(bool isMin, bool isMax, double min, double max){
|
||||
if(isLog) {
|
||||
SetZMinimumToFirstGreaterThanZero();
|
||||
}
|
||||
|
||||
// set zmin and zmax
|
||||
if (isMin || isMax) {
|
||||
double zmin = (isMin ? min : GetZMinimum());
|
||||
double zmax = (isMax ? max : GetZMaximum());
|
||||
SetZMinMax(zmin, zmax);
|
||||
}
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::LogZ(bool on) {
|
||||
@ -303,45 +393,15 @@ void SlsQt2DPlot::LogZ(bool on) {
|
||||
Update();
|
||||
}
|
||||
|
||||
//Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range has been set
|
||||
void SlsQt2DPlot::DisableZoom(bool disable) {
|
||||
if (disableZoom != disable) {
|
||||
disableZoom = disable;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (disable)
|
||||
std::cout << "Disabling zoom\n";
|
||||
else
|
||||
std::cout << "Enabling zoom\n";
|
||||
#endif
|
||||
if (disable) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
void SlsQt2DPlot::showSpectrogram(bool on) {
|
||||
// static int io=0;
|
||||
// FillTestPlot(io++);
|
||||
d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, on);
|
||||
d_spectrogram->setDefaultContourPen(on ? QPen() : QPen(Qt::NoPen));
|
||||
Update();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void SlsQt2DPlot::printPlot(){
|
||||
QPrinter printer;
|
||||
|
@ -1,81 +0,0 @@
|
||||
#include "SlsQt2DPlotLayout.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "ansi.h"
|
||||
#include <qtoolbutton.h>
|
||||
#include <qgroupbox.h>
|
||||
#include <qgridlayout.h>
|
||||
#include <qlabel.h>
|
||||
#include <QString>
|
||||
|
||||
SlsQt2DPlotLayout::SlsQt2DPlotLayout(QWidget *parent):QGroupBox(parent){
|
||||
the_layout=0;
|
||||
the_plot = new SlsQt2DPlot(this);
|
||||
isLog = false;
|
||||
Layout();
|
||||
}
|
||||
|
||||
SlsQt2DPlotLayout::~SlsQt2DPlotLayout(){
|
||||
if(the_layout) delete the_layout;
|
||||
delete the_plot;
|
||||
}
|
||||
|
||||
SlsQt2DPlot* SlsQt2DPlotLayout::GetPlot(){
|
||||
return the_plot;
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetXTitle(QString st){
|
||||
QwtText title(st);
|
||||
title.setFont(QFont("Sans Serif",11,QFont::Normal));
|
||||
GetPlot()->axisWidget(QwtPlot::xBottom)->setTitle(title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetYTitle(QString st){
|
||||
QwtText title(st);
|
||||
title.setFont(QFont("Sans Serif",11,QFont::Normal));
|
||||
GetPlot()->axisWidget(QwtPlot::yLeft)->setTitle(title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetZTitle(QString st){
|
||||
QwtText title(st);
|
||||
title.setFont(QFont("Sans Serif",11,QFont::Normal));
|
||||
GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(title);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetInterpolate(bool enable) {
|
||||
the_plot->InterpolatedPlot(enable);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetContour(bool enable) {
|
||||
the_plot->showContour(enable);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetLogz(bool enable, bool isMin, bool isMax, double min, double max) {
|
||||
isLog = enable;
|
||||
the_plot->LogZ(enable);
|
||||
SetZRange(isMin, isMax, min, max);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::Layout(){
|
||||
if(the_layout) delete the_layout;
|
||||
the_layout = new QGridLayout(this);
|
||||
the_layout->addWidget(the_plot,2,0,3,3);
|
||||
}
|
||||
|
||||
void SlsQt2DPlotLayout::SetZRange(bool isMin, bool isMax, double min, double max){
|
||||
if(isLog) {
|
||||
the_plot->SetZMinimumToFirstGreaterThanZero();
|
||||
}
|
||||
|
||||
// set zmin and zmax
|
||||
if (isMin || isMax) {
|
||||
double zmin = (isMin ? min : the_plot->GetZMinimum());
|
||||
double zmax = (isMax ? max : the_plot->GetZMaximum());
|
||||
the_plot->SetZMinMax(zmin, zmax);
|
||||
}
|
||||
|
||||
the_plot->Update();
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user