QGIS API Documentation  3.0.2-Girona (307d082)
qgslocatorwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslocatorwidget.h
3  ------------------
4  begin : May 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 QGSLOCATORWIDGET_H
19 #define QGSLOCATORWIDGET_H
20 
21 #include "qgis_gui.h"
22 #include "qgslocatorfilter.h"
23 #include "qgsfloatingwidget.h"
24 #include <QWidget>
25 #include <QTreeView>
26 #include <QFocusEvent>
27 #include <QHeaderView>
28 #include <QTimer>
29 
30 class QgsLocator;
31 class QgsFilterLineEdit;
32 class QgsLocatorModel;
33 class QgsLocatorResultsView;
34 class QgsMapCanvas;
36 
45 class GUI_EXPORT QgsLocatorWidget : public QWidget
46 {
47  Q_OBJECT
48 
49  public:
50 
54  QgsLocatorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
55 
59  QgsLocator *locator();
60 
66  void setMapCanvas( QgsMapCanvas *canvas );
67 
68  public slots:
69 
73  void search( const QString &string );
74 
79  void invalidateResults();
80 
81  signals:
82 
86  void configTriggered();
87 
88  protected:
89 
90  bool eventFilter( QObject *obj, QEvent *event ) override;
91 
92  private slots:
93 
94  void scheduleDelayedPopup();
95  void performSearch();
96  void showList();
97  void triggerSearchAndShowList();
98  void searchFinished();
99  void addResult( const QgsLocatorResult &result );
100  void configMenuAboutToShow();
101 
102  private:
103 
104  QgsLocator *mLocator = nullptr;
105  QgsFilterLineEdit *mLineEdit = nullptr;
106  QgsLocatorModel *mLocatorModel = nullptr;
107  QgsLocatorProxyModel *mProxyModel = nullptr;
108  QgsFloatingWidget *mResultsContainer = nullptr;
109  QgsLocatorResultsView *mResultsView = nullptr;
110  QgsMapCanvas *mMapCanvas = nullptr;
111  QMenu *mMenu = nullptr;
112 
113  QString mNextRequestedString;
114  bool mHasQueuedRequest = false;
115  bool mHasSelectedResult = false;
116  QTimer mPopupTimer;
117  QTimer mFocusTimer;
118 
119  void updateResults( const QString &text );
120  void acceptCurrentEntry();
121  QgsLocatorContext createContext();
122 
123 };
124 
125 #ifndef SIP_RUN
126 
128 
129 class QgsLocatorFilterFilter : public QgsLocatorFilter
130 {
131  Q_OBJECT
132 
133  public:
134 
135  QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
136 
137  QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
138  QgsLocatorFilter::Flags flags() const override;
139 
140  QString name() const override { return QStringLiteral( "filters" );}
141  QString displayName() const override { return QString(); }
142  Priority priority() const override { return static_cast< QgsLocatorFilter::Priority>( -1 ); }
143  void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
144  void triggerResult( const QgsLocatorResult &result ) override;
145 
146  private:
147 
148  QgsLocatorWidget *mLocator = nullptr;
149 };
150 
157 class QgsLocatorResultsView : public QTreeView
158 {
159  Q_OBJECT
160 
161  public:
162 
166  QgsLocatorResultsView( QWidget *parent = nullptr );
167 
171  void recalculateSize();
172 
176  void selectNextResult();
177 
181  void selectPreviousResult();
182 
183 };
184 
186 
187 #endif
188 
189 
190 #endif // QGSLOCATORWIDGET_H
191 
192 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A QWidget subclass for creating widgets which float outside of the normal Qt layout system...
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
Priority
Filter priority. Controls the order of results in the locator.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
QLineEdit subclass with built in support for clearing the widget&#39;s value and handling custom null val...
Encapsulates the properties relating to the context of a locator search.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Abstract base class for filters which collect locator results.
Handles the management of QgsLocatorFilter objects and async collection of search results from them...
Definition: qgslocator.h:54
#define SIP_FACTORY
Definition: qgis_sip.h:69
An abstract list model for displaying the results of locator searches.
A special locator widget which allows searching for matching results from a QgsLocator and presenting...