COPASI API  4.16.103
Public Types | Public Slots | Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
CQExpressionWidget Class Reference

#include <CQExpressionWidget.h>

Inheritance diagram for CQExpressionWidget:
Inheritance graph
[legend]
Collaboration diagram for CQExpressionWidget:
Collaboration graph
[legend]

Public Types

enum  ExpressionType { InitialExpression, TransientExpression, ObjectiveFunctions }
 

Public Slots

void slotSelectObject ()
 
void slotTextChanged ()
 

Signals

void valid (bool valid)
 

Public Member Functions

 CQExpressionWidget (QWidget *parent=0, const char *name=0)
 
std::string getExpression () const
 
std::string getFunction () const
 
CQValidator< QTextEdit > * getValidator ()
 
bool isValid ()
 
void setBoolean (bool isBoolean)
 
void setExpression (const std::string &expression)
 
void setExpressionType (const ExpressionType &expressionType)
 
void setFunction (const std::string &function)
 
void writeMathML (std::ostream &out) const
 
 ~CQExpressionWidget ()
 

Static Public Attributes

static const char DisplayPattern [] = "\\{(([^\\\\\\}]|\\\\.)*)\\}"
 
static const char InfixPattern [] = "<(CN=([^\\\>]|\\\\.)*)>"
 

Protected Member Functions

virtual void dropEvent (QDropEvent *e)
 
virtual void keyPressEvent (QKeyEvent *e)
 
virtual void mouseReleaseEvent (QMouseEvent *e)
 
bool objectBoundaries (const int &position, int &left, int &right) const
 

Protected Attributes

QColor mChangedColor
 
CQSimpleSelectionTree::ObjectClasses mObjectClasses
 
std::map< std::string, const
CCopasiObject * > 
mParseList
 
const CCopasiObjectmpCurrentObject
 
QColor mSavedColor
 

Private Attributes

QTextCursor mCursor
 
CQExpressionHighlightermpExpressionHighlighter
 
CQValidatorExpressionmpValidatorExpression
 
CQValidatorFunctionmpValidatorFunction
 

Detailed Description

The class for writing/editing a mathematical expression

Definition at line 117 of file CQExpressionWidget.h.

Member Enumeration Documentation

Enumeration of expression type

Enumerator
InitialExpression 
TransientExpression 
ObjectiveFunctions 

Definition at line 180 of file CQExpressionWidget.h.

Constructor & Destructor Documentation

CQExpressionWidget::CQExpressionWidget ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 194 of file CQExpressionWidget.cpp.

References mChangedColor, mpExpressionHighlighter, mSavedColor, and slotTextChanged().

195  : QTextEdit(parent),
196  mpValidatorExpression(NULL),
197  mpValidatorFunction(NULL),
199  mpCurrentObject(NULL)
200 {
201  setObjectName(QString::fromUtf8(name));
202  setTabChangesFocus(true);
203 
205 
206  int h, s, v;
207 
208  mSavedColor = palette().color(backgroundRole());
209  mSavedColor.getHsv(&h, &s, &v);
210 
211  if (s < 20) s = 20;
212 
213  mChangedColor.setHsv(240, s, v);
214 
215  connect(this, SIGNAL(textChanged()),
216  this, SLOT(slotTextChanged()));
217 }
The class for highlighting the expression syntax.
CQValidatorFunction * mpValidatorFunction
const CCopasiObject * mpCurrentObject
CQValidatorExpression * mpValidatorExpression
CQSimpleSelectionTree::ObjectClasses mObjectClasses
CQExpressionHighlighter * mpExpressionHighlighter
CQExpressionWidget::~CQExpressionWidget ( )

Definition at line 219 of file CQExpressionWidget.cpp.

220 {}

Member Function Documentation

void CQExpressionWidget::dropEvent ( QDropEvent *  e)
protectedvirtual

Function to handle drag leave events.

Definition at line 295 of file CQExpressionWidget.cpp.

References mCursor, and objectBoundaries().

