Skip to content

Commit 3da460e

Browse files
committed
Handle sorted or reordered columns when copying cell contents
1 parent 3da3cf1 commit 3da460e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/gui/attributetable/qgsdualview.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ void QgsDualView::copyCellContent() const
389389
QModelIndex index = action->data().value<QModelIndex>();
390390

391391
QgsFeature f = masterModel()->feature( index );
392-
QVariant var = f.attributes().at( index.column() );
392+
int attrIndex = mMasterModel->fieldIdx( index.column() );
393+
QVariant var = f.attributes().at( attrIndex );
393394
QApplication::clipboard()->setText( var.toString() );
394395
}
395396
}
@@ -401,8 +402,11 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
401402
return;
402403
}
403404

405+
406+
QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );
407+
404408
QAction *copyContentAction = new QAction( tr( "Copy cell content" ), this );
405-
copyContentAction->setData( QVariant::fromValue<QModelIndex>( atIndex ) );
409+
copyContentAction->setData( QVariant::fromValue<QModelIndex>( sourceIndex ) );
406410
menu->addAction( copyContentAction );
407411
connect( copyContentAction, SIGNAL( triggered() ), this, SLOT( copyCellContent() ) );
408412

@@ -413,8 +417,6 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
413417
menu->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToCurrentFeature() ) );
414418
}
415419

416-
QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );
417-
418420
//add user-defined actions to context menu
419421
if ( mLayerCache->layer()->actions()->size() != 0 )
420422
{

0 commit comments

Comments
 (0)