Logo Search packages:      
Sourcecode: kbruch version File versions  Download package

void ExerciseConvert::showResult (  ) [private]
  • checks, if the user solved the task correctly
    • emits signals if task was solved correctly or wrong

Definition at line 318 of file exerciseconvert.cpp.

References ratio::numerator(), ratio::reduce(), ratio::setDenominator(), ratio::setNumerator(), ResultWidget::setResult(), signalExerciseSolvedCorrect(), and signalExerciseSolvedWrong().

{
    QString tmp_str; /* to build a string for a label */
    QPalette pal;
    ratio entered_result;

    // change the tooltip of the check button
    m_checkButton->setToolTip (i18n ("Click on this button to get to the next question."));

    numer_edit->setEnabled (false);
    deno_edit->setEnabled (false);
    m_skipButton->setEnabled (false);

    // an empty numerator field will be interpreted as 0
    if (numer_edit->text().isEmpty() == true)
        numer_edit->setText ("0");

    // an empty denominator field will be interpreted as 1
    if (deno_edit->text().isEmpty() == true)
        deno_edit->setText ("1");

    /* store the entered result to check it, but without reducing */
    entered_result.setNumerator (numer_edit->text().toInt(), false);
    entered_result.setDenominator (deno_edit->text().toInt(), false);

    // check the entered result; 0/1 == 0/5 -> true,
    // but 0/1 == 0/0 -> false
    // a 0 for denominator is never allowed (always counted as wrong)
    //
    // we have to get the 0 directly from the input field, because
    // Ratio::setDenominator(0, false) will set the denominator to 1 to ensure
    // the Ratio is valid
    if ( (deno_edit->text().toInt() != 0) && ( (entered_result == m_result) ||
            (m_result.numerator() == 0 && entered_result.numerator() == 0))) {
        // emit the signal for correct
        signalExerciseSolvedCorrect();

        /* yes, the user entered the correct result */
        m_resultWidget->setResult (m_result, 1);
    } else {
        // emit the signal for wrong
        signalExerciseSolvedWrong();

        /* no, the user entered the wrong result */
        m_resultWidget->setResult (m_result, 0);

        // if the user entered a 0 for the denominator (division by 0) we have to
        // get the 0 directly from the input field, because
        // Ratio::setDenominator(0, true) will set the denominator to 1 to ensure
        // the Ratio is valid
        if (deno_edit->text().toInt() == 0) {
            KMessageBox::information (this,
                                      i18n ("You entered a 0 as the denominator. This means division by zero, which is not allowed. This question will be counted as not correctly solved."));
        } else {
            /* maybe the entered ratio was not reduced */
            entered_result.reduce();
            if (entered_result == m_result)
                KMessageBox::information (this,
                                          i18n ("You entered the correct result, but not reduced.\nAlways enter your results as reduced. This question will be counted as not correctly solved."));
        }
    } /* if (entered_result == result) */

    return;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index