Skip to content
Permalink
Browse files
vector layer: fix attributeAdded signal
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 9d7ef65a2dd4d5a4b07e37af01cff04146bca34e
Showing with 20 additions and 8 deletions.
  1. +6 −0 src/app/qgsfieldcalculator.cpp
  2. +9 −7 src/app/qgsfieldsproperties.cpp
  3. +5 −1 src/core/qgsvectorlayerundocommand.cpp
@@ -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 )
@@ -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 );
@@ -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 );
}


@@ -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()

0 comments on commit 9d7ef65

Please sign in to comment.