QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
113
114 private:
115 QgsLocatorModelBridge *mModelBridge = nullptr;
116 QgsLocatorLineEdit *mLineEdit = nullptr;
117 QgsFloatingWidget *mResultsContainer = nullptr;
118 QgsLocatorResultsView *mResultsView = nullptr;
119 QgsMapCanvas *mMapCanvas = nullptr;
120 QList<QMetaObject::Connection> mCanvasConnections;
121 QMenu *mMenu = nullptr;
122
123 QTimer mFocusTimer;
124 QTimer mPopupTimer;
125 bool mHasSelectedResult = false;
126
127 void acceptCurrentEntry();
128
129};
130
131#ifndef SIP_RUN
132
134
135class QgsLocatorFilterFilter : public QgsLocatorFilter
136{
137 Q_OBJECT
138
139 public:
140
141 QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
142
143 QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
144 QgsLocatorFilter::Flags flags() const override;
145
146 QString name() const override { return QStringLiteral( "filters" );}
147 QString displayName() const override { return QString(); }
148 Priority priority() const override { return static_cast< QgsLocatorFilter::Priority>( -1 ); }
149 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
150 void triggerResult( const QgsLocatorResult &result ) override;
151
152 private:
153 QgsLocatorWidget *mLocator = nullptr;
154};
155
161class GUI_EXPORT QgsLocatorResultsView : public QTreeView
162{
163 Q_OBJECT
164
165 public:
166
170 QgsLocatorResultsView( QWidget *parent = nullptr );
171
175 void recalculateSize();
176
180 void selectNextResult();
181
185 void selectPreviousResult();
186
187};
188
189
196class QgsLocatorLineEdit : public QgsFilterLineEdit
197{
198 Q_OBJECT
199 public:
200 explicit QgsLocatorLineEdit( QgsLocatorWidget *locator, QWidget *parent = nullptr );
201
203 bool performCompletion();
204
205 protected:
206 void paintEvent( QPaintEvent *event ) override;
207
208 private:
209 QgsLocatorWidget *mLocatorWidget = nullptr;
210 QString mCompletionText = nullptr;
211};
212
214
215#endif
216
217
218#endif // QGSLOCATORWIDGET_H
219
220
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.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:76