mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 14:39:00 +01:00
Creating Classes, Libraries and Functions for the Common SLS Detector GUI
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@1 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
73
slsDetectorGui/slsDetectorPlotting/include/SlsQtValidators.h
Normal file
73
slsDetectorGui/slsDetectorPlotting/include/SlsQtValidators.h
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
/**
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef SLSQTVALIDATORS_H
|
||||
#define SLSQTVALIDATORS_H
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qvalidator.h>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class SlsQtIntValidator:public QIntValidator{
|
||||
|
||||
public:
|
||||
SlsQtIntValidator(QWidget *parent):QIntValidator(parent){}
|
||||
|
||||
virtual void fixup (QString& text) const {
|
||||
bool ok = 1;
|
||||
int v = text.toInt(&ok);
|
||||
|
||||
if(!ok){
|
||||
v = text.toDouble(&ok);
|
||||
if(ok) text = QString::number(v);
|
||||
else text = QString::number(0);
|
||||
fixup(text);
|
||||
}
|
||||
|
||||
if(v<bottom()) text = QString::number(bottom());
|
||||
else if(v>top()) text = QString::number(top());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class SlsQtDoubleValidator:public QDoubleValidator{
|
||||
|
||||
public:
|
||||
SlsQtDoubleValidator(QWidget *parent):QDoubleValidator(parent){}
|
||||
|
||||
virtual void fixup (QString& text) const {
|
||||
|
||||
bool ok = 1;
|
||||
double v = text.toDouble(&ok);
|
||||
|
||||
if(!ok){
|
||||
text = QString::number(0);
|
||||
fixup(text);
|
||||
}
|
||||
|
||||
int nd = this->decimals(); //ndigest behind zero
|
||||
if(v<bottom()){
|
||||
text = QString::number(bottom(),'g',nd);
|
||||
}else{
|
||||
if(nd<0) nd=0;
|
||||
if(v>top()){
|
||||
v = floor(top()*pow(10,nd))/pow(10,nd);
|
||||
text = QString::number(v,'g');
|
||||
}else{
|
||||
v = round(v*pow(10,nd))/pow(10,nd);
|
||||
text = QString::number(v,'g');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user