296 {
297  QString SelectedText = textCursor().selectedText();
298 
299  QTextEdit::dropEvent(e);
300 
301  int Left;
302  int Right;
303 
304  if (objectBoundaries(textCursor().position() - SelectedText.length(), Left, Right))
305  {
306  mCursor = textCursor();
307 
308  // Remove the inserted text.
309  mCursor.setPosition(mCursor.position() - SelectedText.length(), QTextCursor::KeepAnchor);
310  mCursor.removeSelectedText();
311 
312  int CurrentPosition = mCursor.position();
313 
314  // Determine the insertion point
315  objectBoundaries(mCursor.position(), Left, Right);
316 
317  if (CurrentPosition - Left < Right - CurrentPosition)
318  {
319  mCursor.setPosition(Left);
320  }
321  else
322  {
323  mCursor.setPosition(Right);
324  }
325 
326  mCursor.insertText(SelectedText);
327  setTextCursor(mCursor);
328  }
329 }
bool objectBoundaries(const int &position, int &left, int &right) const
std::string CQExpressionWidget::getExpression ( ) const

Retrieve the expression from the widget in string format

Returns
std::string expression

Definition at line 779 of file CQExpressionWidget.cpp.

References DisplayPattern, findObjectByDisplayName(), FROM_UTF8, CCopasiRootContainer::getConfiguration(), CCopasiRootContainer::getDatamodelList(), CCopasiObject::getObjectDataModel(), mParseList, mpCurrentObject, TO_UTF8, and CConfigurationFile::useAdvancedEditing().

Referenced by CQValidatorExpression::validate().

780 {
781  QString Infix;
782  const QString Display(toPlainText());
783 
784  QRegExp DisplayObjectPattern(CQExpressionWidget::DisplayPattern);
785 
786  int Index = 0;
787  QString::const_iterator it = Display.begin();
788  QString::const_iterator end;
789 
790  while (true)
791  {
792  Index = DisplayObjectPattern.indexIn(Display, Index);
793 
794  if (Index < 0)
795  {
796  end = Display.end();
797  }
798  else
799  {
800  end = Display.begin() + Index;
801  }
802 
803  // Copy the non-object part
804  for (; it != end; ++it)
805  {
806  Infix.append(*it);
807  }
808 
809  if (DisplayObjectPattern.matchedLength() < 0)
810  break;
811 
812  Index += DisplayObjectPattern.matchedLength();
813  it += DisplayObjectPattern.matchedLength();
814 
815  std::string DisplayName(TO_UTF8(DisplayObjectPattern.cap(1)));
816  std::map< std::string, const CCopasiObject *>::const_iterator itObject = mParseList.find(DisplayName);
817 
819  {
820 
821  // the object pattern does not match the species name if
822  // the species is in a different compartment, in that case we
823  // have to remove the backslash in the displayname.
824  std::string::size_type bsPos = DisplayName.find("\\}");
825 
826  if (bsPos != std::string::npos)
827  DisplayName.erase(bsPos, 1);
828 
829  // here we don't have an object recognized, what we ought to do is to find it in the model
830  const CCopasiObject* object = findObjectByDisplayName(
832  DisplayName);
833 
834  if (object != NULL)
835  {
836  const_cast<CQExpressionWidget*>(this)->mParseList[DisplayName] = object;
837  itObject = mParseList.find(DisplayName);
838  }
839  }
840 
841  if (itObject != mParseList.end())
842  Infix += "<" + FROM_UTF8(itObject->second->getCN()) + ">";
843  else
844  {
845  Infix += "<";
846 
847  // We need to escape '\'
848  std::string CN = TO_UTF8(DisplayObjectPattern.cap(1));
849  std::string::const_iterator it = CN.begin();
850  std::string::const_iterator end = CN.end();
851 
852  for (; it < end; ++it)
853  {
854  if (*it == '\\')
855  {
856  ++it;
857  }
858 
859  Infix += *it;
860  }
861 
862  Infix += ">";
863  }
864  }
865 
866  return TO_UTF8(Infix);
867 }
CCopasiDataModel * getObjectDataModel()
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const char DisplayPattern[]
const CCopasiObject * findObjectByDisplayName(const CCopasiDataModel *dataModel, const std::string displayString)
static CConfigurationFile * getConfiguration()
std::map< std::string, const CCopasiObject * > mParseList
bool useAdvancedEditing() const
const CCopasiObject * mpCurrentObject
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
std::string CQExpressionWidget::getFunction ( ) const

