#include "SpecifyFunDialog.h"
#include <QMessageBox>
//
//##############################################################################
//                          SpecifyFunDialog.cpp
//##############################################################################
//
// Implementation of the SpecifyFunDialog class. 
//
// Math 157                                                       March 3, 2009
//
SpecifyFunDialog::SpecifyFunDialog(QWidget *parent): QDialog(parent)
{
     setupUi(this);
	 currentFtext = "x^2";
}

//
// This member function overrides the QDialog::exec() member
// function and loads the input boxes with current values.
//

int SpecifyFunDialog::exec()
{
    fxInput->setText(currentFtext);

//call base class implementation

	return QDialog::exec();
}

//
// This member function overrides the QDialog::accept() member
// function and processes the contents of the QLineEdit holding
// the function string text when OK is hit. 
//

void SpecifyFunDialog::accept()
{
//
//  Capture input from text box
//
	QString fxText = fxInput->text();
//
//  Validate input. As a test case, if the input string contains
//  a # then pop up an error dialog (using static QMessageBox functions)
//  and don't call the QDialog::accept() so that the dialog remains active. 
//
	if(fxText.contains("#"))
	{
    QMessageBox::critical(this, 
		tr("Function Specification"),
		tr("An unacceptable function has been entered"),
		QMessageBox::Ok);
	return;
	}
//
//  Set current text to contents of text box
//
	currentFtext = fxText;

//call base class implementation

	QDialog::accept();
}





