void BaselineDialog::modifyBaseline()
{
	if (!d_baseline)
		createBaseline();

	disableBaselineTool();

	if (d_baseline->type() == Graph::Function){
		ApplicationWindow *app = (ApplicationWindow *)parent();
		int points = d_baseline->dataSize();
		d_table = app->newTable(points, 2);
		app->setWindowName(d_table, tr("Baseline"));
		app->hideWindow(d_table);
		for (int i = 0; i < points; i++){
			d_table->setCell(i, 0, d_baseline->x(i));
			d_table->setCell(i, 1, d_baseline->y(i));
		}

		QPen pen = d_baseline->pen();
		graph->removeCurve(d_baseline->title().text());
		delete d_baseline;

		d_baseline = graph->insertCurve(d_table, d_table->objectName() + "_2", Graph::Line);
		d_baseline->setPen(pen);
	}

	d_baseline->setSymbol(QwtSymbol(QwtSymbol::Rect, QBrush(Qt::black), d_baseline->pen(), QSize(7, 7)));

	d_picker_tool = new BaselineTool(d_baseline, graph, (ApplicationWindow *)parent());
	graph->setActiveTool(d_picker_tool);
	graph->replot();
}
bool atWrapper::runAutoTests()
{
    //SVG needs this widget...
    QWidget dummy;

    bool haveBaseline = false;

    if (!initTests(&haveBaseline))
        return false;
    executeTests();

    if ( !haveBaseline )
    {
        qDebug( " First run! Creating baseline..." );
        createBaseline();
    }
    else
    {
        qDebug( " Comparing results..." );
        compare();
    }
    return true;
}
BaselineDialog::BaselineDialog( QWidget* parent, Qt::WFlags fl )
	: QDialog( parent, fl ),
	d_baseline(NULL),
	d_table(NULL),
	d_picker_tool(NULL)
{
	setObjectName( "BaselineDialog" );
	setWindowTitle(tr("QtiPlot") + " - " + tr("Baseline"));
	setAttribute(Qt::WA_DeleteOnClose);
	setSizeGripEnabled( true );

	QGroupBox *gb1 = new QGroupBox();
	QGridLayout *gl1 = new QGridLayout(gb1);

	gl1->addWidget(new QLabel(tr("Curve")), 0, 0);

	boxInputName = new QComboBox();
	gl1->addWidget(boxInputName, 0, 1);

	boxPoints = new QSpinBox();
	boxPoints->setMinimum(2);
	boxPoints->setMaximum(INT_MAX);

	gl1->addWidget(new QLabel(tr("Points")), 1, 0);
	gl1->addWidget(boxPoints, 1, 1);

	btnAutomatic = new QRadioButton(tr("&Interpolation"));
	btnAutomatic->setChecked(true);
	gl1->addWidget(btnAutomatic, 2, 0);

	boxInterpolationMethod = new QComboBox();
	boxInterpolationMethod->addItems(QStringList() << tr("Linear") << tr("Cubic") << tr("Non-rounded Akima"));
	gl1->addWidget(boxInterpolationMethod, 2, 1);

	btnEquation = new QRadioButton(tr("User Defined &Equation Y ="));
	btnEquation->setChecked(false);
	gl1->addWidget(btnEquation, 3, 0);

	boxEquation = new QLineEdit();
	gl1->addWidget(boxEquation, 3, 1);

	btnDataset = new QRadioButton(tr("Existing &Dataset"));
	btnDataset->setChecked(false);
	gl1->addWidget(btnDataset, 4, 0);

	boxTableName = new QComboBox();
	boxColumnName = new QComboBox();

	QHBoxLayout *hb0 = new QHBoxLayout();
	hb0->addWidget(boxTableName);
	hb0->addWidget(boxColumnName);
	gl1->addLayout(hb0, 4, 1);

	gl1->setColumnStretch(1, 1);
	gl1->setRowStretch(5, 1);

	ApplicationWindow *app = (ApplicationWindow *)parent;
	boxTableName->addItems(app->tableNames());
	updateTableColumns(0);

	buttonCreate = new QPushButton(tr( "Create &Baseline" ));
	buttonCreate->setDefault( true );
	buttonSubtract = new QPushButton(tr( "&Subtract" ));
	buttonUndo = new QPushButton(tr( "&Undo Subtraction" ));
	buttonModify = new QPushButton(tr( "&Modify" ));
	buttonModify->setCheckable(true);
	buttonCancel = new QPushButton(tr( "&Close" ));

	QVBoxLayout *vl = new QVBoxLayout();
	vl->addWidget(buttonCreate);
	vl->addWidget(buttonModify);
	vl->addWidget(buttonSubtract);
	vl->addWidget(buttonUndo);
	vl->addStretch();
	vl->addWidget(buttonCancel);

	QHBoxLayout *hb = new QHBoxLayout(this);
	hb->addWidget(gb1);
	hb->addLayout(vl);

	enableBaselineOptions();

	connect(boxTableName, SIGNAL(activated(int)), this, SLOT(updateTableColumns(int)));
	connect(buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
	connect(buttonCreate, SIGNAL(clicked()), this, SLOT(createBaseline()));
	connect(buttonSubtract, SIGNAL(clicked()), this, SLOT(subtractBaseline()));
	connect(buttonUndo, SIGNAL(clicked()), this, SLOT(undo()));
	connect(buttonModify, SIGNAL(clicked()), this, SLOT(modifyBaseline()));

	connect(btnAutomatic, SIGNAL(toggled(bool)), this, SLOT(enableBaselineOptions()));
	connect(btnEquation, SIGNAL(toggled(bool)), this, SLOT(enableBaselineOptions()));
	connect(btnDataset, SIGNAL(toggled(bool)), this, SLOT(enableBaselineOptions()));
}