Commit cf39d29d authored by Oleg Popkov's avatar Oleg Popkov Committed by Maximilian Schiller
Browse files

Fix chained operations involving inserted numbers

In brief, KCalc uses a stack in `CalcEngine` for both numbers and operations in order to ensure the correct operation evaluation order (such that `2 + 2 * 2 = 6`) and support parentheses. Operations are pushed along with currently displayed numerical values. KCalc also checks whether it should push the operation onto the stack or just replace a pushed one with the new one without changing the associated number (so that `5 + - 3 = 2`), and for this it uses a flag changed by calling the `CalcEngine::setOnlyUpdateOperation` method. Obviously, this flag must be cleared after a number is entered by any method, but it only happens if a number is entered manually. As a result, inserting a number as a whole, whether as a constant or by pasting from the clipboard, results in replacing the preceding operation with the succeeding one without storing the number in question, unless the succeeding operation is `=` or `%`.

BUG: 412401
parent 2bf2d7ca
......@@ -178,7 +178,7 @@ void KCalculator::setupMainActions() {
KStandardAction::redo(calc_display, SLOT(slotHistoryForward()), actionCollection());
KStandardAction::cut(calc_display, SLOT(slotCut()), actionCollection());
KStandardAction::copy(calc_display, SLOT(slotCopy()), actionCollection());
KStandardAction::paste(calc_display, SLOT(slotPaste()), actionCollection());
KStandardAction::paste(this, SLOT(slotPaste()), actionCollection());
// mode menu
QActionGroup *modeGroup = new QActionGroup(this);
......@@ -723,6 +723,7 @@ void KCalculator::slotConstantToDisplay(const science_constant &const_chosen) {
val.replace(QLatin1Char('.'), KNumber::decimalSeparator());
calc_display->setAmount(KNumber(val));
updateDisplay({});
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -936,6 +937,7 @@ void KCalculator::slotMemRecallclicked() {
calc_display->setAmount(memory_num_);
updateDisplay({});
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -1485,6 +1487,7 @@ void KCalculator::slotStatNumclicked() {
}
updateDisplay(UPDATE_FROM_CORE);
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -1501,6 +1504,7 @@ void KCalculator::slotStatMeanclicked() {
}
updateDisplay(UPDATE_FROM_CORE);
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -1519,6 +1523,7 @@ void KCalculator::slotStatStdDevclicked() {
}
updateDisplay(UPDATE_FROM_CORE);
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -1538,6 +1543,7 @@ void KCalculator::slotStatMedianclicked() {
// TODO: it seems two different modes should be implemented, but...?
updateDisplay(UPDATE_FROM_CORE);
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -1555,6 +1561,7 @@ void KCalculator::slotStatDataInputclicked() {
}
updateDisplay(UPDATE_FROM_CORE);
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -1603,6 +1610,7 @@ void KCalculator::slotConstclicked(int button) {
}
updateDisplay({});
core.setOnlyUpdateOperation(false);
}
}
......@@ -2075,6 +2083,7 @@ void KCalculator::slotBitsetChanged(quint64 value) {
calc_display->setAmount(KNumber(value));
updateDisplay({});
core.setOnlyUpdateOperation(false);
}
//------------------------------------------------------------------------------
......@@ -2354,6 +2363,15 @@ bool KCalculator::eventFilter(QObject *o, QEvent *e) {
}
}
//------------------------------------------------------------------------------
// Name: slotPaste
// Desc: paste a number from the clipboard
//------------------------------------------------------------------------------
void KCalculator::slotPaste() {
calc_display->slotPaste();
core.setOnlyUpdateOperation(false);
}
////////////////////////////////////////////////////////////////
// Include the meta-object code for classes in this file
//
......
......@@ -226,6 +226,8 @@ protected Q_SLOTS:
void slotBaseModeAmountChanged(const KNumber &number);
void slotPaste();
private:
enum StatusField {
ShiftField = 0,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment