diff --git a/kcalc.cpp b/kcalc.cpp --- a/kcalc.cpp +++ b/kcalc.cpp @@ -922,7 +922,8 @@ //------------------------------------------------------------------------------ void KCalculator::slotNumberclicked(int number_clicked) { - calc_display->enterDigit(number_clicked); + calc_display->enterDigit(number_clicked); + core.setOnlyUpdateOperation(false); } //------------------------------------------------------------------------------ @@ -2055,6 +2056,7 @@ if(flags & UPDATE_FROM_CORE) { calc_display->updateFromCore(core, (flags & UPDATE_STORE_RESULT) != 0); + core.setOnlyUpdateOperation(true); } else { calc_display->update(); } diff --git a/kcalc_core.h b/kcalc_core.h --- a/kcalc_core.h +++ b/kcalc_core.h @@ -106,6 +106,8 @@ void TangensHyp(const KNumber &input); void Reset(); + void setOnlyUpdateOperation(bool update); + bool getOnlyUpdateOperation() const; private: KStats stats; @@ -141,6 +143,7 @@ Operation last_operation_; KNumber last_repeat_number_; bool repeat_mode_; + bool only_update_operation_; bool percent_mode_; diff --git a/kcalc_core.cpp b/kcalc_core.cpp --- a/kcalc_core.cpp +++ b/kcalc_core.cpp @@ -169,8 +169,8 @@ } - -CalcEngine::CalcEngine() : repeat_mode_(false), percent_mode_(false) { +CalcEngine::CalcEngine() + : only_update_operation_(false), repeat_mode_(false), percent_mode_(false) { last_number_ = KNumber::Zero; error_ = false; @@ -863,7 +863,11 @@ } } - stack_.push(tmp_node); + if (getOnlyUpdateOperation() && !stack_.isEmpty() && + !(func == FUNC_EQUAL || func == FUNC_PERCENT)) + stack_.top().operation = func; + else + stack_.push(tmp_node); evalStack(); } @@ -903,8 +907,18 @@ last_operation_ = FUNC_EQUAL; error_ = false; last_number_ = KNumber::Zero; + only_update_operation_ = false; stack_.clear(); } +void CalcEngine::setOnlyUpdateOperation(bool update) +{ + only_update_operation_ = update; +} + +bool CalcEngine::getOnlyUpdateOperation() const +{ + return only_update_operation_; +}