Skip to content
Permalink
Browse files

Added expression output preview area. Thanks to Andy Bates for the idea

  • Loading branch information
NathanW2 committed Oct 10, 2011
1 parent 651940c commit ee9ab82666740a77adf09f3d7b6f04301a44231d
Showing with 131 additions and 6 deletions.
  1. +36 −2 src/gui/qgsexpressionbuilder.cpp
  2. +2 −1 src/gui/qgsexpressionbuilder.h
  3. +93 −3 src/ui/qgsexpressionbuilder.ui
@@ -193,10 +193,26 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
{
QString text = this->txtExpressionString->toPlainText();
QgsExpression exp( text );
if ( exp.hasParserError())

// TODO We could do this without a layer to.
// maybe just calling exp.evaluate()?
if ( chkLive->isChecked() && mLayer )
{
QgsFeature feature;
mLayer->featureAtId( 0 , feature );
QVariant value = exp.evaluate( &feature, mLayer->pendingFields() );

if (!exp.hasEvalError())
lblPreview->setText( value.toString() );
}

if ( exp.hasParserError() || exp.hasEvalError())
{
this->txtExpressionString->setStyleSheet("background-color: rgba(255, 6, 10, 75);");
this->txtExpressionString->setToolTip(exp.parserErrorString());
QString tooltip = "<b>Parser Error:</b> <br>" + exp.parserErrorString();
if (exp.hasEvalError())
tooltip += "<br><br> <b>Eval Error:</b> <br>" + exp.evalErrorString();
this->txtExpressionString->setToolTip(tooltip);
emit expressionParsed(false);
}
else
@@ -216,6 +232,24 @@ void QgsExpressionBuilderWidget::on_txtSearchEdit_textChanged()
expressionTree->expandAll();
}

void QgsExpressionBuilderWidget::on_btnUpdatePreview_clicked()
{
QString text = this->txtExpressionString->toPlainText();
QgsExpression exp( text );

// TODO We could do this without a layer maybe just calling exp.evaluate()?
if ( mLayer )
{
QgsFeature feature;
mLayer->featureAtId( 0 , feature );
QVariant value = exp.evaluate( &feature, mLayer->pendingFields() );

if (!exp.hasEvalError())
lblPreview->setText( value.toString() );
}
}


void QgsExpressionBuilderWidget::showContextMenu( const QPoint & pt)
{
QModelIndex idx = expressionTree->indexAt( pt );
@@ -36,7 +36,7 @@ class QgsExpressionItemSearhProxy : public QSortFilterProxyModel
if (source_parent == qobject_cast<QStandardItemModel*>(sourceModel())->invisibleRootItem()->index())
return true;

QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
};

@@ -141,6 +141,7 @@ public slots:
void on_expressionTree_doubleClicked(const QModelIndex &index);
void on_txtExpressionString_textChanged();
void on_txtSearchEdit_textChanged();
void on_btnUpdatePreview_clicked();
void showContextMenu( const QPoint & );
void loadSampleValues();
void loadAllValues();
@@ -212,6 +212,90 @@
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>3</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkLive">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>If enabled the output preview will be generated &lt;br&gt; as the expression string is updated.</string>
</property>
<property name="text">
<string>Live preview</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnUpdatePreview">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="toolTip">
<string>If Live preview is unchecked this button can be &lt;br&gt; used to render a output preview.</string>
</property>
<property name="text">
<string>Update Preview</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Output preview is generated &lt;br&gt; using the first feature from the layer.</string>
</property>
<property name="text">
<string>Output preview: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblPreview">
<property name="font">
<font>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
<underline>false</underline>
</font>
</property>
<property name="toolTip">
<string>Output preview is generated &lt;br&gt; using the first feature from the layer.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -222,6 +306,9 @@
<property name="title">
<string>Function List</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="margin">
<number>0</number>
@@ -260,7 +347,10 @@
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label">
@@ -304,7 +394,7 @@
<item>
<widget class="QLabel" name="mValueListLabel">
<property name="text">
<string>&lt;b&gt;Field Values&lt;/b&gt;</string>
<string>Field Values</string>
</property>
</widget>
</item>
@@ -345,7 +435,7 @@
<string>Function Help</string>
</property>
<property name="flat">
<bool>false</bool>
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<property name="margin">

0 comments on commit ee9ab82

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