QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 QgsLocatorResultsView;
33 class QgsMapCanvas;
35 
44 class GUI_EXPORT QgsLocatorWidget : public QWidget
45 {
46  Q_OBJECT
47 
48  public:
49 
53  QgsLocatorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
54 
58  QgsLocator *locator();
59 
65  void setMapCanvas( QgsMapCanvas *canvas );
66 
67  public slots:
68 
72  void search( const QString &string );
73 
78  void invalidateResults();
79 
80  signals:
81 
85  void configTriggered();
86 
87  protected:
88  bool eventFilter( QObject *obj, QEvent *event ) override;
89 
90  private slots:
91  void performSearch();
92  void showList();
93  void triggerSearchAndShowList();
94  void configMenuAboutToShow();
95  void scheduleDelayedPopup();
96  void resultAdded();
97  void showContextMenu( const QPoint &point );
98 
99  private:
100  QgsLocatorModelBridge *mModelBridge = nullptr;
101  QgsFilterLineEdit *mLineEdit = nullptr;
102  QgsFloatingWidget *mResultsContainer = nullptr;
103  QgsLocatorResultsView *mResultsView = nullptr;
104  QgsMapCanvas *mMapCanvas = nullptr;
105  QList<QMetaObject::Connection> mCanvasConnections;
106  QMenu *mMenu = nullptr;
107 
108  QTimer mFocusTimer;
109  QTimer mPopupTimer;
110  bool mHasSelectedResult = false;
111 
112  void acceptCurrentEntry();
113 };
114 
115 #ifndef SIP_RUN
116 
118 
119 class QgsLocatorFilterFilter : public QgsLocatorFilter
120 {
121  Q_OBJECT
122 
123  public:
124 
125  QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
126 
127  QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
128  QgsLocatorFilter::Flags flags() const override;
129 
130  QString name() const override { return QStringLiteral( "filters" );}
131  QString displayName() const override { return QString(); }
132  Priority priority() const override { return static_cast< QgsLocatorFilter::Priority>( -1 ); }
133  void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
134  void triggerResult( const QgsLocatorResult &result ) override;
135 
136  private:
137  QgsLocatorWidget *mLocator = nullptr;
138 };
139 
146 class GUI_EXPORT QgsLocatorResultsView : public QTreeView
147 {
148  Q_OBJECT
149 
150  public:
151 
155  QgsLocatorResultsView( QWidget *parent = nullptr );
156 
160  void recalculateSize();
161 
165  void selectNextResult();
166 
170  void selectPreviousResult();
171 
172 };
173 
175 
176 #endif
177 
178 
179 #endif // QGSLOCATORWIDGET_H
180 
181 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
A QWidget subclass for creating widgets which float outside of the normal Qt layout system...
Priority
Filter priority. Controls the order of results in the locator.
The QgsLocatorModelBridge class provides the core functionality to be used in a locator widget...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:75
Base class for feedback objects to be used for cancellation 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:57
#define SIP_FACTORY
Definition: qgis_sip.h:76
A special locator widget which allows searching for matching results from a QgsLocator and presenting...