Retrieve the function from the widget in string format

Returns
std::string function

Definition at line 550 of file CQExpressionWidget.cpp.

References TO_UTF8.

Referenced by CQValidatorFunction::validate(), and writeMathML().

551 {
552  return TO_UTF8(toPlainText());
553 }
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
CQValidator< QTextEdit > * CQExpressionWidget::getValidator ( )

Definition at line 222 of file CQExpressionWidget.cpp.

References mpValidatorExpression, and mpValidatorFunction.

223 {
224  if (mpValidatorExpression != NULL)
225  {
226  return mpValidatorExpression;
227  }
228 
229  return mpValidatorFunction;
230 }
CQValidatorFunction * mpValidatorFunction
CQValidatorExpression * mpValidatorExpression
bool CQExpressionWidget::isValid ( )

Check validity of expression

Returns
bool expression

Definition at line 885 of file CQExpressionWidget.cpp.

References mpValidatorExpression, mpValidatorFunction, and CQValidator< Type >::revalidate().

886 {
887  if (mpValidatorExpression != NULL)
888  return mpValidatorExpression->revalidate() == QValidator::Acceptable;
889  else if (mpValidatorFunction != NULL)
890  return mpValidatorFunction->revalidate() == QValidator::Acceptable;
891 
892  return true;
893 }
CQValidatorFunction * mpValidatorFunction
virtual State revalidate()
Definition: CQValidator.h:63
CQValidatorExpression * mpValidatorExpression
void CQExpressionWidget::keyPressEvent ( QKeyEvent *  e)
protectedvirtual

Function to handle key press events.

Definition at line 331 of file CQExpressionWidget.cpp.

References CCopasiRootContainer::getConfiguration(), mCursor, objectBoundaries(), and CConfigurationFile::useAdvancedEditing().

