COPASI API  4.16.103
CQExpressionWidget.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2006 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef CQEXPRESSION
16 #define CQEXPRESSION
17 
18 #include <QtGui/QTextEdit>
19 #include <QtGui/QSyntaxHighlighter>
20 #include <QtGui/QKeyEvent>
21 
22 #include <QtGui/QKeySequence>
23 
24 #include <vector>
25 
26 #include "copasi/UI//CQValidator.h"
28 
31 
32 class CQExpressionWidget;
33 class CCopasiObject;
34 
35 /*!
36  \brief The class for highlighting the expression syntax
37  */
38 class CQExpressionHighlighter: public QSyntaxHighlighter
39 {
40 public:
42  virtual ~CQExpressionHighlighter();
43 
44 protected:
45  void highlightBlock(const QString &text);
46 
47 public:
48  QTextCharFormat mObjectDisplayFormat;
50 };
51 
52 /**
53  * The class for checking the validity of a given mathematical expression
54  */
55 class CQValidatorExpression: public CQValidator< QTextEdit >
56 {
57 public:
58  CQValidatorExpression(QTextEdit * parent, const char * name = 0, bool isBoolean = false);
59 
60  /**
61  * Function to validate a string input
62  */
63  virtual State validate(QString & input, int & pos) const;
64 
65  /**
66  * Function to get CExpression object
67  */
68  virtual CExpression *getExpression();
69 
70  /**
71  * Function to set whether boolean is required
72  */
73  void setBooleanRequired(bool booleanRequired);
74 
75 protected:
77 };
78 
79 /**
80  * The class for checking the validity of a given mathematical function
81  */
82 class CQValidatorFunction: public CQValidator< QTextEdit >
83 {
84  Q_OBJECT
85 public:
86  /**
87  * Specific constructor
88  * @param QTextEdit * parent
89  * @param const char * name (Default: NULL)
90  */
91  CQValidatorFunction(QTextEdit * parent, const char * name = 0);
92 
93  /**
94  * Function to validate a string input
95  * @param QString & input
96  * @param int & pos
97  * @return State
98  */
99  virtual State validate(QString & input, int & pos) const;
100 
101  /**
102  * Retrieve a pointer to the function object
103  * @return CFunction * pFunction
104  */
105  virtual CFunction * getFunction();
106 
107 protected:
109 
110 signals:
111  void stateChanged(bool) const;
112 };
113 
114 /**
115  * The class for writing/editing a mathematical expression
116  */
117 class CQExpressionWidget: public QTextEdit
118 {
119  Q_OBJECT
120 public:
121  static const char InfixPattern[];
122  static const char DisplayPattern[];
123 
124  CQExpressionWidget(QWidget * parent = 0, const char * name = 0);
125 
127 
128  /**
129  * Write display mathml of the expression into the ostream "out"
130  */
131  void writeMathML(std::ostream & out) const;
132 
134 
135 private:
137 
139 
140 protected:
141  /**
142  * Function to indicate whether we are dealing with an INITIAL or TRANSIENT expression
143  */
145 
146  std::map< std::string, const CCopasiObject * > mParseList;
148  QColor mSavedColor;
150 
151  /**
152  * Function to handle key press events.
153  */
154  virtual void keyPressEvent(QKeyEvent * e);
155 
156  /**
157  * Function to handle mouse release events.
158  */
159  virtual void mouseReleaseEvent(QMouseEvent * e);
160 
161  /**
162  * Function to handle drag leave events.
163  */
164  virtual void dropEvent(QDropEvent * e);
165 
166  /**
167  * Function to check whether the given cursor position is in an object.
168  * If the position is within an object left and right mark the boundaries.
169  * @param const int & position
170  * @param int & left
171  * @param int & right
172  * @return bool isInObject
173  */
174  bool objectBoundaries(const int & position, int & left, int & right) const;
175 
176 public:
177  /**
178  * Enumeration of expression type
179  */
181  {
198  };
199 
200  /**
201  * Set the function for the widget
202  * @param const std::string & function
203  */
204  void setFunction(const std::string & function);
205 
206  /**
207  * Retrieve the function from the widget in string format
208  * @return std::string function
209  */
210  std::string getFunction() const;
211 
212  /**
213  * Set the expression for the widget
214  * @param const std::string & expression
215  */
216  void setExpression(const std::string & expression);
217 
218  /**
219  * Retrieve the expression from the widget in string format
220  * @return std::string expression
221  */
222  std::string getExpression() const;
223 
224  /**
225  * Set the type of the current expression
226  * @param const ExpressionType & expressionType
227  */
228  void setExpressionType(const ExpressionType & expressionType);
229 
230  /**
231  * Set the boolean
232  * @param bool isBoolean
233  */
234  void setBoolean(bool isBoolean);
235 
236  /**
237  * Check validity of expression
238  * @return bool expression
239  */
240  bool isValid();
241 
242 public slots:
243  /**
244  * Slot for being activated whenever the text on Expression Widget is changed
245  */
246  void slotTextChanged();
247 
248  /**
249  * Slot for selecting an object
250  */
251  void slotSelectObject();
252 
253 signals:
254  /**
255  * Signal for being sent whenever the expression is valid
256  */
257  void valid(bool valid);
258 
259 private:
261  QTextCursor mCursor;
262 };
263 
264 #endif
Header file of class CExpression.
CQValidatorFunction(QTextEdit *parent, const char *name=0)
CQExpressionHighlighter(CQExpressionWidget *ew)
void highlightBlock(const QString &text)
static const char DisplayPattern[]
virtual void mouseReleaseEvent(QMouseEvent *e)
virtual CExpression * getExpression()
static const char InfixPattern[]
void setExpression(const std::string &expression)
std::string getFunction() const
virtual void keyPressEvent(QKeyEvent *e)
virtual CFunction * getFunction()
virtual State validate(QString &input, int &pos) const
The class for highlighting the expression syntax.
std::map< std::string, const CCopasiObject * > mParseList
CQValidatorFunction * mpValidatorFunction
void stateChanged(bool) const
const CCopasiObject * mpCurrentObject
void setExpressionType(const ExpressionType &expressionType)
QTextCharFormat mObjectDisplayFormat
CQValidatorExpression * mpValidatorExpression
void writeMathML(std::ostream &out) const
CQSimpleSelectionTree::ObjectClasses mObjectClasses
std::string getExpression() const
virtual State validate(QString &input, int &pos) const
void setBooleanRequired(bool booleanRequired)
virtual void dropEvent(QDropEvent *e)
CQValidatorExpression(QTextEdit *parent, const char *name=0, bool isBoolean=false)
void valid(bool valid)
void setFunction(const std::string &function)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CQExpressionHighlighter * mpExpressionHighlighter
CQValidator< QTextEdit > * getValidator()
CQExpressionWidget(QWidget *parent=0, const char *name=0)
void setBoolean(bool isBoolean)
bool objectBoundaries(const int &position, int &left, int &right) const