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();
|
if (args.size() > 0) return args.back();
|
||||||
else return -666;
|
else return -666;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < QPIEvaluatorTypes::operationCount; i++) {
|
int oprior = -1;
|
||||||
coper = operationInOrder(i);
|
QVector<QPIEvaluatorTypes::Operation> opv;
|
||||||
|
while(1) {
|
||||||
|
operationsByPriority(++oprior, opv);
|
||||||
|
if (opv.isEmpty()) break;
|
||||||
for (int j = 0; j < opers.size(); j++) {
|
for (int j = 0; j < opers.size(); j++) {
|
||||||
if (coper == QPIEvaluatorTypes::oDivide || coper == QPIEvaluatorTypes::oMultiply) {
|
if (!opv.contains(opers[j])) continue;
|
||||||
if (opers[j] != QPIEvaluatorTypes::oDivide && opers[j] != QPIEvaluatorTypes::oMultiply) continue;
|
|
||||||
} else {
|
|
||||||
if (opers[j] != coper) continue;
|
|
||||||
}
|
|
||||||
atmp.clear();
|
atmp.clear();
|
||||||
if (j < args.size() && j >= 0) atmp.push_back(args[j]);
|
if (j < args.size() && j >= 0) atmp.push_back(args[j]);
|
||||||
else atmp.push_back(-666);
|
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) {
|
inline complexd QPIEvaluator::residue(const complexd & f, const complexd & s) {
|
||||||
complexd ret;
|
complexd ret;
|
||||||
if (s.real() != 0.) ret = complexd(f.real() - ((int)(f.real() / s.real())) * s.real(), 0.);
|
if (s.real() != 0.) ret = complexd(f.real() - ((int)(f.real() / s.real())) * s.real(), 0.);
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ private:
|
|||||||
bool check();
|
bool check();
|
||||||
bool execInstructions();
|
bool execInstructions();
|
||||||
QString operationChar(const QPIEvaluatorTypes::Operation & operation);
|
QString operationChar(const QPIEvaluatorTypes::Operation & operation);
|
||||||
|
void operationsByPriority(int p, QVector<QPIEvaluatorTypes::Operation> & ret);
|
||||||
QPIEvaluatorTypes::Operation operationInOrder(const int & index);
|
QPIEvaluatorTypes::Operation operationInOrder(const int & index);
|
||||||
complexd value(const int & index) {if (index < 0) return tmpvars[-index - 1].value; else return kvars->at(index).value;}
|
complexd value(const int & index) {if (index < 0) return tmpvars[-index - 1].value; else return kvars->at(index).value;}
|
||||||
inline complexd residue(const complexd & f, const complexd & s);
|
inline complexd residue(const complexd & f, const complexd & s);
|
||||||
|
|||||||
Reference in New Issue
Block a user