Wire up operator buttons

This commit is contained in:
Nathan Woodrow 2011-10-16 12:20:26 +10:00
parent 0359e5b417
commit 5797360c6b
2 changed files with 22 additions and 13 deletions

View File

@ -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 );

View File

@ -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: