QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 <QWidget>
25 #include <QTreeView>
26 #include <QFocusEvent>
27 #include <QHeaderView>
28 #include <QTimer>
29 
30 class QgsLocator;
31 class QgsFilterLineEdit;
32 class QgsLocatorResultsView;
33 class QgsMapCanvas;
35 
44 class GUI_EXPORT QgsLocatorWidget : public QWidget
45 {
46  Q_OBJECT
47 
48  public:
49 
53  QgsLocatorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
54 
58  QgsLocator *locator();
59 
65  void setMapCanvas( QgsMapCanvas *canvas );
66 
67  public slots:
68 
72  void search( const QString &string );
73 
78  void invalidateResults();
79 
80  signals:
81 
85  void configTriggered();
86 
87  protected:
88  bool eventFilter( QObject *obj, QEvent *event ) override;
89 
90  private slots:
91  void performSearch();
92  void showList();
93  void triggerSearchAndShowList();
94  void configMenuAboutToShow();
95  void scheduleDelayedPopup();
96  void resultAdded();
97  void showContextMenu( const QPoint &point );
98 
99  private:
100  QgsLocatorModelBridge *mModelBridge = nullptr;
101  QgsFilterLineEdit *mLineEdit = nullptr;
102  QgsFloatingWidget *mResultsContainer = nullptr;
103  QgsLocatorResultsView *mResultsView = nullptr;
104  QgsMapCanvas *mMapCanvas = nullptr;
105  QList<QMetaObject::Connection> mCanvasConnections;
106  QMenu *mMenu = nullptr;
107 
108  QTimer mFocusTimer;
109  QTimer mPopupTimer;
110  bool mHasSelectedResult = false;
111 
112  void acceptCurrentEntry();
113 };
114 
115 #ifndef SIP_RUN
116 
118 
119 class QgsLocatorFilterFilter : public QgsLocatorFilter
120 {
121  Q_OBJECT
122 
123  public:
124 
125  QgsLocatorFilterFilter( QgsLocatorWidget *widget, QObject *parent = nullptr );
126 
127  QgsLocatorFilterFilter *clone() const override SIP_FACTORY;
128  QgsLocatorFilter::Flags flags() const override;
129 
130  QString name() const override { return QStringLiteral( "filters" );}
131  QString displayName() const override { return QString(); }
132  Priority priority() const override { return static_cast< QgsLocatorFilter::Priority>( -1 ); }
133  void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
134  void triggerResult( const QgsLocatorResult &result ) override;
135 
136  private:
137  QgsLocatorWidget *mLocator = nullptr;
138 };
139 
146 class GUI_EXPORT QgsLocatorResultsView : public QTreeView
147 {
148  Q_OBJECT
149 
150  public:
151 
155  QgsLocatorResultsView( QWidget *parent = nullptr );
156 
160  void recalculateSize();
161 
165  void selectNextResult();
166 
170  void selectPreviousResult();
171 
172 };
173 
175 
176 #endif
177 
178 
179 #endif // QGSLOCATORWIDGET_H
180 
181 
QgsLocatorFilter
Definition: qgslocatorfilter.h:145
QgsLocator
Definition: qgslocator.h:57
QgsLocatorFilter::clone
virtual QgsLocatorFilter * clone() const =0
Creates a clone of the filter.
QgsLocatorFilter::priority
virtual Priority priority() const
Returns the priority for the filter, which controls how results are ordered in the locator.
Definition: qgslocatorfilter.h:202
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsFilterLineEdit
Definition: qgsfilterlineedit.h:39
QgsLocatorWidget
Definition: qgslocatorwidget.h:44
QgsLocatorResult
Definition: qgslocatorfilter.h:39
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgsfloatingwidget.h
QgsLocatorContext
Definition: qgslocatorcontext.h:31
QgsLocatorModelBridge
Definition: qgslocatormodelbridge.h:42
QgsFeedback
Definition: qgsfeedback.h:43
QgsLocatorFilter::displayName
virtual QString displayName() const =0
Returns a translated, user-friendly name for the filter.
QgsFloatingWidget
Definition: qgsfloatingwidget.h:33
QgsLocatorFilter::Priority
Priority
Filter priority. Controls the order of results in the locator.
Definition: qgslocatorfilter.h:152
QgsLocatorFilter::fetchResults
virtual void fetchResults(const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback)=0
Retrieves the filter results for a specified search string.
QgsLocatorFilter::triggerResult
virtual void triggerResult(const QgsLocatorResult &result)=0
Triggers a filter result from this filter.
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgslocatorfilter.h