Skip to content
Permalink
Browse files

References #17412 Fixes problem when changeing sort but not when rena…

…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 ba243e559dcf4c50f30bb7d27d5513aa6d8ac0f0
@@ -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
{
@@ -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()
{

@@ -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 );
@@ -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;
@@ -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++ )
@@ -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" ) );

0 comments on commit ba243e5

Please sign in to comment.
You can’t perform that action at this time.