332 {
333  int Left;
334  int Right;
335  bool isAdvancedEditing = CCopasiRootContainer::getConfiguration()->useAdvancedEditing();
336 
337  if (e == QKeySequence::SelectNextChar && !isAdvancedEditing)
338  {
339  mCursor = textCursor();
340  mCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
341 
342  if (objectBoundaries(mCursor.position(), Left, Right))
343  {
344  mCursor.setPosition(Right - 1, QTextCursor::KeepAnchor);
345  setTextCursor(mCursor);
346  }
347 
348  QTextEdit::keyPressEvent(e);
349 
350  return;
351  }
352 
353  if (e == QKeySequence::SelectPreviousChar && !isAdvancedEditing)
354  {
355  mCursor = textCursor();
356  mCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
357 
358  if (objectBoundaries(mCursor.position(), Left, Right))
359  {
360  mCursor.setPosition(Left + 1, QTextCursor::KeepAnchor);
361  setTextCursor(mCursor);
362  }
363 
364  QTextEdit::keyPressEvent(e);
365 
366  return;
367  }
368 
369  switch (e->key())
370  {
371  case Qt::Key_Backspace:
372 
373  if (isAdvancedEditing) break;
374 
375  mCursor = textCursor();
376 
377  if (mCursor.selectedText().isEmpty())
378  {
379  mCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
380 
381  if (objectBoundaries(mCursor.position(), Left, Right))
382  {
383  mCursor.setPosition(Left + 1, QTextCursor::KeepAnchor);
384  mCursor.deleteChar();
385  setTextCursor(mCursor);
386  }
387  }
388 
389  // delete the selected object or just the character
390  QTextEdit::keyPressEvent(e);
391 
392  return;
393  break;
394 
395  case Qt::Key_Delete:
396 
397  if (isAdvancedEditing) break;
398 
399  mCursor = textCursor();
400 
401  if (mCursor.selectedText().isEmpty())
402  {
403  mCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
404 
405  if (objectBoundaries(mCursor.position(), Left, Right))
406  {
407  mCursor.setPosition(Right - 1, QTextCursor::KeepAnchor);
408  mCursor.deleteChar();
409  setTextCursor(mCursor);
410  }
411  }
412 
413  // delete the selected object or just the character
414  QTextEdit::keyPressEvent(e);
415 
416  return;
417  break;
418 
419  case Qt::Key_Left:
420 
421  if (isAdvancedEditing) break;
422 
423  mCursor = textCursor();
424 
425  // We check whether the new position is in an object.
426  mCursor.movePosition(QTextCursor::PreviousCharacter);
427 
428  if (objectBoundaries(mCursor.position(), Left, Right))
429  {
430  mCursor.setPosition(Left + 1, QTextCursor::KeepAnchor);
431  setTextCursor(mCursor);
432  }
433 
434  QTextEdit::keyPressEvent(e);
435 
436  return;
437  break;
438 
439  case Qt::Key_Right:
440 
441  if (isAdvancedEditing) break;
442 
443  mCursor = textCursor();
444 
445  // We check whether the new position is in an object.
446  mCursor.movePosition(QTextCursor::NextCharacter);
447 
448  if (objectBoundaries(mCursor.position(), Left, Right))
449  {
450  mCursor.setPosition(Right - 1, QTextCursor::KeepAnchor);
451  setTextCursor(mCursor);
452  }
453 
454  QTextEdit::keyPressEvent(e);
455 
456  return;
457  break;
458 
459  case Qt::Key_BraceLeft:
460  case Qt::Key_BraceRight:
461 
462  if (isAdvancedEditing) break;
463 
464  e->ignore();
465  return;
466  break;
467  }
468 
469  if (!e->text().isEmpty())
470  {
471  // set format original
472  QTextCharFormat f;
473  f.setForeground(QColor(0, 0, 0));
474 
475  setCurrentCharFormat(f);
476  QTextEdit::keyPressEvent(e);
477 
478  return;
479  }
480 
481  QTextEdit::keyPressEvent(e);
482 }
static CConfigurationFile * getConfiguration()
bool useAdvancedEditing() const
bool objectBoundaries(const int &position, int &left, int &right) const
void CQExpressionWidget::mouseReleaseEvent ( QMouseEvent *  e)
protectedvirtual

Function to handle mouse release events.

Definition at line 267 of file CQExpressionWidget.cpp.

References mCursor, and objectBoundaries().

268 {
269  QTextEdit::mouseReleaseEvent(e);
270 
271  mCursor = textCursor();
272 
273  int Left;
274  int Right;
275 
276  if (objectBoundaries(mCursor.selectionStart(), Left, Right))
277  {
278  // Move the selection start out of the object.
279  mCursor.setPosition(mCursor.selectionEnd());
280  mCursor.setPosition(Left, QTextCursor::KeepAnchor);
281 
282  setTextCursor(mCursor);
283  }
284 
285  if (objectBoundaries(mCursor.selectionEnd(), Left, Right))
286  {
287  // Move the selection end out of the object.
288  mCursor.setPosition(mCursor.selectionStart());
289  mCursor.setPosition(Right, QTextCursor::KeepAnchor);
290 
291  setTextCursor(mCursor);
292  }
293 }
bool objectBoundaries(const int &position, int &left, int &right) const
bool CQExpressionWidget::objectBoundaries ( const int &  position,
int &  left,
int &  right 
) const
protected

Function to check whether the given cursor position is in an object. If the position is within an object left and right mark the boundaries.

Parameters
constint & position
int& left
int& right
Returns
bool isInObject

Definition at line 504 of file CQExpressionWidget.cpp.

References DisplayPattern.

Referenced by dropEvent(), keyPressEvent(), and mouseReleaseEvent().

505 {
506  static QRegExp ObjectDisplayPattern(CQExpressionWidget::DisplayPattern);
507 
508  int Index = ObjectDisplayPattern.indexIn(toPlainText());
509 
510  while (0 <= Index && Index <= position)
511  {
512  left = Index;
513  Index += ObjectDisplayPattern.matchedLength();
514  right = Index;
515 
516  if (left < position && position < right)
517  {
518  return true;
519  }
520 
521  Index = ObjectDisplayPattern.indexIn(toPlainText(), Index);
522  }
523 
524  left = -1;
525  right = -1;
526 
527  return false;
528 }
static const char DisplayPattern[]
void CQExpressionWidget::setBoolean ( bool  isBoolean)

