Exemplo n.º 1
0
void QMLManager::appendTextToLog(const QString &newText)
{
	if (!timer.isValid())
		timer.start();
	m_logText += "\n" + QString::number(timer.elapsed() / 1000.0,'f', 3) + ": " + newText;
	emit logTextChanged();
}
Exemplo n.º 2
0
/** Parse the expression in m_ExpressionText
  * and calculate result.
  * Return the result as a double.
  * If quiet ist true, no signals will be emitted and m_Expressiontext will not be modified.
  * If quiet is false, Log will be updated and m_Expressiontext will be set to the result of the calculation.
  * A logTextChanged and an expressionTextChanged signal will be emitted.
  */
double Calculator::parseExpression(bool quiet)
{
    QStringList expressionParts = m_ExpressionParts; //work on a copy, keep the original
    int partCount = expressionParts.size();
    double result = 0.0;
    try{
        //Parse the expression
        while(partCount >  1)
        {
            parseSubexpression(expressionParts);
            partCount = expressionParts.size();
        }
        if(expressionParts.size() == 0)
            throw ExExpressionError(tr("Expression could not be evaluated."));
        if( ! quiet)
        {
            m_ExpressionText = m_ExpressionParts.join("") + ( "= " + expressionParts[0]);
            //Log the expression and its result
            m_LogText += m_ExpressionText + "\n";
            emit logTextChanged(m_LogText);
            //replace the expression with its result
            m_ExpressionParts.clear();
            m_ExpressionParts.append(expressionParts[0]);
            m_ExpressionText = expressionParts[0];
            emit expressionTextChanged(m_ExpressionText);
            result = m_ExpressionText.toDouble();
        }
        else //keep m_ExpressionParts and m_Expressiontext as they are
        {
            if(isVariable(expressionParts[0]))
                result = getVariableValue(expressionParts[0]);
           else result = expressionParts[0].toDouble();
        }
    }    
    catch(ExExpressionError & e)
    {
        qDebug("Calculator::parseExpression caught ExExpressionError: %s", e.what());
        if(quiet)
            throw e;
        else emit errorMessage(tr("Error"), e.what());
    }
    catch(std::exception &e)
    {
        qDebug("Calculator::parseExpression caught std::exception: %s", e.what());
        if(quiet)
            throw e;
        else emit errorMessage(tr("Error"), e.what());
    }
    catch(...)
    {
        qDebug("Calculator::parseExpression caught unknown exception.");
        if(quiet)
            throw std::exception();
        else emit errorMessage(tr("Error"),"Calculator::parseExpression caught unknown exception.");
    }
    return result;
}
Exemplo n.º 3
0
/** Deletes expresssion text. Deletes Log, when expression is empty.
  */
void Calculator::clearAll()
{
    if(m_ExpressionText.isEmpty())
    {
        m_LogText = "";
        emit logTextChanged(m_LogText);
    }
    m_ExpressionParts.clear();
    m_ExpressionText = "";
    emit expressionTextChanged(m_ExpressionText);
}
Exemplo n.º 4
0
Calculator::Calculator(QObject *parent) :
    QObject(parent)
{
    m_NextAngleMode = m_TextRad;
    m_AngleMode = m_TextDeg;
    m_x = 0.0;
    //whatever it may be good for. Does not affect GUI, if GUI is not yet ready
    emit logTextChanged(m_LogText);
    emit expressionTextChanged(m_ExpressionText);
    emit angleModeChanged(m_AngleMode, m_NextAngleMode);
    connect(&plotter, SIGNAL(plotSetupChanged(QString)),
            this, SLOT(slot_Plotter_plotSetupChanged(QString)));
    connect(&plotter, SIGNAL(yValueRequest(double,double*)),
            this, SLOT(slot_Plotter_yValueRequest(double,double*)));
}
Exemplo n.º 5
0
void QMLManager::setLogText(const QString &logText)
{
	m_logText = logText;
	emit logTextChanged();
}
Exemplo n.º 6
0
void QMLManager::appendTextToLog(const QString &newText)
{
	m_logText += "\n" + newText;
	emit logTextChanged();
}