QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "qgssettingstree.h"
26
27#include <QWidget>
28#include <QTreeView>
29#include <QFocusEvent>
30#include <QHeaderView>
31#include <QTimer>
32
33class QgsLocator;
34class QgsLocatorResultsView;
35class QgsMapCanvas;
37class QgsLocatorLineEdit;
39
47class GUI_EXPORT QgsLocatorWidget : public QWidget
48{
49 Q_OBJECT
50
51 public:
52#ifndef SIP_RUN
53
54 static inline QgsSettingsTreeNode *sTreeGuiLocator = QgsSettingsTree::sTreeGui->createChildNode( QStringLiteral( "locator" ) );
56#endif
57
61 QgsLocatorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
62
66 QgsLocator *locator();
67
73 void setMapCanvas( QgsMapCanvas *canvas );
74
79 void setPlaceholderText( const QString &text );
80
86 void setResultContainerAnchors( QgsFloatingWidget::AnchorPoint anchorPoint, QgsFloatingWidget::AnchorPoint anchorWidgetPoint );
87
88 public slots:
89
93 void search( const QString &string );
94
99 void invalidateResults();
100
101 signals:
102
107
108 protected:
109 bool eventFilter( QObject *obj, QEvent *event ) override;
110
111 private slots:
112 void performSearch();
113 void showList();
114 void triggerSearchAndShowList();
115 void configMenuAboutToShow();
116 void scheduleDelayedPopup();
117 void resultAdded();
118 void showContextMenu( const QPoint &point );
119 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
120
121 private:
122 QgsLocatorModelBridge *mModelBridge = nullptr;
123 QgsLocatorLineEdit *mLineEdit = nullptr;
124 QgsFloatingWidget *mResultsContainer = nullptr;
125 QgsLocatorResultsView *mResultsView = nullptr;
126 QgsMapCanvas *mMapCanvas = nullptr;
127 QList<QMetaObject::Connection> mCanvasConnections;
128 QMenu *mMenu = nullptr;
129
130 QTimer mFocusTimer;
131 QTimer mPopupTimer;
132 bool mHasSelectedResult = false;
133
134 void acceptCurrentEntry();
135};
136
137#ifndef SIP_RUN
138
140
141class QgsLocatorFilterFilter : public QgsLocatorFilter
142{
143 Q_OBJECT
144
145 public:
146 QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
147
148 QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
149 QgsLocatorFilter::Flags flags() const override;
150
151 QString name() const override { return QStringLiteral( "filters" ); }
152 QString displayName() const override { return QString(); }
153 Priority priority() const override { return static_cast<QgsLocatorFilter::Priority>( -1 ); }
154 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
155 void triggerResult( const QgsLocatorResult &result ) override;
156
157 private:
158 QgsLocatorWidget *mLocator = nullptr;
159};
160
166class GUI_EXPORT QgsLocatorResultsView : public QTreeView
167{
168 Q_OBJECT
169
170 public:
174 QgsLocatorResultsView( QWidget *parent = nullptr );
175
179 void recalculateSize();
180
184 void selectNextResult();
185
189 void selectPreviousResult();
190};
191
192
199class QgsLocatorLineEdit : public QgsFilterLineEdit
200{
201 Q_OBJECT
202 public:
203 explicit QgsLocatorLineEdit( QgsLocatorWidget *locator, QWidget *parent = nullptr );
204
206 bool performCompletion();
207
208 protected:
209 void paintEvent( QPaintEvent *event ) override;
210
211 private:
212 QgsLocatorWidget *mLocatorWidget = nullptr;
213 QString mCompletionText = nullptr;
214};
215
217
218#endif
219
220
221#endif // QGSLOCATORWIDGET_H
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...
static const QgsSettingsEntryInteger * settingLocatorTreeHeight
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.
An integer settings entry.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
static QgsSettingsTreeNode * sTreeGui
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:76