QGIS API Documentation  3.0.2-Girona (307d082)
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 
49  enum Role
50  {
51  ResultDataRole = Qt::UserRole + 1,
56  };
57 
61  QgsLocatorModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
62 
67  void clear();
68 
75  void deferredClear();
76 
77  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
78  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
79  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
80  Qt::ItemFlags flags( const QModelIndex &index ) const override;
81 
82  public slots:
83 
87  void addResult( const QgsLocatorResult &result );
88 
89  private:
90 
91  enum ColumnCount
92  {
93  Name = 0,
94  Description
95  };
96 
97  struct Entry
98  {
99  QgsLocatorResult result;
100  QString filterTitle;
101  QgsLocatorFilter *filter = nullptr;
102  };
103 
104  QList<Entry> mResults;
105  QSet<QString> mFoundResultsFromFilterNames;
106  bool mDeferredClear = false;
107  QTimer mDeferredClearTimer;
108 };
109 
128 class CORE_EXPORT QgsLocatorAutomaticModel : public QgsLocatorModel
129 {
130  Q_OBJECT
131 
132  public:
133 
140 
144  QgsLocator *locator();
145 
155  void search( const QString &string );
156 
162  virtual QgsLocatorContext createContext();
163 
164  private slots:
165 
166  void searchFinished();
167 
168  private:
169 
170  QgsLocator *mLocator = nullptr;
171 
172  QString mNextRequestedString;
173  bool mHasQueuedRequest = false;
174 };
175 
183 class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
184 {
185  Q_OBJECT
186 
187  public:
188 
192  explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
193  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
194 };
195 
196 #endif // QGSLOCATORMODEL_H
197 
198 
#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 ...
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:54
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.