Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #17412 Sorting fixed, no troubles when editing after sorting
Issue was, that the cellchange is triggered at re-sorting - so we need to check the names
Following issue was, that when removing or renaming something in re-sorted table - so there was a bug that referenced to the row instead of the index
Thought about to remove mIndexedWidgets completely, but when renumbering after delete in unsorted table, we cannot reference to the row order.
  • Loading branch information
signedav committed Nov 8, 2017
1 parent ba243e5 commit de33017
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/app/qgssourcefieldsproperties.cpp
Expand Up @@ -142,6 +142,7 @@ void QgsSourceFieldsProperties::attributeAdded( int idx )
setRow( row, idx, fields.at( idx ) );
mFieldsList->setCurrentCell( row, idx );

//in case there are rows following, there is increased the id to the correct ones
for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )
mIndexedWidgets.at( i )->setData( Qt::DisplayRole, i );

Expand All @@ -154,15 +155,15 @@ void QgsSourceFieldsProperties::attributeAdded( int idx )
{
case QgsFields::OriginExpression:
if ( i == 7 ) continue;
mFieldsList->item( idx, i )->setBackgroundColor( QColor( 200, 200, 255 ) );
mFieldsList->item( row, i )->setBackgroundColor( QColor( 200, 200, 255 ) );
break;

case QgsFields::OriginJoin:
mFieldsList->item( idx, i )->setBackgroundColor( QColor( 200, 255, 200 ) );
mFieldsList->item( row, i )->setBackgroundColor( QColor( 200, 255, 200 ) );
break;

default:
mFieldsList->item( idx, i )->setBackgroundColor( QColor( 255, 255, 200 ) );
mFieldsList->item( row, i )->setBackgroundColor( QColor( 255, 255, 200 ) );
break;
}
}
Expand Down Expand Up @@ -367,16 +368,19 @@ void QgsSourceFieldsProperties::attributesListCellChanged( int row, int column )
{
if ( column == AttrNameCol && mLayer && mLayer->isEditable() )
{
int idx = mIndexedWidgets.indexOf( mFieldsList->item( row, AttrIdCol ) );

QTableWidgetItem *nameItem = mFieldsList->item( row, column );
//avoiding that something will be changed, just because this is triggered by simple re-sorting
if ( !nameItem ||
nameItem->text().isEmpty() ||
!mLayer->fields().exists( row ) ||
mLayer->fields().at( mFieldsList->item( row, AttrIdCol )->text().toInt() ).name() == nameItem->text()
mLayer->fields().at( idx ).name() == nameItem->text()
)
return;

mLayer->beginEditCommand( tr( "Rename attribute" ) );
if ( mLayer->renameAttribute( row, nameItem->text() ) )
if ( mLayer->renameAttribute( idx, nameItem->text() ) )
{
mLayer->endEditCommand();
}
Expand Down

0 comments on commit de33017

Please sign in to comment.