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

void TaskView::showResult (  ) [private]
  • checks the entered result and compares it to the task's result
    • shows the correct result and informs the user if he was right or wrong
    • if the user entered the result unreduced, he will be informed about it
    • if the user entered a 0 for the denominator, he will be informed about it (division by zero)
    • emits signals if task was solved right or wrong

Definition at line 276 of file taskview.cpp.

References ratio::denominator(), ratio::numerator(), ratio::reduce(), ratio::setDenominator(), ratio::setNumerator(), ResultWidget::setResult(), signalTaskSolvedCorrect(), signalTaskSolvedWrong(), and task::solve().

    QString tmp_str; /* to build a string for a label */
    QPalette pal;
    bool wrong = false;

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

    numer_edit->setEnabled (false);
    deno_edit->setEnabled (false);
    integer_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");
    int int_numerator = numer_edit->text().toInt();

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

    // get the par (integer) value in case mixed input is enabled
    int int_mixed = 0;
    if (m_answerMixed) {
        // an empty par (integer) field  will be interpreted as 0
        if (integer_edit->text().isEmpty() == true)
            integer_edit->setText ("0");
        int_mixed = integer_edit->text().toInt();

    // get the solution for the current task
    solution = current_task.solve();

    // calculate the combined numerator and preserve prefix sign
    int tmp_num = qAbs (int_mixed * int_denominator) + qAbs (int_numerator);
    if (int_mixed < 0)
        tmp_num *= -1;
    if (int_numerator < 0)
        tmp_num *= -1;

    /* store the entered result to check it, but without reducing it */
    entered_result.setNumerator (tmp_num, false);
    entered_result.setDenominator (int_denominator, false);

    /* check whether we expect the result in reduced form
     * if not, we reduce it for the user
     * we also have to update some temp variables to be reduced
     * we don't recalculate the mixed part, because this should not change
     * by reducing it */
    if (!m_reducedForm) {
        int_numerator = entered_result.numerator() % entered_result.denominator();
        int_denominator = entered_result.denominator();


    /* compare entered result and solution ratio
     * if they are equal it still might be that the user didn't entered a mixed result */
    if (! (entered_result == solution))
        wrong = true;

    /* we do not allow entering a denominator of 0 (division by zero!) */
    if (deno_edit->text().toInt() == 0)
        wrong = true;

    /* now we have to check if the solution was entered as a mixed number if required
     * we only have to do that in case the answer is not already marked as wrong
     * fortunately, we don't have to care about the prefix sign, because that is already
     * handled above */
    if (m_answerMixed == true && wrong == false) {
        int int_solution_mixed = qAbs (int (solution.numerator() / solution.denominator()));
        int int_solution_numerator = qAbs (solution.numerator() % solution.denominator());

        if (! (int_solution_mixed == qAbs (int_mixed) && int_solution_numerator == qAbs (int_numerator)))
            wrong = true;

    // in case the user entered the wrong result, try to give some hints
    if (wrong == true) {
        // emit the signal for wrong
        m_resultWidget->setResult (solution, 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 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 */
            ratio tmp_result = ratio (entered_result);
            if ( (tmp_result == solution) && ! (tmp_result == entered_result)) {
                KMessageBox::information (this,
                                          i18n ("You entered the correct result, but not reduced. This question will be counted as not correctly solved."));
            } else if (tmp_result == solution && tmp_result == entered_result) {
                KMessageBox::information (this,
                                          i18n ("You entered the correct result, but not in the mixed number notation. This question will be counted as not correctly solved."));
    } else {
        // emit the signal for correct
        m_resultWidget->setResult (solution, 1);



Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index