Ejemplo n.º 1
0
void AntProjectPart::optionsAccepted()
{
  if (!m_antOptionsWidget || !m_classPathWidget)
    return;

  m_antOptions.m_buildXML = m_antOptionsWidget->BuildXML->url();

  switch (m_antOptionsWidget->Verbosity->currentItem())
  {
  case 1:
    m_antOptions.m_verbosity = AntOptions::Verbose;
    break;
  case 2:
    m_antOptions.m_verbosity = AntOptions::Debug;
    break;
  default:
    m_antOptions.m_verbosity = AntOptions::Quiet;
    break;
  }

  for (int i=0; i<m_antOptionsWidget->Properties->numRows(); ++i)
  {
    QString key = m_antOptionsWidget->Properties->text(i,0);
    m_antOptions.m_properties.replace(key, m_antOptionsWidget->Properties->text(i,1));
    kdDebug() << "PROP: " << key << "  = " << m_antOptionsWidget->Properties->text(i,1);

    QCheckTableItem *item =(QCheckTableItem*) m_antOptionsWidget->Properties->item(i,0);
    m_antOptions.m_defineProperties.replace(key, item->isChecked());
  }

  m_classPath = m_classPathWidget->ClassPath->items();

  m_antOptionsWidget = 0;
  m_classPathWidget = 0;
}
Ejemplo n.º 2
0
void fitDialog::accept()
{
    QString curve = boxCurve->currentText();
    QStringList curvesList = graph->curvesList();
    if (curvesList.contains(curve) <= 0)
    {
        QMessageBox::critical(this,tr("QtiPlot - Warning"),
                              tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curve));
        boxCurve->clear();
        boxCurve->insertStringList(curvesList);
        return;
    }

    if (!validInitialValues())
        return;

    QString from=boxFrom->text().lower();
    QString to=boxTo->text().lower();
    QString tolerance=boxTolerance->text().lower();
    double start,end,eps;
    try
    {
        myParser parser;
        parser.SetExpr(from.ascii());
        start=parser.Eval();
    }
    catch(mu::ParserError &e)
    {
        QMessageBox::critical(0, tr("QtiPlot - Start limit error"),e.GetMsg());
        boxFrom->setFocus();
        return;
    }

    try
    {
        myParser parser;
        parser.SetExpr(to.ascii());
        end=parser.Eval();
    }
    catch(mu::ParserError &e)
    {
        QMessageBox::critical(0, tr("QtiPlot - End limit error"),e.GetMsg());
        boxTo->setFocus();
        return;
    }

    if (start>=end)
    {
        QMessageBox::critical(0, tr("QtiPlot - Input error"),
                              tr("Please enter x limits that satisfy: from < end!"));
        boxTo->setFocus();
        return;
    }

    try
    {
        myParser parser;
        parser.SetExpr(tolerance.ascii());
        eps=parser.Eval();
    }
    catch(mu::ParserError &e)
    {
        QMessageBox::critical(0, tr("QtiPlot - Tolerance input error"),e.GetMsg());
        boxTolerance->setFocus();
        return;
    }

    if (eps<0 || eps>=1)
    {
        QMessageBox::critical(0, tr("QtiPlot - Tolerance input error"),
                              tr("The tolerance value must be positive and less than 1!"));
        boxTolerance->setFocus();
        return;
    }

    int i, n=0, rows=boxParams->numRows();
    if (boxParams->numCols() == 3)
    {
        for (i=0; i<rows; i++)
        {   //count the non-constant parameters
            QCheckTableItem *it = (QCheckTableItem *)boxParams->item (i, 2);
            if (!it->isChecked())
                n++;
        }
    }
    else
        n=rows;

    QStringList parameters, initialValues;
    myParser parser;
    bool error=FALSE;
    QString formula = boxFunction->text();
    try
    {
        bool withNames = containsUserFunctionName(formula);
        while(withNames)
        {
            for (i=0; i<(int)userFunctionNames.count(); i++)
            {
                if (formula.contains(userFunctionNames[i]))
                {
                    QStringList l = QStringList::split("=", userFunctions[i], true);
                    formula.replace(userFunctionNames[i], "(" + l[1] + ")");
                }
            }
            withNames = containsUserFunctionName(formula);
        }

        for (i=0; i<(int)builtInFunctionNames.count(); i++)
        {
            if (formula.contains(builtInFunctionNames[i]))
                formula.replace(builtInFunctionNames[i], "(" + builtInFunctions[i] + ")");
        }

        double *paramsInit = new double[n];
        if (boxParams->numCols() == 3)
        {
            for (i=0; i<rows; i++)
            {
                QCheckTableItem *it = (QCheckTableItem *)boxParams->item (i, 2);
                int j = 0;
                if (!it->isChecked())
                {
                    paramsInit[j]=boxParams->text(i,1).toDouble();
                    parser.DefineVar(boxParams->text(i,0).ascii(), &paramsInit[j]);
                    parameters<<boxParams->text(i,0);
                    initialValues<<boxParams->text(i,1);
                    j++;
                }
                else
                    formula.replace(boxParams->text(i,0), boxParams->text(i,1));
            }
        }
        else
        {
            for (i=0; i<n; i++)
            {
                paramsInit[i]=boxParams->text(i,1).toDouble();
                parser.DefineVar(boxParams->text(i,0).ascii(), &paramsInit[i]);
                parameters<<boxParams->text(i,0);
                initialValues<<boxParams->text(i,1);
            }
        }

        parser.SetExpr(formula.ascii());
        double x=start;
        parser.DefineVar("x", &x);
        parser.Eval();
        delete[] paramsInit;
    }
    catch(mu::ParserError &e)
    {
        QString errorMsg = boxFunction->text() + " = " + formula + "\n" + e.GetMsg() + "\n" +
                           tr("Please verify that you have initialized all the parameters!");

        QMessageBox::critical(0, tr("QtiPlot - Input function error"), errorMsg);
        boxFunction->setFocus();
        error = true;
    }

    if (!error)
    {
        ApplicationWindow *app = (ApplicationWindow *)this->parent();
        graph->setFitID(++app->fitNumber);
        QString result;
        if (boxUseBuiltIn->isChecked() && categoryBox->currentItem() == 1)
            result = fitBuiltInFunction(curve,funcBox->currentText(),initialValues, start,end,
                                        boxPoints->value(),boxSolver->currentItem(),eps, boxColor->currentItem());
        else if (boxUseBuiltIn->isChecked() && categoryBox->currentItem() == 3)
        {
            result = graph->fitPluginFunction(curve, pluginFilesList[funcBox->currentItem()],
                                              initialValues, start, end, boxPoints->value(),
                                              boxSolver->currentItem(), eps, boxColor->currentItem());
        }
        else
            result = graph->fitNonlinearCurve(curve, lblFunction->text()+"="+formula, parameters, initialValues,
                                              start, end, boxPoints->value(), boxSolver->currentItem(), eps, boxColor->currentItem());

        QStringList res = graph->fitResults();
        if (boxParams->numCols() == 3)
        {
            int j = 0;
            for (i=0; i<rows; i++)
            {
                QCheckTableItem *it = (QCheckTableItem *)boxParams->item (i, 2);
                if (!it->isChecked())
                    boxParams->setText(i, 1, res[j++]);
            }
        }
        else
        {
            for (i=0; i<rows; i++)
                boxParams->setText(i, 1, res[i]);
        }

        app->updateLog(result);
    }
}