Changes for Qwt6, but 2D plot still does not work...and should be checked if Qwt5 still works

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@100 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
bergamaschi 2012-10-22 15:34:14 +00:00
parent 6cec748335
commit 8715a416a0
11 changed files with 184 additions and 21 deletions

View File

@ -227,7 +227,11 @@ void SavePlotAutomatic();
/** Sets the style of the 1d plot */
void SetStyle(SlsQtH1D* h){
if(lines) h->setStyle(QwtPlotCurve::Lines); else h->setStyle(QwtPlotCurve::Dots);
#if QWT_VERSION<0x060000
if(markers) h->setSymbol(*marker); else h->setSymbol(*noMarker);
#else
if(markers) h->setSymbol(marker); else h->setSymbol(noMarker);
#endif
};

View File

@ -20,7 +20,7 @@ QMAKE_CLEAN += docs/*/* \
LIBS += -Wl,-Bstatic -L../slsDetectorSoftware -lSlsDetector -Wl,-Bdynamic\
-L$(QWTDIR)/lib -lqwt
-L$(QWTDIR)/lib -lqwt -L$(QWT3D)/lib
DEPENDPATH += \
slsDetectorPlotting/include\
@ -31,6 +31,7 @@ DEPENDPATH += \
INCLUDEPATH += \
$(QWTDIR)/include\
$(QWTDIR)/src\
$(QWT3D)/include\
slsDetectorPlotting/include\
include\
forms/include\

View File

@ -6,10 +6,10 @@
#ifndef SLSQT1DZOOMER_H
#define SLSQT1DZOOMER_H
#include <qwt_compat.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_global.h>
class SlsQtH1D;
class SlsQt1DZoomer:public QwtPlotZoomer{
@ -42,14 +42,24 @@ class SlsQt1DZoomer:public QwtPlotZoomer{
bool SetLogX(bool yes) { return xIsLog=yes;}
bool SetLogY(bool yes) { return yIsLog=yes;}
#if QWT_VERSION<0x060000
virtual QwtText trackerText(const QwtDoublePoint &pos) const{
#else
virtual QwtText trackerText(const QPointF &pos) const{
#endif
QColor bg(Qt::white);
#if QT_VERSION >= 0x040300
bg.setAlpha(200);
#endif
#if QWT_VERSION<0x060000
QwtText text = QwtPlotZoomer::trackerText(pos);
#else
QPoint p=pos.toPoint();
QwtText text = QwtPlotZoomer::trackerText(p);
#endif
text.setBackgroundBrush( QBrush( bg ));
return text;
}

View File

@ -77,7 +77,14 @@ class SlsQt2DHist: public QwtRasterData{
//just passes a pointer so that data is common to both the copy and the original instance
return (QwtRasterData*) this;
}
#if QWT_VERSION<0x060000
virtual QwtDoubleInterval range() const{ return QwtDoubleInterval(z_min,z_max);}
#else
virtual QwtInterval range() const{ return QwtInterval(z_min,z_max);}
#endif
virtual double value(double x, double y) const{
//if(!interp){ //default is box like plot

View File

@ -16,6 +16,7 @@
#include <qwt_plot.h>
#include <qlist.h>
#include <qwt_plot_spectrogram.h>
#include "SlsQt2DZoomer.h"
@ -39,8 +40,14 @@ private:
QwtLinearColorMap* colorMapLinearScale;
QwtLinearColorMap* colorMapLogScale;
QwtLinearColorMap* currentColorMap;
#if QWT_VERSION<0x060000
QwtValueList* contourLevelsLinear;
QwtValueList* contourLevelsLog;
#else
QList<double> contourLevelsLinear;
QList<double> contourLevelsLog;
#endif
void SetupZoom();
void SetupColorMap();

View File

@ -27,7 +27,12 @@ class SlsQt2DZoomer:public QwtPlotZoomer{
hist=h;
}
#if QWT_VERSION<0x060000
virtual QwtText trackerText(const QwtDoublePoint &pos) const{
#else
virtual QwtText trackerText(const QPointF &pos) const{
#endif
QColor bg(Qt::white);
#if QT_VERSION >= 0x040300
bg.setAlpha(200);
@ -41,8 +46,15 @@ class SlsQt2DZoomer:public QwtPlotZoomer{
static char t[200];
sprintf(t,"%3.2f, %3.2f, %3.2f",pos.x(),pos.y(),hist->value(pos.x(),pos.y()));
text.setText(t);
}else text = QwtPlotZoomer::trackerText(pos);
}else {
#if QWT_VERSION<0x060000
QwtText text = QwtPlotZoomer::trackerText(pos);
#else
QPoint p=pos.toPoint();
QwtText text = QwtPlotZoomer::trackerText(p);
#endif
}
text.setBackgroundBrush( QBrush( bg ));
return text;
}

View File

@ -119,8 +119,11 @@ void SlsQtH1D::SetData(int n, double xmin, double xmax, double *data){
// if(firstXgt0<0)firstXgt0=0.001;
// if(firstYgt0<0)firstYgt0=0.001;
#if QWT_VERSION<0x060000
setRawData(x,y,ndata);
#else
setRawSamples(x,y,ndata);
#endif
}
void SlsQtH1D::SetData(int n, double* data_x, double *data_y){
@ -146,7 +149,11 @@ void SlsQtH1D::SetData(int n, double* data_x, double *data_y){
if(y[b]>0&&(firstYgt0<0||firstYgt0>y[b])) firstYgt0=y[b];
}
#if QWT_VERSION<0x060000
setRawData(x,y,ndata);
#else
setRawSamples(x,y,ndata);
#endif
}
int SlsQtH1D::SetUpArrays(int n){
@ -441,11 +448,19 @@ void SlsQt1DPlot::alignScales(){
}
void SlsQt1DPlot::UnknownStuff(){
#if QWT_VERSION<0x060000
// Disable polygon clipping
//not supported for version 6
QwtPainter::setDeviceClipping(false);
// We don't need the cache here
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
#else
// We don't need the cache here
canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
#endif
#if QT_VERSION >= 0x040000
#ifdef Q_WS_X11

View File

@ -61,7 +61,11 @@ void SlsQt1DZoomer::SetZoomBase(double xmin,double ymin,double x_width, double y
plot()->replot();
}
#if QWT_VERSION<0x060000
setZoomBase(QwtDoubleRect(xmin,ymin,x_width,y_width));
#else
setZoomBase(QRectF(xmin,ymin,x_width,y_width));
#endif
}
void SlsQt1DZoomer::SetZoomBase(SlsQtH1D* h){

View File

@ -54,7 +54,14 @@ void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,doubl
if(x_min!=xmin||x_max!=xmax||y_min!=ymin||y_max!=ymax){
x_min=xmin;x_max=xmax;
y_min=ymin;y_max=ymax;
setBoundingRect(QwtDoubleRect(xmin,ymin,x_max-x_min,y_max-y_min));
#if QWT_VERSION<0x060000
setBoundingRect(QRectF(xmin,ymin,x_max-x_min,y_max-y_min));
#else
setInterval( Qt::XAxis,QwtInterval(xmin,xmax));
setInterval( Qt::YAxis,QwtInterval(ymin,ymax));
#endif
}
if(nbinsx*nbinsy<1){

View File

@ -8,6 +8,7 @@
#include <iostream>
#include <qprinter.h>
#include <qtoolbutton.h>
#include <qlist.h>
#if QT_VERSION >= 0x040000
#include <qprintdialog.h>
@ -33,11 +34,18 @@ SlsQt2DPlot::SlsQt2DPlot(QWidget *parent):QwtPlot(parent){
d_spectrogram = new QwtPlotSpectrogram();
hist = new SlsQt2DHist();
currentColorMap=NULL;
SetupZoom();
SetupColorMap();
#if QWT_VERSION<0x060000
d_spectrogram->setData(*hist);
#else
d_spectrogram->setData(hist);
#endif
d_spectrogram->attach(this);
plotLayout()->setAlignCanvasToScales(true);
@ -55,7 +63,13 @@ void SlsQt2DPlot::SetupColorMap(){
colorMapLinearScale->addColorStop(0.4, Qt::blue);
colorMapLinearScale->addColorStop(0.6, Qt::green);
colorMapLinearScale->addColorStop(0.95, Qt::yellow);
#if QWT_VERSION<0x060000
d_spectrogram->setColorMap(*colorMapLinearScale);
#else
d_spectrogram->setColorMap(colorMapLinearScale);
currentColorMap=colorMapLinearScale;
cout << "current color map is linear" << endl;
#endif
colorMapLogScale = new QwtLinearColorMap(Qt::darkCyan, Qt::red);
@ -64,12 +78,29 @@ void SlsQt2DPlot::SetupColorMap(){
colorMapLogScale->addColorStop((pow(10,2*0.60)-1)/99.0,Qt::green);
colorMapLogScale->addColorStop((pow(10,2*0.95)-1)/99.0,Qt::yellow);
#if QWT_VERSION<0x060000
contourLevelsLinear = new QwtValueList();
for(double level=0.5;level<10.0;level+=1.0 ) (*contourLevelsLinear) += level;
d_spectrogram->setContourLevels(*contourLevelsLinear);
#else
;
// contourLevelsLinear = new QList();
for(double level=0.5;level<10.0;level+=1.0 ) (contourLevelsLinear) += level;
d_spectrogram->setContourLevels(contourLevelsLinear);
#endif
//
#if QWT_VERSION<0x060000
contourLevelsLog = new QwtValueList();
for(double level=0.5;level<10.0;level+=1.0 ) (*contourLevelsLog) += (pow(10,2*level/10.0)-1)/99.0 * 10;
#else
;
// contourLevelsLog = new QList();
for(double level=0.5;level<10.0;level+=1.0 ) (contourLevelsLog) += (pow(10,2*level/10.0)-1)/99.0 * 10;
#endif
// A color bar on the right axis
rightAxis = axisWidget(QwtPlot::yRight);
@ -137,14 +168,23 @@ void SlsQt2DPlot::SetupZoom(){
}*/
void SlsQt2DPlot::UnZoom(){
#if QWT_VERSION<0x060000
zoomer->setZoomBase(QwtDoubleRect(hist->GetXMin(),hist->GetYMin(),hist->GetXMax()-hist->GetXMin(),hist->GetYMax()-hist->GetYMin()));
#else
zoomer->setZoomBase(QRectF(hist->GetXMin(),hist->GetYMin(),hist->GetXMax()-hist->GetXMin(),hist->GetYMax()-hist->GetYMin()));
#endif
zoomer->setZoomBase();//Call replot for the attached plot before initializing the zoomer with its scales.
// zoomer->zoom(0);
}
void SlsQt2DPlot::SetZoom(double xmin,double ymin,double x_width,double y_width){
#if QWT_VERSION<0x060000
zoomer->setZoomBase(QwtDoubleRect(xmin,ymin,x_width,y_width));
#else
zoomer->setZoomBase(QRectF(xmin,ymin,x_width,y_width));
#endif
}
void SlsQt2DPlot::SetZMinMax(double zmin,double zmax){
@ -153,10 +193,32 @@ void SlsQt2DPlot::SetZMinMax(double zmin,double zmax){
void SlsQt2DPlot::Update(){
#if QWT_VERSION<0x060000
rightAxis->setColorMap(d_spectrogram->data().range(),d_spectrogram->colorMap());
#else
;
rightAxis->setColorMap(d_spectrogram->data()->interval(Qt::ZAxis),currentColorMap);
cout << "Should reset the color map? " << currentColorMap << endl;
// QwtColorMap *c=d_spectrogram->colorMap();
// rightAxis->setColorMap(d_spectrogram->data()->interval(Qt::ZAxis),c);
#endif
if(!zoomer->zoomRectIndex()) UnZoom();
#if QWT_VERSION<0x060000
setAxisScale(QwtPlot::yRight,d_spectrogram->data().range().minValue(),
d_spectrogram->data().range().maxValue());
#else
setAxisScale(QwtPlot::yRight,d_spectrogram->data()->interval(Qt::ZAxis).minValue(),
d_spectrogram->data()->interval(Qt::ZAxis).maxValue());
cout << "min is " << d_spectrogram->data()->interval(Qt::YAxis).minValue() << endl;
cout << "max is " << d_spectrogram->data()->interval(Qt::YAxis).maxValue() << endl;
#endif
replot();
}
@ -184,13 +246,31 @@ void SlsQt2DPlot::InterpolatedPlot(bool on){
void SlsQt2DPlot::LogZ(bool on){
if(on){
//if(hist->GetMinimum()<=0) hist->SetMinimumToFirstGreaterThanZero();
#if QWT_VERSION<0x060000
d_spectrogram->setColorMap(*colorMapLogScale);
#else
d_spectrogram->setColorMap(colorMapLogScale);
currentColorMap=colorMapLogScale;
#endif
setAxisScaleEngine(QwtPlot::yRight,new QwtLog10ScaleEngine);
#if QWT_VERSION<0x060000
d_spectrogram->setContourLevels(*contourLevelsLog);
#else
d_spectrogram->setContourLevels(contourLevelsLog);
#endif
}else{
#if QWT_VERSION<0x060000
d_spectrogram->setColorMap(*colorMapLinearScale);
#else
d_spectrogram->setColorMap(colorMapLinearScale);
currentColorMap=colorMapLinearScale;
#endif
setAxisScaleEngine(QwtPlot::yRight,new QwtLinearScaleEngine);
#if QWT_VERSION<0x060000
d_spectrogram->setContourLevels(*contourLevelsLinear);
#else
d_spectrogram->setContourLevels(contourLevelsLinear);
#endif
}
Update();

View File

@ -114,10 +114,18 @@ void qCloneWidget::SetCloneHists(int nHists,int histNBins,double* histXAxis,doub
QwtSymbol *marker = new QwtSymbol();
marker->setStyle(QwtSymbol::Cross);
marker->setSize(5,5);
#if QWT_VERSION<0x060000
k->setSymbol(*marker);
#else
k->setSymbol(marker);
#endif
}else {
QwtSymbol *noMarker = new QwtSymbol();
#if QWT_VERSION<0x060000
k->setSymbol(*noMarker);
#else
k->setSymbol(noMarker);
#endif
}
//set title and attach plot
k->setTitle(histTitle[hist_num].c_str());
@ -149,10 +157,18 @@ void qCloneWidget::SetCloneHists(int nHists,int histNBins,double* histXAxis,doub
QwtSymbol *marker = new QwtSymbol();
marker->setStyle(QwtSymbol::Cross);
marker->setSize(5,5);
#if QWT_VERSION<0x060000
k->setSymbol(*marker);
#else
k->setSymbol(marker);
#endif
}else {
QwtSymbol *noMarker = new QwtSymbol();
#if QWT_VERSION<0x060000
k->setSymbol(*noMarker);
#else
k->setSymbol(noMarker);
#endif
}
//set title and attach plot
k->setTitle(histTitle[hist_num].c_str());