Skip to content

Commit

Permalink
Wire up operator buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Oct 16, 2011
1 parent 0359e5b commit 5797360
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 16 additions & 7 deletions src/gui/qgsexpressionbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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","*"," * ");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -261,6 +264,12 @@ void QgsExpressionBuilderWidget::on_lblPreview_linkActivated(QString link)
mv->exec();
}

void QgsExpressionBuilderWidget::operatorButtonClicked()
{
QPushButton* button = dynamic_cast<QPushButton*>( sender() );
txtExpressionString->insertPlainText( " " + button->text() + " " );
}

void QgsExpressionBuilderWidget::showContextMenu( const QPoint & pt)
{
QModelIndex idx = expressionTree->indexAt( pt );
Expand Down
12 changes: 6 additions & 6 deletions src/gui/qgsexpressionbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,23 @@ class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuil
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:
Expand Down

0 comments on commit 5797360

Please sign in to comment.