EvalSpinBox evaluator operators priority backported from PIP
This commit is contained in:
@@ -715,14 +715,13 @@ int QPIEvaluator::parse(const QString & string, int offset) {
|
||||
if (args.size() > 0) return args.back();
|
||||
else return -666;
|
||||
}
|
||||
for (int i = 0; i < QPIEvaluatorTypes::operationCount; i++) {
|
||||
coper = operationInOrder(i);
|
||||
int oprior = -1;
|
||||
QVector<QPIEvaluatorTypes::Operation> opv;
|
||||
while(1) {
|
||||
operationsByPriority(++oprior, opv);
|
||||
if (opv.isEmpty()) break;
|
||||
for (int j = 0; j < opers.size(); j++) {
|
||||
if (coper == QPIEvaluatorTypes::oDivide || coper == QPIEvaluatorTypes::oMultiply) {
|
||||
if (opers[j] != QPIEvaluatorTypes::oDivide && opers[j] != QPIEvaluatorTypes::oMultiply) continue;
|
||||
} else {
|
||||
if (opers[j] != coper) continue;
|
||||
}
|
||||
if (!opv.contains(opers[j])) continue;
|
||||
atmp.clear();
|
||||
if (j < args.size() && j >= 0) atmp.push_back(args[j]);
|
||||
else atmp.push_back(-666);
|
||||
@@ -834,6 +833,22 @@ QString QPIEvaluator::operationChar(const QPIEvaluatorTypes::Operation & operati
|
||||
}
|
||||
|
||||
|
||||
void QPIEvaluator::operationsByPriority(int p, QVector<QPIEvaluatorTypes::Operation> & ret) {
|
||||
ret.clear();
|
||||
switch (p) {
|
||||
case 0: ret << QPIEvaluatorTypes::oPower; break;
|
||||
case 1: ret << QPIEvaluatorTypes::oMultiply << QPIEvaluatorTypes::oDivide << QPIEvaluatorTypes::oResidue; break;
|
||||
case 2: ret << QPIEvaluatorTypes::oAdd << QPIEvaluatorTypes::oSubtract; break;
|
||||
case 3: ret << QPIEvaluatorTypes::oEqual << QPIEvaluatorTypes::oNotEqual
|
||||
<< QPIEvaluatorTypes::oGreaterEqual << QPIEvaluatorTypes::oSmallerEqual
|
||||
<< QPIEvaluatorTypes::oGreater << QPIEvaluatorTypes::oSmaller; break;
|
||||
case 4: ret << QPIEvaluatorTypes::oAnd; break;
|
||||
case 5: ret << QPIEvaluatorTypes::oOr; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline complexd QPIEvaluator::residue(const complexd & f, const complexd & s) {
|
||||
complexd ret;
|
||||
if (s.real() != 0.) ret = complexd(f.real() - ((int)(f.real() / s.real())) * s.real(), 0.);
|
||||
|
||||
Reference in New Issue
Block a user