From 5797360c6b8dac2c3af239148534282e12a061a9 Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Sun, 16 Oct 2011 12:20:26 +1000 Subject: [PATCH] Wire up operator buttons --- src/gui/qgsexpressionbuilder.cpp | 23 ++++++++++++++++------- src/gui/qgsexpressionbuilder.h | 12 ++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/gui/qgsexpressionbuilder.cpp b/src/gui/qgsexpressionbuilder.cpp index 5b8c5d3566a..7fbfe0c1827 100644 --- a/src/gui/qgsexpressionbuilder.cpp +++ b/src/gui/qgsexpressionbuilder.cpp @@ -35,7 +35,17 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QWidget *parent) expressionTree->setContextMenuPolicy( Qt::CustomContextMenu ); connect( expressionTree, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) ); + connect( btnPlusPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnMinusPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnDividePushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnMultiplyPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnExpButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnConcatButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnOpenBracketPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + connect( btnCloseBracketPushButton, SIGNAL(pressed()), this, SLOT(operatorButtonClicked())); + + // TODO Can we move this stuff to QgsExpression, like the functions? this->registerItem("Operators","+"," + "); this->registerItem("Operators","-"," -"); this->registerItem("Operators","*"," * "); @@ -184,13 +194,6 @@ void QgsExpressionBuilderWidget::setExpressionString(const QString expressionStr this->txtExpressionString->setPlainText(expressionString); } -bool QgsExpressionBuilderWidget::hasExpressionError() -{ - QString text = this->txtExpressionString->toPlainText(); - QgsExpression exp( text ); - return exp.hasParserError(); -} - void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged() { QString text = this->txtExpressionString->toPlainText(); @@ -261,6 +264,12 @@ void QgsExpressionBuilderWidget::on_lblPreview_linkActivated(QString link) mv->exec(); } +void QgsExpressionBuilderWidget::operatorButtonClicked() +{ + QPushButton* button = dynamic_cast( sender() ); + txtExpressionString->insertPlainText( " " + button->text() + " " ); +} + void QgsExpressionBuilderWidget::showContextMenu( const QPoint & pt) { QModelIndex idx = expressionTree->indexAt( pt ); diff --git a/src/gui/qgsexpressionbuilder.h b/src/gui/qgsexpressionbuilder.h index d2d3b53c280..862a0617a7f 100644 --- a/src/gui/qgsexpressionbuilder.h +++ b/src/gui/qgsexpressionbuilder.h @@ -130,23 +130,23 @@ public: QString helpText = "", QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode); - /** Does the expression used in the widget have any errors - * @note Users of this widget can check this to see if they should let the - * user move forward. - */ - bool hasExpressionError(); - public slots: void on_expressionTree_clicked(const QModelIndex &index); void on_expressionTree_doubleClicked(const QModelIndex &index); void on_txtExpressionString_textChanged(); void on_txtSearchEdit_textChanged(); void on_lblPreview_linkActivated(QString link); + void operatorButtonClicked(); void showContextMenu( const QPoint & ); void loadSampleValues(); void loadAllValues(); signals: + /** Emited when the user changes the expression in the widget. + * Users of this widget should connect to this signal to decide if to let the user + * continue. + * @param isVaild Is true if the expression the user has typed is vaild. + */ void expressionParsed(bool isVaild); private: