mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Allowing associating QgsLocatorWidget with a map canvas
This allows the widget's locator to prioritise results which are close to the current canvas extent
This commit is contained in:
parent
a7d590e041
commit
ab02f2b79c
@ -35,6 +35,13 @@ class QgsLocatorWidget : QWidget
|
||||
:rtype: QgsLocator
|
||||
%End
|
||||
|
||||
void setMapCanvas( QgsMapCanvas *canvas );
|
||||
%Docstring
|
||||
Sets a map ``canvas`` to associate with the widget. This allows the
|
||||
widget to customise the searches performed by its locator(), such
|
||||
as prioritizing results which are near the current canvas extent.
|
||||
%End
|
||||
|
||||
public slots:
|
||||
|
||||
void search( const QString &string );
|
||||
|
@ -966,6 +966,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
|
||||
// set graphical credential requester
|
||||
new QgsCredentialDialog( this );
|
||||
|
||||
mLocatorWidget->setMapCanvas( mMapCanvas );
|
||||
|
||||
qApp->processEvents();
|
||||
|
||||
// load providers
|
||||
|
@ -72,7 +72,7 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c
|
||||
}
|
||||
mFeedback = feedback;
|
||||
|
||||
auto gatherFilterResults = [string, feedback]( QgsLocatorFilter * filter )
|
||||
auto gatherFilterResults = [string, context, feedback]( QgsLocatorFilter * filter )
|
||||
{
|
||||
if ( !feedback->isCanceled() )
|
||||
filter->fetchResults( string, context, feedback );
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "qgslocatorwidget.h"
|
||||
#include "qgslocator.h"
|
||||
#include "qgsfilterlineedit.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
#include <QLayout>
|
||||
#include <QCompleter>
|
||||
#include "qgsapplication.h"
|
||||
@ -87,6 +88,11 @@ QgsLocator *QgsLocatorWidget::locator()
|
||||
return mLocator;
|
||||
}
|
||||
|
||||
void QgsLocatorWidget::setMapCanvas( QgsMapCanvas *canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
}
|
||||
|
||||
void QgsLocatorWidget::search( const QString &string )
|
||||
{
|
||||
mLineEdit->setText( string );
|
||||
@ -207,7 +213,9 @@ void QgsLocatorWidget::updateResults( const QString &text )
|
||||
{
|
||||
mLocatorModel->clear();
|
||||
if ( !text.isEmpty() )
|
||||
mLocator->fetchResults( text );
|
||||
{
|
||||
mLocator->fetchResults( text, createContext() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,6 +241,17 @@ void QgsLocatorWidget::acceptCurrentEntry()
|
||||
}
|
||||
}
|
||||
|
||||
QgsLocatorContext QgsLocatorWidget::createContext()
|
||||
{
|
||||
QgsLocatorContext context;
|
||||
if ( mMapCanvas )
|
||||
{
|
||||
context.targetExtent = mMapCanvas->mapSettings().visibleExtent();
|
||||
context.targetExtentCrs = mMapCanvas->mapSettings().destinationCrs();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
//
|
||||
|
@ -32,6 +32,7 @@ class QgsLocator;
|
||||
class QgsFilterLineEdit;
|
||||
class QgsLocatorModel;
|
||||
class QgsLocatorResultsView;
|
||||
class QgsMapCanvas;
|
||||
|
||||
/**
|
||||
* \class QgsLocatorWidget
|
||||
@ -57,6 +58,13 @@ class GUI_EXPORT QgsLocatorWidget : public QWidget
|
||||
*/
|
||||
QgsLocator *locator();
|
||||
|
||||
/**
|
||||
* Sets a map \a canvas to associate with the widget. This allows the
|
||||
* widget to customise the searches performed by its locator(), such
|
||||
* as prioritizing results which are near the current canvas extent.
|
||||
*/
|
||||
void setMapCanvas( QgsMapCanvas *canvas );
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
@ -83,6 +91,7 @@ class GUI_EXPORT QgsLocatorWidget : public QWidget
|
||||
QgsLocatorModel *mLocatorModel = nullptr;
|
||||
QgsFloatingWidget *mResultsContainer = nullptr;
|
||||
QgsLocatorResultsView *mResultsView = nullptr;
|
||||
QgsMapCanvas *mMapCanvas = nullptr;
|
||||
|
||||
QString mNextRequestedString;
|
||||
bool mHasQueuedRequest = false;
|
||||
@ -90,6 +99,7 @@ class GUI_EXPORT QgsLocatorWidget : public QWidget
|
||||
|
||||
void updateResults( const QString &text );
|
||||
void acceptCurrentEntry();
|
||||
QgsLocatorContext createContext();
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user