diff --git a/python/gui/auto_generated/attributetable/qgsattributetableview.sip.in b/python/gui/auto_generated/attributetable/qgsattributetableview.sip.in index 5b7c671b1d1..da1cf2eb23f 100644 --- a/python/gui/auto_generated/attributetable/qgsattributetableview.sip.in +++ b/python/gui/auto_generated/attributetable/qgsattributetableview.sip.in @@ -126,13 +126,12 @@ Saves geometry to the settings on close signals: - void willShowContextMenu( QMenu *menu, const QModelIndex &atIndex ); + void willShowContextMenu( QMenu *menu, const QgsFeatureId featureId ); %Docstring Emitted in order to provide a hook to add additional* menu entries to the context menu. :param menu: If additional QMenuItems are added, they will show up in the context menu. -:param atIndex: The QModelIndex, to which the context menu belongs. Relative to the source model. - In most cases, this will be a :py:class:`QgsAttributeTableFilterModel` +:param featureId: The ID of the current feature %End void columnResized( int column, int width ); diff --git a/python/gui/auto_generated/attributetable/qgsfeaturelistview.sip.in b/python/gui/auto_generated/attributetable/qgsfeaturelistview.sip.in index 0fe6eb39ed9..0732742f92e 100644 --- a/python/gui/auto_generated/attributetable/qgsfeaturelistview.sip.in +++ b/python/gui/auto_generated/attributetable/qgsfeaturelistview.sip.in @@ -138,12 +138,12 @@ Emitted whenever the display expression is successfully changed %End - void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex ); + void willShowContextMenu( QgsActionMenu *menu, const QgsFeatureId featureId ); %Docstring Emitted when the context menu is created to add the specific actions to it :param menu: is the already created context menu -:param atIndex: is the position of the current feature in the model +:param featureId: is the ID of the current feature %End public slots: diff --git a/src/gui/attributetable/qgsattributetableview.cpp b/src/gui/attributetable/qgsattributetableview.cpp index 507cca874d5..f13e0edf3aa 100644 --- a/src/gui/attributetable/qgsattributetableview.cpp +++ b/src/gui/attributetable/qgsattributetableview.cpp @@ -363,7 +363,7 @@ void QgsAttributeTableView::contextMenuEvent( QContextMenuEvent *event ) mActionPopup->addAction( tr( "Select All" ), this, SLOT( selectAll() ), QKeySequence::SelectAll ); // let some other parts of the application add some actions - emit willShowContextMenu( mActionPopup, idx ); + emit willShowContextMenu( mActionPopup, mFilterModel->rowToId( idx ) ); if ( !mActionPopup->actions().isEmpty() ) { diff --git a/src/gui/attributetable/qgsattributetableview.h b/src/gui/attributetable/qgsattributetableview.h index cd3b98eecb3..131436c2cbe 100644 --- a/src/gui/attributetable/qgsattributetableview.h +++ b/src/gui/attributetable/qgsattributetableview.h @@ -144,10 +144,9 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView * Emitted in order to provide a hook to add additional* menu entries to the context menu. * * \param menu If additional QMenuItems are added, they will show up in the context menu. - * \param atIndex The QModelIndex, to which the context menu belongs. Relative to the source model. - * In most cases, this will be a QgsAttributeTableFilterModel + * \param featureId The ID of the current feature */ - void willShowContextMenu( QMenu *menu, const QModelIndex &atIndex ); + void willShowContextMenu( QMenu *menu, const QgsFeatureId featureId ); /** * Emitted when a column in the view has been resized. diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 8f777c4bbce..b9b4bc16936 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -657,14 +657,19 @@ void QgsDualView::hideEvent( QHideEvent *event ) saveRecentDisplayExpressions(); } -void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex ) +void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QgsFeatureId featureId ) { if ( !menu ) { return; } - QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex ); + QModelIndex sourceIndex = mFilterModel->fidToIndex( featureId ); + + if ( ! sourceIndex.isValid() ) + { + return; + } QAction *copyContentAction = new QAction( tr( "Copy Cell Content" ), this ); copyContentAction->setData( QVariant::fromValue( sourceIndex ) ); @@ -722,9 +727,9 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd } -void QgsDualView::widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex ) +void QgsDualView::widgetWillShowContextMenu( QgsActionMenu *menu, const QgsFeatureId featureId ) { - emit showContextMenuExternally( menu, mFilterModel->rowToId( atIndex ) ); + emit showContextMenuExternally( menu, featureId ); } diff --git a/src/gui/attributetable/qgsdualview.h b/src/gui/attributetable/qgsdualview.h index 8f08eae2a14..55531f2be7b 100644 --- a/src/gui/attributetable/qgsdualview.h +++ b/src/gui/attributetable/qgsdualview.h @@ -312,9 +312,9 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas void previewColumnChanged( QAction *previewAction, const QString &expression ); - void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex ); + void viewWillShowContextMenu( QMenu *menu, const QgsFeatureId featureId ); - void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex ); + void widgetWillShowContextMenu( QgsActionMenu *menu, const QgsFeatureId featureId ); void showViewHeaderMenu( QPoint point ); diff --git a/src/gui/attributetable/qgsfeaturelistview.cpp b/src/gui/attributetable/qgsfeaturelistview.cpp index e3b73e46970..008149a44b3 100644 --- a/src/gui/attributetable/qgsfeaturelistview.cpp +++ b/src/gui/attributetable/qgsfeaturelistview.cpp @@ -325,11 +325,7 @@ void QgsFeatureListView::contextMenuEvent( QContextMenuEvent *event ) QgsActionMenu *menu = new QgsActionMenu( mModel->layerCache()->layer(), feature, QStringLiteral( "Feature" ), this ); - // Index is from feature list model, but we need an index from the - // filter model to be passed to listeners, using fid instead would - // have been much better in term of bugs (and headaches) but this - // belongs to the API unfortunately. - emit willShowContextMenu( menu, mModel->mapToSource( index ) ); + emit willShowContextMenu( menu, feature.id() ); menu->exec( event->globalPos() ); } diff --git a/src/gui/attributetable/qgsfeaturelistview.h b/src/gui/attributetable/qgsfeaturelistview.h index 130cc91866c..6b371695003 100644 --- a/src/gui/attributetable/qgsfeaturelistview.h +++ b/src/gui/attributetable/qgsfeaturelistview.h @@ -156,9 +156,9 @@ class GUI_EXPORT QgsFeatureListView : public QListView /** * Emitted when the context menu is created to add the specific actions to it * \param menu is the already created context menu - * \param atIndex is the position of the current feature in the model + * \param featureId is the ID of the current feature */ - void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex ); + void willShowContextMenu( QgsActionMenu *menu, const QgsFeatureId featureId ); public slots: