QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgslocatormodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslocatormodel.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 QGSLOCATORMODEL_H
19 #define QGSLOCATORMODEL_H
20 
21 #include "qgis_core.h"
22 #include "qgslocatorfilter.h"
23 #include <QAbstractListModel>
24 #include <QTimer>
25 #include <QSet>
26 #include <QSortFilterProxyModel>
27 
28 class QgsLocator;
29 class QgsLocatorModel;
31 
42 class CORE_EXPORT QgsLocatorModel : public QAbstractTableModel
43 {
44  Q_OBJECT
45 
46  public:
47 
48  static const int NoGroup = 9999;
49 
51  enum Role
52  {
53  ResultDataRole = Qt::UserRole + 1,
60  };
61 
65  QgsLocatorModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
66 
71  void clear();
72 
79  void deferredClear();
80 
81  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
82  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
83  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
84  Qt::ItemFlags flags( const QModelIndex &index ) const override;
85  QHash<int, QByteArray> roleNames() const override;
86 
87  public slots:
88 
92  void addResult( const QgsLocatorResult &result );
93 
94  private:
95 
96  enum ColumnCount
97  {
98  Name = 0,
99  Description
100  };
101 
102  struct Entry
103  {
104  QgsLocatorResult result;
105  QString filterTitle;
106  QgsLocatorFilter *filter = nullptr;
107  QString groupTitle = QString();
108  int groupSorting = 0;
109  };
110 
111  QList<Entry> mResults;
112  QSet<QString> mFoundResultsFromFilterNames;
113  QMap<QgsLocatorFilter *, QStringList> mFoundResultsFilterGroups;
114  bool mDeferredClear = false;
115  QTimer mDeferredClearTimer;
116 };
117 
136 class CORE_EXPORT QgsLocatorAutomaticModel : public QgsLocatorModel
137 {
138  Q_OBJECT
139 
140  public:
141 
148 
152  QgsLocator *locator();
153 
163  void search( const QString &string );
164 
170  virtual QgsLocatorContext createContext();
171 
172  private slots:
173 
174  void searchFinished();
175 
176  private:
177 
178  QgsLocator *mLocator = nullptr;
179 
180  QString mNextRequestedString;
181  bool mHasQueuedRequest = false;
182 };
183 
191 class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
192 {
193  Q_OBJECT
194 
195  public:
196 
200  explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
201  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
202 };
203 
204 #endif // QGSLOCATORMODEL_H
205 
206 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
The actions to be shown for the given result in a context menu.
A QgsLocatorModel which has is associated directly with a QgsLocator, and is automatically populated ...
Group results within the same filter results.
Encapsulates the properties relating to the context of a locator search.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Abstract base class for filters which collect locator results.
Handles the management of QgsLocatorFilter objects and async collection of search results from them...
Definition: qgslocator.h:57
An abstract list model for displaying the results of locator searches.
Result priority, used by QgsLocatorProxyModel for sorting roles.
Result match score, used by QgsLocatorProxyModel for sorting roles.
Role
Custom model roles.
Associated filter name which created the result.