Skip to content
Permalink
Browse files

Wire up operator buttons

  • Loading branch information
NathanW2 committed Oct 16, 2011
1 parent 0359e5b commit 5797360c6b8dac2c3af239148534282e12a061a9
Showing with 22 additions and 13 deletions.
  1. +16 −7 src/gui/qgsexpressionbuilder.cpp
  2. +6 −6 src/gui/qgsexpressionbuilder.h
@@ -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<QPushButton*>( sender() );
txtExpressionString->insertPlainText( " " + button->text() + " " );
}

void QgsExpressionBuilderWidget::showContextMenu( const QPoint & pt)
{
QModelIndex idx = expressionTree->indexAt( pt );
@@ -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:

0 comments on commit 5797360

Please sign in to comment.
You can’t perform that action at this time.