Skip to content
Permalink
Browse files

Make field expression widget work even without a layer (needed in com…

…poser)
  • Loading branch information
wonder-sk committed Jun 17, 2014
1 parent 8097d04 commit 172277e8363062e02591c824068e94887e19429d
Showing with 8 additions and 17 deletions.
  1. +3 −7 src/gui/qgsfieldexpressionwidget.cpp
  2. +5 −10 src/gui/qgsfieldmodel.cpp
@@ -90,7 +90,8 @@ QString QgsFieldExpressionWidget::currentText()
bool QgsFieldExpressionWidget::isValidExpression( QString *expressionError )
{
QString temp;
return QgsExpression::isValid( currentText(), layer()->pendingFields(), expressionError ? *expressionError : temp );
QgsVectorLayer* vl = layer();
return QgsExpression::isValid( currentText(), vl ? vl->pendingFields() : QgsFields(), expressionError ? *expressionError : temp );
}

bool QgsFieldExpressionWidget::isExpression()
@@ -163,9 +164,6 @@ void QgsFieldExpressionWidget::editExpression()
QString currentExpression = currentText();
QgsVectorLayer* vl = layer();

if ( !vl )
return;

QgsExpressionBuilderDialog dlg( vl, currentExpression );
if ( !mDa.isNull() )
{
@@ -263,10 +261,8 @@ void QgsFieldExpressionWidget::updateLineEditStyle( const QString expression )
bool QgsFieldExpressionWidget::isExpressionValid( const QString expressionStr )
{
QgsVectorLayer* vl = layer();
if ( !vl )
return false;

QgsExpression expression( expressionStr );
expression.prepare( vl->pendingFields() );
expression.prepare( vl ? vl->pendingFields() : QgsFields() );
return !expression.hasParserError();
}
@@ -165,9 +165,6 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
if ( !index.isValid() )
return QVariant();

if ( !mLayer )
return QVariant();

qint64 exprIdx = index.internalId() - mFields.count();

switch ( role )
@@ -213,10 +210,8 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
{
if ( exprIdx >= 0 )
{
if ( !mLayer )
return false;
QgsExpression exp( mExpression[exprIdx] );
exp.prepare( mLayer->pendingFields() );
exp.prepare( mLayer ? mLayer->pendingFields() : QgsFields() );
return !exp.hasParserError();
}
return true;
@@ -243,21 +238,21 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
{
return mFields[index.internalId()].name();
}
else
else if ( mLayer )
{
return mLayer->attributeDisplayName( index.internalId() );
}
else
return QVariant();
}

case Qt::ForegroundRole:
{
if ( exprIdx >= 0 )
{
// if expression, test validity
if ( !mLayer )
return false;
QgsExpression exp( mExpression[exprIdx] );
exp.prepare( mLayer->pendingFields() );
exp.prepare( mLayer ? mLayer->pendingFields() : QgsFields() );
if ( exp.hasParserError() )
{
return QBrush( QColor( Qt::red ) );

0 comments on commit 172277e

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