Skip to content

Commit

Permalink
References #17412 Fixes problem when changeing sort but not when rena…
Browse files Browse the repository at this point in the history
…ming

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
  • Loading branch information
signedav committed Nov 7, 2017
1 parent 44d8db9 commit ba243e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
19 changes: 4 additions & 15 deletions src/app/qgsattributesformproperties.cpp
Expand Up @@ -217,7 +217,7 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
{
//check if item or field with the items name for some reason not available anymore
if ( !mAvailableWidgetsTree->currentItem() ||
getFieldIndexByName( mAvailableWidgetsTree->currentItem()->data( 0, FieldNameRole ).toString() ) < 0 )
mLayer->fields().indexOf( mAvailableWidgetsTree->currentItem()->data( 0, FieldNameRole ).toString() ) < 0 )
mAttributeTypeDialog->setEnabled( false );
else
{
Expand Down Expand Up @@ -625,18 +625,6 @@ void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
mEditFormLineEdit->setText( uifilename );
}

int QgsAttributesFormProperties::getFieldIndexByName( const QString &name )
{
for ( int idx = 0; idx < mLayer->fields().size(); idx++ )
{
//only save the files that are still existing in fields
if ( mLayer->fields().at( idx ).name() == name )
return idx;
}

return -1;
}

void QgsAttributesFormProperties::apply()
{

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

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

//continue in case field does not exist anymore
if ( idx < 0 ) continue;
if ( idx < 0 )
continue;

editFormConfig.setReadOnly( idx, !cfg.mEditable );
editFormConfig.setLabelOnTop( idx, cfg.mLabelOnTop );
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsattributesformproperties.h
Expand Up @@ -213,8 +213,6 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
void loadAttributeRelationEdit();
void storeAttributeRelationEdit( );

int getFieldIndexByName( const QString &name );

QgsEditFormConfig::PythonInitCodeSource mInitCodeSource;
QString mInitFunction;
QString mInitFilePath;
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgssourcefieldsproperties.cpp
Expand Up @@ -280,8 +280,6 @@ bool QgsSourceFieldsProperties::addAttribute( const QgsField &field )

void QgsSourceFieldsProperties::apply()
{
// Disabled: we deal with the configuration in the new tabs

QSet<QString> excludeAttributesWMS, excludeAttributesWFS;

for ( int i = 0; i < mFieldsList->rowCount(); i++ )
Expand Down Expand Up @@ -373,7 +371,8 @@ void QgsSourceFieldsProperties::attributesListCellChanged( int row, int column )
if ( !nameItem ||
nameItem->text().isEmpty() ||
!mLayer->fields().exists( row ) ||
mLayer->fields().at( row ).name() == nameItem->text() )
mLayer->fields().at( mFieldsList->item( row, AttrIdCol )->text().toInt() ).name() == nameItem->text()
)
return;

mLayer->beginEditCommand( tr( "Rename attribute" ) );
Expand Down

0 comments on commit ba243e5

Please sign in to comment.