Skip to content
Permalink
Browse files

save current extent and CRS in locator core

remove remaining bits of interface
  • Loading branch information
3nids committed Nov 6, 2018
1 parent 8e34e37 commit f652e8dcba373e633281de6df2509bf657688614
@@ -28,11 +28,6 @@ to be used in a locator widget.
explicit QgsLocatorWidgetCore( QObject *parent = 0 );
%Docstring
Constructor of QgsLocatorWidgetCore
%End

void setMapCanvasInterface( QgsMapCanvasInterface *canvasInterface );
%Docstring
Set the map canvas interface
%End

void performSearch( const QString &text );
@@ -80,6 +75,16 @@ Emitted when the results are cleared
void invalidateResults();
%Docstring
This will invalidate current search results
%End

void updateCanvasExtent( const QgsRectangle &extent );
%Docstring
Update the canvas extent used to create search context
%End

void updateCanvasCrs( const QgsCoordinateReferenceSystem &crs );
%Docstring
Update the canvas CRS used to create search context
%End

};
@@ -18,7 +18,6 @@
#include "qgslocatorwidgetcore.h"
#include "qgslocator.h"
#include "qgslocatormodel.h"
#include "qgsmapcanvasinterface.h"
#include "qgsmapsettings.h"

QgsLocatorWidgetCore::QgsLocatorWidgetCore( QObject *parent )
@@ -33,11 +32,6 @@ QgsLocatorWidgetCore::QgsLocatorWidgetCore( QObject *parent )
connect( mLocator, &QgsLocator::finished, this, &QgsLocatorWidgetCore::searchFinished );
}

void QgsLocatorWidgetCore::setMapCanvasInterface( QgsMapCanvasInterface *canvasInterface )
{
mCanvasInterface = canvasInterface;
}

bool QgsLocatorWidgetCore::isRunning() const
{
return mIsRunning;
@@ -58,6 +52,16 @@ void QgsLocatorWidgetCore::invalidateResults()
mLocatorModel->clear();
}

void QgsLocatorWidgetCore::updateCanvasExtent( const QgsRectangle &extent )
{
mCanvasExtent = extent;
}

void QgsLocatorWidgetCore::updateCanvasCrs( const QgsCoordinateReferenceSystem &crs )
{
mCanvasCrs = crs;
}

void QgsLocatorWidgetCore::addResult( const QgsLocatorResult &result )
{
mLocatorModel->addResult( result );
@@ -121,10 +125,7 @@ bool QgsLocatorWidgetCore::hasQueueRequested() const
QgsLocatorContext QgsLocatorWidgetCore::createContext()
{
QgsLocatorContext context;
if ( mCanvasInterface )
{
context.targetExtent = mCanvasInterface->mapSettings().visibleExtent();
context.targetExtentCrs = mCanvasInterface->mapSettings().destinationCrs();
}
context.targetExtent = mCanvasExtent;
context.targetExtentCrs = mCanvasCrs;
return context;
}
@@ -21,13 +21,14 @@
#include <QObject>

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

class QgsLocatorResult;
class QgsLocator;
class QgsLocatorContext;
class QgsLocatorModel;
class QgsLocatorProxyModel;
class QgsMapCanvasInterface;


/**
@@ -44,9 +45,6 @@ class CORE_EXPORT QgsLocatorWidgetCore : public QObject
//! Constructor of QgsLocatorWidgetCore
explicit QgsLocatorWidgetCore( QObject *parent = nullptr );

//! Set the map canvas interface
void setMapCanvasInterface( QgsMapCanvasInterface *canvasInterface );

//! Perform a search
Q_INVOKABLE void performSearch( const QString &text );

@@ -76,6 +74,12 @@ class CORE_EXPORT QgsLocatorWidgetCore : public QObject
//! This will invalidate current search results
void invalidateResults();

//! Update the canvas extent used to create search context
void updateCanvasExtent( const QgsRectangle &extent );

//! Update the canvas CRS used to create search context
void updateCanvasCrs( const QgsCoordinateReferenceSystem &crs );

private slots:
void searchFinished();
void addResult( const QgsLocatorResult &result );
@@ -87,11 +91,17 @@ class CORE_EXPORT QgsLocatorWidgetCore : public QObject
QgsLocator *mLocator = nullptr;
QgsLocatorModel *mLocatorModel = nullptr;
QgsLocatorProxyModel *mProxyModel = nullptr;
QgsMapCanvasInterface *mCanvasInterface = nullptr;

QString mNextRequestedString;
bool mHasQueuedRequest = false;
bool mIsRunning = false;

// keep track of map canvas extent and CRS
// if much if needed, it would be possible to add
// a QgsMapCanvasController in core to achieve this
// see discussion in https://github.com/qgis/QGIS/pull/8404
QgsRectangle mCanvasExtent;
QgsCoordinateReferenceSystem mCanvasCrs;
};

#endif // QGSLOCATORWIDGETCORE_H
@@ -116,7 +116,22 @@ QgsLocator *QgsLocatorWidget::locator()

void QgsLocatorWidget::setMapCanvas( QgsMapCanvas *canvas )
{
mWidgetCore->setMapCanvasInterface( canvas );
if ( mMapCanvas == canvas )
return;

for ( const QMetaObject::Connection &conn : qgis::as_const( mCanvasConnections ) )
{
disconnect( conn );
}
mCanvasConnections.clear();

mMapCanvas = canvas;
if ( mMapCanvas )
{
mCanvasConnections
<< connect( mMapCanvas, &QgsMapCanvas::extentsChanged, this, [ = ]() {mWidgetCore->updateCanvasExtent( mMapCanvas->extent() );} )
<< connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, [ = ]() {mWidgetCore->updateCanvasCrs( mMapCanvas->mapSettings().destinationCrs() );} ) ;
}
}

void QgsLocatorWidget::search( const QString &string )
@@ -101,6 +101,7 @@ class GUI_EXPORT QgsLocatorWidget : public QWidget
QgsFloatingWidget *mResultsContainer = nullptr;
QgsLocatorResultsView *mResultsView = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QList<QMetaObject::Connection> mCanvasConnections;
QMenu *mMenu = nullptr;

QTimer mFocusTimer;

0 comments on commit f652e8d

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