Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move part of the logic of QgsLocatorWidget to core
- Loading branch information
Showing
8 changed files
with
366 additions
and
107 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
python/core/auto_generated/locator/qgslocatorwidgetcore.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/locator/qgslocatorwidgetcore.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
class QgsLocatorWidgetCore : QObject | ||
{ | ||
%Docstring | ||
The QgsLocatorWidgetCore class provides the core functionality | ||
to be used in a locator widget. | ||
|
||
.. versionadded:: 3.6 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslocatorwidgetcore.h" | ||
%End | ||
public: | ||
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 ); | ||
%Docstring | ||
Perform a search | ||
%End | ||
|
||
QgsLocator *locator() const; | ||
%Docstring | ||
Returns the locator | ||
%End | ||
|
||
QgsLocatorProxyModel *proxyModel() const; | ||
%Docstring | ||
Returns the proxy model | ||
%End | ||
|
||
bool hasQueueRequested() const; | ||
%Docstring | ||
Returns true if some text to be search is pending in the queue | ||
%End | ||
|
||
bool isRunning() const; | ||
%Docstring | ||
Returns true if the a search is currently running | ||
%End | ||
|
||
signals: | ||
void resultAdded(); | ||
%Docstring | ||
Emitted when a result is added | ||
%End | ||
|
||
void isRunningChanged(); | ||
%Docstring | ||
Emitted when the running status changes | ||
%End | ||
|
||
void resultsCleared(); | ||
%Docstring | ||
Emitted when the results are cleared | ||
%End | ||
|
||
public slots: | ||
void invalidateResults(); | ||
%Docstring | ||
This will invalidate current search results | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/locator/qgslocatorwidgetcore.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/*************************************************************************** | ||
qgslocatorwidgetcore.cpp | ||
------------------ | ||
begin : November 2018 | ||
copyright : (C) 2018 by Denis Rouzaud | ||
email : denis@opengis.ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslocatorwidgetcore.h" | ||
#include "qgslocator.h" | ||
#include "qgslocatormodel.h" | ||
#include "qgsmapcanvasinterface.h" | ||
#include "qgsmapsettings.h" | ||
|
||
QgsLocatorWidgetCore::QgsLocatorWidgetCore( QObject *parent ) | ||
: QObject( parent ) | ||
, mLocator( new QgsLocator( this ) ) | ||
, mLocatorModel( new QgsLocatorModel( this ) ) | ||
{ | ||
mProxyModel = new QgsLocatorProxyModel( mLocatorModel ); | ||
mProxyModel->setSourceModel( mLocatorModel ); | ||
|
||
connect( mLocator, &QgsLocator::foundResult, this, &QgsLocatorWidgetCore::addResult ); | ||
connect( mLocator, &QgsLocator::finished, this, &QgsLocatorWidgetCore::searchFinished ); | ||
} | ||
|
||
void QgsLocatorWidgetCore::setMapCanvasInterface( QgsMapCanvasInterface *canvasInterface ) | ||
{ | ||
mCanvasInterface = canvasInterface; | ||
} | ||
|
||
bool QgsLocatorWidgetCore::isRunning() const | ||
{ | ||
return mIsRunning; | ||
} | ||
|
||
void QgsLocatorWidgetCore::setIsRunning( bool isRunning ) | ||
{ | ||
if ( mIsRunning == isRunning ) | ||
return; | ||
|
||
mIsRunning = isRunning; | ||
emit isRunningChanged(); | ||
} | ||
|
||
void QgsLocatorWidgetCore::invalidateResults() | ||
{ | ||
mLocator->cancelWithoutBlocking(); | ||
mLocatorModel->clear(); | ||
} | ||
|
||
void QgsLocatorWidgetCore::addResult( const QgsLocatorResult &result ) | ||
{ | ||
mLocatorModel->addResult( result ); | ||
emit resultAdded(); | ||
} | ||
|
||
|
||
void QgsLocatorWidgetCore::searchFinished() | ||
{ | ||
if ( mHasQueuedRequest ) | ||
{ | ||
// a queued request was waiting for this - run the queued search now | ||
QString nextSearch = mNextRequestedString; | ||
mNextRequestedString.clear(); | ||
mHasQueuedRequest = false; | ||
performSearch( nextSearch ); | ||
} | ||
else | ||
{ | ||
if ( !mLocator->isRunning() ) | ||
setIsRunning( false ); | ||
} | ||
} | ||
|
||
void QgsLocatorWidgetCore::performSearch( const QString &text ) | ||
{ | ||
setIsRunning( true ); | ||
if ( mLocator->isRunning() ) | ||
{ | ||
// can't do anything while a query is running, and can't block | ||
// here waiting for the current query to cancel | ||
// so we queue up this string until cancel has happened | ||
mLocator->cancelWithoutBlocking(); | ||
mNextRequestedString = text; | ||
mHasQueuedRequest = true; | ||
return; | ||
} | ||
else | ||
{ | ||
emit resultsCleared(); | ||
mLocatorModel->deferredClear(); | ||
mLocator->fetchResults( text, createContext() ); | ||
} | ||
} | ||
|
||
QgsLocator *QgsLocatorWidgetCore::locator() const | ||
{ | ||
return mLocator; | ||
} | ||
|
||
QgsLocatorProxyModel *QgsLocatorWidgetCore::proxyModel() const | ||
{ | ||
return mProxyModel; | ||
} | ||
|
||
bool QgsLocatorWidgetCore::hasQueueRequested() const | ||
{ | ||
return mHasQueuedRequest; | ||
} | ||
|
||
QgsLocatorContext QgsLocatorWidgetCore::createContext() | ||
{ | ||
QgsLocatorContext context; | ||
if ( mCanvasInterface ) | ||
{ | ||
context.targetExtent = mCanvasInterface->mapSettings().visibleExtent(); | ||
context.targetExtentCrs = mCanvasInterface->mapSettings().destinationCrs(); | ||
} | ||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*************************************************************************** | ||
qgslocatorwidgetcore.h | ||
------------------ | ||
begin : November 2018 | ||
copyright : (C) 2018 by Denis Rouzaud | ||
email : denis@opengis.ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLOCATORWIDGETCORE_H | ||
#define QGSLOCATORWIDGETCORE_H | ||
|
||
#include <QObject> | ||
|
||
#include "qgis_core.h" | ||
|
||
class QgsLocatorResult; | ||
class QgsLocator; | ||
class QgsLocatorContext; | ||
class QgsLocatorModel; | ||
class QgsLocatorProxyModel; | ||
class QgsMapCanvasInterface; | ||
|
||
|
||
/** | ||
* \ingroup core | ||
* The QgsLocatorWidgetCore class provides the core functionality | ||
* to be used in a locator widget. | ||
* \since QGIS 3.6 | ||
*/ | ||
class CORE_EXPORT QgsLocatorWidgetCore : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY( bool isRunning READ isRunning NOTIFY isRunningChanged ) | ||
public: | ||
//! 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 ); | ||
|
||
//! Returns the locator | ||
QgsLocator *locator() const; | ||
|
||
//! Returns the proxy model | ||
QgsLocatorProxyModel *proxyModel() const; | ||
|
||
//! Returns true if some text to be search is pending in the queue | ||
bool hasQueueRequested() const; | ||
|
||
//! Returns true if the a search is currently running | ||
bool isRunning() const; | ||
|
||
signals: | ||
//! Emitted when a result is added | ||
void resultAdded(); | ||
|
||
//! Emitted when the running status changes | ||
void isRunningChanged(); | ||
|
||
//! Emitted when the results are cleared | ||
void resultsCleared(); | ||
|
||
public slots: | ||
//! This will invalidate current search results | ||
void invalidateResults(); | ||
|
||
private slots: | ||
void searchFinished(); | ||
void addResult( const QgsLocatorResult &result ); | ||
|
||
private: | ||
QgsLocatorContext createContext(); | ||
void setIsRunning( bool isRunning ); | ||
|
||
QgsLocator *mLocator = nullptr; | ||
QgsLocatorModel *mLocatorModel = nullptr; | ||
QgsLocatorProxyModel *mProxyModel = nullptr; | ||
QgsMapCanvasInterface *mCanvasInterface = nullptr; | ||
|
||
QString mNextRequestedString; | ||
bool mHasQueuedRequest = false; | ||
bool mIsRunning = false; | ||
}; | ||
|
||
#endif // QGSLOCATORWIDGETCORE_H |
Oops, something went wrong.