void fitDialog::showFunctionsList(int category)
{
    boxUseBuiltIn->setChecked(false);
    boxUseBuiltIn->setEnabled(false);
    boxUseBuiltIn->hide();
    buttonPlugins->hide();
    btnDelFunc->setEnabled(false);
    funcBox->clear();

    switch (category)
    {
    case 0:
        if ((int)userFunctionNames.size() > 0)
        {
            showUserFunctions();
            boxUseBuiltIn->setEnabled(true);
        }

        boxUseBuiltIn->setText(tr("Fit with selected &user function"));
        boxUseBuiltIn->show();
        btnDelFunc->setEnabled(true);
        break;

    case 1:
        boxUseBuiltIn->setText(tr("Fit using &built-in function"));
        boxUseBuiltIn->show();
        boxUseBuiltIn->setEnabled(true);
        funcBox->insertStringList(builtInFunctionNames, -1);
        break;

    case 2:
        showParseFunctions();
        break;

    case 3:
        buttonPlugins->show();
        boxUseBuiltIn->setText(tr("Fit using &plugin function"));
        boxUseBuiltIn->show();
        if ((int)pluginFunctionNames.size() > 0)
        {
            funcBox->insertStringList(pluginFunctionNames, -1);
            boxUseBuiltIn->setEnabled(true);
        }
        break;
    }

    funcBox->setCurrentItem(0);
    showExpression(0);
}
Beispiel #2
0
void FitDialog::saveUserFunction()
{
	if (editBox->text().isEmpty())
	{
		QMessageBox::critical(this, tr("Input function error"), tr("Please enter a valid function!"));
		editBox->setFocus();
		return;
	}
	else if (boxName->text().isEmpty())
	{
		QMessageBox::critical(this, tr("Input function error"),
				tr("Please enter a function name!"));
		boxName->setFocus();
		return;
	}
	else if (boxParam->text().remove(QRegExp("[,;\\s]")).isEmpty())
	{
		QMessageBox::critical(this, tr("Input function error"),
				tr("Please enter at least one parameter name!"));
		boxParam->setFocus();
		return;
	}

	if (d_built_in_function_names.contains(boxName->text()))
	{
		QMessageBox::critical(this, tr("Error: function name"),
				"<p><b>" + boxName->text() + "</b>" + tr(" is a built-in function name"
					"<p>You must choose another name for your function!"));
		editBox->setFocus();
		return;
	}
	if (editBox->text().contains(boxName->text()))
	{
		QMessageBox::critical(this, tr("Input function error"),
				tr("You can't define functions recursevely!"));
		editBox->setFocus();
		return;
	}

	QString name = boxName->text();
	QString f = name + "(x, " + boxParam->text() + ")=" + editBox->text().remove("\n");

	if (d_user_function_names.contains(name))
	{
		int index = d_user_function_names.indexOf(name);
		d_user_functions[index] = f;
		d_user_function_params[index] = boxParam->text();

		if (funcBox->currentItem()->text() == name)
			showExpression(index);
	}
	else
	{
		d_user_function_names << name;
		d_user_functions << f;
		d_user_function_params << boxParam->text();

		if (categoryBox->currentRow() == 0)
		{
			funcBox->addItem(name);
			funcBox->setCurrentRow (funcBox->count()-1);
		}

		if (d_user_function_names.count()>0 && !boxUseBuiltIn->isEnabled() && categoryBox->currentRow() == 0)
			boxUseBuiltIn->setEnabled(true);
	}
    buttonClearUsrList->setEnabled(true);
	emit saveFunctionsList(d_user_functions);
}
void fitDialog::saveUserFunction()
{
    if (editBox->text().isEmpty())
    {
        QMessageBox::critical(0, tr("QtiPlot - Input function error"),
                              tr("Please enter a valid function!"));
        editBox->setFocus();
        return;
    }
    else if (boxName->text().isEmpty())
    {
        QMessageBox::critical(0, tr("QtiPlot - Input function error"),
                              tr("Please enter a function name!"));
        boxName->setFocus();
        return;
    }
    else if (boxParam->text().remove(QRegExp("[,;\\s]")).isEmpty())
    {
        QMessageBox::critical(0, tr("QtiPlot - Input function error"),
                              tr("Please enter at least one parameter name!"));
        boxParam->setFocus();
        return;
    }

    if (builtInFunctionNames.contains(boxName->text()))
    {
        QMessageBox::critical(0, tr("QtiPlot - Error: function name"),
                              "<p><b>"+boxName->text()+ "</b>"+tr(" is a built-in function name"
                                      "<p>You must choose another name for your function!"));
        editBox->setFocus();
        return;
    }
    if (editBox->text().contains(boxName->text()))
    {
        QMessageBox::critical(0, tr("QtiPlot - Input function error"),
                              tr("You can't define functions recursevely!"));
        editBox->setFocus();
        return;
    }
    QString name = boxName->text();
    QString f = name +"(x, " + boxParam->text() + ")="+editBox->text().remove("\n");
    if (userFunctionNames.contains(name))
    {
        int index = userFunctionNames.findIndex(name);
        userFunctions[index] = f;
        userFunctionParams[index] = boxParam->text();

        if (funcBox->currentText() == name)
            showExpression(index);
    }
    else
    {
        userFunctionNames << name;
        userFunctions << f;
        userFunctionParams << boxParam->text();

        if (categoryBox->currentItem() == 0)
        {
            funcBox->insertItem(name, -1);
            funcBox->setCurrentItem(funcBox->numRows()-1);
        }

        if ((int)userFunctionNames.count()>0 && !boxUseBuiltIn->isEnabled() && categoryBox->currentItem() == 0)
            boxUseBuiltIn->setEnabled(true);
    }

    emit saveFunctionsList(userFunctions);
}