Set the boolean

Parameters
boolisBoolean

Definition at line 874 of file CQExpressionWidget.cpp.

References mpValidatorExpression, CQValidator< Type >::revalidate(), and CQValidatorExpression::setBooleanRequired().

875 {
876  if (mpValidatorExpression == NULL)
877  {
880  }
881 
883 };
virtual State revalidate()
Definition: CQValidator.h:63
CQValidatorExpression * mpValidatorExpression
void setBooleanRequired(bool booleanRequired)
void CQExpressionWidget::setExpression ( const std::string &  expression)

Set the expression for the widget

Parameters
conststd::string & expression

Definition at line 555 of file CQExpressionWidget.cpp.

References FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CCopasiRootContainer::getFunctionList(), CCopasiObject::getObjectDisplayName(), InfixPattern, mCursor, mParseList, mpValidatorExpression, CCopasiDataModel::ObjectFromName(), CQValidator< Type >::revalidate(), CQValidator< Type >::saved(), and TO_UTF8.

556 {
557  if (mpValidatorExpression == NULL)
558  {
561  }
562 
563  // Reset the parse list.
564  mParseList.clear();
565 
566  mCursor = textCursor();
567 
569  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
571  assert(pDataModel != NULL);
572  std::vector<CCopasiContainer*> containers;
573  containers.push_back(pDataModel);
574  containers.push_back(pFunDB);
575 
576  const QString Infix(FROM_UTF8(expression));
577  QString Display;
578 
579  QRegExp InfixObjectPattern(CQExpressionWidget::InfixPattern);
580 
581  int Index = 0;
582  QString::const_iterator it = Infix.begin();
583  QString::const_iterator end;
584 
585  while (true)
586  {
587  Index = InfixObjectPattern.indexIn(Infix, Index);
588 
589  if (Index < 0)
590  {
591  end = Infix.end();
592  }
593  else
594  {
595  end = Infix.begin() + Index;
596  }
597 
598  // Copy the non-object part
599  for (; it != end; ++it)
600  {
601  Display.append(*it);
602  }
603 
604  if (InfixObjectPattern.matchedLength() < 0)
605  break;
606 
607  Index += InfixObjectPattern.matchedLength();
608  it += InfixObjectPattern.matchedLength();
609 
610  CCopasiObjectName InfixName(TO_UTF8(InfixObjectPattern.cap(1)));
611  CCopasiObject * pObject = pDataModel->ObjectFromName(containers, InfixName);
612 
613  if (pObject != NULL)
614  {
615  std::string DisplayName = pObject->getObjectDisplayName();
616 
617  // We need to escape '\' and '}'
618  std::string::size_type pos = DisplayName.find_first_of("\\}");
619 
620  while (pos != std::string::npos)
621  {
622  DisplayName.insert(pos, "\\");
623  pos += 2;
624  pos = DisplayName.find_first_of("\\}", pos);
625  }
626 
627  mParseList[DisplayName] = pObject;
628 
629  Display += '{' + FROM_UTF8(DisplayName) + '}';
630  }
631  else
632  {
633  std::string DisplayName = InfixName;
634 
635  // We need to escape '\' and '}'
636  std::string::size_type pos = DisplayName.find_first_of("\\}");
637 
638  while (pos != std::string::npos)
639  {
640  DisplayName.insert(pos, "\\");
641  pos += 2;
642  pos = DisplayName.find_first_of("\\}", pos);
643  }
644 
645  Display += '{' + FROM_UTF8(DisplayName) + '}';
646  }
647  }
648 
649  setText(Display);
651 
652  return;
653 }
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const char InfixPattern[]
std::map< std::string, const CCopasiObject * > mParseList
virtual void saved() const
Definition: CQValidator.h:71
virtual State revalidate()
Definition: CQValidator.h:63
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
static CFunctionDB * getFunctionList()
CQValidatorExpression * mpValidatorExpression
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
void CQExpressionWidget::setExpressionType ( const ExpressionType expressionType)

