QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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,
59  };
60 
64  QgsLocatorModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
65 
70  void clear();
71 
78  void deferredClear();
79 
80  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
81  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
82  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
83  Qt::ItemFlags flags( const QModelIndex &index ) const override;
84 
85  public slots:
86 
90  void addResult( const QgsLocatorResult &result );
91 
92  private:
93 
94  enum ColumnCount
95  {
96  Name = 0,
97  Description
98  };
99 
100  struct Entry
101  {
102  QgsLocatorResult result;
103  QString filterTitle;
104  QgsLocatorFilter *filter = nullptr;
105  QString groupTitle = QString();
106  int groupSorting = 0;
107  };
108 
109  QList<Entry> mResults;
110  QSet<QString> mFoundResultsFromFilterNames;
111  QMap<QgsLocatorFilter *, QStringList> mFoundResultsFilterGroups;
112  bool mDeferredClear = false;
113  QTimer mDeferredClearTimer;
114 };
115 
134 class CORE_EXPORT QgsLocatorAutomaticModel : public QgsLocatorModel
135 {
136  Q_OBJECT
137 
138  public:
139 
146 
150  QgsLocator *locator();
151 
161  void search( const QString &string );
162 
168  virtual QgsLocatorContext createContext();
169 
170  private slots:
171 
172  void searchFinished();
173 
174  private:
175 
176  QgsLocator *mLocator = nullptr;
177 
178  QString mNextRequestedString;
179  bool mHasQueuedRequest = false;
180 };
181 
189 class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
190 {
191  Q_OBJECT
192 
193  public:
194 
198  explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
199  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
200 };
201 
202 #endif // QGSLOCATORMODEL_H
203 
204 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
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.