Skip to content

Commit ba243e5

Browse files
committedNov 7, 2017
References #17412 Fixes problem when changeing sort but not when renaming
When sort and then toggle edditing, the problem was that it wanted to rename all the fields Whis is avoided now by checking the indexes But still problems open when one wants to rename fields in unsorted layout
1 parent 44d8db9 commit ba243e5

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed
 

‎src/app/qgsattributesformproperties.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
217217
{
218218
//check if item or field with the items name for some reason not available anymore
219219
if ( !mAvailableWidgetsTree->currentItem() ||
220-
getFieldIndexByName( mAvailableWidgetsTree->currentItem()->data( 0, FieldNameRole ).toString() ) < 0 )
220+
mLayer->fields().indexOf( mAvailableWidgetsTree->currentItem()->data( 0, FieldNameRole ).toString() ) < 0 )
221221
mAttributeTypeDialog->setEnabled( false );
222222
else
223223
{
@@ -625,18 +625,6 @@ void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
625625
mEditFormLineEdit->setText( uifilename );
626626
}
627627

628-
int QgsAttributesFormProperties::getFieldIndexByName( const QString &name )
629-
{
630-
for ( int idx = 0; idx < mLayer->fields().size(); idx++ )
631-
{
632-
//only save the files that are still existing in fields
633-
if ( mLayer->fields().at( idx ).name() == name )
634-
return idx;
635-
}
636-
637-
return -1;
638-
}
639-
640628
void QgsAttributesFormProperties::apply()
641629
{
642630

@@ -652,10 +640,11 @@ void QgsAttributesFormProperties::apply()
652640
QTreeWidgetItem *fieldItem = fieldContainer->child( i );
653641
FieldConfig cfg = fieldItem->data( 0, FieldConfigRole ).value<FieldConfig>();
654642

655-
int idx = getFieldIndexByName( fieldItem->data( 0, FieldNameRole ).toString() );
643+
int idx = mLayer->fields().indexOf( fieldItem->data( 0, FieldNameRole ).toString() );
656644

657645
//continue in case field does not exist anymore
658-
if ( idx < 0 ) continue;
646+
if ( idx < 0 )
647+
continue;
659648

660649
editFormConfig.setReadOnly( idx, !cfg.mEditable );
661650
editFormConfig.setLabelOnTop( idx, cfg.mLabelOnTop );

‎src/app/qgsattributesformproperties.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
213213
void loadAttributeRelationEdit();
214214
void storeAttributeRelationEdit( );
215215

216-
int getFieldIndexByName( const QString &name );
217-
218216
QgsEditFormConfig::PythonInitCodeSource mInitCodeSource;
219217
QString mInitFunction;
220218
QString mInitFilePath;

‎src/app/qgssourcefieldsproperties.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ bool QgsSourceFieldsProperties::addAttribute( const QgsField &field )
280280

281281
void QgsSourceFieldsProperties::apply()
282282
{
283-
// Disabled: we deal with the configuration in the new tabs
284-
285283
QSet<QString> excludeAttributesWMS, excludeAttributesWFS;
286284

287285
for ( int i = 0; i < mFieldsList->rowCount(); i++ )
@@ -373,7 +371,8 @@ void QgsSourceFieldsProperties::attributesListCellChanged( int row, int column )
373371
if ( !nameItem ||
374372
nameItem->text().isEmpty() ||
375373
!mLayer->fields().exists( row ) ||
376-
mLayer->fields().at( row ).name() == nameItem->text() )
374+
mLayer->fields().at( mFieldsList->item( row, AttrIdCol )->text().toInt() ).name() == nameItem->text()
375+
)
377376
return;
378377

379378
mLayer->beginEditCommand( tr( "Rename attribute" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.