QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 QAction;
29 
30 class QgsLocatorResult;
31 class QgsLocator;
32 class QgsLocatorContext;
33 class QgsLocatorModel;
35 
36 
43 class CORE_EXPORT QgsLocatorModelBridge : public QObject
44 {
45  Q_OBJECT
46  Q_PROPERTY( bool isRunning READ isRunning NOTIFY isRunningChanged )
47  public:
49  explicit QgsLocatorModelBridge( QObject *parent = nullptr );
50  virtual ~QgsLocatorModelBridge() = default;
51 
53  Q_INVOKABLE void performSearch( const QString &text );
54 
56  QgsLocator *locator() const;
57 
59  Q_INVOKABLE QgsLocatorProxyModel *proxyModel() const;
60 
62  bool hasQueueRequested() const;
63 
65  bool isRunning() const;
66 
68  void triggerResult( const QModelIndex &index, const int actionId = -1 );
69 
77  QgsCoordinateTransformContext transformContext() const { return mTransformContext; }
78 
86  void setTransformContext( const QgsCoordinateTransformContext &context ) { mTransformContext = context; }
87 
88  signals:
90  void resultAdded();
91 
94 
97 
98  public slots:
100  void invalidateResults();
101 
103  void updateCanvasExtent( const QgsRectangle &extent );
104 
106  void updateCanvasCrs( const QgsCoordinateReferenceSystem &crs );
107 
108  private slots:
109  void searchFinished();
110  void addResult( const QgsLocatorResult &result );
111 
112  private:
113  QgsLocatorContext createContext();
114  void setIsRunning( bool isRunning );
115 
116  QgsLocator *mLocator = nullptr;
117  QgsLocatorModel *mLocatorModel = nullptr;
118  QgsLocatorProxyModel *mProxyModel = nullptr;
119 
120  QString mNextRequestedString;
121  bool mHasQueuedRequest = false;
122  bool mIsRunning = false;
123 
124  // keep track of map canvas extent and CRS
125  // if much if needed, it would be possible to add
126  // a QgsMapCanvasController in core to achieve this
127  // see discussion in https://github.com/qgis/QGIS/pull/8404
128  QgsRectangle mCanvasExtent;
129  QgsCoordinateReferenceSystem mCanvasCrs;
130  QgsCoordinateTransformContext mTransformContext;
131 };
132 
133 #endif // QGSLOCATORMODELBRIDGE_H
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Encapsulates the properties relating to the context of a locator search.
The QgsLocatorModelBridge class provides the core functionality to be used in a locator widget.
void isRunningChanged()
Emitted when the running status changes.
void resultAdded()
Emitted when a result is added.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which should be used whenever the locator constructs a coordin...
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which should be used whenever the locator constructs a coor...
void resultsCleared()
Emitted when the results are cleared.
virtual ~QgsLocatorModelBridge()=default
An abstract list model for displaying the results of locator searches.
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition: qgslocator.h:58
A rectangle specified with double values.
Definition: qgsrectangle.h:42
const QgsCoordinateReferenceSystem & crs