Skip to content

Commit de33017

Browse files
committed
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.
1 parent ba243e5 commit de33017

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/app/qgssourcefieldsproperties.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ void QgsSourceFieldsProperties::attributeAdded( int idx )
142142
setRow( row, idx, fields.at( idx ) );
143143
mFieldsList->setCurrentCell( row, idx );
144144

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

@@ -154,15 +155,15 @@ void QgsSourceFieldsProperties::attributeAdded( int idx )
154155
{
155156
case QgsFields::OriginExpression:
156157
if ( i == 7 ) continue;
157-
mFieldsList->item( idx, i )->setBackgroundColor( QColor( 200, 200, 255 ) );
158+
mFieldsList->item( row, i )->setBackgroundColor( QColor( 200, 200, 255 ) );
158159
break;
159160

160161
case QgsFields::OriginJoin:
161-
mFieldsList->item( idx, i )->setBackgroundColor( QColor( 200, 255, 200 ) );
162+
mFieldsList->item( row, i )->setBackgroundColor( QColor( 200, 255, 200 ) );
162163
break;
163164

164165
default:
165-
mFieldsList->item( idx, i )->setBackgroundColor( QColor( 255, 255, 200 ) );
166+
mFieldsList->item( row, i )->setBackgroundColor( QColor( 255, 255, 200 ) );
166167
break;
167168
}
168169
}
@@ -367,16 +368,19 @@ void QgsSourceFieldsProperties::attributesListCellChanged( int row, int column )
367368
{
368369
if ( column == AttrNameCol && mLayer && mLayer->isEditable() )
369370
{
371+
int idx = mIndexedWidgets.indexOf( mFieldsList->item( row, AttrIdCol ) );
372+
370373
QTableWidgetItem *nameItem = mFieldsList->item( row, column );
374+
//avoiding that something will be changed, just because this is triggered by simple re-sorting
371375
if ( !nameItem ||
372376
nameItem->text().isEmpty() ||
373377
!mLayer->fields().exists( row ) ||
374-
mLayer->fields().at( mFieldsList->item( row, AttrIdCol )->text().toInt() ).name() == nameItem->text()
378+
mLayer->fields().at( idx ).name() == nameItem->text()
375379
)
376380
return;
377381

378382
mLayer->beginEditCommand( tr( "Rename attribute" ) );
379-
if ( mLayer->renameAttribute( row, nameItem->text() ) )
383+
if ( mLayer->renameAttribute( idx, nameItem->text() ) )
380384
{
381385
mLayer->endEditCommand();
382386
}

0 commit comments

Comments
 (0)