Set the type of the current expression

Parameters
constExpressionType & expressionType

Definition at line 869 of file CQExpressionWidget.cpp.

References mObjectClasses.

870 {
871  mObjectClasses = expressionType;
872 }
CQSimpleSelectionTree::ObjectClasses mObjectClasses
void CQExpressionWidget::setFunction ( const std::string &  function)

Set the function for the widget

Parameters
conststd::string & function

Definition at line 530 of file CQExpressionWidget.cpp.

References FROM_UTF8, mCursor, mpValidatorFunction, and CQValidator< Type >::revalidate().

531 {
532  if (mpValidatorFunction == NULL)
533  {
536  }
537 
538  // clear the text edit
539  clear();
540 
541  mCursor = textCursor();
542 
543  QTextCharFormat f1;
544  f1.setForeground(QColor(0, 0, 0));
545 
546  setCurrentCharFormat(f1);
547  insertPlainText(FROM_UTF8(function));
548 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CQValidatorFunction * mpValidatorFunction
virtual State revalidate()
Definition: CQValidator.h:63
void CQExpressionWidget::slotSelectObject ( )
slot

Slot for selecting an object

Definition at line 895 of file CQExpressionWidget.cpp.

References CQMessageBox::critical(), CQSimpleSelectionTree::filter(), FROM_UTF8, CCopasiObject::getObjectDisplayName(), CCopasiSelectionDialog::getObjectSingle(), mObjectClasses, CQExpressionHighlighter::mObjectDisplayFormat, mParseList, and mpExpressionHighlighter.

896 {
897  const CCopasiObject * pObject =
899 
900  if (pObject)
901  {
902  // Check whether the object is valid
904  {
905  CQMessageBox::critical(this, "Invalid Selection",
906  "The use of the selected object is not allowed in this type of expression.");
907  return;
908  }
909 
910  std::string Insert = pObject->getObjectDisplayName();
911 
912  // We need to escape >
913  std::string::size_type pos = Insert.find_first_of("}");
914 
915  while (pos != std::string::npos)
916  {
917  Insert.insert(pos, "\\");
918  pos += 2;
919  pos = Insert.find_first_of("}", pos);
920  }
921 
922  mParseList[Insert] = pObject;
923 
924  QTextCharFormat f1;
925  f1.setForeground(QColor(0, 0, 0));
926 
927  QTextCharFormat f = mpExpressionHighlighter->mObjectDisplayFormat;
928  //QColor color2 = f.foreground().color();
929 
930  setCurrentCharFormat(f);
931  insertPlainText(FROM_UTF8("{" + Insert + "}"));
932  setCurrentCharFormat(f1);
933  }
934 }
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static bool filter(const ObjectClasses &classes, const CCopasiObject *pObject)
std::map< std::string, const CCopasiObject * > mParseList
QTextCharFormat mObjectDisplayFormat
CQSimpleSelectionTree::ObjectClasses mObjectClasses
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CQExpressionHighlighter * mpExpressionHighlighter
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
void CQExpressionWidget::slotTextChanged ( )
slot

Slot for being activated whenever the text on Expression Widget is changed

This slot checks any characters that are newly typed on Expression Widget.

Definition at line 487 of file CQExpressionWidget.cpp.

References mpValidatorExpression, mpValidatorFunction, valid(), and CQValidator< Type >::validate().

Referenced by CQExpressionWidget().

488 {
489  CQValidator< QTextEdit > * pValidator = NULL;
490 
491  if (mpValidatorExpression != NULL)
492  pValidator = mpValidatorExpression;
493  else if (mpValidatorFunction != NULL)
494  pValidator = mpValidatorFunction;
495  else
496  return;
497 
498  int pos = 0;
499  QString Input = toPlainText();
500 
501  emit valid(pValidator->validate(Input, pos) == QValidator::Acceptable);
502 }
CQValidatorFunction * mpValidatorFunction
CQValidatorExpression * mpValidatorExpression
void valid(bool valid)
virtual State validate(QString &input, int &) const
Definition: CQValidator.h:51
void CQExpressionWidget::valid ( bool  valid)
signal

Signal for being sent whenever the expression is valid

Referenced by slotTextChanged().

void CQExpressionWidget::writeMathML ( std::ostream &  out) const

Write display mathml of the expression into the ostream "out"

Definition at line 232 of file CQExpressionWidget.cpp.

References CFunction::createListOfParametersForMathML(), CQValidatorExpression::getExpression(), CQValidatorFunction::getFunction(), getFunction(), CMassAction::Infix, mpValidatorExpression, mpValidatorFunction, TriFalse, TriTrue, CMassAction::writeMathML(), CExpression::writeMathML(), and CFunction::writeMathML().

233 {
234  if (mpValidatorExpression != NULL)
236  else if (mpValidatorFunction != NULL)
237  {
238  std::string Infix = getFunction();
239 
240  if (Infix == CMassAction::Infix[0])
241  {
242  CMassAction Function(TriTrue, NULL);
243  std::vector<std::vector<std::string> > params;
244 
245  Function.createListOfParametersForMathML(params);
246  out << Function.writeMathML(params, true, false);
247  }
248  else if (Infix == CMassAction::Infix[1])
249  {
250  CMassAction Function(TriFalse, NULL);
251  std::vector<std::vector<std::string> > params;
252 
253  Function.createListOfParametersForMathML(params);
254  out << Function.writeMathML(params, true, false);
255  }
256  else
257  {
258  std::vector<std::vector<std::string> > params;
260  out << mpValidatorFunction->getFunction()->writeMathML(params, true, false);
261  }
262  }
263 
264  return;
265 }
static const char * Infix[]
Definition: CMassAction.h:34
virtual CExpression * getExpression()
std::string getFunction() const
virtual CFunction * getFunction()
CQValidatorFunction * mpValidatorFunction
virtual void writeMathML(std::ostream &out, size_t l=0) const
Definition: CFunction.cpp:389
void createListOfParametersForMathML(std::vector< std::vector< std::string > > &env)
Definition: CFunction.cpp:340
CQValidatorExpression * mpValidatorExpression
void writeMathML(std::ostream &out, bool fullExpand, size_t l) const

Member Data Documentation

const char CQExpressionWidget::DisplayPattern = "\\{(([^\\\\\\}]|\\\\.)*)\\}"
static

Definition at line 122 of file CQExpressionWidget.h.

Referenced by getExpression(), and objectBoundaries().

const char CQExpressionWidget::InfixPattern = "<(CN=([^\\\>]|\\\\.)*)>"
static

Definition at line 121 of file CQExpressionWidget.h.

Referenced by setExpression().

QColor CQExpressionWidget::mChangedColor
protected

Definition at line 149 of file CQExpressionWidget.h.

Referenced by CQExpressionWidget().

QTextCursor CQExpressionWidget::mCursor
private
CQSimpleSelectionTree::ObjectClasses CQExpressionWidget::mObjectClasses
protected

Function to indicate whether we are dealing with an INITIAL or TRANSIENT expression

Definition at line 144 of file CQExpressionWidget.h.

Referenced by setExpressionType(), and slotSelectObject().

std::map< std::string, const CCopasiObject * > CQExpressionWidget::mParseList
protected

Definition at line 146 of file CQExpressionWidget.h.

Referenced by getExpression(), setExpression(), and slotSelectObject().

const CCopasiObject* CQExpressionWidget::mpCurrentObject
protected

Definition at line 147 of file CQExpressionWidget.h.

Referenced by getExpression().

CQExpressionHighlighter* CQExpressionWidget::mpExpressionHighlighter
private

Definition at line 260 of file CQExpressionWidget.h.

Referenced by CQExpressionWidget(), and slotSelectObject().

CQValidatorExpression* CQExpressionWidget::mpValidatorExpression
private
CQValidatorFunction* CQExpressionWidget::mpValidatorFunction
private
QColor CQExpressionWidget::mSavedColor
protected

Definition at line 148 of file CQExpressionWidget.h.

Referenced by CQExpressionWidget().


The documentation for this class was generated from the following files: