#include "FitWidget.qo.h"
#include <guitools/Histogram/Fitter.h>
#include <guitools/Histogram/FitterGaussian.h>
#include <guitools/Histogram/FitterPoisson.h>
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/aipstype.h>
using namespace casacore;
FitWidget::FitWidget(QWidget *parent)
setSolutionVisible( false );
QDoubleValidator* posValidator = new QDoubleValidator( 0, std::numeric_limits<double>::max(), 10, this);
QDoubleValidator* validator = new QDoubleValidator(std::numeric_limits<double>::min(),
std::numeric_limits<double>::max(), 10, this);
ui.gaussCenterLineEdit->setValidator( validator );
ui.gaussPeakLineEdit->setValidator( validator );
ui.gaussFWHMLineEdit->setValidator( validator );
ui.poissonLambdaLineEdit->setValidator( posValidator );
connect( ui.gaussCenterLineEdit, SIGNAL(textEdited( const QString&)), this, SLOT( centerEdited( const QString& )));
connect( ui.gaussPeakLineEdit, SIGNAL(textEdited( const QString&)), this, SLOT( peakEdited( const QString& )));
connect( ui.gaussFWHMLineEdit, SIGNAL(textEdited(const QString&)), this, SLOT( fwhmEdited( const QString& )));
connect( ui.poissonLambdaLineEdit, SIGNAL(textEdited(const QString&)), this, SLOT( lambdaEdited( const QString&)));
QStringList fitList =(QStringList()<< "Gaussian" << "Poisson");
for ( int i = 0; i < fitList.size(); i++ ){
ui.fitDistributionComboBox->addItem( fitList[i] );
connect( ui.fitDistributionComboBox, SIGNAL( currentIndexChanged( int )),
this, SLOT(fitSelected(int)));
fitterGaussian = new FitterGaussian();
fitterPoisson = new FitterPoisson();
ui.fitStackedWidget->setCurrentIndex(0);
connect( ui.fitButton, SIGNAL(clicked()), this, SLOT(doFit()));
connect( ui.clearFitButton, SIGNAL(clicked()), this, SLOT(clearFit()));
bool FitWidget::isGaussian() const {
int index = ui.fitDistributionComboBox->currentIndex();
bool gaussianMode = false;
if ( index == GAUSSIAN_MODE ){
double FitWidget::getCenter() const {
double centerVal = ui.gaussCenterLineEdit->text().toDouble();
double FitWidget::getPeak() const {
double peakVal = ui.gaussPeakLineEdit->text().toDouble();