mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-03 00:02:25 -05:00
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)
This commit is contained in:
parent
3b438e22dd
commit
9d7ef65a2d
@ -150,6 +150,12 @@ void QgsFieldCalculator::accept()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! exp.prepare( mVectorLayer->pendingFields() ) )
|
||||||
|
{
|
||||||
|
QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mAttributeId == -1 )
|
if ( mAttributeId == -1 )
|
||||||
|
@ -207,7 +207,8 @@ void QgsFieldsProperties::loadRows()
|
|||||||
|
|
||||||
void QgsFieldsProperties::setRow( int row, int idx, const QgsField &field )
|
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() );
|
DesignerTreeItemData itemData( DesignerTreeItemData::Field, field.name() );
|
||||||
dataItem->setData( DesignerTreeRole, itemData.asQVariant() );
|
dataItem->setData( DesignerTreeRole, itemData.asQVariant() );
|
||||||
mFieldsList->setItem( row, attrIdCol, dataItem );
|
mFieldsList->setItem( row, attrIdCol, dataItem );
|
||||||
@ -498,19 +499,20 @@ void QgsFieldsProperties::attributeTypeDialog()
|
|||||||
void QgsFieldsProperties::attributeAdded( int idx )
|
void QgsFieldsProperties::attributeAdded( int idx )
|
||||||
{
|
{
|
||||||
bool sorted = mFieldsList->isSortingEnabled();
|
bool sorted = mFieldsList->isSortingEnabled();
|
||||||
mFieldsList->setSortingEnabled( false );
|
if ( sorted )
|
||||||
|
mFieldsList->setSortingEnabled( false );
|
||||||
|
|
||||||
const QgsFields &fields = mLayer->pendingFields();
|
const QgsFields &fields = mLayer->pendingFields();
|
||||||
int row = mFieldsList->rowCount();
|
int row = mFieldsList->rowCount();
|
||||||
mFieldsList->insertRow( row );
|
mFieldsList->insertRow( row );
|
||||||
setRow( row, idx, fields[idx] );
|
setRow( row, idx, fields[idx] );
|
||||||
|
|
||||||
for ( int i = idx; i < mIndexedWidgets.count(); i++ )
|
|
||||||
{
|
|
||||||
mIndexedWidgets[i]->setData( Qt::DisplayRole, i );
|
|
||||||
}
|
|
||||||
|
|
||||||
mFieldsList->setCurrentCell( row, idx );
|
mFieldsList->setCurrentCell( row, idx );
|
||||||
mFieldsList->setSortingEnabled( sorted );
|
|
||||||
|
for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )
|
||||||
|
mIndexedWidgets[i]->setData( Qt::DisplayRole, i );
|
||||||
|
|
||||||
|
if ( sorted )
|
||||||
|
mFieldsList->setSortingEnabled( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -311,7 +311,11 @@ QgsVectorLayerUndoCommandAddAttribute::QgsVectorLayerUndoCommandAddAttribute( Qg
|
|||||||
: QgsVectorLayerUndoCommand( buffer )
|
: QgsVectorLayerUndoCommand( buffer )
|
||||||
, mField( field )
|
, 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()
|
void QgsVectorLayerUndoCommandAddAttribute::undo()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user