Skip to content

Commit

Permalink
Handle sorted or reordered columns when copying cell contents
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 2, 2016
1 parent 3da3cf1 commit 3da460e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/gui/attributetable/qgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ void QgsDualView::copyCellContent() const
QModelIndex index = action->data().value<QModelIndex>();

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


QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );

QAction *copyContentAction = new QAction( tr( "Copy cell content" ), this );
copyContentAction->setData( QVariant::fromValue<QModelIndex>( atIndex ) );
copyContentAction->setData( QVariant::fromValue<QModelIndex>( sourceIndex ) );
menu->addAction( copyContentAction );
connect( copyContentAction, SIGNAL( triggered() ), this, SLOT( copyCellContent() ) );

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

QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );

//add user-defined actions to context menu
if ( mLayerCache->layer()->actions()->size() != 0 )
{
Expand Down

0 comments on commit 3da460e

Please sign in to comment.