Skip to content

Commit

Permalink
vector layer: fix attributeAdded signal
Browse files Browse the repository at this point in the history
don't assume new attributes are added at end, because in case of joins
they are added after the provider fields and before the joined fields.

field calculator: prepare expression again after attribute was added
(fixes #9320)
  • Loading branch information
jef-n committed Feb 11, 2014
1 parent 3b438e2 commit 9d7ef65
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/app/qgsfieldcalculator.cpp
Expand Up @@ -150,6 +150,12 @@ void QgsFieldCalculator::accept()
break;
}
}

if ( ! exp.prepare( mVectorLayer->pendingFields() ) )
{
QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() );
return;
}
}

if ( mAttributeId == -1 )
Expand Down
16 changes: 9 additions & 7 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -207,7 +207,8 @@ void QgsFieldsProperties::loadRows()

void QgsFieldsProperties::setRow( int row, int idx, const QgsField &field )
{
QTableWidgetItem* dataItem = new QTableWidgetItem( idx );
QTableWidgetItem* dataItem = new QTableWidgetItem();
dataItem->setData( Qt::DisplayRole, idx );
DesignerTreeItemData itemData( DesignerTreeItemData::Field, field.name() );
dataItem->setData( DesignerTreeRole, itemData.asQVariant() );
mFieldsList->setItem( row, attrIdCol, dataItem );
Expand Down Expand Up @@ -498,19 +499,20 @@ void QgsFieldsProperties::attributeTypeDialog()
void QgsFieldsProperties::attributeAdded( int idx )
{
bool sorted = mFieldsList->isSortingEnabled();
mFieldsList->setSortingEnabled( false );
if ( sorted )
mFieldsList->setSortingEnabled( false );

const QgsFields &fields = mLayer->pendingFields();
int row = mFieldsList->rowCount();
mFieldsList->insertRow( row );
setRow( row, idx, fields[idx] );
mFieldsList->setCurrentCell( row, idx );

for ( int i = idx; i < mIndexedWidgets.count(); i++ )
{
for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )
mIndexedWidgets[i]->setData( Qt::DisplayRole, i );
}

mFieldsList->setCurrentCell( row, idx );
mFieldsList->setSortingEnabled( sorted );
if ( sorted )
mFieldsList->setSortingEnabled( true );
}


Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsvectorlayerundocommand.cpp
Expand Up @@ -311,7 +311,11 @@ QgsVectorLayerUndoCommandAddAttribute::QgsVectorLayerUndoCommandAddAttribute( Qg
: QgsVectorLayerUndoCommand( buffer )
, mField( field )
{
mFieldIndex = layer()->pendingFields().count();
const QgsFields &fields = layer()->pendingFields();
int i;
for ( i = 0; i < fields.count() && fields.fieldOrigin( i ) != QgsFields::OriginJoin; i++ )
;
mFieldIndex = i;
}

void QgsVectorLayerUndoCommandAddAttribute::undo()
Expand Down

0 comments on commit 9d7ef65

Please sign in to comment.