QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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"
25 #include "qgsrectangle.h"
26 
27 class QAction;
28 
29 class QgsLocatorResult;
30 class QgsLocator;
31 class QgsLocatorContext;
32 class QgsLocatorModel;
34 
35 
42 class CORE_EXPORT QgsLocatorModelBridge : public QObject
43 {
44  Q_OBJECT
45  Q_PROPERTY( bool isRunning READ isRunning NOTIFY isRunningChanged )
46  public:
48  explicit QgsLocatorModelBridge( QObject *parent = nullptr );
49  virtual ~QgsLocatorModelBridge() = default;
50 
52  Q_INVOKABLE void performSearch( const QString &text );
53 
55  QgsLocator *locator() const;
56 
58  Q_INVOKABLE QgsLocatorProxyModel *proxyModel() const;
59 
61  bool hasQueueRequested() const;
62 
64  bool isRunning() const;
65 
67  void triggerResult( const QModelIndex &index, const int actionId = -1 );
68 
69  signals:
71  void resultAdded();
72 
74  void isRunningChanged();
75 
77  void resultsCleared();
78 
79  public slots:
81  void invalidateResults();
82 
84  void updateCanvasExtent( const QgsRectangle &extent );
85 
87  void updateCanvasCrs( const QgsCoordinateReferenceSystem &crs );
88 
89  private slots:
90  void searchFinished();
91  void addResult( const QgsLocatorResult &result );
92 
93  private:
94  QgsLocatorContext createContext();
95  void setIsRunning( bool isRunning );
96 
97  QgsLocator *mLocator = nullptr;
98  QgsLocatorModel *mLocatorModel = nullptr;
99  QgsLocatorProxyModel *mProxyModel = nullptr;
100 
101  QString mNextRequestedString;
102  bool mHasQueuedRequest = false;
103  bool mIsRunning = false;
104 
105  // keep track of map canvas extent and CRS
106  // if much if needed, it would be possible to add
107  // a QgsMapCanvasController in core to achieve this
108  // see discussion in https://github.com/qgis/QGIS/pull/8404
109  QgsRectangle mCanvasExtent;
110  QgsCoordinateReferenceSystem mCanvasCrs;
111 };
112 
113 #endif // QGSLOCATORMODELBRIDGE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
The QgsLocatorModelBridge class provides the core functionality to be used in a locator widget...
const QgsCoordinateReferenceSystem & crs
Encapsulates the properties relating to the context of a locator search.
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:57
An abstract list model for displaying the results of locator searches.
This class represents a coordinate reference system (CRS).