Skip to content
Permalink
Browse files

Add transform context to QgsLocatorContext

Allows locators to correctly perform transformations during their
result fetching/handling
  • Loading branch information
nyalldawson committed Oct 30, 2020
1 parent 4f6f163 commit d0ea8faf3c835f9d69424882d8ded1cd6afb0a3c
@@ -31,6 +31,8 @@ Constructor for QgsLocatorContext.

QgsCoordinateReferenceSystem targetExtentCrs;

QgsCoordinateTransformContext transformContext;

bool usingPrefix;

};
@@ -60,6 +60,26 @@ Returns ``True`` if the a search is currently running
void triggerResult( const QModelIndex &index, const int actionId = -1 );
%Docstring
Triggers the result at given ``index`` and with optional ``actionId`` if an additional action was triggered
%End

QgsCoordinateTransformContext transformContext() const;
%Docstring
Returns the coordinate transform context, which should be used whenever the
locator constructs a coordinate transform.

.. seealso:: :py:func:`setTransformContext`

.. versionadded:: 3.18
%End

void setTransformContext( const QgsCoordinateTransformContext &context );
%Docstring
Sets the coordinate transform ``context``, which should be used whenever the
locator constructs a coordinate transform.

.. seealso:: :py:func:`transformContext`

.. versionadded:: 3.18
%End

signals:
@@ -21,6 +21,7 @@
#include "qgis_core.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"

/**
* \class QgsLocatorContext
@@ -51,6 +52,14 @@ class CORE_EXPORT QgsLocatorContext
*/
QgsCoordinateReferenceSystem targetExtentCrs;

/**
* Coordinate transform context, to use whenever performing coordinate transformations inside
* a locator.
*
* \since QGIS 3.16
*/
QgsCoordinateTransformContext transformContext;

/**
* Will be TRUE if search is being conducted using a filter prefix.
*/
@@ -141,5 +141,6 @@ QgsLocatorContext QgsLocatorModelBridge::createContext()
QgsLocatorContext context;
context.targetExtent = mCanvasExtent;
context.targetExtentCrs = mCanvasCrs;
context.transformContext = mTransformContext;
return context;
}
@@ -22,6 +22,7 @@

#include "qgis_core.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"
#include "qgsrectangle.h"

class QAction;
@@ -66,6 +67,24 @@ class CORE_EXPORT QgsLocatorModelBridge : public QObject
//! Triggers the result at given \a index and with optional \a actionId if an additional action was triggered
void triggerResult( const QModelIndex &index, const int actionId = -1 );

/**
* Returns the coordinate transform context, which should be used whenever the
* locator constructs a coordinate transform.
*
* \see setTransformContext()
* \since QGIS 3.18
*/
QgsCoordinateTransformContext transformContext() const { return mTransformContext; }

/**
* Sets the coordinate transform \a context, which should be used whenever the
* locator constructs a coordinate transform.
*
* \see transformContext()
* \since QGIS 3.18
*/
void setTransformContext( const QgsCoordinateTransformContext &context ) { mTransformContext = context; }

signals:
//! Emitted when a result is added
void resultAdded();
@@ -108,6 +127,7 @@ class CORE_EXPORT QgsLocatorModelBridge : public QObject
// see discussion in https://github.com/qgis/QGIS/pull/8404
QgsRectangle mCanvasExtent;
QgsCoordinateReferenceSystem mCanvasCrs;
QgsCoordinateTransformContext mTransformContext;
};

#endif // QGSLOCATORMODELBRIDGE_H
@@ -114,6 +114,12 @@ QgsLocatorWidget::QgsLocatorWidget( QWidget *parent )
} );
connect( mMenu, &QMenu::aboutToShow, this, &QgsLocatorWidget::configMenuAboutToShow );

mModelBridge->setTransformContext( QgsProject::instance()->transformContext() );
connect( QgsProject::instance(), &QgsProject::transformContextChanged,
this, [ = ]
{
mModelBridge->setTransformContext( QgsProject::instance()->transformContext() );
} );
}

QgsLocator *QgsLocatorWidget::locator()

0 comments on commit d0ea8fa

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