42static const char*
sum_xpm[] = {
"16 16 6 1",
"# c None",
". c None",
"b c #808080",
43 "d c #010000",
"c c #aaaaaa",
"a c #303030",
"................",
44 ".#aaaaaaaaaa##..",
".abbbbbbcbbba...",
".#abbaaaaabba...",
"..#aabba..aba...",
45 "....#abba..a#...",
".....#abba......",
".....#abba......",
"...##abba...#...",
46 "...#abba...aa...",
"..#abba...aca...",
".#abbaaaaabba...",
".abbbbbbbbbba...",
47 ".aaaaaaaaaaa#...",
"................",
"................"};
50static const char*
stop_xpm[] = {
"16 16 4 1",
" c None",
". c #FF0000",
"+ c #FF8080",
51 "@ c #FFFFFF",
" ",
" ",
" ...... ",
52 " ...+++.. ",
" ....@@@... ",
" .....@@@.... ",
" .....@@@.... ",
53 " .....@@@.... ",
" .....@@@.... ",
" ............ ",
" ....@@@.... ",
54 " ...@@@... ",
" ....... ",
" ..... ",
" ",
58 : QWidget(parent), _dialog(0), _context(
""), _searchPath(
""), _applyOnSelect(applyOnSelect) {
71 error->setHidden(
true);
82 QToolButton* button =
new QToolButton();
84 button->setIcon(QIcon(QPixmap(
sum_xpm)));
176 edit->setText(QString(expression.c_str()));
191 edit->setText(newText);
214 bool valid =
expr.isValid();
216 if (!valid) err =
expr.parseError();
222 error->setHidden(hidden);
224 error->setToolTip(QString::fromStdString(err));
229 edit->setHidden(enabled);
239 edit->setHorizontalScrollBarPolicy(policy);
246 setMaximumHeight(25);
256 QTreeView* treePopup =
new QTreeView;
258 treePopup->setRootIsDecorated(
false);
259 treePopup->setMinimumWidth(300);
260 treePopup->setMinimumHeight(50);
261 treePopup->setItemsExpandable(
true);
264 completer->setCompletionMode(QCompleter::PopupCompletion);
265 completer->setCaseSensitivity(Qt::CaseInsensitive);
272 QTextEdit::focusInEvent(e);
278 QTextCursor newCursor = textCursor();
279 newCursor.clearSelection();
280 setTextCursor(newCursor);
283 QTextEdit::focusOutEvent(e);
288 QTextEdit::mousePressEvent(event);
293 QTextEdit::mouseDoubleClickEvent(event);
302 QTextEdit::paintEvent(e);
314 case Qt::Key_Backtab:
323 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
327 }
else if (e->key() == Qt::Key_Escape) {
332 }
else if (e->key() == Qt::Key_Tab) {
333 QWidget::keyPressEvent(e);
342 bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E);
344 QTextEdit::keyPressEvent(e);
346 const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
347 if (!
completer || (ctrlOrShift && e->text().isEmpty()))
return;
349 bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
352 QTextCursor tc = textCursor();
353 tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
354 QString line = tc.selectedText();
357 static QRegExp completion(
"^(?:.*[^A-Za-z0-9_$])?((?:\\$[A-Za-z0-9_]*)|[A-Za-z]+[A-Za-z0-9_]*)$");
358 int index = completion.indexIn(line);
359 QString completionPrefix;
360 if (
index != -1 && !line.contains(
'#')) {
361 completionPrefix = completion.cap(1);
366 if (!isShortcut && (hasModifier || e->text().isEmpty() || completionPrefix.length() < 1 ||
index == -1)) {
371 if (completionPrefix !=
completer->completionPrefix()) {
372 completer->setCompletionPrefix(completionPrefix);
377 QRect cr = cursorRect();
378 cr.setWidth(2 * (
completer->popup()->sizeHintForColumn(0) +
completer->popup()->sizeHintForColumn(1) +
379 completer->popup()->verticalScrollBar()->sizeHint().width()));
386 static QRegExp inFunction(
"^(?:.*[^A-Za-z0-9_$])?([A-Za-z0-9_]+)\\([^()]*$");
387 int index2 = inFunction.indexIn(line);
389 QString functionName = inFunction.cap(1);
391 QString tip =
"<b>" + tips[0] +
"</b>";
392 for (
int i = 1; i < tips.size(); i++) {
393 tip +=
"<br>" + tips[i];
403 if (
string ==
"")
return;
407 QRect cr = cursorRect();
409 cr.setWidth(cr.width() * 3);
423 QTextCursor tc = textCursor();
424 int extra = completion.length() -
completer->completionPrefix().length();
425 tc.movePosition(QTextCursor::Left);
426 tc.movePosition(QTextCursor::EndOfWord);
427 tc.insertText(completion.right(extra));
428 if (completion[0] !=
'$') tc.insertText(
"(");
static const char * stop_xpm[]
static const char * sum_xpm[]
void setSearchPath(const QString &context, const QString &path)
void setApplyOnSelect(bool on)
std::vector< QString > local_variables
QString getDocString(const QString &s)
void addVariable(const QString &str, const QString &comment)
void addFunction(const QString &function, const QString &docString)
bool rebuildControls(const QString &expressionText, std::vector< QString > &variables)
Rebuild the controls given the new expressionText. Return any local variables found.
int numControls()
Number of controls.
void updateText(const int id, QString &text)
Request new text, given taking into account control id's new values.
std::string getExpressionString()
void setExpressionString(const std::string &str)
void replaceExtras(const ExprCompletionModel &completer)
void fixStyle(const QPalette &palette)
void clearExtraCompleters()
void setDetailsMenu(QMenu *menu)
virtual void rebuildControls()
void setExpressionString(const std::string &expression)
std::string getExpressionString() const
virtual void dialogClosed()
void setSimple(bool enabled)
virtual void expressionApplied()
void registerExtraFunction(const std::string &name, const std::string &docString)
void registerExtraVariable(const std::string &name, const std::string &docString)
QTimer * controlRebuildTimer
void showDetails(int idx)
ExprShortEdit(QWidget *parent, bool expanded=true, bool applyOnSelect=true)
void setLineWrapMode(QTextEdit::LineWrapMode mode)
virtual void hideErrors(bool hidden, const std::string &err)
QToolButton * expandButton
virtual void expandPressed()
virtual void handleTextEdited()
ExprControlCollection * controls
void setSearchPath(const QString &context, const QString &path)
virtual void detailPressed()
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
virtual void textFinished()
QString getExpression() const
virtual void controlChanged(int id)
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
virtual void mousePressEvent(QMouseEvent *event)
void showTip(const QString &string)
virtual void mouseDoubleClickEvent(QMouseEvent *event)
void paintEvent(QPaintEvent *e)
ExprShortTextEdit(QWidget *parent)
ExprCompletionModel * completionModel
virtual void keyPressEvent(QKeyEvent *e)
void setColor(bool editing)
virtual void focusOutEvent(QFocusEvent *e)
ExprHighlighter * highlighter
void insertCompletion(const QString &completion)
virtual void focusInEvent(QFocusEvent *e)
QStyle * lastStyleForHighlighter
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate(). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr expr("x+x^2")
"margin-left: 40px;">< br > $a=noise( $P) style
If a scalar is used in a vector context
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).