Skip to content

Commit

Permalink
Fix grabbing of first QgsFeature; Cache QgsFeature being used to eval…
Browse files Browse the repository at this point in the history
…; Handle layers with no objects
  • Loading branch information
NathanW2 committed Oct 27, 2011
1 parent 7940c39 commit 9b2bf0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/gui/qgsexpressionbuilderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsexpressionbuilderwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.