August 7, 2012

laurent bauer laurent bauer
Lab Rat
26 posts

Strict knowledge of subset of properties involved in a userdefined script

 

Hello,

I’ve a QScriptvalue m_ParametersObject containing a set of properties/double P1,P2…Pn
I want the user to define formula in a QTextEdit where a formula is a relation between a choice of parameters

ex: Let the parametersObject contain p1..p5.
The user defines the followinf formula in a textEdit : “p5 = p2+p4”
I need to know that p2 and p4 are involved in the forumla and that p1 and p3 are not involved.

  1. void AddFormulaDialog::formulaChanged() // textEdit slot
  2. {
  3.     QString formula = ui->textEdit->toPlainText();
  4.     QScriptEngine * engine = m_ParametersObject->engine();
  5.     // m_ParametersObject is a QScriptValue, with parameters as properties p1, p2...pn
  6.     QScriptContext * context = engine->pushContext();
  7.     context->setActivationObject(*m_ParametersObject);
  8.     QScriptValue res = engine->evaluate(formula);
  9.  
  10.     QPushButton * okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
  11.     okButton->setEnabled(!res.isError());
  12.  
  13.     engine->popContext();
  14. }

With this, I can get the analytical formula and the evaluation, but not the topological information: I don’t know which parameters are actually involved int the relation.

QScriptValueIterator doesn’t help here:
QScriptValueIterator it(*m_ParametersObject) gives me all properties of the context (not only of the formula)
QScriptValueIterator it(res) gives nothing.

Is there a way (even completely different), to strictly retrieve the set of properties involved in the interactively user defined formula?

Note: I’m new to QtScript

Thank you in advance
Laurent

0 replies

 
  ‹‹ [SOLVED]Login dialog ?      Inconvenient Behaviour: QSqlTableModel.removeRow() ››

You must log in to post a reply. Not a member yet? Register here!