Skip to content
Permalink
Browse files

Show current expression of virtual fields

  • Loading branch information
m-kuhn committed Mar 27, 2015
1 parent 733b7c9 commit 7905f7f93fe38f799cab16699f5754a2d0467d85
@@ -37,6 +37,7 @@
#include <QMessageBox>
#include <QSettings>
#include <QFileDialog>
#include <QHBoxLayout>

QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent )
: QWidget( parent )
@@ -242,9 +243,23 @@ void QgsFieldsProperties::setRow( int row, int idx, const QgsField& field )
mFieldsList->setItem( row, attrTypeNameCol, new QTableWidgetItem( field.typeName() ) );
mFieldsList->setItem( row, attrLengthCol, new QTableWidgetItem( QString::number( field.length() ) ) );
mFieldsList->setItem( row, attrPrecCol, new QTableWidgetItem( QString::number( field.precision() ) ) );
mFieldsList->setItem( row, attrCommentCol, new QTableWidgetItem( field.comment() ) );
if ( mLayer->pendingFields().fieldOrigin( idx ) == QgsFields::OriginExpression )
{
QWidget* expressionWidget = new QWidget;
expressionWidget->setLayout( new QHBoxLayout );
QToolButton* editExpressionButton = new QToolButton;
editExpressionButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpression.svg" ) );
expressionWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
expressionWidget->layout()->addWidget( editExpressionButton );
expressionWidget->layout()->addWidget( new QLabel( mLayer->expressionField( idx ) ) );
mFieldsList->setCellWidget( row, attrCommentCol, expressionWidget );
}
else
{
mFieldsList->setItem( row, attrCommentCol, new QTableWidgetItem( field.comment() ) );
}

for ( int i = 0; i < attrEditTypeCol; i++ )
for ( int i = 0; i < attrCommentCol; i++ )
mFieldsList->item( row, i )->setFlags( mFieldsList->item( row, i )->flags() & ~Qt::ItemIsEditable );

FieldConfig cfg( mLayer, idx );
@@ -2235,8 +2235,8 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
case boPlus:
if ( vL.type() == QVariant::String && vR.type() == QVariant::String )
{
QString sL = getStringValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
QString sR = getStringValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
QString sL = isNull( vL ) ? QString() : getStringValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
QString sR = isNull( vR ) ? QString() : getStringValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
return QVariant( sL + sR );
}
//intentional fall-through
@@ -75,7 +75,7 @@ class CORE_EXPORT QgsExpressionFieldBuffer
*/
void updateFields( QgsFields& flds );

const QList<ExpressionField> expressions() const { return mExpressions; }
const QList<ExpressionField>& expressions() const { return mExpressions; }

private:
QList<ExpressionField> mExpressions;
@@ -2859,6 +2859,12 @@ void QgsVectorLayer::removeExpressionField( int index )
emit attributeDeleted( index );
}

const QString QgsVectorLayer::expressionField( int index )
{
int oi = mUpdatedFields.fieldOriginIndex( index );
return mExpressionFieldBuffer->expressions().value( oi ).expression;
}

void QgsVectorLayer::updateFields()
{
if ( !mDataProvider )
@@ -668,6 +668,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
void removeExpressionField( int index );

const QString expressionField( int index );

/** Get the label object associated with this layer */
QgsLabel *label();

0 comments on commit 7905f7f

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