Skip to content
Permalink
Browse files

[Fix #7858] Toggle editing mode resets edit widget

And introduces full mapping between table row and field index ( Fix for loosing index mapping after sorting rows )
  • Loading branch information
m-kuhn committed May 18, 2013
1 parent a98ffed commit 99aaa5979f34ac91e633385b3223c24ce804f18e
Showing with 25 additions and 7 deletions.
  1. +21 −7 src/app/qgsfieldsproperties.cpp
  2. +4 −0 src/app/qgsfieldsproperties.h
@@ -286,7 +286,6 @@ void QgsFieldsProperties::loadRows()
mAttributesList->clear();

mAttributesList->setColumnCount( attrColCount );
mAttributesList->setRowCount( fields.size() );
mAttributesList->setSelectionBehavior( QAbstractItemView::SelectRows );
mAttributesList->setDragDropMode( QAbstractItemView::DragOnly );
mAttributesList->setHorizontalHeaderItem( attrIdCol, new QTableWidgetItem( tr( "Id" ) ) );
@@ -306,7 +305,7 @@ void QgsFieldsProperties::loadRows()
mAttributesList->verticalHeader()->hide();

for ( int i = 0; i < fields.count(); ++i )
setRow( i, i, fields[i] );
attributeAdded( i );

mAttributesList->resizeColumnsToContents();
connect( mAttributesList, SIGNAL( cellChanged( int, int ) ), this, SLOT( attributesListCellChanged( int, int ) ) );
@@ -526,17 +525,32 @@ void QgsFieldsProperties::attributeTypeDialog()

void QgsFieldsProperties::attributeAdded( int idx )
{
bool sorted = mAttributesList->isSortingEnabled();
mAttributesList->setSortingEnabled( false );
const QgsFields &fields = mLayer->pendingFields();
int row = mAttributesList->rowCount();
mAttributesList->insertRow( row );
setRow( row, idx, fields[idx] );
mIndexedWidgets.insert( idx, mAttributesList->item( row, 0 ) );

for ( int i = idx; i < mIndexedWidgets.count(); i++ )
{
mIndexedWidgets[i]->setText( QString::number( i ) );
}

mAttributesList->setCurrentCell( row, idx );
mAttributesList->setSortingEnabled( sorted );
}


void QgsFieldsProperties::attributeDeleted( int idx )
{
mAttributesList->removeRow( idx );
mAttributesList->removeRow( mIndexedWidgets.at( idx )->row() );
mIndexedWidgets.removeAt( idx );
for ( int i = idx; i < mIndexedWidgets.count(); i++ )
{
mIndexedWidgets[i]->setText( QString::number( i ) );
}
}

void QgsFieldsProperties::addAttribute()
@@ -575,9 +589,6 @@ bool QgsFieldsProperties::addAttribute( const QgsField &field )

void QgsFieldsProperties::editingToggled()
{
if ( !mLayer->isEditable() )
loadRows();

updateButtons();
}

@@ -604,7 +615,10 @@ void QgsFieldsProperties::on_mDeleteAttributeButton_clicked()
QSet<int> attrs;
foreach ( QTableWidgetItem* item, mAttributesList->selectedItems() )
{
attrs << mAttributesList->row( item );
if ( item->column() == 0 )
{
attrs << mIndexedWidgets.indexOf( item );
}
}

mLayer->beginEditCommand( tr( "Deleted attribute" ) );
@@ -114,6 +114,10 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
QMap<int, QPushButton*> mButtonMap;
QMap<int, QString> mDateFormat;
QMap<int, QSize> mWidgetSize;
// Holds all the first column items (header: id) of the table.
// The index in the list is the fieldIdx, and therefore acts as a mapping
// between fieldIdx and QTableWidgetItem->row()
QList<QTableWidgetItem*> mIndexedWidgets;

enum attrColumns
{

0 comments on commit 99aaa59

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