Skip to content

Commit 5797360

Browse files
committed
Wire up operator buttons
1 parent 0359e5b commit 5797360

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/gui/qgsexpressionbuilder.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QWidget *parent)
3535

3636
expressionTree->setContextMenuPolicy( Qt::CustomContextMenu );
3737
connect( expressionTree, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
38+
connect( btnPlusPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
39+
connect( btnMinusPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
40+
connect( btnDividePushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
41+
connect( btnMultiplyPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
42+
connect( btnExpButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
43+
connect( btnConcatButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
44+
connect( btnOpenBracketPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
45+
connect( btnCloseBracketPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked()));
3846

47+
48+
// TODO Can we move this stuff to QgsExpression, like the functions?
3949
this->registerItem("Operators","+"," + ");
4050
this->registerItem("Operators","-"," -");
4151
this->registerItem("Operators","*"," * ");
@@ -184,13 +194,6 @@ void QgsExpressionBuilderWidget::setExpressionString(const QString expressionStr
184194
this->txtExpressionString->setPlainText(expressionString);
185195
}
186196

187-
bool QgsExpressionBuilderWidget::hasExpressionError()
188-
{
189-
QString text = this->txtExpressionString->toPlainText();
190-
QgsExpression exp( text );
191-
return exp.hasParserError();
192-
}
193-
194197
void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
195198
{
196199
QString text = this->txtExpressionString->toPlainText();
@@ -261,6 +264,12 @@ void QgsExpressionBuilderWidget::on_lblPreview_linkActivated(QString link)
261264
mv->exec();
262265
}
263266

267+
void QgsExpressionBuilderWidget::operatorButtonClicked()
268+
{
269+
QPushButton* button = dynamic_cast<QPushButton*>( sender() );
270+
txtExpressionString->insertPlainText( " " + button->text() + " " );
271+
}
272+
264273
void QgsExpressionBuilderWidget::showContextMenu( const QPoint & pt)
265274
{
266275
QModelIndex idx = expressionTree->indexAt( pt );

src/gui/qgsexpressionbuilder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,23 @@ class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuil
130130
QString helpText = "",
131131
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode);
132132

133-
/** Does the expression used in the widget have any errors
134-
* @note Users of this widget can check this to see if they should let the
135-
* user move forward.
136-
*/
137-
bool hasExpressionError();
138-
139133
public slots:
140134
void on_expressionTree_clicked(const QModelIndex &index);
141135
void on_expressionTree_doubleClicked(const QModelIndex &index);
142136
void on_txtExpressionString_textChanged();
143137
void on_txtSearchEdit_textChanged();
144138
void on_lblPreview_linkActivated(QString link);
139+
void operatorButtonClicked();
145140
void showContextMenu( const QPoint & );
146141
void loadSampleValues();
147142
void loadAllValues();
148143

149144
signals:
145+
/** Emited when the user changes the expression in the widget.
146+
* Users of this widget should connect to this signal to decide if to let the user
147+
* continue.
148+
* @param isVaild Is true if the expression the user has typed is vaild.
149+
*/
150150
void expressionParsed(bool isVaild);
151151

152152
private:

0 commit comments

Comments
 (0)