Skip to content
Permalink
Browse files

Remove red highlight from textarea; show expresion invaild note in pr…

…eview area with more info button; remove live preview checkbox and update button (not needed at this time)
  • Loading branch information
NathanW2 committed Oct 15, 2011
1 parent ee9ab82 commit 4e6f83b3cdf948a855a186aaa1d004a59540e472
Showing with 33 additions and 61 deletions.
  1. +31 −20 src/gui/qgsexpressionbuilder.cpp
  2. +2 −1 src/gui/qgsexpressionbuilder.h
  3. +0 −40 src/ui/qgsexpressionbuilder.ui
@@ -16,6 +16,7 @@
#include "qgsexpressionbuilder.h"
#include "qgslogger.h"
#include "qgsexpression.h"
#include "qgsmessageviewer.h"

#include <QMenu>

@@ -57,6 +58,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QWidget *parent)
};
}


QgsExpressionBuilderWidget::~QgsExpressionBuilderWidget()
{

@@ -192,12 +194,26 @@ bool QgsExpressionBuilderWidget::hasExpressionError()
void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
{
QString text = this->txtExpressionString->toPlainText();

// If the string is empty the expression will still "fail" although
// we don't show the user an error as it will be confusing.
if ( text.isEmpty() )
{
this->lblPreview->setStyleSheet("");
this->txtExpressionString->setToolTip("");
this->lblPreview->setToolTip("");
// Return false for isVaild because a null expression is still invaild.
emit expressionParsed(false);
return;
}

QgsExpression exp( text );

// TODO We could do this without a layer to.
// maybe just calling exp.evaluate()?
if ( chkLive->isChecked() && mLayer )
// TODO We could do this without a layer.
// Maybe just calling exp.evaluate()?
if ( mLayer )
{
// TODO We should really cache the feature.
QgsFeature feature;
mLayer->featureAtId( 0 , feature );
QVariant value = exp.evaluate( &feature, mLayer->pendingFields() );
@@ -208,17 +224,22 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()

if ( exp.hasParserError() || exp.hasEvalError())
{
this->txtExpressionString->setStyleSheet("background-color: rgba(255, 6, 10, 75);");
QString tooltip = "<b>Parser Error:</b> <br>" + exp.parserErrorString();
if (exp.hasEvalError())
tooltip += "<br><br> <b>Eval Error:</b> <br>" + exp.evalErrorString();

this->lblPreview->setText( "Expression is invaild <a href=""more"">(more info)</a>" );
this->lblPreview->setStyleSheet("color: rgba(255, 6, 10, 255);");
this->txtExpressionString->setToolTip(tooltip);
this->lblPreview->setToolTip(tooltip);
emit expressionParsed(false);
return;
}
else
{
this->txtExpressionString->setStyleSheet("");
this->lblPreview->setStyleSheet("");
this->txtExpressionString->setToolTip("");
this->lblPreview->setToolTip("");
emit expressionParsed(true);
}
}
@@ -232,24 +253,14 @@ void QgsExpressionBuilderWidget::on_txtSearchEdit_textChanged()
expressionTree->expandAll();
}

void QgsExpressionBuilderWidget::on_btnUpdatePreview_clicked()
void QgsExpressionBuilderWidget::on_lblPreview_linkActivated(QString link)
{
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() );
}
QgsMessageViewer * mv = new QgsMessageViewer( this );
mv->setWindowTitle( "More info on expression error" );
mv->setMessageAsHtml( this->txtExpressionString->toolTip());
mv->exec();
}


void QgsExpressionBuilderWidget::showContextMenu( const QPoint & pt)
{
QModelIndex idx = expressionTree->indexAt( pt );
@@ -141,7 +141,7 @@ public slots:
void on_expressionTree_doubleClicked(const QModelIndex &index);
void on_txtExpressionString_textChanged();
void on_txtSearchEdit_textChanged();
void on_btnUpdatePreview_clicked();
void on_lblPreview_linkActivated(QString link);
void showContextMenu( const QPoint & );
void loadSampleValues();
void loadAllValues();
@@ -156,6 +156,7 @@ public slots:
QStandardItemModel *mModel;
QgsExpressionItemSearhProxy *mProxyModel;
QMap<QString, QgsExpressionItem*> mExpressionGroups;
QgsFeature* mFeature;
};

#endif // QGSEXPRESSIONBUILDER_H
@@ -220,46 +220,6 @@
<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">

0 comments on commit 4e6f83b

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