QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgslocatormodelbridge.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslocatormodelbridge.h
3  ------------------
4  begin : November 2018
5  copyright : (C) 2018 by Denis Rouzaud
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSLOCATORMODELBRIDGE_H
19 #define QGSLOCATORMODELBRIDGE_H
20 
21 #include <QObject>
22 
23 #include "qgis_core.h"
26 #include "qgsrectangle.h"
27 
28 class QgsLocatorResult;
29 class QgsLocator;
30 class QgsLocatorContext;
31 class QgsLocatorModel;
33 
34 
41 class CORE_EXPORT QgsLocatorModelBridge : public QObject
42 {
43  Q_OBJECT
44  Q_PROPERTY( bool isRunning READ isRunning NOTIFY isRunningChanged )
45  public:
47  explicit QgsLocatorModelBridge( QObject *parent = nullptr );
48  virtual ~QgsLocatorModelBridge() = default;
49 
51  Q_INVOKABLE void performSearch( const QString &text );
52 
54  QgsLocator *locator() const;
55 
57  Q_INVOKABLE QgsLocatorProxyModel *proxyModel() const;
58 
60  bool hasQueueRequested() const;
61 
63  bool isRunning() const;
64 
66  void triggerResult( const QModelIndex &index, const int actionId = -1 );
67 
75  QgsCoordinateTransformContext transformContext() const { return mTransformContext; }
76 
84  void setTransformContext( const QgsCoordinateTransformContext &context ) { mTransformContext = context; }
85 
86  signals:
88  void resultAdded();
89 
91  void isRunningChanged();
92 
94  void resultsCleared();
95 
96  public slots:
98  void invalidateResults();
99 
101  void updateCanvasExtent( const QgsRectangle &extent );
102 
104  void updateCanvasCrs( const QgsCoordinateReferenceSystem &crs );
105 
106  private slots:
107  void searchFinished();
108  void addResult( const QgsLocatorResult &result );
109 
110  private:
111  QgsLocatorContext createContext();
112  void setIsRunning( bool isRunning );
113 
114  QgsLocator *mLocator = nullptr;
115  QgsLocatorModel *mLocatorModel = nullptr;
116  QgsLocatorProxyModel *mProxyModel = nullptr;
117 
118  QString mNextRequestedString;
119  bool mHasQueuedRequest = false;
120  bool mIsRunning = false;
121 
122  // keep track of map canvas extent and CRS
123  // if much if needed, it would be possible to add
124  // a QgsMapCanvasController in core to achieve this
125  // see discussion in https://github.com/qgis/QGIS/pull/8404
126  QgsRectangle mCanvasExtent;
127  QgsCoordinateReferenceSystem mCanvasCrs;
128  QgsCoordinateTransformContext mTransformContext;
129 };
130 
131 #endif // QGSLOCATORMODELBRIDGE_H
QgsLocator
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition: qgslocator.h:58
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
qgsrectangle.h
qgscoordinatetransformcontext.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsLocatorResult
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Definition: qgslocatorfilter.h:38
QgsLocatorModel
An abstract list model for displaying the results of locator searches.
Definition: qgslocatormodel.h:42
QgsLocatorContext
Encapsulates the properties relating to the context of a locator search.
Definition: qgslocatorcontext.h:32
QgsLocatorModelBridge
The QgsLocatorModelBridge class provides the core functionality to be used in a locator widget.
Definition: qgslocatormodelbridge.h:41
QgsLocatorModelBridge::setTransformContext
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which should be used whenever the locator constructs a coordin...
Definition: qgslocatormodelbridge.h:84
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsLocatorProxyModel
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
Definition: qgslocatormodel.h:191
QgsLocatorModelBridge::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which should be used whenever the locator constructs a coor...
Definition: qgslocatormodelbridge.h:75
qgscoordinatereferencesystem.h