QGIS API Documentation 3.99.0-Master (357b655ed83)
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 "qgsfilterlineedit.h"
23#include "qgsfloatingwidget.h"
24#include "qgslocatorfilter.h"
25#include "qgssettingstree.h"
26
27#include <QFocusEvent>
28#include <QHeaderView>
29#include <QString>
30#include <QTimer>
31#include <QTreeView>
32#include <QWidget>
33
34using namespace Qt::StringLiterals;
35
36class QgsLocator;
37class QgsLocatorResultsView;
38class QgsMapCanvas;
40class QgsLocatorLineEdit;
42
50class GUI_EXPORT QgsLocatorWidget : public QWidget
51{
52 Q_OBJECT
53
54 public:
55#ifndef SIP_RUN
56
57 static inline QgsSettingsTreeNode *sTreeGuiLocator = QgsSettingsTree::sTreeGui->createChildNode( u"locator"_s );
59#endif
60
64 QgsLocatorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
65
70
76 void setMapCanvas( QgsMapCanvas *canvas );
77
82 void setPlaceholderText( const QString &text );
83
90
91 public slots:
92
96 void search( const QString &string );
97
102 void invalidateResults();
103
104 signals:
105
110
111 protected:
112 bool eventFilter( QObject *obj, QEvent *event ) override;
113
114 private slots:
115 void performSearch();
116 void showList();
117 void triggerSearchAndShowList();
118 void configMenuAboutToShow();
119 void scheduleDelayedPopup();
120 void resultAdded();
121 void showContextMenu( const QPoint &point );
122 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
123
124 private:
125 QgsLocatorModelBridge *mModelBridge = nullptr;
126 QgsLocatorLineEdit *mLineEdit = nullptr;
127 QgsFloatingWidget *mResultsContainer = nullptr;
128 QgsLocatorResultsView *mResultsView = nullptr;
129 QgsMapCanvas *mMapCanvas = nullptr;
130 QList<QMetaObject::Connection> mCanvasConnections;
131 QMenu *mMenu = nullptr;
132
133 QTimer mFocusTimer;
134 QTimer mPopupTimer;
135 bool mHasSelectedResult = false;
136
137 void acceptCurrentEntry();
138};
139
140#ifndef SIP_RUN
141
143
144class QgsLocatorFilterFilter : public QgsLocatorFilter
145{
146 Q_OBJECT
147
148 public:
149 QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
150
151 QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
152 QgsLocatorFilter::Flags flags() const override;
153
154 QString name() const override { return u"filters"_s; }
155 QString displayName() const override { return QString(); }
156 Priority priority() const override { return static_cast<QgsLocatorFilter::Priority>( -1 ); }
157 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
158 void triggerResult( const QgsLocatorResult &result ) override;
159
160 private:
161 QgsLocatorWidget *mLocator = nullptr;
162};
163
169class GUI_EXPORT QgsLocatorResultsView : public QTreeView
170{
171 Q_OBJECT
172
173 public:
177 QgsLocatorResultsView( QWidget *parent = nullptr );
178
182 void recalculateSize();
183
187 void selectNextResult();
188
192 void selectPreviousResult();
193};
194
195
202class QgsLocatorLineEdit : public QgsFilterLineEdit
203{
204 Q_OBJECT
205 public:
206 explicit QgsLocatorLineEdit( QgsLocatorWidget *locator, QWidget *parent = nullptr );
207
209 bool performCompletion();
210
211 protected:
212 void paintEvent( QPaintEvent *event ) override;
213
214 private:
215 QgsLocatorWidget *mLocatorWidget = nullptr;
216 QString mCompletionText = nullptr;
217};
218
220
221#endif
222
223
224#endif // QGSLOCATORWIDGET_H
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.
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.
Provides the core functionality to be used in a locator widget.
A special locator widget which allows searching for matching results from a QgsLocator and presenting...
static const QgsSettingsEntryInteger * settingLocatorTreeHeight
void setResultContainerAnchors(QgsFloatingWidget::AnchorPoint anchorPoint, QgsFloatingWidget::AnchorPoint anchorWidgetPoint)
Sets the result container anchorPoint and anchorWidgetPoint position.
static QgsSettingsTreeNode * sTreeGuiLocator
void configTriggered()
Emitted when the configure option is triggered in the widget.
void setPlaceholderText(const QString &text)
Set placeholder text for the line edit.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the widget.
void search(const QString &string)
Triggers the locator widget to focus, open and start searching for a specified string.
QgsLocatorWidget(QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor for QgsLocatorWidget.
bool eventFilter(QObject *obj, QEvent *event) override
void invalidateResults()
Invalidates the current search results, e.g.
QgsLocator * locator()
Returns a pointer to the locator utilized by this widget.
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition qgslocator.h:65
Map canvas is a class for displaying all GIS data types on a canvas.
An integer settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
static QgsSettingsTreeNode * sTreeGui
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:84