QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
46class GUI_EXPORT QgsLocatorWidget : public QWidget
47{
48 Q_OBJECT
49
50 public:
51
55 QgsLocatorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
56
60 QgsLocator *locator();
61
67 void setMapCanvas( QgsMapCanvas *canvas );
68
69 public slots:
70
74 void search( const QString &string );
75
80 void invalidateResults();
81
82 signals:
83
88
89 protected:
90 bool eventFilter( QObject *obj, QEvent *event ) override;
91
92 private slots:
93 void performSearch();
94 void showList();
95 void triggerSearchAndShowList();
96 void configMenuAboutToShow();
97 void scheduleDelayedPopup();
98 void resultAdded();
99 void showContextMenu( const QPoint &point );
100
101 private:
102 QgsLocatorModelBridge *mModelBridge = nullptr;
103 QgsLocatorLineEdit *mLineEdit = nullptr;
104 QgsFloatingWidget *mResultsContainer = nullptr;
105 QgsLocatorResultsView *mResultsView = nullptr;
106 QgsMapCanvas *mMapCanvas = nullptr;
107 QList<QMetaObject::Connection> mCanvasConnections;
108 QMenu *mMenu = nullptr;
109
110 QTimer mFocusTimer;
111 QTimer mPopupTimer;
112 bool mHasSelectedResult = false;
113
114 void acceptCurrentEntry();
115
116};
117
118#ifndef SIP_RUN
119
121
122class QgsLocatorFilterFilter : public QgsLocatorFilter
123{
124 Q_OBJECT
125
126 public:
127
128 QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
129
130 QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
131 QgsLocatorFilter::Flags flags() const override;
132
133 QString name() const override { return QStringLiteral( "filters" );}
134 QString displayName() const override { return QString(); }
135 Priority priority() const override { return static_cast< QgsLocatorFilter::Priority>( -1 ); }
136 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
137 void triggerResult( const QgsLocatorResult &result ) override;
138
139 private:
140 QgsLocatorWidget *mLocator = nullptr;
141};
142
149class GUI_EXPORT QgsLocatorResultsView : public QTreeView
150{
151 Q_OBJECT
152
153 public:
154
158 QgsLocatorResultsView( QWidget *parent = nullptr );
159
163 void recalculateSize();
164
168 void selectNextResult();
169
173 void selectPreviousResult();
174
175};
176
177
184class QgsLocatorLineEdit : public QgsFilterLineEdit
185{
186 Q_OBJECT
187 public:
188 explicit QgsLocatorLineEdit( QgsLocatorWidget *locator, QWidget *parent = nullptr );
189
191 bool performCompletion();
192
193 protected:
194 void paintEvent( QPaintEvent *event ) override;
195
196 private:
197 QgsLocatorWidget *mLocatorWidget = nullptr;
198 QString mCompletionText = nullptr;
199};
200
202
203#endif
204
205
206#endif // QGSLOCATORWIDGET_H
207
208
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
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.
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:59
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76