Skip to content

Commit

Permalink
change to a parallel thread approach
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Nov 25, 2020
1 parent 740c0f7 commit 6212551
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 168 deletions.
24 changes: 22 additions & 2 deletions python/gui/auto_generated/qgsmaptool.sip.in
Expand Up @@ -195,7 +195,25 @@ The values is calculated from :py:func:`~QgsMapTool.searchRadiusMM`.
.. versionadded:: 2.3
%End

virtual void populateContextMenu( QMenu *menu, QgsMapMouseEvent *event = 0 );
virtual void populateContextMenu( QMenu *menu );
%Docstring
Allows the tool to populate and customize the given ``menu``,
prior to showing it in response to a right-mouse button click.

``menu`` will be initially populated with a set of default, generic actions.
Any new actions added to the menu should be correctly parented to ``menu``.

The default implementation does nothing.

.. note::

The context menu is only shown when the ShowContextMenu flag
is present in :py:func:`~QgsMapTool.flags`.

.. versionadded:: 3.14
%End

virtual bool populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEvent *event );
%Docstring
Allows the tool to populate and customize the given ``menu``,
prior to showing it in response to a right-mouse button click.
Expand All @@ -205,7 +223,9 @@ Any new actions added to the menu should be correctly parented to ``menu``.

A pointer to the map mouse ``event`` can be provided to allow particular behavior depending on the map tool.

The default implementation does nothing.
This method can return true to inform the caller that the menu was effectivly populated.

The default implementation does nothing and return false;

.. note::

Expand Down
31 changes: 6 additions & 25 deletions src/app/qgsmaptoolselect.cpp
Expand Up @@ -141,9 +141,7 @@ QgsMapTool::Flags QgsMapToolSelect::flags() const
return QgsMapTool::flags();
}



void QgsMapToolSelect::populateContextMenu( QMenu *menu, QgsMapMouseEvent *event )
bool QgsMapToolSelect::populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEvent *event )
{
menu->addSeparator();
QgsVectorLayer *vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas );
Expand All @@ -163,13 +161,14 @@ void QgsMapToolSelect::populateContextMenu( QMenu *menu, QgsMapMouseEvent *event
else if ( modifiers & Qt::ControlModifier )
behavior = QgsVectorLayer::RemoveFromSelection;

QgsRectangle r = QgsMapToolSelectUtils::expandSelectRectangle( mapPoint, mCanvas, vlayer );

QgsMapToolSelectUtils::QgsMapToolSelectMenuActions *menuActions
= new QgsMapToolSelectUtils::QgsMapToolSelectMenuActions( mCanvas, vlayer, behavior, menu );
= new QgsMapToolSelectUtils::QgsMapToolSelectMenuActions( mCanvas, vlayer, behavior, QgsGeometry::fromRect( r ), menu );

QgsRectangle r = QgsMapToolSelectUtils::expandSelectRectangle( mapPoint, mCanvas, vlayer );
QgsFeatureIds selectedFeatures = QgsMapToolSelectUtils::getMatchingFeatures( mCanvas, QgsGeometry::fromRect( r ), false, false );
menuActions->populateMenu( menu );

menu->addActions( menuActions->actions( selectedFeatures ) );
return true;
}

void QgsMapToolSelect::selectFeatures( Qt::KeyboardModifiers modifiers )
Expand Down Expand Up @@ -204,21 +203,3 @@ void QgsMapToolSelect::modifiersChanged( bool ctrlModifier, bool shiftModifier,
else if ( ctrlModifier && shiftModifier && altModifier )
emit modeChanged( GeometryWithinIntersectWithSelection );
}

void QgsMapToolSelect::highlightFeature( const QgsFeatureId &id, QgsVectorLayer *layer )
{
for ( QgsHighlight *hl : mHighlights )
delete hl;

mHighlights.clear();

QgsFeature feat = layer->getFeature( id );
mHighlights.append( new QgsHighlight( mCanvas, feat.geometry(), layer ) );

}






8 changes: 1 addition & 7 deletions src/app/qgsmaptoolselect.h
Expand Up @@ -54,8 +54,7 @@ class APP_EXPORT QgsMapToolSelect : public QgsMapTool
void deactivate() override;
Flags flags() const override;


void populateContextMenu( QMenu *menu, QgsMapMouseEvent *event = nullptr ) override;
bool populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEvent *event ) override;

signals:

Expand All @@ -68,11 +67,6 @@ class APP_EXPORT QgsMapToolSelect : public QgsMapTool
std::unique_ptr<QgsMapToolSelectionHandler> mSelectionHandler;

void modifiersChanged( bool ctrlModifier, bool shiftModifier, bool altModifier );

void highlightFeature( const QgsFeatureId &id, QgsVectorLayer *layer );

QList<QgsHighlight *> mHighlights;

};

#endif

0 comments on commit 6212551

Please sign in to comment.