Skip to content
Permalink
Browse files

Fix grabbing of first QgsFeature; Cache QgsFeature being used to eval…

…; Handle layers with no objects
  • Loading branch information
NathanW2 committed Oct 27, 2011
1 parent 7940c39 commit 9b2bf0afd6b022c20e0b7720a74cc9d6180bd4a1
Showing with 19 additions and 8 deletions.
  1. +18 −7 src/gui/qgsexpressionbuilderwidget.cpp
  2. +1 −1 src/gui/qgsexpressionbuilderwidget.h
@@ -230,13 +230,24 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
// 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() );

if ( !exp.hasEvalError() )
lblPreview->setText( value.toString() );
if ( !mFeature.isValid() )
{
mLayer->select( mLayer->pendingAllAttributesList() );
mLayer->nextFeature( mFeature );
}

if ( mFeature.isValid() )
{
QVariant value = exp.evaluate( &mFeature, mLayer->pendingFields() );
if ( !exp.hasEvalError() )
lblPreview->setText( value.toString() );
}
else
{
// The feautre is invaild because we don't have one but that doesn't mean user can't
// build a expression string. They just get no preview.
lblPreview->setText("");
}
}

if ( exp.hasParserError() || exp.hasEvalError() )
@@ -164,7 +164,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
QStandardItemModel *mModel;
QgsExpressionItemSearchProxy *mProxyModel;
QMap<QString, QgsExpressionItem*> mExpressionGroups;
QgsFeature* mFeature;
QgsFeature mFeature;
};

#endif // QGSEXPRESSIONBUILDER_H

0 comments on commit 9b2bf0a

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