QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 "qgsfilterlineedit.h"
25
26#include <QWidget>
27#include <QTreeView>
28#include <QFocusEvent>
29#include <QHeaderView>
30#include <QTimer>
31
32class QgsLocator;
33class QgsLocatorResultsView;
34class QgsMapCanvas;
36class QgsLocatorLineEdit;
37
45class 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
72 void setPlaceholderText( const QString &text );
73
79 void setResultContainerAnchors( QgsFloatingWidget::AnchorPoint anchorPoint, QgsFloatingWidget::AnchorPoint anchorWidgetPoint );
80
81 public slots:
82
86 void search( const QString &string );
87
92 void invalidateResults();
93
94 signals:
95
100
101 protected:
102 bool eventFilter( QObject *obj, QEvent *event ) override;
103
104 private slots:
105 void performSearch();
106 void showList();
107 void triggerSearchAndShowList();
108 void configMenuAboutToShow();
109 void scheduleDelayedPopup();
110 void resultAdded();
111 void showContextMenu( const QPoint &point );
112
113 private:
114 QgsLocatorModelBridge *mModelBridge = nullptr;
115 QgsLocatorLineEdit *mLineEdit = nullptr;
116 QgsFloatingWidget *mResultsContainer = nullptr;
117 QgsLocatorResultsView *mResultsView = nullptr;
118 QgsMapCanvas *mMapCanvas = nullptr;
119 QList<QMetaObject::Connection> mCanvasConnections;
120 QMenu *mMenu = nullptr;
121
122 QTimer mFocusTimer;
123 QTimer mPopupTimer;
124 bool mHasSelectedResult = false;
125
126 void acceptCurrentEntry();
127
128};
129
130#ifndef SIP_RUN
131
133
134class QgsLocatorFilterFilter : public QgsLocatorFilter
135{
136 Q_OBJECT
137
138 public:
139
140 QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
141
142 QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
143 QgsLocatorFilter::Flags flags() const override;
144
145 QString name() const override { return QStringLiteral( "filters" );}
146 QString displayName() const override { return QString(); }
147 Priority priority() const override { return static_cast< QgsLocatorFilter::Priority>( -1 ); }
148 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
149 void triggerResult( const QgsLocatorResult &result ) override;
150
151 private:
152 QgsLocatorWidget *mLocator = nullptr;
153};
154
160class GUI_EXPORT QgsLocatorResultsView : public QTreeView
161{
162 Q_OBJECT
163
164 public:
165
169 QgsLocatorResultsView( QWidget *parent = nullptr );
170
174 void recalculateSize();
175
179 void selectNextResult();
180
184 void selectPreviousResult();
185
186};
187
188
195class QgsLocatorLineEdit : public QgsFilterLineEdit
196{
197 Q_OBJECT
198 public:
199 explicit QgsLocatorLineEdit( QgsLocatorWidget *locator, QWidget *parent = nullptr );
200
202 bool performCompletion();
203
204 protected:
205 void paintEvent( QPaintEvent *event ) override;
206
207 private:
208 QgsLocatorWidget *mLocatorWidget = nullptr;
209 QString mCompletionText = nullptr;
210};
211
213
214#endif
215
216
217#endif // QGSLOCATORWIDGET_H
218
219
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's value and handling custom null val...
A QWidget subclass for creating widgets which float outside of the normal Qt layout system.
AnchorPoint
Reference points for anchoring widget position.
Encapsulates the properties relating to the context of a locator search.
Abstract base class for filters which collect locator results.
Priority
Filter priority. Controls the order of results in the locator.
virtual QString displayName() const =0
Returns a translated, user-friendly name for the filter.
virtual Priority priority() const
Returns the priority for the filter, which controls how results are ordered in the locator.
virtual void triggerResult(const QgsLocatorResult &result)=0
Triggers a filter result from this filter.
virtual QgsLocatorFilter * clone() const =0
Creates a clone of the filter.
virtual void fetchResults(const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback)=0
Retrieves the filter results for a specified search string.
The QgsLocatorModelBridge class provides the core functionality to be used in a locator widget.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
A special locator widget which allows searching for matching results from a QgsLocator and presenting...
void configTriggered()
Emitted when the configure option is triggered in the widget.
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition: qgslocator.h:61
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:93
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76